-
Notifications
You must be signed in to change notification settings - Fork 2
/
Nave.c
87 lines (75 loc) · 1.99 KB
/
Nave.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
#include <stdlib.h>
#include <math.h>
#include "Nave.h"
#include "Tiro.h"
#include "Cenario.h"
#include "general.h"
#include "teste_nave.h"
Ship *ship;
void initShip()
{
ship = mallocSafe(sizeof(Ship));
ship->hp = INITIAL_HP;
ship->vidas = 3;
ship->score = 0;
ship->speed = INITIAL_SPEED;
ship->position = initPoint(INITIAL_HPOS, INITIAL_HEIGHT, INITIAL_SPOS);
ship->orientation = initPoint(0.0, 0.0, 1.0);/*direcao do comeco*/
ship->attackType = NORMAL;
}
int isShipDestroyed()
{
return ship->hp <= 0;
}
void shipShoot()
{
Point *position = initPoint(ship->position->x, ship->position->y, ship->position->z + 2*EPSILON);
Point *orientation = initPoint(ship->orientation->x, ship->orientation->y, ship->orientation->z);
includeTiro(initTiro(position, orientation, NORMAL, NAVE));
}
void shipGotHit(int dmg)
{
ship->hp -= dmg;
}
void reviveShip()
{
ship->hp = INITIAL_HP;
ship->vidas -= 1;
ship->speed = INITIAL_SPEED;
ship->position = initPoint(INITIAL_HPOS, INITIAL_HEIGHT, INITIAL_SPOS);
ship->orientation = initPoint(0.0, 0.0,20.0);/*direcao do comeco*/
ship->attackType = NORMAL;
}
void collisionsShip(){
nodeTiro *at = tiroList;
nodeTiro *t = at->next;
while (t != NULL) {
/*criar um campo position para a nave*/
if (t->tiro->source == DEFESA && collision(t->tiro->position, 0.15, ship->position, 3.5)) {
if (!forceField) shipGotHit(t->tiro->shotPower);
at->next = t->next;
freeTiro(t->tiro);
free(t);
t = at->next;
at = t;
if (t != NULL) t = t->next;
}
else {
at = t;
if (t != NULL) t = t->next;
}
if (isShipDestroyed()) reviveShip();
}
}
int updateShip()
{
Point *p, *q;
collisionsShip();/*Checa colisão nave<=>tiro*/
return TRUE;
}
void freeShip()
{
free(ship->orientation);
free(ship->position);
free(ship);
}