-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
121 lines (66 loc) · 3.05 KB
/
Copy pathmain.cpp
File metadata and controls
121 lines (66 loc) · 3.05 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>
#include "SDL.h"
#include "classes.h"
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>
int main(int argc, char* argv[])
{
Game* g_game = 0;
g_game = new Game();
g_game->initSDL();
g_game->background = g_game->loadTexture("Textures/background.png");
g_game->bullet_texture = g_game->loadTexture("Textures/bullet.png");
g_game->setBackgroundCoordinates();
g_game->camera.w = 640;
g_game->camera.h = 480;
playerCharacter mainCharacter;
mainCharacter.setSize(PLAYER_WIDTH, PLAYER_HEIGHT);
mainCharacter.image[0] = g_game->loadTexture("Textures/man1_v2.png");
mainCharacter.image[1] = g_game->loadTexture("Textures/man2_v2.png");
mainCharacter.image[2] = g_game->loadTexture("Textures/man_side0.png");
mainCharacter.image[3] = g_game->loadTexture("Textures/man_side1.png");
mainCharacter.image[4] = g_game->loadTexture("Textures/man1.png");
mainCharacter.image[5] = g_game->loadTexture("Textures/player_shot1.png");
mainCharacter.image[6] = g_game->loadTexture("Textures/player_shot2.png");
mainCharacter.image[7] = g_game->loadTexture("Textures/player_shot3.png");
mainCharacter.image[8] = g_game->loadTexture("Textures/player_shot4.png");
mainCharacter.image[9] = g_game->loadTexture("Textures/player_shot5.png");
mainCharacter.image[10] = g_game->loadTexture("Textures/player_shot6.png");
mainCharacter.image[11] = g_game->loadTexture("Textures/player_shot7.png");
bulletClassManager bulletManager;
const int fps = 60;
int delayTime = 1000/fps;
uint32_t frameStart, frameTime;
while(g_game->running())
{
frameStart = SDL_GetTicks();
g_game->incrementTime();
if(g_game->whatsTheTime() % 500 == 0){
g_game->incrementEnemies();
enemyCharacter* new_enemy;
new_enemy = new enemyCharacter();
new_enemy->image[0] = g_game->loadTexture("Textures/enemy.png");
new_enemy->image[1] = g_game->loadTexture("Textures/enemy_shot1.png");
new_enemy->image[2] = g_game->loadTexture("Textures/enemy_shot2.png");
new_enemy->image[3] = g_game->loadTexture("Textures/enemy_shot3.png");
new_enemy->image[4] = g_game->loadTexture("Textures/enemy_shot4.png");
new_enemy->setSize(ENEMY_WIDTH, ENEMY_HEIGHT);
g_game->characterVector.push_back(new_enemy);
}
g_game->handleEvents(mainCharacter);
g_game->update(mainCharacter, bulletManager);
mainCharacter.fireBullet(bulletManager);
g_game->moveEnemies(mainCharacter, bulletManager);
g_game->move(mainCharacter);
g_game->positionCamera(mainCharacter);
g_game->doAnimation(mainCharacter);
g_game->drawFigures(mainCharacter, bulletManager);
SDL_RenderPresent(g_game->renderer);
frameTime = SDL_GetTicks() - frameStart;
if(frameTime < delayTime){
SDL_Delay((int)delayTime - frameTime);
}
}
};