summaryrefslogtreecommitdiff
path: root/src/spaceship.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/spaceship.c')
-rw-r--r--src/spaceship.c71
1 files changed, 45 insertions, 26 deletions
diff --git a/src/spaceship.c b/src/spaceship.c
index e92c4bb..2abf321 100644
--- a/src/spaceship.c
+++ b/src/spaceship.c
@@ -1,6 +1,7 @@
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <stdio.h>
+#include <math.h>
#include <rb.h>
#include <spaceship.h>
@@ -10,44 +11,62 @@ rb_ship_init(struct spaceship *sp)
{
sp->x = RB_X_CENTER;
sp->y = RB_Y_CENTER;
- sp->heading = 24;
- sp->speed = 0;
- sp->rot_velocity = 0;
+ 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");
}
-#if 0
void
-rb_ship_accelerate(struct spaceship *sp,
- float x, float, y)
+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;
+
}
-#endif
void
rb_draw_ship(struct spaceship *sp)
{
- ALLEGRO_TRANSFORM transform;
- al_identity_transform(&transform);
- al_rotate_transform(&transform, (ALLEGRO_PI / 180) * sp->heading);
- al_translate_transform(&transform, sp->x, sp->y);
- al_use_transform(&transform);
-
- al_draw_line(RB_X_CENTER - 8, RB_Y_CENTER + 9,
- RB_X_CENTER, RB_Y_CENTER - 11,
- sp->color, 3.0f);
-
- al_draw_line(RB_X_CENTER, RB_Y_CENTER - 11,
- RB_X_CENTER + 8, RB_Y_CENTER + 9,
- sp->color, 3.0f);
- al_draw_line(RB_X_CENTER - 6, RB_Y_CENTER + 4,
- RB_X_CENTER - 1, RB_Y_CENTER + 4,
- sp->color, 3.0f);
- al_draw_line(RB_X_CENTER + 6, RB_Y_CENTER + 4,
- RB_X_CENTER + 1, RB_Y_CENTER + 4,
- sp->color, 3.0f);
+ 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);
}