-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol_tank_move.hpp
55 lines (47 loc) · 1.32 KB
/
control_tank_move.hpp
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
#pragma once
int control_tank_move(Tank* tank, Direction direction, IMAGE* img) {
switch (direction) {
case UP:
//ÏòÉÏÒƶ¯
if (tank->tank_direction == UP && tank->y - 1 >= 0 && map[tank->y - 1][tank->x] == 0 && map[tank->y - 1][tank->x + 1] == 0)
{
tank_move(tank, UP, img, 1);
}
else if (tank->tank_direction != UP) {
tank->tank_direction = UP;
tank_move(tank, UP, img, 0);
}
break;
case LEFT:
if (tank->tank_direction == LEFT && tank->x - 1 >= 0 && map[tank->y][tank->x - 1] == 0 && map[tank->y + 1][tank->x - 1] == 0)
{
tank_move(tank, LEFT, img, 1);
}
else if (tank->tank_direction != LEFT) {
tank->tank_direction = LEFT;
tank_move(tank, LEFT, img, 0);
}
break;
case DOWN:
if (tank->tank_direction == DOWN && tank->y + 2 <= 25 && map[tank->y + 2][tank->x] == 0 && map[tank->y + 2][tank->x + 1] == 0)
{
tank_move(tank, DOWN, img, 1);
}
else if (tank->tank_direction != DOWN) {
tank->tank_direction = DOWN;
tank_move(tank, DOWN, img, 0);
}
break;
case RIGHT:
if (tank->tank_direction == RIGHT && tank->x + 2 <= 25 && map[tank->y][tank->x + 2] == 0 && map[tank->y + 1][tank->x + 2] == 0)
{
tank_move(tank, RIGHT, img, 1);
}
else if (tank->tank_direction != RIGHT) {
tank->tank_direction = RIGHT;
tank_move(tank, RIGHT, img, 0);
}
break;
return 1;
}
}