-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some changes for compilance with c99
- Loading branch information
Santurysim
committed
Nov 5, 2018
1 parent
ada5b79
commit 831f03f
Showing
13 changed files
with
152 additions
and
109 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
CFLAGS =-Wall -Wextra -I ./include -g | ||
CFLAGS =-Wall -Wextra -I ./include -g -std=c99 | ||
LIBS=`pkg-config --cflags --libs allegro-5 allegro_primitives-5` | ||
|
||
/bin/blasteroids: obj/blast.o obj/spaceship.o obj/asteroid.o obj/blasteroids.o | ||
gcc $^ -lm $(CFLAGS) `pkg-config --cflags --libs allegro-5 allegro_primitives-5` -o bin/blasteroids | ||
echo "./blasteroids" > ./bin/run.sh && chmod 777 ./bin/run.sh | ||
bin/blasteroids: obj/blast.o obj/spaceship.o obj/asteroid.o obj/blasteroids.o | ||
gcc $^ -lm $(CFLAGS) $(LIBS) -o bin/blasteroids | ||
printf "#!/bin/sh\n./blasteroids" > ./bin/run.sh && chmod 777 ./bin/run.sh #Temp script for opening the game from Nautilus since it thinks that game is a shared lib | ||
|
||
obj/%.o: src/%.c | ||
gcc -c $^ $(CFLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef BLASTEROIDS_LINKED_LIST | ||
#define BLASTEROIDS_LINKED_LIST | ||
#include "blast.h" | ||
|
||
//Linked list. At this time for blasts | ||
|
||
typedef struct Node{ | ||
Blast *data; | ||
Node *next; | ||
Node *previous; | ||
} Node; | ||
|
||
typedef struct LinkedList{ | ||
int size; | ||
Node *begin; | ||
Node* end; | ||
} LinkedList; | ||
|
||
LinkedList* create_linked_list(); | ||
|
||
Node* insert_new_node(LinkedList* list, Node* before); | ||
|
||
Node* add_new_node(LinkedList* list); | ||
|
||
void delete_node(LinkedList* list, Node* which); | ||
|
||
void destroy_list(LinkedList* list); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,92 @@ | ||
#include "blasteroids.h" | ||
#include <stdio.h> | ||
|
||
int main(/*int argc, char const *argv[]*/) { | ||
al_init(); | ||
al_init_primitives_addon(); | ||
al_install_keyboard(); | ||
ALLEGRO_DISPLAY* display = al_create_display(800, 640); | ||
al_clear_to_color(al_map_rgba(0,0,0,255)); | ||
al_flip_display(); | ||
int main(void) { | ||
ALLEGRO_DISPLAY *display; | ||
int display_width, display_height; | ||
Spaceship s; | ||
ALLEGRO_EVENT_QUEUE *q; | ||
ALLEGRO_TIMER *timer; | ||
ALLEGRO_EVENT event; | ||
|
||
int display_width = al_get_display_width(display); | ||
int display_height = al_get_display_height(display); | ||
al_init(); | ||
al_init_primitives_addon(); | ||
al_install_keyboard(); | ||
display = al_create_display(800, 640); | ||
al_clear_to_color(al_map_rgba(0,0,0,255)); | ||
al_flip_display(); | ||
|
||
Spaceship s; | ||
s.x = display_width/2; | ||
s.y = display_height/2; | ||
s.rotation = M_PI; | ||
display_width = al_get_display_width(display); | ||
display_height = al_get_display_height(display); | ||
|
||
s.rotating = 0; | ||
s.speed = 0; | ||
s.accelerating = 0; | ||
s.lifes = 3; | ||
s.color = al_map_rgb(255,255,255); | ||
s.x = display_width/2; | ||
s.y = display_height/2; | ||
s.rotation = M_PI; | ||
|
||
ALLEGRO_EVENT_QUEUE *q = al_create_event_queue(); | ||
al_register_event_source(q, al_get_keyboard_event_source()); | ||
ALLEGRO_TIMER *timer = al_create_timer(1.0f/FPS); | ||
al_register_event_source(q, al_get_timer_event_source(timer)); | ||
ALLEGRO_EVENT event; | ||
al_start_timer(timer); | ||
while (true) { | ||
al_wait_for_event(q, &event); | ||
if(event.type == ALLEGRO_EVENT_KEY_DOWN){ | ||
switch (event.keyboard.keycode) { | ||
case ALLEGRO_KEY_LEFT: | ||
s.rotating = 1; | ||
break; | ||
case ALLEGRO_KEY_RIGHT: | ||
s.rotating = -1; | ||
break; | ||
case ALLEGRO_KEY_UP: | ||
s.accelerating = 1; | ||
break; | ||
case ALLEGRO_KEY_DOWN: | ||
s.accelerating = -1; | ||
break; | ||
case ALLEGRO_KEY_SPACE: | ||
//TODO | ||
break; | ||
} | ||
}else if(event.type == ALLEGRO_EVENT_KEY_UP){ | ||
switch (event.keyboard.keycode) { | ||
case ALLEGRO_KEY_LEFT: //fall through | ||
case ALLEGRO_KEY_RIGHT: | ||
s.rotating = 0; | ||
break; | ||
case ALLEGRO_KEY_UP: //fall through | ||
case ALLEGRO_KEY_DOWN: | ||
s.accelerating = 0; | ||
break; | ||
case ALLEGRO_KEY_SPACE: | ||
//TODO | ||
break; | ||
} | ||
}else if (event.type == ALLEGRO_EVENT_TIMER){ | ||
//Redraw scene, ... | ||
al_clear_to_color(al_map_rgb(0,0,0)); | ||
draw_spaceship(&s); | ||
al_flip_display(); | ||
s.rotating = 0; | ||
s.speed = 0; | ||
s.accelerating = 0; | ||
s.lifes = 3; | ||
s.color = al_map_rgb(255,255,255); | ||
|
||
q = al_create_event_queue(); | ||
al_register_event_source(q, al_get_keyboard_event_source()); | ||
timer = al_create_timer(1.0f/FPS); | ||
al_register_event_source(q, al_get_timer_event_source(timer)); | ||
al_start_timer(timer); | ||
while (true) { | ||
al_wait_for_event(q, &event); | ||
if(event.type == ALLEGRO_EVENT_KEY_DOWN){ | ||
switch (event.keyboard.keycode) { | ||
case ALLEGRO_KEY_LEFT: | ||
s.rotating = 1; | ||
break; | ||
case ALLEGRO_KEY_RIGHT: | ||
s.rotating = -1; | ||
break; | ||
case ALLEGRO_KEY_UP: | ||
s.accelerating = 1; | ||
break; | ||
case ALLEGRO_KEY_DOWN: | ||
s.accelerating = -1; | ||
break; | ||
case ALLEGRO_KEY_SPACE: | ||
//TODO | ||
break; | ||
} | ||
}else if(event.type == ALLEGRO_EVENT_KEY_UP){ | ||
switch (event.keyboard.keycode) { //TODO: need to get adequate input. Considering using multiple threads | ||
case ALLEGRO_KEY_LEFT: //fall through | ||
case ALLEGRO_KEY_RIGHT: | ||
s.rotating = 0; | ||
break; | ||
case ALLEGRO_KEY_UP: //fall through | ||
case ALLEGRO_KEY_DOWN: | ||
s.accelerating = 0; | ||
break; | ||
case ALLEGRO_KEY_SPACE: | ||
//TODO | ||
break; | ||
} | ||
}else if (event.type == ALLEGRO_EVENT_TIMER){ | ||
//Redraw scene, ... | ||
al_clear_to_color(al_map_rgb(0,0,0)); | ||
draw_spaceship(&s); | ||
al_flip_display(); | ||
|
||
//... then compute physics | ||
//s.rotation += SPACESHIP_ANGULAR_VELOCITY*s.rotating/FPS; | ||
s.rotation = repeat(s.rotation + SPACESHIP_ANGULAR_VELOCITY*s.rotating/FPS, 2*M_PI); | ||
s.speed = clamp(s.speed + SPACESHIP_ACCELERATION*s.accelerating*(1.0f/FPS), SPACESHIP_MIN_SPEED, SPACESHIP_MAX_SPEED); | ||
//... then compute physics | ||
//s.rotation += SPACESHIP_ANGULAR_VELOCITY*s.rotating/FPS; | ||
s.rotation = fmod(s.rotation + SPACESHIP_ANGULAR_VELOCITY*s.rotating/FPS, 2*M_PI); | ||
s.speed = clamp(s.speed + SPACESHIP_ACCELERATION*s.accelerating*(1.0f/FPS), SPACESHIP_MIN_SPEED, SPACESHIP_MAX_SPEED); | ||
|
||
s.x = clamp(s.x + s.speed*sin(s.rotation)*(1.0f/FPS), 0, (float)display_width); | ||
s.y = clamp(s.y + s.speed*cos(s.rotation)*(1.0f/FPS), 0, (float)display_height); | ||
s.x = clamp(s.x + s.speed*sin(s.rotation)*(1.0f/FPS), 0, (float)display_width); | ||
s.y = clamp(s.y + s.speed*cos(s.rotation)*(1.0f/FPS), 0, (float)display_height); | ||
} | ||
} | ||
} | ||
return 0; | ||
return 0; | ||
} | ||
|
||
float clamp(float val, float min_val, float max_val){ | ||
if(val > max_val) val = max_val; | ||
else if(val < min_val) val = min_val; | ||
return val; | ||
} | ||
|
||
float repeat(float val, float module){ | ||
if(val < 0) val += module; | ||
else if(val > module) val -= module; | ||
return val; | ||
if(val > max_val) val = max_val; | ||
else if(val < min_val) val = min_val; | ||
return val; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "linkedlist.h" | ||
#include<stdlib.h> | ||
|
||
LinkedList* create_linked_list(){ | ||
LinkedList* list = malloc(sizeof(LinkedList)); | ||
list->size = 0; | ||
list->begin = NULL; | ||
list->end = NULL; | ||
return list; | ||
} | ||
|
||
Node* add_new_node(LinkedList* list){ | ||
Node* new_node = malloc(sizeof(Node)); | ||
new_node->data = NULL; | ||
new_node->next = NULL; | ||
new_node->previous = list->end; | ||
if(list->size == 0){ | ||
list->start = new_node; | ||
list->end = new_node; | ||
} else list->end->next = new_node; | ||
list->size += 1; | ||
return new_node; | ||
} | ||
|
||
Node* insert_new_node(LinkedList* list, Node* before){ | ||
Node* new_node = malloc(sizeof(Node)); | ||
new_node->data = NULL; | ||
new_node->next = before; | ||
} |
Empty file.