#include <ctime>
int scrW = 800;
int scrH = 650;
-
Color Space = {21, 0, 26};
+int astr_spawner = 0;
Vector4 nose, port, starboard, center;
float ship_bearing;
bool throttle = false;
Vector4* bullets;
const int MAX_BULLETS = 32;
unsigned int score = 0;
-Rectangle screenspace = {-10, -10, scrW+10, scrH+10};
+Rectangle screenspace = {-200, -200, scrW+200, scrH+200};
// x/y pos, z heading, w size/life
Vector4* asteroids;
const int MAX_ASTEROIDS = 16;
+
+Vector4 NE = {0, scrH, 0, 90};
+Vector4 NW = {scrW, scrH, 91, 180};
+Vector4 SW = {0, 0, 181, 275};
+Vector4 SE = {scrW, 0, 276, 359};
+
+Vector4** astr_dirs;
#endif //__ass
}
void init_ship(){
+ ship_alive = true;
+ score = 0;
nose.z = 270;
port.z = 55;
starboard.z = 125;
center.x = scrW/2; center.y = scrH/2;
ship_bearing = 0;
- //allocate bullets;
bullets = (Vector4*)malloc(sizeof(Vector4)*MAX_BULLETS);
memset(bullets, 0, sizeof(Vector4) * MAX_BULLETS);
- //allocate bullets;
asteroids = (Vector4*)malloc(sizeof(Vector4)*MAX_ASTEROIDS);
memset(asteroids, 0, sizeof(Vector4) * MAX_ASTEROIDS);
}
void die(){
ship_alive = false;
- init_ship();
}
void spin_ship(int az_delta){
}
void spawn_astr() {
+ int heading = rand() % 360;
for(int i = 0; i < MAX_ASTEROIDS; i++){
// find available asteroid
// no size means you're fuckin dead, gyro
if(asteroids[i].w == 0) {
- asteroids[i].x = 9;
- asteroids[i].y = scrH/2;
- asteroids[i].z = 0; //head to right I think
- asteroids[i].w = 64; //size
+ asteroids[i].z = heading;
+ asteroids[i].w = rand() % 34 + 30;
+ asteroids[i].x = (heading > 90 && heading < 270) ? scrW : 0;
+ asteroids[i].y = (heading > 180 && heading < 360) ? scrH : 0;
break;
}
}
int main(void) {
srand(time(NULL));
+ astr_dirs = (Vector4**)malloc(sizeof(Vector4*) * 4);
+ astr_dirs[0] = &NE;
+ astr_dirs[1] = &NW;
+ astr_dirs[2] = &SE;
+ astr_dirs[3] = &SW;
InitWindow(scrW, scrH, "Assteroids Raylib");
SetTargetFPS(50);
if(IsKeyPressed('K')) {
spawn_astr();
}
+ if(IsKeyPressed('R') && !ship_alive) {
+ init_ship();
+ spin_ship(0);
+ }
if(!onscreen(flatten(center)))
die();
flatten(translate(port, center)),
flatten(translate(starboard, center)),
RAYWHITE);
+ astr_spawner = rand() & 1000 + 1;
+ if(throttle && astr_spawner > 989) {
+ spawn_astr();
+ }
update_bullets();
update_astrs();
} else {
CloseWindow();
free(bullets);
free(asteroids);
-
+
return 0;
}