| @@ -0,0 +1,275 @@ | ||
| #include "DeathScreen.h" | ||
| #include "GL\glew.h" | ||
| #include "shader.hpp" | ||
| #include "Utility.h" | ||
| #include "MeshBuilder.h" | ||
| #include "LoadTGA.h" | ||
| #include "LoadOBJ.h" | ||
| #include "LoadHmap.h" | ||
| #include "GenerateRange.h" | ||
| #include "Collision.h" | ||
| #include "Application.h" | ||
| #include "SceneManager.h" | ||
|
|
||
| DeathScreen::DeathScreen() { | ||
| } | ||
|
|
||
| DeathScreen::~DeathScreen() { | ||
| } | ||
|
|
||
| void DeathScreen::Exit() { | ||
|
|
||
| for (unsigned int i = 0; i < NUM_GEOMETRY; ++i) { | ||
| if (meshList[i]) { | ||
| delete meshList[i]; | ||
| } | ||
| } | ||
|
|
||
| for (unsigned int i = 0; i < NUM_SPRITE; ++i) { | ||
| if (spriteAnimationList[i]) { | ||
| delete spriteAnimationList[i]; | ||
| } | ||
| } | ||
|
|
||
| Scene3D::Exit(); | ||
| } | ||
|
|
||
| void DeathScreen::Init() { | ||
|
|
||
| InitGL(); | ||
|
|
||
| //Create & User Our Shader | ||
| InitShaders("Shader//Default.vertexshader", "Shader//Default.fragmentshader", DEFAULT); | ||
| UseShader(DEFAULT); | ||
|
|
||
| Scene3D::Init(); | ||
| InitMeshes(); | ||
| InitSpriteAnimations(); | ||
|
|
||
| InitLights(); | ||
| InitFog(Color(0.5f, 0.5f, 0.5f), 2, 20.0f, 800.0f, 0.005f); | ||
| EnableFog(false); | ||
|
|
||
|
|
||
| tileMap.LoadFile("TileMap//DeathScreen.csv"); | ||
| tileMap.SetTileSize(1.0f); | ||
| InitPlayer(); | ||
| InitCamera(); | ||
|
|
||
| drop = 0.0f; | ||
| Level = 1; | ||
| } | ||
|
|
||
| void DeathScreen::InitMeshes() { | ||
|
|
||
| for (unsigned int i = 0; i < NUM_GEOMETRY; ++i) { | ||
| meshList[i] = nullptr; | ||
| } | ||
| //meshList[GEO_PLAYER] = MeshBuilder::Generate2DTile("Player", Color(1, 1, 1), 1); | ||
|
|
||
| //meshList[GEO_TILE_BRICK] = MeshBuilder::Generate2DTile("Tile Brick", Color(1, 1, 1), 1); | ||
|
|
||
| meshList[GEO_DIRT] = MeshBuilder::GenerateQuad("Tile Brick", Color(1, 1, 1), 1); | ||
| meshList[GEO_DIRT]->textureArray[0] = LoadTGA("Image//SP3_Texture//Tiles//ground.tga"); | ||
|
|
||
| meshList[GEO_GRASS] = MeshBuilder::GenerateQuad("Tile Brick", Color(1, 1, 1), 1); | ||
| meshList[GEO_GRASS]->textureArray[0] = LoadTGA("Image//SP3_Texture//Tiles//ground_grass.tga"); | ||
|
|
||
| meshList[GEO_BACKGROUND_1] = MeshBuilder::GenerateQuad("Background1", Color(1, 1, 1), 1); | ||
| meshList[GEO_BACKGROUND_1]->textureArray[0] = LoadTGA("Image//SP3_Texture//Background//death.tga"); | ||
|
|
||
| meshList[GEO_BACKGROUND_2] = MeshBuilder::GenerateQuad("Background2", Color(1, 1, 1), 0.7); | ||
| meshList[GEO_BACKGROUND_2]->textureArray[0] = LoadTGA("Image//SP3_Texture//Background//mountains.tga"); | ||
|
|
||
| meshList[GEO_BACKGROUND_3] = MeshBuilder::GenerateQuad("Background3", Color(1, 1, 1), 0.4); | ||
| meshList[GEO_BACKGROUND_3]->textureArray[0] = LoadTGA("Image//SP3_Texture//Background//clouds.tga"); | ||
|
|
||
| } | ||
|
|
||
| void DeathScreen::InitSpriteAnimations() { | ||
|
|
||
| for (unsigned int i = 0; i < NUM_SPRITE; ++i) { | ||
| spriteAnimationList[i] = nullptr; | ||
| } | ||
|
|
||
| spriteAnimationList[SPRITE_PLAYER] = MeshBuilder::GenerateSpriteAnimation("Player", 1, 4); | ||
| spriteAnimationList[SPRITE_PLAYER]->textureArray[0] = LoadTGA("Image//SP3_Texture//Sprite_Animation//player.tga"); | ||
| spriteAnimationList[SPRITE_PLAYER]->animation = new Animation(); | ||
| spriteAnimationList[SPRITE_PLAYER]->animation->Set(0, 3, 0, 1.f, true); | ||
|
|
||
| spriteAnimationList[SPRITE_PLAYER_IDLE] = MeshBuilder::GenerateSpriteAnimation("Player", 1, 2); | ||
| spriteAnimationList[SPRITE_PLAYER_IDLE]->textureArray[0] = LoadTGA("Image//SP3_Texture//Sprite_Animation//player_idle.tga"); | ||
| spriteAnimationList[SPRITE_PLAYER_IDLE]->animation = new Animation(); | ||
| spriteAnimationList[SPRITE_PLAYER_IDLE]->animation->Set(0, 1, 0, 1.f, true); | ||
|
|
||
| spriteAnimationList[SPRITE_PLAYER_JUMP] = MeshBuilder::GenerateSpriteAnimation("Player", 1, 1); | ||
| spriteAnimationList[SPRITE_PLAYER_JUMP]->textureArray[0] = LoadTGA("Image//SP3_Texture//Sprite_Animation//player_jump.tga"); | ||
| spriteAnimationList[SPRITE_PLAYER_JUMP]->animation = new Animation(); | ||
| spriteAnimationList[SPRITE_PLAYER_JUMP]->animation->Set(0, 0, 0, 1.f, true); | ||
|
|
||
| spriteAnimationList[SPRITE_PORTAL] = MeshBuilder::GenerateSpriteAnimation("portal", 1, 4); | ||
| spriteAnimationList[SPRITE_PORTAL]->textureArray[0] = LoadTGA("Image//SP3_Texture//Sprite_Animation//portal.tga"); | ||
| spriteAnimationList[SPRITE_PORTAL]->animation = new Animation(); | ||
| spriteAnimationList[SPRITE_PORTAL]->animation->Set(0, 3, 0, 1.f, true); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
| void DeathScreen::InitPlayer() { | ||
|
|
||
| player.SetTileMap(tileMap); | ||
|
|
||
| for (int row = 0; row < tileMap.GetNumRows(); ++row) { | ||
| for (int col = 0; col < tileMap.GetNumColumns(); ++col) { | ||
| if (tileMap.map[row][col] == 99) { | ||
| housePos.Set(col * tileMap.GetTileSize(), row * tileMap.GetTileSize(), -20); | ||
| player.transform.SetPosition(tileMap.GetTileSize() * col, tileMap.GetTileSize() * row, 0); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| void DeathScreen::InitCamera() { | ||
|
|
||
| camera.SetPlayer(player); | ||
| camera.SetTileMap(tileMap); | ||
|
|
||
| } | ||
|
|
||
| void DeathScreen::Update(const double& deltaTime) { | ||
|
|
||
|
|
||
| for (unsigned int i = 0; i < NUM_SPRITE; ++i) | ||
| { | ||
|
|
||
| spriteAnimationList[i]->Update(deltaTime); | ||
| spriteAnimationList[i]->animation->animActive = true; | ||
| } | ||
|
|
||
| player.Update(deltaTime); | ||
| camera.Update(deltaTime); | ||
|
|
||
| } | ||
|
|
||
| void DeathScreen::Render() { | ||
| SetToCameraView(&camera); | ||
| //Scene3D::Render(); | ||
| RenderDeath(); | ||
|
|
||
| RenderTileMap(); | ||
| RenderBackground(); | ||
| RenderPlayer(); | ||
| RenderText(); | ||
|
|
||
| } | ||
|
|
||
| void DeathScreen::RenderTileMap() { | ||
|
|
||
| float cameraAspectRatio = static_cast<float>(camera.aspectRatio.x) / static_cast<float>(camera.aspectRatio.y); | ||
| float cameraWidth = cameraAspectRatio * camera.GetOrthoSize(); | ||
|
|
||
| int startCol = tileMap.GetTileX(camera.transform.position.x - cameraWidth); | ||
| int endCol = tileMap.GetTileX(camera.transform.position.x + cameraWidth) + 1; | ||
|
|
||
| int startRow = tileMap.GetTileX(camera.transform.position.y - camera.GetOrthoSize()); | ||
| int endRow = tileMap.GetTileX(camera.transform.position.y + camera.GetOrthoSize()) + 1; | ||
|
|
||
| for (int row = Math::Max(0, startRow); row < Math::Min(endRow, tileMap.GetNumRows()); ++row) { | ||
| for (int col = Math::Max(0, startCol); col < Math::Min(endCol, tileMap.GetNumColumns()); ++col) { | ||
| modelStack.PushMatrix(); | ||
| modelStack.Translate(col * tileMap.GetTileSize(), row * tileMap.GetTileSize(), -1); | ||
| modelStack.Scale(tileMap.GetTileSize(), tileMap.GetTileSize(), tileMap.GetTileSize()); | ||
| switch (tileMap.map[row][col]) { | ||
| case 1: | ||
| //RenderMesh(meshList[GEO_DIRT]); | ||
| break; | ||
| case 2: | ||
| //RenderMesh(meshList[GEO_GRASS]); | ||
| break; | ||
| case 3: | ||
| glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
| RenderSpriteAnimation(spriteAnimationList[SPRITE_PORTAL]); | ||
| glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
| break; | ||
| case 9: | ||
| glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
| RenderSpriteAnimation(spriteAnimationList[SPRITE_PORTAL]); | ||
| glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
| break; | ||
|
|
||
| } | ||
| modelStack.PopMatrix(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| void DeathScreen::RenderPlayer() { | ||
|
|
||
| modelStack.PushMatrix(); | ||
| modelStack.Translate(player.transform.position.x, player.transform.position.y - 0.1f, player.transform.position.z); | ||
| //modelStack.Rotate(player.transform.rotation.z, 0, 0, 1); | ||
| if (player.getInvert()) | ||
| modelStack.Scale(-player.transform.scale.x, player.transform.scale.y, player.transform.scale.z); | ||
| else | ||
| modelStack.Scale(player.transform.scale.x, player.transform.scale.y, player.transform.scale.z); | ||
| if (player.playerState == Player::WALKING) | ||
| RenderSpriteAnimation(spriteAnimationList[SPRITE_PLAYER], false, player.getInvert()); | ||
| else if (player.playerState == Player::IDLE) | ||
| RenderSpriteAnimation(spriteAnimationList[SPRITE_PLAYER_IDLE], false, player.getInvert()); | ||
| else if (player.playerState == Player::JUMPING) | ||
| RenderSpriteAnimation(spriteAnimationList[SPRITE_PLAYER_JUMP], false, player.getInvert()); | ||
| modelStack.PopMatrix(); | ||
|
|
||
| } | ||
|
|
||
| void DeathScreen::RenderText() { | ||
| RenderTextOnScreen(fontList[FONT_CONSOLAS], "DEAD", Color(1, 0, 0), 4, -8, 5); | ||
|
|
||
| if (player.transform.position.x < housePos.x + 5) | ||
| RenderTextOnScreen(fontList[FONT_CONSOLAS], "Enter the portal on the left to respawn", Color(1, 0, 0), 0.8, -16, 0); | ||
| else | ||
| RenderTextOnScreen(fontList[FONT_CONSOLAS], "Are you sure you want to abandon your family?", Color(1, 0, 0), 0.65, -16, 0); | ||
|
|
||
| } | ||
| void DeathScreen::RenderBackground() | ||
| { | ||
|
|
||
| float xRatio = (static_cast<float>(camera.aspectRatio.x / static_cast<float>(camera.aspectRatio.y))); | ||
| float camWidth = xRatio * camera.GetOrthoSize(); | ||
| float backgroundScaleX = camWidth * 2.0f; | ||
| float backgroundScaleY = camera.GetOrthoSize() * 2.0f; | ||
|
|
||
| glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
| modelStack.PushMatrix(); | ||
| modelStack.Translate(housePos.x, housePos.y + 2, housePos.z); | ||
| modelStack.Scale(50, 50, 1); | ||
| RenderMesh(meshList[GEO_BACKGROUND_1], false); | ||
| modelStack.PopMatrix(); | ||
| glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
|
|
||
| /*for (int i = 0; i < 5; ++i) | ||
| { | ||
| modelStack.PushMatrix(); | ||
| modelStack.Translate((0.7 * camera.transform.position.x) + (i * backgroundScaleX), camera.transform.position.y, -49); | ||
| modelStack.Scale(backgroundScaleX, backgroundScaleY, 1); | ||
| RenderMesh(meshList[GEO_BACKGROUND_2], false); | ||
| modelStack.PopMatrix(); | ||
| } | ||
| for (int i = 0; i < 5; ++i) | ||
| { | ||
| modelStack.PushMatrix(); | ||
| modelStack.Translate((0.5 * camera.transform.position.x) + (i * backgroundScaleX), 8.7, -48); | ||
| modelStack.Scale(backgroundScaleX, backgroundScaleY, 1); | ||
| RenderMesh(meshList[GEO_BACKGROUND_3], false); | ||
| modelStack.PopMatrix(); | ||
| }*/ | ||
| } | ||
|
|
||
|
|
| @@ -0,0 +1,75 @@ | ||
| #ifndef DEATH_SCREEN_H | ||
| #define DEATH_SCREEN_H | ||
|
|
||
| #include "Scene3D.h" | ||
| #include "Mesh.h" | ||
| #include "SpriteAnimation.h" | ||
| #include "TileMap.h" | ||
| #include "Camera2D.h" | ||
| #include "PlayerSS.h" | ||
|
|
||
| class DeathScreen : public Scene3D { | ||
|
|
||
| private: | ||
| enum GEOMETRY_TYPE { | ||
| //Tiles | ||
| GEO_EMPTY, | ||
| GEO_DIRT, | ||
| GEO_GRASS, | ||
| GEO_BACKGROUND_1, | ||
| GEO_BACKGROUND_2, | ||
| GEO_BACKGROUND_3, | ||
|
|
||
| //Others | ||
| GEO_PLAYER, | ||
|
|
||
| NUM_GEOMETRY, | ||
| }; | ||
|
|
||
| enum SPRITE_TYPE { | ||
| SPRITE_PLAYER, | ||
| SPRITE_PLAYER_IDLE, | ||
| SPRITE_PLAYER_JUMP, | ||
| SPRITE_PORTAL, | ||
| NUM_SPRITE, | ||
| }; | ||
|
|
||
| Mesh* meshList[NUM_GEOMETRY]; | ||
| SpriteAnimation* spriteAnimationList[NUM_SPRITE]; | ||
|
|
||
| TileMap tileMap; | ||
|
|
||
| void InitMeshes(); | ||
| void InitSpriteAnimations(); | ||
| void InitCamera(); | ||
| virtual void InitPlayer(); | ||
|
|
||
| void RenderTileMap(); | ||
| void RenderPlayer(); | ||
| void RenderBackground(); | ||
| void RenderText(); | ||
|
|
||
| Camera2D camera; | ||
| PlayerSS player; | ||
|
|
||
| float drop; | ||
| int Level; | ||
|
|
||
| Vector3 housePos; | ||
|
|
||
| public: | ||
| //Constructor(s) & Destructor | ||
| DeathScreen(); | ||
| virtual ~DeathScreen(); | ||
|
|
||
| //Virtual Function(s) | ||
| virtual void Init(); | ||
| virtual void Update(const double& deltaTime); | ||
| virtual void UpdateSub(const double& deltaTime){}; | ||
| virtual void Render(); | ||
| virtual void RenderSub(){}; | ||
| virtual void Exit(); | ||
|
|
||
| }; | ||
|
|
||
| #endif |
| @@ -20,7 +20,7 @@ enum INPUT_TYPE { | ||
| INPUT_WELL, | ||
| INPUT_WELL2, | ||
| INPUT_JUMP, | ||
| INPUT_PAUSE, | ||
| INPUT_QUIT, | ||
|
|
||
| NUM_KEYS, | ||
| @@ -0,0 +1,275 @@ | ||
| #include "LoseScreen.h" | ||
| #include "GL\glew.h" | ||
| #include "shader.hpp" | ||
| #include "Utility.h" | ||
| #include "MeshBuilder.h" | ||
| #include "LoadTGA.h" | ||
| #include "LoadOBJ.h" | ||
| #include "LoadHmap.h" | ||
| #include "GenerateRange.h" | ||
| #include "Collision.h" | ||
| #include "Application.h" | ||
| #include "SceneManager.h" | ||
|
|
||
| LoseScreen::LoseScreen() { | ||
| } | ||
|
|
||
| LoseScreen::~LoseScreen() { | ||
| } | ||
|
|
||
| void LoseScreen::Exit() { | ||
|
|
||
| for (unsigned int i = 0; i < NUM_GEOMETRY; ++i) { | ||
| if (meshList[i]) { | ||
| delete meshList[i]; | ||
| } | ||
| } | ||
|
|
||
| for (unsigned int i = 0; i < NUM_SPRITE; ++i) { | ||
| if (spriteAnimationList[i]) { | ||
| delete spriteAnimationList[i]; | ||
| } | ||
| } | ||
|
|
||
| Scene3D::Exit(); | ||
| } | ||
|
|
||
| void LoseScreen::Init() { | ||
|
|
||
| InitGL(); | ||
|
|
||
| //Create & User Our Shader | ||
| InitShaders("Shader//Default.vertexshader", "Shader//Default.fragmentshader", DEFAULT); | ||
| UseShader(DEFAULT); | ||
|
|
||
| Scene3D::Init(); | ||
| InitMeshes(); | ||
| InitSpriteAnimations(); | ||
|
|
||
| InitLights(); | ||
| InitFog(Color(0.5f, 0.5f, 0.5f), 2, 20.0f, 800.0f, 0.005f); | ||
| EnableFog(false); | ||
|
|
||
|
|
||
| tileMap.LoadFile("TileMap//LoseScreen.csv"); | ||
| tileMap.SetTileSize(1.0f); | ||
| InitPlayer(); | ||
| InitCamera(); | ||
|
|
||
| drop = 0.0f; | ||
| Level = 1; | ||
| } | ||
|
|
||
| void LoseScreen::InitMeshes() { | ||
|
|
||
| for (unsigned int i = 0; i < NUM_GEOMETRY; ++i) { | ||
| meshList[i] = nullptr; | ||
| } | ||
| //meshList[GEO_PLAYER] = MeshBuilder::Generate2DTile("Player", Color(1, 1, 1), 1); | ||
|
|
||
| //meshList[GEO_TILE_BRICK] = MeshBuilder::Generate2DTile("Tile Brick", Color(1, 1, 1), 1); | ||
|
|
||
| meshList[GEO_DIRT] = MeshBuilder::GenerateQuad("Tile Brick", Color(1, 1, 1), 1); | ||
| meshList[GEO_DIRT]->textureArray[0] = LoadTGA("Image//SP3_Texture//Tiles//ground.tga"); | ||
|
|
||
| meshList[GEO_GRASS] = MeshBuilder::GenerateQuad("Tile Brick", Color(1, 1, 1), 1); | ||
| meshList[GEO_GRASS]->textureArray[0] = LoadTGA("Image//SP3_Texture//Tiles//ground_grass.tga"); | ||
|
|
||
| meshList[GEO_BACKGROUND_1] = MeshBuilder::GenerateQuad("Background1", Color(1, 1, 1), 1); | ||
| meshList[GEO_BACKGROUND_1]->textureArray[0] = LoadTGA("Image//SP3_Texture//Background//lose.tga"); | ||
|
|
||
| meshList[GEO_BACKGROUND_2] = MeshBuilder::GenerateQuad("Background2", Color(1, 1, 1), 0.7); | ||
| meshList[GEO_BACKGROUND_2]->textureArray[0] = LoadTGA("Image//SP3_Texture//Background//mountains.tga"); | ||
|
|
||
| meshList[GEO_BACKGROUND_3] = MeshBuilder::GenerateQuad("Background3", Color(1, 1, 1), 0.4); | ||
| meshList[GEO_BACKGROUND_3]->textureArray[0] = LoadTGA("Image//SP3_Texture//Background//clouds.tga"); | ||
|
|
||
| } | ||
|
|
||
| void LoseScreen::InitSpriteAnimations() { | ||
|
|
||
| for (unsigned int i = 0; i < NUM_SPRITE; ++i) { | ||
| spriteAnimationList[i] = nullptr; | ||
| } | ||
|
|
||
| spriteAnimationList[SPRITE_PLAYER] = MeshBuilder::GenerateSpriteAnimation("Player", 1, 4); | ||
| spriteAnimationList[SPRITE_PLAYER]->textureArray[0] = LoadTGA("Image//SP3_Texture//Sprite_Animation//player.tga"); | ||
| spriteAnimationList[SPRITE_PLAYER]->animation = new Animation(); | ||
| spriteAnimationList[SPRITE_PLAYER]->animation->Set(0, 3, 0, 1.f, true); | ||
|
|
||
| spriteAnimationList[SPRITE_PLAYER_IDLE] = MeshBuilder::GenerateSpriteAnimation("Player", 1, 2); | ||
| spriteAnimationList[SPRITE_PLAYER_IDLE]->textureArray[0] = LoadTGA("Image//SP3_Texture//Sprite_Animation//player_idle.tga"); | ||
| spriteAnimationList[SPRITE_PLAYER_IDLE]->animation = new Animation(); | ||
| spriteAnimationList[SPRITE_PLAYER_IDLE]->animation->Set(0, 1, 0, 1.f, true); | ||
|
|
||
| spriteAnimationList[SPRITE_PLAYER_JUMP] = MeshBuilder::GenerateSpriteAnimation("Player", 1, 1); | ||
| spriteAnimationList[SPRITE_PLAYER_JUMP]->textureArray[0] = LoadTGA("Image//SP3_Texture//Sprite_Animation//player_jump.tga"); | ||
| spriteAnimationList[SPRITE_PLAYER_JUMP]->animation = new Animation(); | ||
| spriteAnimationList[SPRITE_PLAYER_JUMP]->animation->Set(0, 0, 0, 1.f, true); | ||
|
|
||
| spriteAnimationList[SPRITE_PORTAL] = MeshBuilder::GenerateSpriteAnimation("portal", 1, 4); | ||
| spriteAnimationList[SPRITE_PORTAL]->textureArray[0] = LoadTGA("Image//SP3_Texture//Sprite_Animation//portal.tga"); | ||
| spriteAnimationList[SPRITE_PORTAL]->animation = new Animation(); | ||
| spriteAnimationList[SPRITE_PORTAL]->animation->Set(0, 3, 0, 1.f, true); | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
| void LoseScreen::InitPlayer() { | ||
|
|
||
| player.SetTileMap(tileMap); | ||
|
|
||
| for (int row = 0; row < tileMap.GetNumRows(); ++row) { | ||
| for (int col = 0; col < tileMap.GetNumColumns(); ++col) { | ||
| if (tileMap.map[row][col] == 99) { | ||
| housePos.Set(col * tileMap.GetTileSize(), row * tileMap.GetTileSize(), -20); | ||
| player.transform.SetPosition(tileMap.GetTileSize() * col, tileMap.GetTileSize() * row, 0); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| void LoseScreen::InitCamera() { | ||
|
|
||
| camera.SetPlayer(player); | ||
| camera.SetTileMap(tileMap); | ||
|
|
||
| } | ||
|
|
||
| void LoseScreen::Update(const double& deltaTime) { | ||
|
|
||
|
|
||
| for (unsigned int i = 0; i < NUM_SPRITE; ++i) | ||
| { | ||
|
|
||
| spriteAnimationList[i]->Update(deltaTime); | ||
| spriteAnimationList[i]->animation->animActive = true; | ||
| } | ||
|
|
||
| player.Update(deltaTime); | ||
| camera.Update(deltaTime); | ||
|
|
||
| } | ||
|
|
||
| void LoseScreen::Render() { | ||
| SetToCameraView(&camera); | ||
| //Scene3D::Render(); | ||
| RenderDeath(); | ||
|
|
||
| RenderTileMap(); | ||
| RenderBackground(); | ||
| RenderPlayer(); | ||
| RenderText(); | ||
|
|
||
| } | ||
|
|
||
| void LoseScreen::RenderTileMap() { | ||
|
|
||
| float cameraAspectRatio = static_cast<float>(camera.aspectRatio.x) / static_cast<float>(camera.aspectRatio.y); | ||
| float cameraWidth = cameraAspectRatio * camera.GetOrthoSize(); | ||
|
|
||
| int startCol = tileMap.GetTileX(camera.transform.position.x - cameraWidth); | ||
| int endCol = tileMap.GetTileX(camera.transform.position.x + cameraWidth) + 1; | ||
|
|
||
| int startRow = tileMap.GetTileX(camera.transform.position.y - camera.GetOrthoSize()); | ||
| int endRow = tileMap.GetTileX(camera.transform.position.y + camera.GetOrthoSize()) + 1; | ||
|
|
||
| for (int row = Math::Max(0, startRow); row < Math::Min(endRow, tileMap.GetNumRows()); ++row) { | ||
| for (int col = Math::Max(0, startCol); col < Math::Min(endCol, tileMap.GetNumColumns()); ++col) { | ||
| modelStack.PushMatrix(); | ||
| modelStack.Translate(col * tileMap.GetTileSize(), row * tileMap.GetTileSize(), -1); | ||
| modelStack.Scale(tileMap.GetTileSize(), tileMap.GetTileSize(), tileMap.GetTileSize()); | ||
| switch (tileMap.map[row][col]) { | ||
| case 1: | ||
| //RenderMesh(meshList[GEO_DIRT]); | ||
| break; | ||
| case 2: | ||
| //RenderMesh(meshList[GEO_GRASS]); | ||
| break; | ||
| case 3: | ||
| glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
| RenderSpriteAnimation(spriteAnimationList[SPRITE_PORTAL]); | ||
| glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
| break; | ||
| case 9: | ||
| glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
| RenderSpriteAnimation(spriteAnimationList[SPRITE_PORTAL]); | ||
| glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
| break; | ||
|
|
||
| } | ||
| modelStack.PopMatrix(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| void LoseScreen::RenderPlayer() { | ||
|
|
||
| modelStack.PushMatrix(); | ||
| modelStack.Translate(player.transform.position.x, player.transform.position.y - 0.1f, player.transform.position.z); | ||
| //modelStack.Rotate(player.transform.rotation.z, 0, 0, 1); | ||
| if (player.getInvert()) | ||
| modelStack.Scale(-player.transform.scale.x, player.transform.scale.y, player.transform.scale.z); | ||
| else | ||
| modelStack.Scale(player.transform.scale.x, player.transform.scale.y, player.transform.scale.z); | ||
| if (player.playerState == Player::WALKING) | ||
| RenderSpriteAnimation(spriteAnimationList[SPRITE_PLAYER], false, player.getInvert()); | ||
| else if (player.playerState == Player::IDLE) | ||
| RenderSpriteAnimation(spriteAnimationList[SPRITE_PLAYER_IDLE], false, player.getInvert()); | ||
| else if (player.playerState == Player::JUMPING) | ||
| RenderSpriteAnimation(spriteAnimationList[SPRITE_PLAYER_JUMP], false, player.getInvert()); | ||
| modelStack.PopMatrix(); | ||
|
|
||
| } | ||
|
|
||
| void LoseScreen::RenderText() { | ||
|
|
||
| RenderTextOnScreen(fontList[FONT_CONSOLAS], "LOSE", Color(1, 0, 0), 4, -8, 5); | ||
|
|
||
| if (player.transform.position.x < housePos.x + 5) | ||
| RenderTextOnScreen(fontList[FONT_CONSOLAS], "Enter the portal on the left to restart", Color(1, 0, 0), 0.8, -16, 0); | ||
| else | ||
| RenderTextOnScreen(fontList[FONT_CONSOLAS], "Are you sure you don't want to retry?", Color(1, 0, 0), 0.8, -16, 0); | ||
| } | ||
| void LoseScreen::RenderBackground() | ||
| { | ||
|
|
||
| float xRatio = (static_cast<float>(camera.aspectRatio.x / static_cast<float>(camera.aspectRatio.y))); | ||
| float camWidth = xRatio * camera.GetOrthoSize(); | ||
| float backgroundScaleX = camWidth * 2.0f; | ||
| float backgroundScaleY = camera.GetOrthoSize() * 2.0f; | ||
|
|
||
| glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
| modelStack.PushMatrix(); | ||
| modelStack.Translate(housePos.x, housePos.y + 2, housePos.z); | ||
| modelStack.Scale(50, 50, 1); | ||
| RenderMesh(meshList[GEO_BACKGROUND_1], false); | ||
| modelStack.PopMatrix(); | ||
| glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); | ||
|
|
||
| /*for (int i = 0; i < 5; ++i) | ||
| { | ||
| modelStack.PushMatrix(); | ||
| modelStack.Translate((0.7 * camera.transform.position.x) + (i * backgroundScaleX), camera.transform.position.y, -49); | ||
| modelStack.Scale(backgroundScaleX, backgroundScaleY, 1); | ||
| RenderMesh(meshList[GEO_BACKGROUND_2], false); | ||
| modelStack.PopMatrix(); | ||
| } | ||
| for (int i = 0; i < 5; ++i) | ||
| { | ||
| modelStack.PushMatrix(); | ||
| modelStack.Translate((0.5 * camera.transform.position.x) + (i * backgroundScaleX), 8.7, -48); | ||
| modelStack.Scale(backgroundScaleX, backgroundScaleY, 1); | ||
| RenderMesh(meshList[GEO_BACKGROUND_3], false); | ||
| modelStack.PopMatrix(); | ||
| }*/ | ||
| } | ||
|
|
||
|
|
| @@ -0,0 +1,75 @@ | ||
| #ifndef LOSE_SCREEN_H | ||
| #define LOSE_SCREEN_H | ||
|
|
||
| #include "Scene3D.h" | ||
| #include "Mesh.h" | ||
| #include "SpriteAnimation.h" | ||
| #include "TileMap.h" | ||
| #include "Camera2D.h" | ||
| #include "PlayerSS.h" | ||
|
|
||
| class LoseScreen : public Scene3D { | ||
|
|
||
| private: | ||
| enum GEOMETRY_TYPE { | ||
| //Tiles | ||
| GEO_EMPTY, | ||
| GEO_DIRT, | ||
| GEO_GRASS, | ||
| GEO_BACKGROUND_1, | ||
| GEO_BACKGROUND_2, | ||
| GEO_BACKGROUND_3, | ||
|
|
||
| //Others | ||
| GEO_PLAYER, | ||
|
|
||
| NUM_GEOMETRY, | ||
| }; | ||
|
|
||
| enum SPRITE_TYPE { | ||
| SPRITE_PLAYER, | ||
| SPRITE_PLAYER_IDLE, | ||
| SPRITE_PLAYER_JUMP, | ||
| SPRITE_PORTAL, | ||
| NUM_SPRITE, | ||
| }; | ||
|
|
||
| Mesh* meshList[NUM_GEOMETRY]; | ||
| SpriteAnimation* spriteAnimationList[NUM_SPRITE]; | ||
|
|
||
| TileMap tileMap; | ||
|
|
||
| void InitMeshes(); | ||
| void InitSpriteAnimations(); | ||
| void InitCamera(); | ||
| virtual void InitPlayer(); | ||
|
|
||
| void RenderTileMap(); | ||
| void RenderPlayer(); | ||
| void RenderBackground(); | ||
| void RenderText(); | ||
|
|
||
| Camera2D camera; | ||
| PlayerSS player; | ||
|
|
||
| float drop; | ||
| int Level; | ||
|
|
||
| Vector3 housePos; | ||
|
|
||
| public: | ||
| //Constructor(s) & Destructor | ||
| LoseScreen(); | ||
| virtual ~LoseScreen(); | ||
|
|
||
| //Virtual Function(s) | ||
| virtual void Init(); | ||
| virtual void Update(const double& deltaTime); | ||
| virtual void UpdateSub(const double& deltaTime){}; | ||
| virtual void Render(); | ||
| virtual void RenderSub(){}; | ||
| virtual void Exit(); | ||
|
|
||
| }; | ||
|
|
||
| #endif |
| @@ -61,7 +61,7 @@ class Scene4FishingPond : public Scene3D { | ||
|
|
||
| float drop; | ||
| float accumTime; | ||
|
|
||
| int Level; | ||
| int maxFish; | ||
| int fishCount; | ||
| @@ -27,7 +27,7 @@ enum TILE_TYPE { | ||
| TILE_DAUGHTER = 20, | ||
| TILE_MOTHER, | ||
| TILE_SON, | ||
| TILE_ELECTRIC, | ||
|
|
||
| TILE_CENTRE = 88, | ||
|
|
||
| @@ -1,88 +1,94 @@ | ||
| #include "Time.h" | ||
|
|
||
| Time::Time() | ||
| : | ||
| hour(0), | ||
| minute(0.f), | ||
| day(1), | ||
| active(false), | ||
| rotation(0) | ||
| {} | ||
|
|
||
| Time::Time(int h, double m) | ||
| : | ||
| hour(h), | ||
| minute(m), | ||
| day(1), | ||
| active(false), | ||
| rotation(0) | ||
| {} | ||
|
|
||
| Time::Time(int h, double m, int d, bool a) | ||
| : | ||
| hour(h), | ||
| minute(m), | ||
| day(d), | ||
| active(a), | ||
| rotation(0) | ||
| {} | ||
|
|
||
| Time::~Time() | ||
| {} | ||
|
|
||
| void Time::UpdateTime(const double& deltaTime) | ||
| { | ||
| if (active) | ||
| { | ||
| minute += 1.8 * deltaTime; | ||
| rotation = float(-hour * 30); | ||
| if (minute > 60) | ||
| { | ||
| hour++; | ||
| minute = 0; | ||
| } | ||
|
|
||
| if (hour >= 9) | ||
| { | ||
| hour = minute = 0; | ||
| day++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| float Time::getRotation() | ||
| { | ||
| return rotation; | ||
| } | ||
|
|
||
| int Time::getHour() | ||
| { | ||
| return hour; | ||
| } | ||
|
|
||
| double Time::getMinute() | ||
| { | ||
| return minute; | ||
| } | ||
|
|
||
| int Time::getDay() | ||
| { | ||
| return day; | ||
| } | ||
|
|
||
| bool Time::getActive() | ||
| { | ||
| return active; | ||
| } | ||
|
|
||
| Time Time::getTime() | ||
| { | ||
| return Time(hour, minute, day, active); | ||
| } | ||
|
|
||
| void Time::setTime(int h, double min) | ||
| { | ||
| hour = h; | ||
| minute = min; | ||
| } | ||
|
|
||
| std::ostream & operator<<(std::ostream& os, Time& time) | ||
| { | ||
| os.precision(3); | ||
| os << time.getHour() << "hr, " << time.getMinute() << "mins, " << time.getDay() << "days, " << time.getActive() << std::endl; | ||
| return os; | ||
| } |
| @@ -0,0 +1,30 @@ | ||
| 0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, |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