-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
188 lines (139 loc) · 3.65 KB
/
main.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include "task.h"
#include "util.h"
#define W 800
#define H 600
void init_attr(void){
pthread_condattr_t ca;
pthread_mutexattr_t ma;
pthread_condattr_init(&ca);
pthread_mutexattr_init(&ma);
pthread_cond_init(&palla.ready, &ca);
pthread_mutex_init(&palla.m, &ma);
pthread_mutex_init(&portiere.m, &ma);
pthread_mutex_init(&freccia.m, &ma);
pthread_mutex_init(&potenza.m, &ma);
}
void init_freccia(void){
// da aggiustare
freccia.x = -RAGGIO_FRECCIA;
freccia.y = 0;
freccia.dir_chosen = 0;
freccia.angle = M_PI;
}
void init_barra_indicatore(void){
barra_b = load_bitmap("img/barra_p.bmp", NULL);
if(barra_b == NULL){
printf("barra file not found\n");
exit(1);
}
potenza.pot = 0;
potenza.barra.x = campo.border_x.up - barra_b->w - 40;
potenza.barra.y = campo.border_y.up - barra_b->h;
draw_sprite(screen, barra_b, potenza.barra.x, potenza.barra.y);
indicatore_b = load_bitmap("img/indicatore_p.bmp", NULL);
if(indicatore_b == NULL){
printf("indicatore file not found\n");
exit(1);
}
potenza.indicatore.x = potenza.barra.x + barra_b->w;
potenza.indicatore.y = potenza.barra.y + barra_b->h - 31;
draw_sprite(screen, indicatore_b, potenza.indicatore.x, potenza.indicatore.y);
}
void init_bground(void){
BITMAP *tmp;
int w = 750;
int h = 520;
int x, y;
bground_b = create_bitmap(w, h);
tmp = load_bitmap("img/campo.bmp", NULL);
if(tmp == NULL){
printf("background file not found\n");
exit(1);
}
x = SCREEN_W/2 - bground_b->w/2;
y = SCREEN_H - bground_b->h - 10;
stretch_sprite(bground_b, tmp, 0, 0, w, h);
blit(bground_b, screen, 0, 0, x, y, SCREEN_W, SCREEN_H);
campo.border_x.low = x;
campo.border_x.up = campo.border_x.low + bground_b->w;
campo.border_y.low = y;
campo.border_y.up = campo.border_y.low + bground_b->h;
}
void init_portiere(void){
// size di portiere_p : 100x100
int x, y;
portiere_b = load_bitmap("img/portiere_p.bmp", NULL);
if(portiere_b == NULL){
printf("portiere file not found\n");
exit(1);
}
x = SCREEN_W/2 - portiere_b->w/2;
y = SCREEN_H - bground_b->h - 10;
draw_sprite(screen, portiere_b, x, y);
portiere.pos.x = center_x(portiere_b, x);
portiere.pos.y = center_y(portiere_b, y);
portiere.dir = 0;
}
void init_palla(void){
// size di palla_p : 40x40
int x, y;
palla_b = load_bitmap("img/palla_p.bmp", NULL);
if(palla_b == NULL){
printf("palla file not found\n");
exit(1);
}
x = SCREEN_W/2 - palla_b->w/2;
y = SCREEN_H/2 + 120;
draw_sprite(screen, palla_b, x, y);
palla.pos.x = center_x(palla_b, x);
palla.pos.y = center_y(palla_b, y);
palla.v.x = 0;
palla.v.y = 0;
}
void init_porta(void){
BITMAP *tmp;
int w = 350;
int h = 50;
int bground_y = SCREEN_H - bground_b->h - 10;
tmp = load_bitmap("img/porta.bmp", NULL);
if(tmp == NULL){
printf("porta file not found\n");
exit(1);
}
porta_b = create_bitmap(w, h);
stretch_sprite(porta_b, tmp, 0, 0, w, h);
porta.pos.x = SCREEN_W/2 - porta_b->w/2;
porta.pos.y = bground_y - porta_b->h;
blit(porta_b, screen, 0, 0, porta.pos.x,
porta.pos.y,
SCREEN_W, SCREEN_H);
portiere.border.low = SCREEN_W/2 - porta_b->w/2;
portiere.border.up = portiere.border.low + porta_b->w;
}
void init(void){
allegro_init();
install_keyboard();
set_color_depth(desktop_color_depth());
set_gfx_mode(GFX_AUTODETECT_WINDOWED, W, H, 0, 0);
init_bground();
init_portiere();
init_palla();
init_porta();
init_barra_indicatore();
init_freccia();
init_attr(); //init mutex e cond variables
init_tasks();
}
void stop(void){
//destroy_bitmap(); // automatic action
allegro_exit();
}
int main(void){
init();
while(!key[KEY_ESC]){}
stop();
return 0;
}