-#include "assteroids.h"
#include <cstring>
#include <math.h>
+#include "assteroids.h"
+#include "powerups.hpp"
#include "vectormath.hpp"
Vector2 flatten(Vector4 pV){
return stan;
}
+
+
Vector4 translate(Vector4 v1, Vector4 v2) {
Vector4 translation = {v1.x+v2.x, v1.y+v2.y, v1.y+v2.y, v1.z+v2.z};
return translation;
memset(bullets, 0, sizeof(Vector4) * MAX_BULLETS);
memset(asteroids, 0, sizeof(Vector4) * MAX_ASTEROIDS);
memset(dead_ship, 0, sizeof(Vector4) * SHIP_DEBRIS);
-
+ init_shotgun();
+ memset(&shotgun_box, 0, sizeof(Vector4));
memset(dead_astr, 0, sizeof(Vector4) * SHIP_DEBRIS * MAX_ASTEROIDS);
+ memset(&shield_pickup, 0, sizeof(Vector4));
}
void die(){
ship_alive = false;
+ disable_shield();
for(int i = 0; i < SHIP_DEBRIS; i++) {
if (!onscreen(flatten(dead_ship[i])))
continue;
dead_ship[i].z = (360/SHIP_DEBRIS) * (i + 1);
dead_ship[i].w = 6;
}
+ disable_shotgun();
}
}
void shoot(){
- for(int i = 0; i < MAX_BULLETS; i++){
- // find available bullet
- if(bullets[i].w == 0 && time(NULL) > last_fire) {
- bullets[i].x = center.x;
- bullets[i].y = center.y;
- bullets[i].z = nose.z;
- bullets[i].w = 1;
- time(&last_fire);
- break;
+ if(time(NULL) <= last_fire)
+ return;
+ for(int s = 0; s < 1 + (4 * (active_powerups & SHOTGUN)); s++) {
+ for(int i = 0; i < MAX_BULLETS; i++){
+ // find available bullet
+ if(bullets[i].w == 0) {
+ bullets[i].x = center.x;
+ bullets[i].y = center.y;
+ bullets[i].z = nose.z + bullet_offsets[s];
+ bullets[i].w = 1;
+ break;
+ }
}
}
+ if(active_powerups & SHOTGUN)
+ shotgun_blasts--;
+ if(shotgun_blasts == 0 && active_powerups & SHOTGUN)
+ disable_shotgun();
+ time(&last_fire);
}
void update_bullets(){
}
if(ship_collision(astr) && ship_alive){
+ if((active_powerups & GOD)) {
+ continue;
+ }
die();
}
-
}
}
flatten(translate(starboard, center)),
RAYWHITE);
astr_spawner = rand() & 1000 + 1;
- } else {
+ if(active_powerups & GOD) {
+ DrawCircleSectorLines(flatten(center), 3*shield_hp, 0, 360, 6, SKYBLUE);
+ DrawCircleSectorLines(flatten(center), 2*shield_hp, 0, 360, 6, SKYBLUE);
+ if(time(NULL) > shield_spawn_time) {
+ time(&shield_spawn_time);
+ shield_hp--;
+ }
+ if(shield_hp <= 0)
+ disable_shield();
+ }
+ } else if(!(active_powerups & GOD)) {
DrawText("YOU DIED", (scrW/2)-(MeasureText("YOU DIED", 64)/2), (scrH/2)-64, 64, RED);
DrawText("FUCK YOU", (scrW/2)-(MeasureText("FUCK YOU", 16)/2), (scrH/2)-8, 16, RED);
explode_ship();
update_bullets();
update_astrs();
update_explosions();
+ if(throttle && shotgun_box.w == 0 && (rand() % 10000) < 8 && !active_powerups & SHOTGUN)
+ init_shotgun(); //a little treat
+ if(shotgun_box.w == 1)
+ draw_shotgun();
+ if(shield_pickup.w > 0)
+ draw_shield_pickup();
DrawText(TextFormat("%d", score), 4, scrH-34, 32, WHITE);
DrawFPS(0, 0);
return 0;
}
+//spawn a shield pickup at a dead asteroid
+void init_shield(Vector4* v) {
+ shield_pickup.x = v->x;
+ shield_pickup.y = v->y;
+ shield_pickup.w = 16;
+}
+void draw_shield_pickup() {
+ DrawRingLines(flatten(shield_pickup), shield_pickup.w, shield_pickup.w * 1.3, 0, 360, 6, SKYBLUE);
+ DrawRingLines(flatten(shield_pickup), shield_pickup.w/3, shield_pickup.w * 0.66, 0, 360, 6, SKYBLUE);
+ if(CheckCollisionPointCircle(flatten(center), flatten(shield_pickup), shield_pickup.w)) {
+ shield_pickup.w = 0;
+ enable_shield();
+ }
+}
+
+void enable_shield() {
+ memset(&shield_pickup, 0, sizeof(Vector4));
+ shield_hp = 9;
+ active_powerups |= GOD;
+ time(&shield_spawn_time);
+ printf("powerups: %d\n", active_powerups);
+}
+
+void disable_shield() {
+ active_powerups ^= GOD;
+ shield_hp = 9;
+ printf("powerups: %d\n", active_powerups);
+}
+
void explode_asteroid(Vector4* astr) {
for(int i = 0; i < MAX_ASTEROIDS; i++) {
if(dead_astr[i][0].w == 0) {
dead_astr[i][a].z = ((360/SHIP_DEBRIS) * a) + (360/(SHIP_DEBRIS*3));
dead_astr[i][a].w = 1;
}
+ if(shield_pickup.w == 0 && rand() % 20 < 3)
+ init_shield(astr);
break;
}
}
}
}
+
+void init_shotgun() {
+ int heading = rand() % 360;
+ shotgun_box.z = heading;
+ shotgun_box.w = 1;
+ shotgun_box.x = (heading > 90 && heading < 270) ? scrW : 0;
+ shotgun_box.y = (heading > 180 && heading < 360) ? scrH : 0;
+
+ memcpy(s_top_box, master_s_top_box, sizeof(Vector2)*4);
+ memcpy(s_bot_box, master_s_bot_box, sizeof(Vector2)*4);
+ for(int i = 0; i < 4; i++) {
+ s_top_box[i].x += shotgun_box.x;
+ s_top_box[i].y += shotgun_box.y;
+ s_bot_box[i].x += shotgun_box.x;
+ s_bot_box[i].y += shotgun_box.y;
+ }
+}
+
+void update_shotgun() {
+ float xd = cos(shotgun_box.z * (PI/180)) *2;
+ float yd = sin(shotgun_box.z * (PI/180)) *2;
+ shotgun_box.x += xd;
+ shotgun_box.y += yd;
+
+ for(int i = 0; i < 4; i++) {
+ s_top_box[i].x += xd;
+ s_top_box[i].y += yd;
+ s_bot_box[i].x += xd;
+ s_bot_box[i].y += yd;
+ }
+
+ if(!onscreen(flatten(shotgun_box)))
+ shotgun_box.w = 0;
+ if(CheckCollisionPointCircle(flatten(center), flatten(shotgun_box), 32)) {
+ enable_shotgun();
+ shotgun_box.w = 0;
+ }
+}
+
+void draw_shotgun() {
+ update_shotgun();
+ DrawLineStrip(s_top_box, 4, WHITE);
+ DrawLineStrip(s_bot_box, 4, WHITE);
+ DrawText("S", shotgun_box.x-6, shotgun_box.y-8, 20, GOLD);
+}