forked from szekelyszilv/pisquare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.h
99 lines (76 loc) · 2.4 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef PLAYER_H
#define PLAYER_H
#include "rpi-gpio.h"
#include "entity.h"
#include "color.h"
#include "bullet.h"
#include "powerup.h"
#include "renderer.h"
#define PLAYER_LIVES_DEFAULT 3
#define PLAYER_LIVES_MAX 3
#define PLAYER_SPEED_DEFAULT 120
#define PLAYER_SPEED_INCREASE 40
#define PLAYER_SPEED_MAX (PLAYER_SPEED_DEFAULT + PLAYER_SPEED_INCREASE)
#define PLAYER_SPEED_ANGULAR 320
#define PLAYER_SIZE_DEFAULT 12
#define PLAYER_SIZE_TINY 6
#define PLAYER_TRAIL_SEGMENTS 9
#define PLAYER_DIRECTION_DEFAULT 90
#define PLAYER_DEBOUNCE_TIME 1.5f
#define PLAYER_TIMER_FLASH 0.3f
#define PLAYER_TIMER_SHOOT 0.8f
#define PLAYER_OFFSET_START 200
#define PLAYER_1_RIGHT RPI_GPIO4
#define PLAYER_1_LEFT RPI_GPIO7
#define PLAYER_1_COLOR ((color_t){0, 255, 0, 255})
#define PLAYER_2_RIGHT RPI_GPIO2
#define PLAYER_2_LEFT RPI_GPIO3
#define PLAYER_2_COLOR ((color_t){255, 0, 255, 255})
#define PLAYER_3_RIGHT RPI_GPIO10
#define PLAYER_3_LEFT RPI_GPIO9
#define PLAYER_3_COLOR ((color_t){255, 255, 0, 255})
#define PLAYER_4_RIGHT RPI_GPIO8
#define PLAYER_4_LEFT RPI_GPIO7
#define PLAYER_4_COLOR ((color_t){0, 150, 255, 255})
typedef struct {
/* Motion */
entity_t *entity;
float dir; /* angle from x-axis in degrees */
float speed;
float angular_vel; /* angular velocity */
cvertex_t *trail; /* motion trail */
int trail_toggle;
/* Timing */
float debounce_time; /* invincibility after collision */
float timer_flash; /* counter for low-life flashing */
float timer_shoot; /* reload */
float timer_powerup_bullets;
float timer_powerup_bullets_delay;
float timer_powerup_ghost;
float timer_powerup_tiny;
/* State */
int lives;
/* Flags */
int normal; /* can be damaged */
int shoot; /* request bullet */
int powerup_tiny;
int powerup_bullets;
int powerup_ghost;
int powerup_shield;
color_t color;
/* IO */
rpi_gpio_pin_t left_pin;
rpi_gpio_pin_t right_pin;
} player_t;
player_t *player_new(int num, int player_count);
void player_rotate(player_t *player, float angle);
void player_injure(player_t *player);
void player_free(player_t *player);
void player_shoot(player_t *player, bullet_t *bullet);
void player_powerup(player_t *player, powerup_t *powerup);
void player_resize(player_t *player, float width);
vector2_t player_direction_vector(const player_t *player);
color_t player_number_color(int num);
rpi_gpio_pin_t player_number_right_pin(int player);
rpi_gpio_pin_t player_number_left_pin(int player);
#endif