aboutsummaryrefslogtreecommitdiff
path: root/src/entities/soldato.c
blob: 74544aae749e36c8989ce1bfb72144ed34822cc6 (plain)
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
#include "soldato.h"
#include "game.h"

void initSoldato(Entity * entity, Game * game) {
	entity->model = &game->assets.models[SOLDATO_ASSET];
	setEntityRadius(entity);

	// Acceleration.
	entity->useAcceleration = true;
	entity->acceleration = (EntityAcceleration){
		.speedUp = 20.0,
		.speedDown = 15.0
	};

	// PID configs.
	PIDConfig speedPIDConfig = {
		.kP = 1,
		.kI = 0.0,
		.kD = 0.0,
		.angleMode = false,
		.doClamp = true,
		.min = 0.0,
		.max = 100.0
	};

	// Allocate data.
	entity->data = KF_MALLOC(sizeof(Soldato));

	if (entity->data == NULL) {
		ALLOCATION_ERROR;
		return;
	}

	Soldato * data = (Soldato*)entity->data;

	// Create fly to point.
	data->flyToPoint = (EntityFlyToPointInfo){
		//.controller.speedPID = createPID(speedPIDConfig),
		.controller.bangbang.speed = 20.0,
		.controller.bangbang.stopAt = 0.0,
		.controlType = ENTITY_FLY_TO_POINT_BANG_BANG,
		.rotationSpeed = 0.0
	};
}

void closeSoldato(Entity * entity) {
	if (entity->data != NULL)
		KF_FREE(entity->data);
}

void updateSoldato(Game * game, Entity * entity) {
	Entity * player = getEntityFromWorld(game->world, 0);
	Soldato * data = (Soldato*)entity->data;

	entityFlyToPoint(
		entity,
		player->position,
		&data->flyToPoint
	);
}

void drawSoldato(Game * game, Entity * entity) {
	entityDraw(entity);
}