Skip to content

Commit

Permalink
more work on the rocket
Browse files Browse the repository at this point in the history
  • Loading branch information
Kade-github committed May 19, 2024
1 parent 90b85d8 commit c6858f1
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 24 deletions.
Binary file modified Assets/Textures/rocket_frim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ glad.c
"Game/Objects/Base/FallingBlock.h" "Game/Objects/Base/FallingBlock.cpp" "Game/Objects/Base/Blocks/Sand.cpp" "Game/Objects/Base/Blocks/NullBlock.h" "Game/Objects/Base/Blocks/Torch.h" "Game/Objects/Base/Blocks/Torch.cpp" "Game/Objects/Base/Blocks/Furnace.h" "Game/Objects/Base/Blocks/Furnace.cpp"

"Game/Objects/Base/Blocks/RuinedCobblestone.h"
"Game/Objects/Base/Blocks/RuinedDebris.h" "Game/Objects/Base/Blocks/ReinforcedIronBlock.h" "Game/Objects/Base/Zombie.h" "Game/Objects/Base/AI.h" "Game/Objects/Base/AI.cpp" "Game/MobManager.h" "Game/MobManager.cpp" "Game/Objects/Base/Pig.h" "Game/Objects/Base/Pig.cpp" "Game/Data/Structures/Ruins.h" "Game/Data/Structures/Ruins.cpp")
"Game/Objects/Base/Blocks/RuinedDebris.h" "Game/Objects/Base/Blocks/ReinforcedIronBlock.h" "Game/Objects/Base/Zombie.h" "Game/Objects/Base/AI.h" "Game/Objects/Base/AI.cpp" "Game/MobManager.h" "Game/MobManager.cpp" "Game/Objects/Base/Pig.h" "Game/Objects/Base/Pig.cpp" "Game/Data/Structures/Ruins.h" "Game/Data/Structures/Ruins.cpp" "Game/Objects/Base/Blocks/Rocket.h" "Game/Objects/Base/Blocks/Rocket.cpp")

link_directories(bassLibrary)

Expand Down
57 changes: 57 additions & 0 deletions src/Game/Objects/Base/Blocks/Rocket.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "Rocket.h"
#include "../../../LightingManager.h"
#include "../../../Scenes/Gameplay.h"
#include <Game.h>

Rocket::Rocket(glm::vec3 _position) : Block(_position, BlockType::ROCKET)
{
position = _position;

soundType = SoundType::S_STONE;
toughness = 0.3f;

isModel = true;
transparent = true;
isInteractable = true;
updateable = true;

currentChunk = WorldManager::instance->GetChunk(position.x, position.z);
}

void Rocket::LoadModel()
{
m = Model("Assets/Models/rocket_frim.obj");
m.LoadUVMap("rocket_frim");
m.scale = glm::vec3(0.6f, 0.8f, 0.6f);
}

void Rocket::Mo()
{
m.position += glm::vec3(0.5f, 0, 0.5f);
}

void Rocket::OnInteract()
{
Gameplay* gp = (Gameplay*)Game::instance->currentScene;

gp->hud->ShowRocketScreen();
}

bool Rocket::Update(int tick)
{
if (!Hud::endSequence)
return true;

int highest = currentChunk->GetHighestBlock(position.x, position.z);

if (position.y < highest)
{
Gameplay* gp = (Gameplay*)Game::instance->currentScene;

gp->hud->ShowHint("Route blocked, unable to launch.");
Hud::endSequence = false;
return true;
}

return true;
}
23 changes: 23 additions & 0 deletions src/Game/Objects/Base/Blocks/Rocket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef _ROCKET_H
#define _ROCKET_H

#include "../Block.h"
#include "../Chunk.h"

class Rocket : public Block
{
public:
Chunk* currentChunk;

Rocket(glm::vec3 _position);

void LoadModel() override;

void Mo() override;

void OnInteract() override;

bool Update(int tick) override;
};

#endif
34 changes: 27 additions & 7 deletions src/Game/Objects/Base/Chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Blocks/RuinedCobblestone.h"
#include "Blocks/RuinedDebris.h"
#include "Blocks/ReinforcedIronBlock.h"
#include "Blocks/Rocket.h"

void Chunk::ApplyNormal(std::vector<GameObject::VVertex>& vertices, glm::vec3 normal)
{
Expand Down Expand Up @@ -117,7 +118,7 @@ int Chunk::GetHighestBlock(float x, float z, bool water)
}
else
{
if (data > 0 && data != WATER && data != LEAVES && data != TORCH)
if (data > 0 && data != WATER && data != LEAVES && data != TORCH && data != ROCKET)
return y;
}
}
Expand Down Expand Up @@ -419,22 +420,22 @@ void Chunk::CreateFaces(Block* b)

int t = GetBlock(x, y + 1, z);
// in our chunk
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH) || b->transparent))
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH && t != ROCKET) || b->transparent))
top = false;
t = GetBlock(x, y - 1, z);
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH) || b->transparent))
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH && t != ROCKET) || b->transparent))
bottom = false;
t = GetBlockInterchunk(x + 1, y, z);
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH) || b->transparent))
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH && t != ROCKET) || b->transparent))
left = false;
t = GetBlockInterchunk(x - 1, y, z);
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH) || b->transparent))
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH && t != ROCKET) || b->transparent))
right = false;
t = GetBlockInterchunk(x, y, z - 1);
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH) || b->transparent))
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH && t != ROCKET) || b->transparent))
front = false;
t = GetBlockInterchunk(x, y, z + 1);
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH) || b->transparent))
if (t > 0 && ((t != WATER && t != GLASS && t != TORCH && t != ROCKET) || b->transparent))
back = false;

// create faces
Expand Down Expand Up @@ -887,6 +888,9 @@ Block* Chunk::CreateBlock(int x, int y, int z, int id, Data::BlockData data)
case REINFORCED_IRON_BLOCK:
block = new ReinforcedIronBlock(position + glm::vec3(x, y, z));
break;
case ROCKET:
block = new Rocket(position + glm::vec3(x, y, z));
break;
default:
block = new NullBlock(position + glm::vec3(x, y, z));
break;
Expand Down Expand Up @@ -1175,11 +1179,27 @@ void Chunk::DrawModels()
glEnable(GL_DEPTH_CLAMP);
glEnable(GL_CULL_FACE);

Shader* s = Game::instance->shader;

for (int i = 0; i < modelsPresent.size(); i++)
{
auto&& m = modelsPresent[i];

int lightLevel = LightingManager::GetInstance()->GetLightLevel(m.position);

s->Bind();

s->SetUniform1f("lightLevel", lightLevel);

s->Unbind();

m.Draw();

s->Bind();

s->SetUniform1f("lightLevel", 10.0f);

s->Unbind();
}

glDisable(GL_CULL_FACE);
Expand Down
102 changes: 86 additions & 16 deletions src/Game/Objects/Base/Hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../../Scenes/MainMenu.h"

bool Hud::GamePaused = false;
bool Hud::endSequence = false;

void Hud::InventoryShown(bool s)
{
Expand Down Expand Up @@ -114,6 +115,25 @@ void Hud::ShowDeathScreen()
resume->SetText("Respawn");
}

void Hud::ShowRocketScreen()
{
player->TogglePauseMenu();

rocketScreen = true;

Game::instance->SetLockedCursor(false);

pauseHeader->text = "Escape?";

// change text for respawn

resume->SetText("Yes");

// change text for resume

title->SetText("Not yet");
}

void Hud::ShowKnowledgementTablet(Data::InventoryItem& item)
{
if (hintShown || GamePaused)
Expand Down Expand Up @@ -366,6 +386,13 @@ void Hud::UpdateArmor()
}
}

void Hud::ShowHint(std::string text)
{
hintText->text = text;

hintTime = glfwGetTime() + 2.0f;
}

Hud::Hud(glm::vec3 _pos, Player* _p, Camera2D* _c2d) : GameObject(_pos)
{
player = _p;
Expand Down Expand Up @@ -491,6 +518,18 @@ Hud::Hud(glm::vec3 _pos, Player* _p, Camera2D* _c2d) : GameObject(_pos)

pauseHeader->order = 3;

hintText = new Text2D("", "ArialFrim", glm::vec3(0, 0, 0), glm::vec4(1, 1, 1, 1), 32);

hintText->position.x = (c2d->_w / 2) - (hintText->width / 2);

hintText->position.y = 350;

hintText->color = glm::vec4(1, 1, 1, 1);

hintText->order = 3;

c2d->AddObject(hintText);

c2d->AddObject(pauseHeader);

UpdateHotbar();
Expand Down Expand Up @@ -557,6 +596,17 @@ void Hud::Draw()
pauseHeader->position.y = resume->position.y + resume->height + 100;
}

hintText->position.x = (c2d->_w / 2) - (hintText->width / 2);

if (hintTime > glfwGetTime())
{
hintText->color.a = 1.0f;
}
else
{
hintText->color.a = std::lerp(hintText->color.a, 0.0f, 0.1f);
}

Game::instance->shader->Bind();

Game::instance->shader->SetUniform1f("lightLevel", player->lightLevel);
Expand Down Expand Up @@ -625,14 +675,14 @@ void Hud::Draw()
title->color = glm::vec4(1, 1, 1, 1);
}

if (_exiting && !Game::instance->DidTakeScreenshot() && !_askedForScreenshot)
if (_exiting && !_askedForScreenshot && title->color.a <= 0)
{
_askedForScreenshot = true;
// take screenshot

Game::instance->TakeScreenshot(WorldManager::instance->_path + "/screenshot.png");
}
else if (_exiting && _askedForScreenshot)
else if (_exiting && _askedForScreenshot && Game::instance->DidTakeScreenshot())
{
// exit

Expand All @@ -645,29 +695,49 @@ void Hud::MouseClick(int button, glm::vec2 pos)
{
if (GamePaused && !inv->shown)
{
if (Collision2D::PointInRect(pos, resume->position, glm::vec2(resume->width, resume->height)))
if (rocketScreen)
{
if (deathOverlay->color.a < 0.5f)
if (Collision2D::PointInRect(pos, resume->position, glm::vec2(resume->width, resume->height)))
{
MusicManager::GetInstance()->PlaySFX("select");
ShowPauseMenu(false);

endSequence = true;
rocketScreen = false;
player->TogglePauseMenu();
}
else
else if (Collision2D::PointInRect(pos, title->position, glm::vec2(title->width, title->height)))
{
player->wasDead = true;
player->dead = false;
deathOverlay->color.a = 0.0f;
ShowPauseMenu(false);
MusicManager::GetInstance()->PlaySFX("select");
rocketScreen = false;
player->TogglePauseMenu();
}
}
else if (Collision2D::PointInRect(pos, title->position, glm::vec2(title->width, title->height)))
else
{
MusicManager::GetInstance()->PlaySFX("select");
player->TogglePauseMenu();
if (Collision2D::PointInRect(pos, resume->position, glm::vec2(resume->width, resume->height)))
{
if (deathOverlay->color.a < 0.5f)
{
MusicManager::GetInstance()->PlaySFX("select");
ShowPauseMenu(false);
}
else
{
player->wasDead = true;
player->dead = false;
deathOverlay->color.a = 0.0f;
ShowPauseMenu(false);
}
}
else if (Collision2D::PointInRect(pos, title->position, glm::vec2(title->width, title->height)))
{
MusicManager::GetInstance()->PlaySFX("select");
player->TogglePauseMenu();

WorldManager::instance->SetPlayerPosition(player->position);
WorldManager::instance->SaveWorldNow();
_exiting = true;
WorldManager::instance->SetPlayerPosition(player->position);
WorldManager::instance->SaveWorldNow();
_exiting = true;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/Game/Objects/Base/Hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Hud : public GameObject

public:
Text2D* pauseHeader;
Text2D* hintText;

Sprite2D* pauseBackground;
Sprite2D* waterOverlay;
Expand All @@ -37,6 +38,9 @@ class Hud : public GameObject
Sprite3D* hand;

static bool GamePaused;
static bool endSequence;

bool rocketScreen = false;

Inventory* inv;

Expand All @@ -58,6 +62,8 @@ class Hud : public GameObject
void ShowPauseMenu(bool s);
void ShowDeathScreen();

void ShowRocketScreen();

void ShowKnowledgementTablet(Data::InventoryItem& item);

void SetSelected(int s);
Expand All @@ -68,6 +74,10 @@ class Hud : public GameObject
void UpdateAir();
void UpdateArmor();

float hintTime = 0;

void ShowHint(std::string text);

Hud(glm::vec3 _pos, Player* _p, Camera2D* _c2d);

~Hud();
Expand Down
13 changes: 13 additions & 0 deletions src/Game/Scenes/Gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,19 @@ void Gameplay::KeyPress(int key)

if (c != nullptr)
UnloadChunk(c);

hud->ShowHint("Reloading chunk");
}

if (key == GLFW_KEY_Y)
{
Data::InventoryItem item(Data::ITEM_ROCKET, 1);

player->playerData.GiveItem(item);

hud->UpdateHotbar();

hud->ShowHint("Gave you a rocket");
}


Expand Down

0 comments on commit c6858f1

Please sign in to comment.