aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-10-11 18:54:50 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-10-11 18:54:50 -0600
commitbbb2c70cd1a0603d57d0fc7615ad8994bfaf39bc (patch)
tree903a18ad8e33f240a278401fa7114b86f5733dc1
parent720467f4b295d86aac8acb75c78822c21fcba281 (diff)
Made player gun a bit better
-rw-r--r--src/entities/antifaShip.c49
-rw-r--r--src/entities/antifaShip.h5
-rw-r--r--src/entities/generale.c2
-rw-r--r--src/levels/level1.c2
-rw-r--r--src/settings.c2
5 files changed, 46 insertions, 14 deletions
diff --git a/src/entities/antifaShip.c b/src/entities/antifaShip.c
index e7f6d91..cf63698 100644
--- a/src/entities/antifaShip.c
+++ b/src/entities/antifaShip.c
@@ -30,6 +30,7 @@ void initAntifaShip(Entity * entity, Game * game) {
data->lastMouse = GetMousePosition();
data->forwardSpeed = 0.0;
data->shouldInitMousePosition = true;
+ data->timeSinceLastBullet = GetTime();
}
void closeAntifaShip(Entity * entity) {
@@ -40,6 +41,31 @@ void closeAntifaShip(Entity * entity) {
entityFreeCollisionModel(entity->transformedCollisionModel);
}
+// This fucker will fire a bullet!!!
+void fireBulletAntifa(Game * game, Entity * entity) {
+ double t = GetTime();
+ AntifaShip * data = (AntifaShip*)entity->data;
+
+ // Let it cool down.
+ if (t - data->timeSinceLastBullet < ANTIFA_BULLET_COOLDOWN)
+ return;
+
+ puts("shoot shoot");
+
+ Bullet bullet = createBulletFromEntity(*entity, 1.0);
+ BulletHitInfo info = shootBullet(&game->world, bullet);
+ data->lastBulletShot = bullet;
+
+ if (info.hit) {
+ Entity * hitEntity = getEntityFromWorld(game->world, info.hitId);
+ printVector3(hitEntity->position);
+ } else {
+ puts("you stink");
+ }
+
+ data->timeSinceLastBullet = t;
+}
+
void controlAntifaShipJoystick(Game * game, Entity * entity) {
Settings settings = game->settings;
int gamePadNum = settings.gamePadNum;
@@ -51,17 +77,8 @@ void controlAntifaShipJoystick(Game * game, Entity * entity) {
float speedStick = GetGamepadAxisMovement(gamePadNum, settings.speedStick);
// Shoot button.
- if (IsGamepadButtonPressed(gamePadNum, 8)) {
- Bullet bullet = createBulletFromEntity(*entity, 1.0);
- BulletHitInfo info = shootBullet(&game->world, bullet);
-
- if (info.hit) {
- Entity * hitEntity = getEntityFromWorld(game->world, info.hitId);
- printVector3(hitEntity->position);
- } else {
- puts("no stink");
- }
- }
+ if (IsGamepadButtonPressed(gamePadNum, 8))
+ fireBulletAntifa(game, entity);
Vector3 stick = (Vector3){
pitchStick,
@@ -85,6 +102,10 @@ void controlAntifaShipKeyboardAndMouse(Game * game, Entity * entity) {
data->lastMouse = Vector2Zero();
}
+ // Shoot bullet.
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
+ fireBulletAntifa(game, entity);
+
// Get mouse values.
Vector2 mouse = GetMousePosition();
float speed = GetMouseWheelMove();
@@ -134,4 +155,10 @@ void updateAntifaShip(Game * game, Entity * entity) {
void drawAntifaShip(Game * game, Entity * entity) {
entityDraw(entity);
+
+ // Draw bullet.
+ AntifaShip * data = (AntifaShip*)entity->data;
+
+ if (GetTime() - data->timeSinceLastBullet <= ANTIFA_DRAW_BULLET_FOR)
+ DrawRay(data->lastBulletShot.ray, BLUE);
}
diff --git a/src/entities/antifaShip.h b/src/entities/antifaShip.h
index e9c78bd..460fe38 100644
--- a/src/entities/antifaShip.h
+++ b/src/entities/antifaShip.h
@@ -1,15 +1,20 @@
#include "gameCommon.h"
#include "entity.h"
+#include "bullets.h"
#ifndef ANTIFA_SHIP_H
#define ANTIFA_SHIP_H
#define ANTIFA_SHIP_MAX_SPEED 200.0
+#define ANTIFA_BULLET_COOLDOWN 0.5
+#define ANTIFA_DRAW_BULLET_FOR 0.05
typedef struct AntifaShip {
Vector2 lastMouse;
float forwardSpeed;
bool shouldInitMousePosition;
+ double timeSinceLastBullet;
+ Bullet lastBulletShot;
} AntifaShip;
void initAntifaShip(Entity * entity, Game * game);
diff --git a/src/entities/generale.c b/src/entities/generale.c
index 3cf9854..dff04be 100644
--- a/src/entities/generale.c
+++ b/src/entities/generale.c
@@ -75,7 +75,7 @@ void updateGeneraleLaser(Game * game, Entity * entity) {
if (collision.hit)
player->health -= t * GENERALE_LASER_DAMAGE;
- printf("%d\n", collision.hit);
+ //printf("%d\n", collision.hit);
}
void drawGeneraleLaser(Entity * entity) {
diff --git a/src/levels/level1.c b/src/levels/level1.c
index 67fb91d..f182ccf 100644
--- a/src/levels/level1.c
+++ b/src/levels/level1.c
@@ -6,7 +6,7 @@
void initLevel1(Game * game, Levels * levels) {
WorldEntry entries[2] = {
(WorldEntry){ENTITY_ANTIFA, (Vector3){0.0, 0.0, 0.0}, QuaternionIdentity()},
- (WorldEntry){ENTITY_GENERALE, (Vector3){0.0, 0.0, 10.0}, QuaternionIdentity()}
+ (WorldEntry){ENTITY_SOLDATO, (Vector3){0.0, 0.0, 10.0}, QuaternionIdentity()}
};
addEntriesToWorld(
diff --git a/src/settings.c b/src/settings.c
index 391169b..b5614f1 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -12,7 +12,7 @@ void initSettings(Settings * settings) {
.rollStick = 2,
.speedStick = 3,
.joystickSensitivity = 0.5,
- .fps = 60,
+ .fps = 0,
.drawFps = true
};
}