-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathai.c
100 lines (89 loc) · 1.9 KB
/
ai.c
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
#include "ai.h"
void AI_move_to_ship_and_shot(enemy *this)
{
if(SDL_GetTicks() - this->ai_timestop > 1250)
{
enemy_set_dir_to_ship(this);
this->ai_timestop = SDL_GetTicks();
}
enemy_move(this);
enemy_shot(this);
}
void AI_move_fast_to_ship_and_shot(enemy *this)
{
this->dir_x = -4;
enemy_set_dir_to_ship(this);
this->dir_x = -1;
enemy_move(this);
enemy_shot(this);
}
void AI_move_to_ship_and_dodge(enemy *this)
{
if(SDL_GetTicks() - this->ai_timestop > 1250)
{
enemy_set_dir_to_ship(this);
this->ai_timestop = SDL_GetTicks();
}
enemy_dodge(this);
enemy_move(this);
enemy_shot(this);
}
void AI_move_into_screen_and_shot(enemy *this)
{
if(this->x > SDL_GetVideoSurface()->w - get_enemy_w(this->level) - 10)
{
enemy_set_dir_to_ship(this);
}
else
{
this->dir_x = -4;
enemy_set_dir_to_ship(this);
this->dir_x = 0;
}
enemy_move(this);
enemy_shot(this);
}
void AI_move_into_screen_and_dodge(enemy *this)
{
if(this->x > SDL_GetVideoSurface()->w - get_enemy_w(this->level) - 10)
{
enemy_set_dir_to_ship(this);
}
else
{
if(SDL_GetTicks() - this->ai_timestop > 750)
{
this->dir_x = -1;
enemy_set_dir_to_ship(this);
this->ai_timestop = SDL_GetTicks();
}
this->dir_x = 0;
enemy_dodge(this);
}
enemy_move(this);
enemy_shot(this);
}
void AI_move_into_screen_and_dodge_quick(enemy *this)
{
if(this->x > SDL_GetVideoSurface()->w - get_enemy_w(this->level) - 10)
{
enemy_set_dir_to_ship(this);
}
else
{
/* point 'this' to ship */
if(SDL_GetTicks() - this->ai_timestop > 750)
{
this->dir_x = -1;
enemy_set_dir_to_ship(this);
this->ai_timestop = SDL_GetTicks();
}
/* dodge bullets with 4 x speed */
this->dir_x = -4.0;
enemy_dodge(this);
/* set dir_x to 0 */
this->dir_x = 0;
}
enemy_move(this);
enemy_shot(this);
}