-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
221 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "gamestate.h" | ||
|
||
void GameState::spawnObject(WorldObject* object) { | ||
objects.push_back(object); | ||
} | ||
|
||
void GameState::update() { | ||
for (WorldObject* object : objects) { | ||
object->update(worldState, objects); | ||
} | ||
} | ||
|
||
std::vector<WorldObject*>::iterator GameState::objectsBegin() { | ||
return objects.begin(); | ||
} | ||
|
||
std::vector<WorldObject*>::iterator GameState::objectsEnd() { | ||
return objects.end(); | ||
} | ||
|
||
void GameState::clear() { | ||
while (!objects.empty()) { | ||
// TODO: good memory freeing? | ||
delete objects.back(); | ||
objects.pop_back(); | ||
} | ||
} | ||
|
||
GameState::~GameState() { | ||
clear(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include "worldobject.h" | ||
#include "worldstate.h" | ||
|
||
// Store the full state of the world and all objects | ||
class GameState { | ||
private: | ||
WorldState worldState; | ||
std::vector<WorldObject*> objects; | ||
|
||
public: | ||
// Spawn an object | ||
void spawnObject(WorldObject* object); | ||
// Update | ||
void update(); | ||
// Get all objects | ||
std::vector<WorldObject*>::iterator objectsBegin(); | ||
std::vector<WorldObject*>::iterator objectsEnd(); | ||
// Clear all items | ||
void clear(); | ||
// Destructor to free memory | ||
~GameState(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include "../worldobject.h" | ||
|
||
// An object that does not move, but that other objects can collide with | ||
class StaticCollider : public WorldObject { | ||
public: | ||
// Constructor | ||
StaticCollider(double spawnx, double spawny, double width, double height) : WorldObject() { | ||
locx = spawnx; | ||
locy = spawny; | ||
this->width = width; | ||
this->height = height; | ||
} | ||
|
||
// Override update: gravity | ||
UpdateResult update(WorldState& worldState, std::vector<WorldObject*>& objects) { | ||
return UpdateResult::None; | ||
} | ||
|
||
// Override rendering | ||
RenderData getRenderData() { | ||
// TODO: image/animations | ||
return { | ||
RenderType::Rectangle, | ||
coordType, | ||
locx, | ||
locy, | ||
width, | ||
height, | ||
{ 14, 92, 81 }, | ||
"" | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.