#include #include #include #include #include #include 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); }