-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanding_menu_scene.cpp
executable file
·87 lines (71 loc) · 2.05 KB
/
landing_menu_scene.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "headers/landing_menu_scene.h"
void LandingMenuScene::init()
{
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 3; y++)
{
AddSprite(new Sprite("../resources/tileable_background.png",x*512*.5,y*512*.5,.5));
}
}
Sprite* landing_button = new Sprite("../resources/gui_landing_start_button.png",0,0,.5);
landing_button->SetPos(Window::width/2 - landing_button->GetTransformRect()->w/2,
Window::height/1.5 - landing_button->GetTransformRect()->h/2);
landingPlayButton = landing_button;
AddSprite(landing_button);
}
void LandingMenuScene::update(double deltaTime)
{
}
void LandingMenuScene::handleInput(SDL_Event e)
{
int mouseX,mouseY;
SDL_GetMouseState(&mouseX,&mouseY);
if(e.type == SDL_MOUSEBUTTONDOWN)
{
if(mouseX > landingPlayButton->GetTransformRect()->x &&
mouseX < landingPlayButton->GetTransformRect()->x + landingPlayButton->GetTransformRect()->w
&& mouseY > landingPlayButton->GetTransformRect()->y &&
mouseY < landingPlayButton->GetTransformRect()->y + landingPlayButton->GetTransformRect()->h)
nextScene = new GameScene();
}
}
void LandingMenuScene::render(Window* window)
{
SDL_SetRenderDrawColor( window->GetRenderer(), 0x00, 0x00, 0x00, 0x00 );
//Clear screen
SDL_RenderClear( window->GetRenderer() );
for(int i = 0; i < sprites.size(); i++)
{
SDL_Rect adjustedRect = {sprites[i]->GetTransformRect()->x,sprites[i]->GetTransformRect()->y
,sprites[i]->GetTransformRect()->w,sprites[i]->GetTransformRect()->h};
SDL_RenderCopy( window->GetRenderer(),sprites[i]->GetTexture(),NULL,&adjustedRect);
}
//Update screen
SDL_RenderPresent( window->GetRenderer() );
}
void LandingMenuScene::exit()
{
for(int i = 0; i < sprites.size();i++)
{
delete sprites[i];
}
}
void LandingMenuScene::AddSprite(Sprite* sta)
{
sprites.push_back(sta);
}
LandingMenuScene::~LandingMenuScene()
{
exit();
}
LandingMenuScene::LandingMenuScene()
{
}
void LandingMenuScene::goToScene(Scene*& activeScene)
{
if(nextScene == NULL || activeScene == nextScene) return;
activeScene->exit();
activeScene = nextScene;
activeScene->init();
}