-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.c
138 lines (121 loc) · 3.43 KB
/
init.c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "init.h"
#include "struct_pool.h"
#include "proj.h"
#include "collision.h"
///C stuff.
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <time.h>
#else
#include <sys/time.h>
#endif
//Allegro stuff.
#include <allegro5/allegro.h>
#include <allegro5/allegro_image.h>
void init_random()
{
//struct timeval tv;
//gettimeofday(&tv, NULL);
//Seeding with microseconds.
//You can re-seed rapidly without getting the same results.
srand(time(NULL));
}
int init_stuff()
{
int collision_array_width;
int collision_array_height;
init_random();
if(!al_init())
{
fprintf(stderr, "Failed to initialize allegro!\n");
return -1;
}
if(!al_install_keyboard())
{
fprintf(stderr, "Failed to initialize the keyboard!\n");
return -1;
}
timer = al_create_timer(1.0 / FPS);
if(!timer)
{
fprintf(stderr, "Failed to create timer!\n");
return -1;
}
if(!al_init_image_addon())
{
fprintf(stderr, "Failed to initialize al_init_image_addon!\n");
return -1;
}
display = al_create_display(SCREEN_W, SCREEN_H);
if(!display)
{
fprintf(stderr, "Failed to create display!\n");
al_destroy_timer(timer);
return -1;
}
ship = init_proj();
ship->kind = SHIP;
ship->health = 100;
ship->offsetX = 26;
ship->offsetY = 22;
ship->sizeX = 45;
ship->sizeY = 7;
//Setup the ship's laser pool.
sl_pool = init_smartItemPool(PROJ_POOL_SIZE, (void *(*)())&init_proj);
for (i = 0; i < sl_pool->poolsize; i++) {
PROJP tmp = (PROJP)sl_pool->pool[i];
tmp->kind = BOLT;
tmp->sizeX = 50;
tmp->sizeY = 20;
}
//Setup some asteroids for test purposes.
ast_pool = init_smartItemPool(AST_POOL_SIZE, (void *(*)())&init_proj);
for (i = 0; i < ast_pool->poolsize; i++) {
PROJP tmp = (PROJP)ast_pool->pool[i];
tmp->kind = ASTEROID;
tmp->offsetX = 6;
tmp->offsetY = 7;
tmp->sizeX = 12;
tmp->sizeY = 12;
}
//Setup the pool of "particle" effects.
blast_pool = init_smartItemPool(PROJ_POOL_SIZE, (void *(*)())&init_proj);
for (i = 0; i < blast_pool->poolsize; i++) {
PROJP tmp = (PROJP)blast_pool->pool[i];
tmp->kind = BLAST;
tmp->health = 36;
tmp->animFrame = 0;
}
//Setup the enemy pool.
enemy_pool = init_smartItemPool(ENEMY_POOL_SIZE, (void *(*)())&init_proj);
for (i = 0; i < enemy_pool->poolsize; i++) {
PROJP tmp = (PROJP)enemy_pool->pool[i];
tmp->kind = ENEMY;
tmp->health = 5;
tmp->animFrame = 0;
}
//Setup the enemy bolt pool.
enemy_bolt_pool = init_smartItemPool(ENEMY_BOLT_POOL_SIZE, (void *(*)())&init_proj);
for (i = 0; i < enemy_bolt_pool->poolsize; i++) {
PROJP tmp = (PROJP)enemy_bolt_pool->pool[i];
tmp->kind = ENEMYBOLT;
tmp->health = 1;
tmp->animFrame = 0;
}
//The +1 is for the ship projectile, the *4 is for the 4 corners of each projectile.
node_pool = init_smartItemPool((AST_POOL_SIZE + PROJ_POOL_SIZE + ENEMY_POOL_SIZE + ENEMY_BOLT_POOL_SIZE + 1) * 4, (void *(*)())&init_node);
// Set initial backdrop y position because this can't be done in the definitions C file beause reasons
backdropy = (SCREEN_H - BACKDROP_H) / 2;
// More "non-const" initialization??
ship_cooldown = SHOT_COOLDOWN_MAX;
ast_cooldown = AST_COOLDOWN_MAX;
// Set up collision array
collision_array_width = (SCREEN_W / 100);
collision_array_height = (SCREEN_H / 100);
collision_array = (COLLBOX **)malloc(collision_array_width*sizeof(COLLBOX *));
for(i = 0; i < collision_array_width; i++)
collision_array[i] = (COLLBOX *)malloc(collision_array_height*sizeof(COLLBOX));
//Return 0 if everything went okay.
return 0;
}