-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.c
More file actions
66 lines (54 loc) · 1.41 KB
/
Copy pathgame.c
File metadata and controls
66 lines (54 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdlib.h>
#include <math.h>
#include "game.h"
Game* game_new(int resX, int resY) {
Game* game = malloc(sizeof(Game));
game->resolution.x = resX;
game->resolution.y = resY;
game->lives = 3;
game->objects = list_new();
game->ship = object_new(Spaceship, game->resolution);
list_add(game->objects, game->ship);
int i;
for (i = 0; i < 5; i++) {
list_add(game->objects, object_new(Asteroid, game->resolution));
}
return game;
}
void game_draw(Game* game) {
Object* o;
for(o = list_next(game->objects); o != NULL; o = list_next(game->objects)) {
object_draw(o, game->resolution);
}
}
void game_move(Game* game) {
Object* o;
for(o = list_next(game->objects); o != NULL; o = list_next(game->objects)) {
object_move(o, game->objects, game->resolution);
}
}
void ship_rotate(Object* o, int direction) {
o->velocity.r = (float)direction;
}
void ship_accelerate(Object* o, float direction) {
o->acceleration.x = direction * 0.05 * sinf(o->position.r);
o->acceleration.y = direction * 0.05 * cosf(o->position.r);
}
void game_delete() {
return;
//TODO
/*
list_reset(game->objects);
Object* o;
for(o = list_next(game->objects); o != NULL; o = list_next(game->objects))
delete_object(o);
delete_list(game->objects);
free(game);
*/
}
/*
void accelerate_object(Object* o, float linear) {
o->acceleration.x = linear * sinf(o->position.r);
o->acceleration.y = linear * cosf(o->position.r);
}
*/