forked from Kiritouse/TouHouInc--
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
220 lines (204 loc) · 9.49 KB
/
Player.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include "Player.h"
#include <graphics.h>
#include "FrameManager.h"
#include "Operation.h"
#include "Map.h"
#include "Draw.h"
#include "LoadResources.h"
int lastLeftState = 0;
PlayerCollider playerCollider;//点的顺序从左上角出发,顺时针旋转
struct orimg {
int x = 3, y = 0;
}originPoint_img;
Player::Position Struct_PlayerPosition;
Player::Direction Struct_Direction;
Player::ObjectState E_TYPE_PlayerState;
int leftOpFramebuffer, rightOpFramebuffer, upOpFramebuffer, downOpFramebuffer, tempframe;
Player::Player() {
speed = 6;
Struct_PlayerPosition.x = 240;
Struct_PlayerPosition.y = 670;
health = 100;
E_TYPE_PlayerState = Live;
Struct_Direction.up = 0;
Struct_Direction.down = 0;
Struct_Direction.left = 0;
Struct_Direction.right = 0;
}
void Player::update_PlayerPosition(int _cmd, int framebuffer) {
//更新碰撞体
playerCollider.xl = Struct_PlayerPosition.x + ((WIDTH_PLAYER - 8) >> 1);
playerCollider.xr = playerCollider.xl + 8;
playerCollider.yu = Struct_PlayerPosition.y + ((HEIGHT_PLAYER - 8) >> 1);
playerCollider.yd = playerCollider.yu + 8;
static int stateRightStop = 1, stateLeftStop = 1, stateUpStop = 1, stateDownStop = 1, stateRight = 0, stateLeft = 0, stateUp = 0, stateDown = 0;
if (_cmd & CMD_UP && Struct_PlayerPosition.y >= 0) {
Struct_Direction.up = 1;
Struct_PlayerPosition.y -= speed;
if (stateUpStop == 1) {//保证长按右键的时候只会记录一次的时间
upOpFramebuffer = framebuffer;//记录下当前按下右键操作的时间
stateUpStop = 0;
}
stateUp = 1;
}
else {
if (stateUp == 1) {//如果之前的操作是右移动状态
Struct_Direction.up = 0;
stateUp = 0;
}
stateUpStop = 1;
}
if (_cmd & CMD_DOWN && Struct_PlayerPosition.y < HEIGHT_MAP - HEIGHT_PLAYER) {
Struct_Direction.down = 1;
Struct_PlayerPosition.y += speed;
if (stateDownStop == 1) {//保证长按右键的时候只会记录一次的时间
downOpFramebuffer = framebuffer;//记录下当前按下右键操作的时间
stateDownStop = 0;
}
stateDown = 1;
}
else {
if (stateDown == 1) {//如果之前的操作是右移动状态
Struct_Direction.down = 0;
stateDown = 0;
}
stateDown = 1;
}
if (_cmd & CMD_RIGHT && Struct_PlayerPosition.x < WIDTH_MAP - WIDTH_PLAYER) {
Struct_Direction.right = 1;
Struct_PlayerPosition.x += speed;
if (stateRightStop == 1) {//保证长按右键的时候只会记录一次的时间
rightOpFramebuffer = framebuffer;//记录下当前按下右键操作的时间
stateRightStop = 0;
}
stateRight = 1;
}
else {
if (stateRight == 1) {//如果之前的操作是右移动状态
Struct_Direction.right = 0;
stateRight = 0;
}
stateRightStop = 1;
}
if (_cmd & CMD_LEFT && Struct_PlayerPosition.x >= 0) {
Struct_Direction.left = 1;
Struct_PlayerPosition.x -= speed;
if (stateLeftStop == 1) {
leftOpFramebuffer = framebuffer;//记录下当前按下左键操作的时间
stateLeftStop = 0;
}
stateLeft = 1;//进入左移动状态
}
else {
if (stateLeft == 1) {
Struct_Direction.left = 0;
stateLeft = 0;//
}
stateLeftStop = 1;
}
}
void Player::update_PlayerImage(int frameBuffer) {//
if (health = 0) return;
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
originPoint_img.x, originPoint_img.y, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
if (Struct_Direction.up - Struct_Direction.down > 0) {
frameBuffer = frameBuffer - upOpFramebuffer;
if (frameBuffer >= 0 && frameBuffer < 5)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
36, 0, WIDTH_PLAYER, HEIGHT_PLAYER_RIGHT, &player);
if (frameBuffer >= 5 && frameBuffer < 10)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
68, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
if (frameBuffer >= 10 && frameBuffer < 15)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
100, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
if (frameBuffer >= 15 && frameBuffer < 20)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
132, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
if (frameBuffer >= 20 && frameBuffer < 25)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
164, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
if (frameBuffer >= 25 && frameBuffer < 30)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
196, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
if (frameBuffer >= 30)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
223, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
}
else if (Struct_Direction.up - Struct_Direction.down < 0) {
frameBuffer = frameBuffer - downOpFramebuffer;
if (frameBuffer >= 0 && frameBuffer < 5)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
36, 0, WIDTH_PLAYER, HEIGHT_PLAYER_RIGHT, &player);
if (frameBuffer >= 5 && frameBuffer < 10)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
68, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
if (frameBuffer >= 10 && frameBuffer < 15)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
100, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
if (frameBuffer >= 15 && frameBuffer < 20)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
132, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
if (frameBuffer >= 20 && frameBuffer < 25)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
164, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
if (frameBuffer >= 25 && frameBuffer < 30)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
196, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
if (frameBuffer >= 30)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER, HEIGHT_PLAYER,
223, 0, WIDTH_PLAYER, HEIGHT_PLAYER, &player);
}
else if (Struct_Direction.right - Struct_Direction.left > 0) {
frameBuffer = frameBuffer - rightOpFramebuffer;
if (frameBuffer >= 0 && frameBuffer < 5)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT,
33, 0, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT, &playerRight);
if (frameBuffer >= 5 && frameBuffer < 10)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT,
64, 0, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT, &playerRight);
if (frameBuffer >= 10 && frameBuffer < 15)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT,
96, 0, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT, &playerRight);
if (frameBuffer >= 15 && frameBuffer < 20)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT,
128, 0, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT, &playerRight);
if (frameBuffer >= 20 && frameBuffer < 25)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT,
160, 0, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT, &playerRight);
if (frameBuffer >= 25 && frameBuffer < 30)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT,
192, 0, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT, &playerRight);
if (frameBuffer >= 30)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT,
223, 0, WIDTH_PLAYER_RIGHT, HEIGHT_PLAYER_RIGHT, &playerRight);
}
else if (Struct_Direction.right - Struct_Direction.left < 0) {
frameBuffer = frameBuffer - leftOpFramebuffer;
if (frameBuffer >= 0 && frameBuffer < 5)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT,
36, 0, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT, &playerLeft);
if (frameBuffer >= 5 && frameBuffer < 10)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT,
68, 0, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT, &playerLeft);
if (frameBuffer >= 10 && frameBuffer < 15)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT,
99, 0, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT, &playerLeft);
if (frameBuffer >= 15 && frameBuffer < 20)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT,
132, 0, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT, &playerLeft);
if (frameBuffer >= 20 && frameBuffer < 25)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT,
164, 0, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT, &playerLeft);
if (frameBuffer >= 25 && frameBuffer < 30)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT,
196, 0, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT, &playerLeft);
if (frameBuffer >= 30)
transparentimage(NULL, Struct_PlayerPosition.x, Struct_PlayerPosition.y, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT,
228, 0, WIDTH_PLAYER_LEFT, HEIGHT_PLAYER_LEFT, &playerLeft);
}
}
void Player::update_Player(int n_command, int framebuffer) {
update_PlayerPosition(n_command, framebuffer);
update_PlayerImage(framebuffer);
}