forked from Kiritouse/TouHouInc--
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameManager.cpp
194 lines (167 loc) · 8.75 KB
/
GameManager.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <Windows.h>
#include <time.h>
#include "GameManager.h"
#include "LoadResources.h"
#include "Interface.h"
#include "Map.h"
#include "Player.h"
#include "Operation.h"
#include "FrameManager.h"
#include "Draw.h"
#include "Bullet.h"
#include "Enemy.h"
#include "EnemyBullet.h"
#include "Music.h"
#include "ParticleManager.h"
#define PI 3.1415926
GameState gameState;
Interface OBJ_interface;
Map OBJ_Map;
Player OBJ_Player;
EnemyBullet OBJ_EnemyBullet;
Enemy OBJ_Enemy;
Frame frame(0, 0, 0, 0);
BulletNode* p_Player_Bullet_List_Node = NULL;//飞机子弹列表的头节点
//EnemyBulletNode* p_Enemy_Bullet_List_Node = NULL;//敌机子弹列表头节点
//EnemyNode* p_Enemy_List_Node = NULL;
clock_t t_begin = clock();
clock_t t_update;
int n_command;//获取操作
int deltaFrame_LineMove = 0;
int deltaFrame_CircleMove = 0;
int tempFrame_LineMove = 0;
int tempFrame_CircleMove = 0;
void AddItem(int framebuffer) {
srand(framebuffer);
int randFireOn = rand() % 31 + 20;
int randHeight = rand() % (HEIGHT_MAP / 4 * 3 - HEIGHT_MAP / 4 + 1) + HEIGHT_MAP / 4;
int randDelta = rand() % 100 - 50;
deltaFrame_LineMove = framebuffer - tempFrame_LineMove;//tempframe记录上一次调用AddItem函数的时间
deltaFrame_CircleMove = framebuffer - tempFrame_CircleMove;
if (deltaFrame_LineMove == 40) {
tempFrame_LineMove = framebuffer;
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, randFireOn, rand() % (WIDTH_MAP / 5 * 4 - WIDTH_MAP / 5 + 1) + WIDTH_MAP / 5, 3, DEF_MOVE_LINE, PI / 2, 2, OBJ_Enemy.ENEMY0, 50, 0, frame));
}
if (deltaFrame_CircleMove == 100) {
tempFrame_CircleMove = framebuffer;
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, randFireOn, 10, randHeight, DEF_MOVE_CIRCLE_RIGHT, 10, 10, 0.0f, 0.00625, OBJ_Enemy.ENEMY1, 100, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, randFireOn, 400, randHeight + randDelta, DEF_MOVE_CIRCLE_LEFT, 400, 10, 0.0f, PI / 500, OBJ_Enemy.ENEMY1, 100, 0, frame));
}
switch (framebuffer)
{
//每隔40帧创建敌人从天上随机移动下来
//开局先直线移动
case 100:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, WIDTH_MAP / 5 * 1, 3, DEF_MOVE_LINE, PI / 2, 2, OBJ_Enemy.ENEMY0, 50, 0, frame));
break;
case 120:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, WIDTH_MAP / 5 * 2, 3, DEF_MOVE_LINE, PI / 2, 2, OBJ_Enemy.ENEMY0, 50, 0, frame));
break;
case 140:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, WIDTH_MAP / 5 * 3, 3, DEF_MOVE_LINE, PI / 2, 2, OBJ_Enemy.ENEMY0, 50, 0, frame));
break;
case 160:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, WIDTH_MAP / 5 * 4, 3, DEF_MOVE_LINE, PI / 2, 2, OBJ_Enemy.ENEMY0, 50, 0, frame));
break;
//左边出来敌机
case 300:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 3, HEIGHT_MAP / 7 * 1, DEF_MOVE_LINE, 0.0f, 2, OBJ_Enemy.ENEMY0, 50, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 3, HEIGHT_MAP / 7 * 2, DEF_MOVE_LINE, 0.0f, 2, OBJ_Enemy.ENEMY0, 50, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 3, HEIGHT_MAP / 7 * 3, DEF_MOVE_LINE, 0.0f, 2, OBJ_Enemy.ENEMY0, 50, 0, frame));
break;
//右边出来敌机
case 500:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, WIDTH_MAP - 50, HEIGHT_MAP / 7 * 4, DEF_MOVE_LINE, PI, 2, OBJ_Enemy.ENEMY0, 50, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, WIDTH_MAP - 50, HEIGHT_MAP / 7 * 5, DEF_MOVE_LINE, PI, 2, OBJ_Enemy.ENEMY0, 50, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, WIDTH_MAP - 50, HEIGHT_MAP / 7 * 6, DEF_MOVE_LINE, PI, 2, OBJ_Enemy.ENEMY0, 50, 0, frame));
break;
//飞机向着右边和向着左边弧形移动
case 600:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 10, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_RIGHT, 10, 10, 0.0f, 0.00625, OBJ_Enemy.ENEMY1, 100, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 400, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_LEFT, 400, 10, 0.0f, PI / 500, OBJ_Enemy.ENEMY1, 100, 0, frame));
break;
case 620:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 10, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_RIGHT, 10, 10, 0.0f, 0.00625, OBJ_Enemy.ENEMY1, 100, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 400, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_LEFT, 400, 10, 0.0f, PI / 500, OBJ_Enemy.ENEMY1, 100, 0, frame));
break;
case 640:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 10, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_RIGHT, 10, 10, 0.0f, 0.00625, OBJ_Enemy.ENEMY1, 100, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 400, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_LEFT, 400, 10, 0.0f, PI / 500, OBJ_Enemy.ENEMY1, 100, 0, frame));
break;
case 660:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 10, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_RIGHT, 10, 10, 0.0f, 0.00625, OBJ_Enemy.ENEMY1, 100, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 400, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_LEFT, 400, 10, 0.0f, PI / 500, OBJ_Enemy.ENEMY1, 100, 0, frame));
break;
case 680:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 10, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_RIGHT, 10, 10, 0.0f, 0.00625, OBJ_Enemy.ENEMY1, 100, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 400, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_LEFT, 400, 10, 0.0f, PI / 500, OBJ_Enemy.ENEMY1, 100, 0, frame));
break;
case 700:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 10, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_RIGHT, 10, 10, 0.0f, 0.00625, OBJ_Enemy.ENEMY1, 100, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 400, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_LEFT, 400, 10, 0.0f, PI / 500, OBJ_Enemy.ENEMY1, 100, 0, frame));
break;
case 720:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 10, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_RIGHT, 10, 10, 0.0f, 0.00625, OBJ_Enemy.ENEMY1, 100, 0, frame));
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 20, 400, HEIGHT_MAP / 2, DEF_MOVE_CIRCLE_LEFT, 400, 10, 0.0f, PI / 500, OBJ_Enemy.ENEMY1, 100, 0, frame));
break;
//开始随机移动
case 800:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 50, rand() % (WIDTH_MAP / 3 * 2 - WIDTH_MAP / 3 + 1) + WIDTH_MAP / 3, 20, DEF_MOVE_RAND, 6.0f, OBJ_Enemy.ENEMY0, 100, 0, frame));
break;
case 840:
OBJ_Enemy.Enemy_ListPushHead(&OBJ_Enemy.p_Enemy_List_Node, OBJ_Enemy.createEnemy(1, 50, rand() % (WIDTH_MAP / 3 * 2 - WIDTH_MAP / 3 + 1) + WIDTH_MAP / 3, 20, DEF_MOVE_RAND, 6.0f, OBJ_Enemy.ENEMY0, 100, 0, frame));
break;
}
}
void Awake() {
OBJ_EnemyBullet.p_Enemy_Bullet_List_Node = NULL;
OBJ_Enemy.p_Enemy_List_Node = NULL;
OBJ_interface.InitGraphInterface();
}
void update_Paintings(int framebuffer) {
BeginBatchDraw();
cleardevice();
OBJ_Map.update_MapImage();
OBJ_interface.paintGameInterface();
OBJ_Player.update_PlayerImage(framebuffer);
update_BulletImage(&p_Player_Bullet_List_Node);
OBJ_Enemy.update_EnemyImage(&OBJ_Enemy.p_Enemy_List_Node);
OBJ_EnemyBullet.update_EnemyBulletImage(&OBJ_EnemyBullet.p_Enemy_Bullet_List_Node);
update_Particle();
cal_FPS();
EndBatchDraw();
}
void Update() {//帧更新
int framebuffer;
while (gameState.gaming == 1) {
t_update = clock();
if (t_update - t_begin >= 10) {
t_begin = t_update;
frame.f_total++;//总帧数,10ms为一帧
framebuffer = frame.f_total - frame.f_pause;
}
else continue;
MouseLisenter();//获取鼠标事件
if (!gameState.pause) {
update_Paintings(framebuffer);
AddItem(framebuffer);
n_command = GetInput();
OBJ_Map.update_Map();
OBJ_Player.update_Player(n_command, framebuffer);
update_Bullet(&OBJ_Enemy.p_Enemy_List_Node, &p_Player_Bullet_List_Node, n_command, framebuffer, 0, -10, 10);
OBJ_Enemy.update_Enemy(&OBJ_Enemy.p_Enemy_List_Node, frame);
OBJ_EnemyBullet.update_EnemyBullet(OBJ_Player, &OBJ_Enemy.p_Enemy_List_Node, &OBJ_EnemyBullet.p_Enemy_Bullet_List_Node, 0, 6, 0, 10, framebuffer);
}
else {
OBJ_interface.paintPauseInterface();//存档
}
//FlushBatchDraw();
Sleep(20);
}
}
void Gaming() {
BeginBatchDraw();
playsound(0, 1);
Update();
EndBatchDraw();
}