-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.h
85 lines (75 loc) · 2.54 KB
/
player.h
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
/* Copyright 2012 Nicholas Parkanyi
* Contains data structure typedefs for player */
enum colours { YELLOW, RED, BLUE, BLACK };
typedef struct {
SDL_Surface * animation[4];
SDL_Rect destrect;
int direction_x;
int direction_y;
int visible;
} bullet;
typedef struct {
/* either 1 or 0 to indicate whether the player is currently
* moving in that direction.
* Elements 0-3 represent the
* cardinal directions.*/
int direction[4];
/* 0 to 3 */
int orientation;
int colour;
/* used for bullet timing. */
int time;
int visible;
/* 4 directions for each of the ship's four colours */
SDL_Surface * sprites[4][4];
/* used for SDL blitting, contains the coordinates to blit to */
SDL_Rect destrect;
/* the player can shoot up to 10 bullets on the screen at the
* same time for each of the four colours. */
bullet bullets[4][10];
} player;
/* The same data structure for the player will be used for the
* enemies. */
typedef struct {
/* directions currently travelled in */
int direction[4];
int colour;
/* bullet timing */
int time;
/* frequency of gunfire */
int frequency;
int speed;
/* 3 indicates the enemy is in the process of being blown up. */
int visible;
SDL_Surface * sprite;
SDL_Rect destrect;
bullet bullets[10];
}enemy;
typedef struct {
SDL_Surface * sprite;
int visible;
int speed; /* can be between 5 and 9 */
int orientation; /* 0 up-down, 1 left-right */
int direction;
int offset;
int amplitude;
SDL_Rect destrect;
} asteroid;
/* general function for loading series of numbered bitmaps into sprites. */
void load_sprite(SDL_Surface ** sprites, int num_sprites, const char * prefix, const char * postfix, SDL_Surface * format_surface);
/* load_bullet and load_player initialize the structures and load the necessary
* bitmaps */
player load_player(SDL_Surface * format_surface);
enemy load_enemy(const char * prefix, const char * bullet_prefix, SDL_Surface * format_surface);
asteroid load_asteroid(SDL_Surface * sprite);
void move_player(player * ship, int time);
void move_enemy(enemy * enemy, int player_x, int player_y, int time);
void move_asteroid(asteroid * asteroid, int time);
void move_bullets(player * ship, int time);
void move_bullets_enemy(enemy * enemy, int time);
void draw_player(player * ship, SDL_Surface * destbuff);
void draw_asteroid(asteroid * asteroid, SDL_Surface * destbuff);
void draw_enemy(enemy * enemy, SDL_Surface * destbuff);
void draw_bullet(player * ship, SDL_Surface * destbuff);
void delete_player(player * ship);
void delete_enemy(enemy * enemy);