-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.cpp
34 lines (31 loc) · 825 Bytes
/
Enemy.cpp
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
#include "raylib.h"
#include "Enemy.h"
#include "raymath.h"
Enemy::Enemy(Vector2 pos, Texture2D idle_texture, Texture2D run_texture)
{
worldPos = pos;
texture = idle_texture;
idle = idle_texture;
run = run_texture;
width = texture.width / maxFrames;
height = texture.height;
speed = 3.5f;
}
void Enemy::tick(float deltaTime)
{
if (!getAlive())
return;
// get toTarget
velocity = Vector2Subtract(target->getScreenPos(), getScreenPos());
if (Vector2Length(velocity) < radius)
velocity = {};
BaseCharacter::tick(deltaTime);
if (CheckCollisionRecs(target->getCollisionRec(), getCollisionRec()))
{
target->takeDamage(damagePerSec * deltaTime);
}
}
Vector2 Enemy::getScreenPos()
{
return Vector2Subtract(worldPos, target->getWorldPos());
}