-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenergia.c
146 lines (115 loc) · 3.74 KB
/
energia.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
#include <raylib.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "deflib.h"
/*
- ENERGIA:
- Possui todas as funções de geração das células
de energia e utilização das mesmas.
*/
int sorteiaZero(int contFrames) {
int res = 0;
if(contFrames == 0) {
int random = rand()%17;
if(random == 0) {
res = 1;
}
}
return res;
}
void sorteiaPos(Energia energCel[], int end, Jogador player, Rectangle wallRecs[][N_COLUNAS]) {
int screenWidth = GetScreenWidth();
int screenHeight = GetScreenHeight();
int randX, randY;
int lin, col, ok, i;
int cont = 0;
do { // TENTA SORTEAR UMA POSIÇÃO ALEATÓRIA PARA UMA CÉLULA DE ENERGIA 20 VEZES
cont++;
ok = 1;
int shouldBreak = 0;
randX = (int)rand()%(screenWidth - energCel[end].sizeX);
randY = (int)rand()%(screenHeight - energCel[end].sizeY - 100);
Rectangle randPos = {randX, randY, energCel[end].sizeX, energCel[end].sizeY};
// COLISÃO COM O PLAYER
if(CheckCollisionRecs(randPos, (Rectangle){player.x, player.y, player.sizeX, player.sizeY})) {
ok = 0;
}
// COLISÃO COM PAREDES
for(lin = 0; lin < N_LINHAS; lin++) {
for(col = 0; col < N_COLUNAS; col++) {
if(CheckCollisionRecs(randPos, wallRecs[lin][col])) {
ok = 0;
shouldBreak = 1;
break;
}
}
if(shouldBreak)
break;
}
// COLISÃO COM CÉLULAS JÁ EXISTENTES
for(i = 0; i < QUANT_ENERG; i++) {
if(energCel[i].naTela == 1) {
Rectangle celNaTela = {energCel[i].Px, energCel[i].Py,
energCel[i].sizeX, energCel[i].sizeY};
if(CheckCollisionRecs(randPos, celNaTela)) {
ok = 0;
break;
}
}
}
//printf("%d\n", ok);
} while(ok == 0 && cont < 20);
if(cont < 20) {
energCel[end].Px = randX;
energCel[end].Py = randY;
} else {
//printf("Nao coloquei a celula!\n");
energCel[end].naTela = 0;
}
}
void UpdateEnergCels(Energia energCel[], int contFrames,
Jogador player, Rectangle wallRecs[][N_COLUNAS]) {
int end;
if(sorteiaZero(contFrames) == 1){
for(end = 0; end < QUANT_ENERG; end++) {
if(energCel[end].naTela == 0) {
energCel[end].naTela = 1;
break;
}
}
// OBS: NESSE MOMENTO, END POSSUI O PRIMEIRO ENDEREÇO LIVRE DO
// ARRAY DE CÉLULAS DE ENERGIA
if(end < QUANT_ENERG) {
sorteiaPos(energCel, end, player, wallRecs);
}
}
}
// OBS: ESTÁ PROGRAMADA PARA FUNCIONAR APENAS PARA O JOGADOR
// OBS2: NÃO MAIS!!!
void UseEnergCels(Energia energCel[], Jogador *player,
float velIniP, float velIniT) {
int i;
for(i = 0; i < QUANT_ENERG; i++) {
if(energCel[i].naTela == 1) {
if (CheckCollisionRecs(
(Rectangle){energCel[i].Px, energCel[i].Py, energCel[i].sizeX, energCel[i].sizeY},
(Rectangle){player->x, player->y, player->sizeX, player->sizeY})) {
player->timer = 5*60; // 5 segundos
energCel[i].naTela = 0;
}
}
}
// OBS: TIMER É ATUALIZADO EM GAME
if(player->timer > 0) {
player->vel = 1.5*velIniP;
for(i = 0; i < QUANT_TIROS; i++) {
player->tiros[i].vel = 1.5*velIniT;
}
} else {
player->vel = velIniP;
for(i = 0; i < QUANT_TIROS; i++) {
player->tiros[i].vel = velIniT;
}
}
}