Skip to content

Commit

Permalink
Add Parallax
Browse files Browse the repository at this point in the history
Signed-off-by: Okami <tomaspp515@gmail.com>
  • Loading branch information
Okami115 committed Nov 8, 2022
1 parent 1c75f9a commit 89c0883
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 1 deletion.
4 changes: 4 additions & 0 deletions SRC/CoreLoop/CoreLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace OkamiIndustries
bool QuitGame = true;

Texture2D BackgroundGame;
Texture2D Parallax1Game;
Texture2D Parallax2Game;
Texture2D Parallax3Game;
Texture2D FloorGame;

int SelectScene = 0;
int SetScene = 0;
Expand Down
72 changes: 71 additions & 1 deletion SRC/GameLoop/GameLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,98 @@ namespace OkamiIndustries

extern int SetScene;
extern Texture2D BackgroundGame;
extern Texture2D Parallax1Game;
extern Texture2D Parallax2Game;
extern Texture2D Parallax3Game;
extern Texture2D FloorGame;
Vector2 BackgroundPos = { 0,0 };
Vector2 Parallax1pos = { 0,0 };
Vector2 Parallax1pos2 = { 1920,0 };
Vector2 Parallax2pos = { 0,0 };
Vector2 Parallax2pos2 = { 1920,0 };
Vector2 Parallax3pos = { 0,0 };
Vector2 Parallax3pos2 = { 1920,0 };
Vector2 Floorpos = { 0,0 };
Vector2 Floorpos2 = { 1920,0 };

void GameLoop()
{
if (IsKeyPressed(KEY_ESCAPE))
{
SetScene = 0;
}
updateBackground();
MoveExplorer();
MoveObstacles();
}

void DrawGame()
{
DrawTextureEx(BackgroundGame, BackgroundPos, 0, 1, WHITE);
DrawTextureEx(Parallax1Game, Parallax1pos, 0, 1, WHITE);
DrawTextureEx(Parallax1Game, Parallax1pos2, 0, 1, WHITE);
DrawTextureEx(Parallax2Game, Parallax2pos, 0, 1, WHITE);
DrawTextureEx(Parallax2Game, Parallax2pos, 0, 1, WHITE);
DrawTextureEx(Parallax3Game, Parallax3pos, 0, 1, WHITE);
DrawTextureEx(Parallax3Game, Parallax3pos2, 0, 1, WHITE);
DrawTextureEx(FloorGame, Floorpos, 0, 1, WHITE);
DrawTextureEx(FloorGame, Floorpos2, 0, 1, WHITE);
DrawExplorer();
DrawObstacles();
}

void InitGame()
{
BackgroundGame = LoadTexture("../assets/Background.png");
BackgroundGame = LoadTexture("C:/Users/tomas/Desktop/Mars X/Mars X/assets/Background.png");
Parallax1Game = LoadTexture("C:/Users/tomas/Desktop/Mars X/Mars X/assets/parallax 1.png");
Parallax2Game = LoadTexture("C:/Users/tomas/Desktop/Mars X/Mars X/assets/parallax 2.png");
Parallax3Game = LoadTexture("C:/Users/tomas/Desktop/Mars X/Mars X/assets/parallax 3.png");
FloorGame = LoadTexture("C:/Users/tomas/Desktop/Mars X/Mars X/assets/Floor.png");

}

static void updateBackground()
{
Parallax1pos.x -= 200* GetFrameTime();
Parallax1pos2.x -= 200* GetFrameTime();
Parallax2pos.x -= 400* GetFrameTime();
Parallax2pos2.x -= 400* GetFrameTime();
Parallax3pos.x -= 600* GetFrameTime();
Parallax3pos2.x -= 600* GetFrameTime();
Floorpos.x -= 800* GetFrameTime();
Floorpos2.x -= 800* GetFrameTime();
if (Parallax1pos.x < -1920)
{
Parallax1pos.x = 1920;
}
if (Parallax1pos2.x < -1920)
{
Parallax1pos2.x = 1920;
}
if (Parallax2pos.x < -1920)
{
Parallax2pos.x = 1920;
}
if (Parallax2pos2.x < -1920)
{
Parallax2pos2.x = 1920;
}
if (Parallax3pos.x < -1920)
{
Parallax3pos.x = 1920;
}
if (Parallax3pos2.x < -1920)
{
Parallax3pos2.x = 1920;
}
if (Floorpos.x < -1920)
{
Floorpos.x = 1920;
}
if (Floorpos2.x < -1920)
{
Floorpos2.x = 1920;
}

}
}
1 change: 1 addition & 0 deletions SRC/GameLoop/GameLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace OkamiIndustries
void GameLoop();
void DrawGame();
void InitGame();
static void updateBackground();

}
Binary file removed assets/BackgroundGame.png
Binary file not shown.
Binary file added assets/Floor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/Parallax 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/parallax 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/parallax 3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 89c0883

Please sign in to comment.