aboutsummaryrefslogtreecommitdiff
path: root/src/entities
diff options
context:
space:
mode:
authornathansmithsmith <thenathansmithsmith@gmail.com>2023-07-18 05:54:30 -0600
committernathansmithsmith <thenathansmithsmith@gmail.com>2023-07-18 05:54:30 -0600
commitf3f5fedbf591c10fa675a32103bab9480b42abe8 (patch)
tree54b46a23279cc45091393762c0d01b9c3637b729 /src/entities
parent77a06748f9f394486cad833e2ca351e8dbcc7361 (diff)
Bullet system added
Diffstat (limited to 'src/entities')
-rw-r--r--src/entities/antifaShip.c20
-rw-r--r--src/entities/soldato.c23
-rw-r--r--src/entities/soldato.h2
3 files changed, 34 insertions, 11 deletions
diff --git a/src/entities/antifaShip.c b/src/entities/antifaShip.c
index c2e292a..2d58510 100644
--- a/src/entities/antifaShip.c
+++ b/src/entities/antifaShip.c
@@ -1,8 +1,7 @@
#include "antifaShip.h"
#include "game.h"
#include "settings.h"
-
-// TODO: Get rid of some magic numbers.
+#include "bullets.h"
void initAntifaShip(Entity * entity, Game * game) {
entity->model = &game->assets.models[ANTIFA_SHIP_ASSET];
@@ -43,6 +42,23 @@ void controlAntifaShipJoystick(Game * game, Entity * entity) {
float rollStick = GetGamepadAxisMovement(gamePadNum, settings.rollStick);
float speedStick = GetGamepadAxisMovement(gamePadNum, settings.speedStick);
+ // Shoot button.
+ if (IsGamepadButtonPressed(gamePadNum, 8)) {
+ Vector3 dir = Vector3Normalize(Vector3Subtract(
+ getEntityFromWorld(game->world, 1)->position,
+ entity->position
+ ));
+
+ Bullet bullet = createBullet(
+ *entity,
+ dir,
+ Vector3Zero(),
+ 0.1
+ );
+
+ addBullet(&game->bullets, bullet);
+ }
+
Vector3 stick = (Vector3){
pitchStick,
-yawStick,
diff --git a/src/entities/soldato.c b/src/entities/soldato.c
index 30dfa6b..beec40a 100644
--- a/src/entities/soldato.c
+++ b/src/entities/soldato.c
@@ -7,19 +7,19 @@ void initSoldato(Entity * entity, Game * game) {
// Acceleration.
entity->useAcceleration = true;
entity->acceleration = (EntityAcceleration){
- .speedUp = 5.0,
- .speedDown = 0.00001
+ .speedUp = 20.0,
+ .speedDown = 15.0
};
// PID configs.
PIDConfig speedPIDConfig = {
- .kP = -0.5,
+ .kP = 1,
.kI = 0.0,
.kD = 0.0,
.angleMode = false,
.doClamp = true,
.min = 0.0,
- .max = 30.0
+ .max = 100.0
};
// Allocate data.
@@ -31,7 +31,15 @@ void initSoldato(Entity * entity, Game * game) {
}
Soldato * data = (Soldato*)entity->data;
- data->speedPID = createPID(speedPIDConfig);
+
+ // 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) {
@@ -43,11 +51,10 @@ void updateSoldato(Game * game, Entity * entity) {
Entity * player = getEntityFromWorld(game->world, 0);
Soldato * data = (Soldato*)entity->data;
- entityFlightToPoint(
+ entityFlyToPoint(
entity,
player->position,
- &data->speedPID,
- 5.0
+ &data->flyToPoint
);
}
diff --git a/src/entities/soldato.h b/src/entities/soldato.h
index 5123aee..f93206d 100644
--- a/src/entities/soldato.h
+++ b/src/entities/soldato.h
@@ -6,7 +6,7 @@
#define SOLDATO_H
typedef struct Soldato {
- PID speedPID;
+ EntityFlyToPointInfo flyToPoint;
} Soldato;
void initSoldato(Entity * entity, Game * game);