-
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
14 changed files
with
183 additions
and
54 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
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,7 @@ | ||
// Example level (level_1) | ||
// Cycle back to the start | ||
nextLevelName level_0 | ||
// Bottom collider | ||
StaticCollider, 2, 30, 30, 2 | ||
// Next level | ||
LevelTp, 50, 29 |
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,42 @@ | ||
#pragma once | ||
|
||
#include "../worldobject.h" | ||
|
||
// An object that teleports the player to another level | ||
class LevelTp : public WorldObject { | ||
private: | ||
long frameCount = 0; | ||
|
||
public: | ||
// Constructor | ||
LevelTp(double spawnx, double spawny) : WorldObject() { | ||
locx = spawnx; | ||
locy = spawny; | ||
this->width = 1; | ||
this->height = 1; | ||
this->objectAttributes.insert(ObjectAttribute::OverlapDetect); | ||
this->objectAttributes.insert(ObjectAttribute::LevelTeleport); | ||
} | ||
|
||
// Override update: check with player | ||
UpdateResult update(WorldState& worldState, std::vector<WorldObject*>& objects) { | ||
// TODO: stuff | ||
return UpdateResult::None; | ||
} | ||
|
||
// Override rendering | ||
RenderData getRenderData() { | ||
frameCount++; | ||
// TODO: image? | ||
return { | ||
RenderType::Rectangle, | ||
coordType, | ||
locx + sin(frameCount / 20.0) * 0.3, | ||
locy + cos(frameCount / 20.0) * 0.3, | ||
width, | ||
height, | ||
{ 66, 135, 245 }, | ||
"" | ||
}; | ||
} | ||
}; |
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,51 @@ | ||
#include "worldspawner.h" | ||
|
||
void WorldSpawner::spawnWorld(GameState& gameState, std::string levelName) { | ||
// Load the file based on the level name | ||
// todo: error handling | ||
std::ifstream file("assets/" + levelName + ".csv"); | ||
std::string line; | ||
std::string newNextLevelName = "level_0"; | ||
// Clear the world | ||
gameState.clear(); | ||
// Update | ||
while (std::getline(file, line)) { | ||
// Parse line | ||
std::vector<std::string> parsed; | ||
std::string thisitem = ""; | ||
for (char c : line) { | ||
if (c == ',') { | ||
parsed.push_back(thisitem); | ||
thisitem = ""; | ||
} else if (c != ' ' && c != '\n') { | ||
thisitem += c; | ||
} | ||
} | ||
if (thisitem != "") parsed.push_back(thisitem); | ||
// Process arguments | ||
// todo: error handling with try catch | ||
if (parsed[0].rfind("//", 0) == 0) { | ||
// Comment: skip | ||
} else if (parsed[0] == "nextLevelName") { | ||
newNextLevelName = parsed[1]; | ||
} else if (parsed[0] == "StaticCollider") { | ||
gameState.spawnObject(new StaticCollider( | ||
std::stoi(parsed[1]), std::stoi(parsed[2]), std::stoi(parsed[3]), std::stoi(parsed[4]) | ||
)); | ||
} else if (parsed[0] == "Spike") { | ||
gameState.spawnObject(new Spike( | ||
std::stoi(parsed[1]), std::stoi(parsed[2]) | ||
)); | ||
} else if (parsed[0] == "StaticDeadly") { | ||
gameState.spawnObject(new StaticDeadly( | ||
std::stoi(parsed[1]), std::stoi(parsed[2]), std::stoi(parsed[3]), std::stoi(parsed[4]) | ||
)); | ||
} else if (parsed[0] == "LevelTp") { | ||
gameState.spawnObject(new LevelTp( | ||
std::stoi(parsed[1]), std::stoi(parsed[2]) | ||
)); | ||
} | ||
} | ||
// Successful load: update the game state | ||
gameState.updateLevelNames(levelName, newNextLevelName); | ||
} |
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