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
|
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <stdio.h>
#include <math.h>
#include <rb.h>
#include <spaceship.h>
void
rb_ship_init(struct spaceship *sp)
{
sp->x = RB_X_CENTER;
sp->y = RB_Y_CENTER;
sp->heading = 0;
sp->speed = 3;
sp->rot_velocity = 1;
sp->scale = 0;
sp->alive = 1;
sp->color = al_map_rgb(255, 255, 255);
printf("ship initialized\n");
}
void
rb_ship_accelerate(struct spaceship *sp)
{
sp->x += sin(sp->heading * ALLEGRO_PI / 180) * sp->speed;
if (sp->x >= RB_WIDTH)
sp->x = 0;
if (sp->x < 0)
sp->x = RB_WIDTH;
sp->y += -cos(sp->heading * ALLEGRO_PI / 180) * sp->speed;
if (sp->y >= RB_HEIGHT)
sp->y = 0;
if (sp->y < 0)
sp->y = RB_HEIGHT;
}
void
rb_ship_rotate_left(struct spaceship *sp)
{
if (sp->heading == 0)
sp->heading = 360;
sp->heading -= sp->rot_velocity;
}
void
rb_ship_rotate_right(struct spaceship *sp)
{
if (sp->heading >= 360)
sp->heading = 0;
sp->heading += sp->rot_velocity;
}
void
rb_draw_ship(struct spaceship *sp)
{
float scale = 1.9;
ALLEGRO_TRANSFORM t;
al_build_transform(&t,sp->x, sp->y, scale, scale,
(ALLEGRO_PI) / 180 * sp->heading);
al_use_transform(&t);
al_draw_line(-8, 9, 0, -11, sp->color, 3.0f);
al_draw_line(0, -11, 8, 9, sp->color, 3.0f);
al_draw_line(-6, 4, -1, 4, sp->color, 3.0f);
al_draw_line(6, 4, 1, 4, sp->color, 3.0f);
}
|