-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemy.c
More file actions
44 lines (36 loc) · 1.05 KB
/
enemy.c
File metadata and controls
44 lines (36 loc) · 1.05 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
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "enemy.h"
Enemy* createEnemy(Position myPosition, Dimension myDimension, int precision) {
Enemy *newEnemy = malloc(sizeof (Enemy));
newEnemy->life = 100;
newEnemy->position = myPosition;
newEnemy->dimension = myDimension;
newEnemy->precision = precision;
return newEnemy;
}
void killEnemy(Enemy* dead) {
free(dead);
}
Shot* shootFromEnemy(Position enemyP, Position shipP, int power) {
Shot* newShot;
Position shotP = enemyP;
Velocity shotV;
shotV.x = shipP.x - enemyP.x;
shotV.y = shipP.y - enemyP.y;
shotV.z = -1 * sqrt(ENEMY_SHOT_VELOCITY * ENEMY_SHOT_VELOCITY - shotV.x * shotV.x - shotV.y * shotV.y);
newShot = createShot(shotP, shotV, power);
return newShot;
}
BOOL shouldShoot(Position shipP, Position enemyP) {
if (distance(shipP, enemyP) < SHOOTABLE_DISTANCE)
return TRUE;
return FALSE;
}
void gotShotEnemy(Enemy* en, int damage) {
en->life -= damage;
}
BOOL isEnemyAlive(Enemy* en) {
return en->life > 0;
}