This commit is contained in:
shweet 2023-08-16 09:19:53 -04:00
parent 68a202445e
commit 15ff064243
36 changed files with 469 additions and 243 deletions

View File

@ -13,6 +13,9 @@ file(GLOB src
"${PROJECT_SOURCE_DIR}/src/game/*.c"
"${PROJECT_SOURCE_DIR}/src/game/ecs/*.c"
"${PROJECT_SOURCE_DIR}/src/game/ecs/component/*.c"
"${PROJECT_SOURCE_DIR}/src/game/ecs/component/action/*.c"
"${PROJECT_SOURCE_DIR}/src/game/ecs/component/control/*.c"
"${PROJECT_SOURCE_DIR}/src/game/ecs/component/stat/*.c"
"${PROJECT_SOURCE_DIR}/src/game/ecs/entity/*.c"
"${PROJECT_SOURCE_DIR}/src/game/ecs/entity/play/*.c"
"${PROJECT_SOURCE_DIR}/src/game/ecs/entity/play/enemy*.c"

View File

@ -57,10 +57,9 @@ typedef enum OriginType
ORIGIN_CENTER
} OriginType;
#define DIRECTION_COUNT DIRECITON_NORTH_WEST + 1
#define DIRECTION_COUNT DIRECTION_NORTH_WEST + 1
typedef enum Direction
{
DIRECTION_NONE,
DIRECTION_NORTH,
DIRECTION_EAST,
DIRECTION_SOUTH,
@ -73,13 +72,12 @@ typedef enum Direction
static const f32 DIRECTION_ANGLES[DIRECTION_COUNT] =
{
0.0f,
PI + PI_HALF,
PI,
PI - PI_HALF,
PI,
PI + PI_HALF,
0.0f,
TAU - PI_FOURTH,
PI_FOURTH,
PI - PI_FOURTH,
PI + PI_FOURTH
} Direction;
PI + PI_FOURTH,
TAU - PI_FOURTH,
PI_FOURTH
};

View File

@ -8,7 +8,7 @@ fullscreen_set(Window* self, Renderer* renderer)
renderer_update(renderer);
SDL_SetWindowFullscreen(self->sdl, SDL_WINDOW_FULLSCREEN);
SDL_SetWindowFullscreen(self->sdl, SDL_WINDOW_FULLSCREEN_DESKTOP);
}
/* Exits fullscreen. */

View File

@ -59,3 +59,15 @@ mouse_release(Mouse* self, MouseButtonType type)
{
return (!self->current[type] && self->previous[type]);
}
/* Fetches the world position of the cursor. */
void
mouse_world_position_get(Mouse* mouse, Renderer* renderer, vec2 position)
{
vec2 mousePosition;
mousePosition[0] = (f32)mouse->position[0];
mousePosition[1] = (f32)mouse->position[1];
renderer_world_position_from_window_position(renderer, mousePosition, position);
}

View File

@ -2,7 +2,7 @@
#include <SDL2/SDL.h>
#include "../COMMON.h"
#include "renderer.h"
#define MOUSE_BUTTON_COUNT MOUSE_BUTTON_X2 + 1
typedef enum MouseButtonType
@ -26,3 +26,4 @@ void mouse_update(Mouse* self);
bool mouse_press(Mouse* self, MouseButtonType type);
bool mouse_held(Mouse* self, MouseButtonType type);
bool mouse_release(Mouse* self, MouseButtonType type);
void mouse_world_position_get(Mouse* mouse, Renderer* renderer, vec2 position);

View File

@ -100,5 +100,5 @@ renderer_world_position_from_window_position
window_size_get(self->window, windowSize);
rendererPosition[0] = (windowPosition[0] / windowSize[0]) * self->size[0];
rendererPosition[1] = (windowPosition[1] / windowPosition[1]) * self->size[1];
rendererPosition[1] = (windowPosition[1] / windowSize[1]) * self->size[1];
}

View File

@ -7,8 +7,10 @@ typedef enum ECSComponentType
{
ECS_COMPONENT_PHYSICS,
ECS_COMPONENT_SHOOT,
ECS_COMPONENT_RETURN,
ECS_COMPONENT_CONTROL_MOVE,
ECS_COMPONENT_CONTROL_SHOOT,
ECS_COMPONENT_CONTROL_AIM,
ECS_COMPONENT_HEALTH,
ECS_COMPONENT_AMMO,
ECS_COMPONENT_SPRITE,

View File

@ -0,0 +1,36 @@
#include "component_collider.h"
/* DEPENDENCIES: Physics */
/* Sets collider component info. */
void
component_collider_init(ComponentCollider* self, vec2 offset, vec2 size)
{
glm_vec2_copy(size, self->size);
glm_vec2_copy(offset, self->offset);
vector_init(&self->collisions, sizeof(u32);
}
/* Ticks collider component. */
void
component_collider_tick(ComponentCollider* self, ECS* ecs)
{
ComponentPhysics* physics;
vec4 rectangle;
vector_clear(&self->collisions);
ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->id);
rectangle[0] = physics->position[0] + self->offset[0];
rectangle[1] = physics->position[1] + self->offset[1];
rectangle[2] = rectangle[0] + self->size[0];
rectangle[3] = rectangle[1] + self->size[1];
for (s32 i = 0; i < ecs->lists[ECS_COMPONENT_COLLIDER]; i++)
{
}
}

View File

@ -0,0 +1,38 @@
#pragma once
#include "../../../GAME_COMMON.h"
#include "../../ecs_entity.h"
#include "../component_game_object.h"
typedef void (*ProjectileInit)(ECS*, u32, vec3, u32);
typedef struct ComponentShoot
{
u32 id;
ProjectileInit projectileInit;
f32 offset;
f32 speed;
bool isFire;
} ComponentShoot;
void component_shoot_init(ComponentShoot* self, ProjectileInit projectileInit, f32 speed, f32 offset);
void component_shoot_tick(ComponentShoot* self, ECS* ecs);
static const ECSComponentInfo COMPONENT_SHOOT_INFO =
{
.system =
{
.functions =
{
NULL,
NULL,
(ECSFunction)component_shoot_tick,
NULL
}
},
.type = ECS_COMPONENT_SHOOT,
.size = sizeof(ComponentShoot)
};

View File

@ -0,0 +1,45 @@
#include "component_return.h"
/* DEPENDENCIES: Physics */
/* Initializes return component. */
void
component_return_init(ComponentReturn* self, f32 speed, f32 velocityMax, u32 lifetime, u32 senderID)
{
self->speed = speed;
self->velocityMax = velocityMax;
self->lifetime = lifetime;
self->senderID = senderID;
}
/* Ticks return component. */
/* Rapidly accelerates entity towards sender. */
void
component_return_tick(ComponentReturn* self, ECS* ecs)
{
f32 angle;
ComponentPhysics* senderPhysics;
ComponentPhysics* physics;
if (self->lifetime > 0)
{
self->lifetime--;
if (self->lifetime <= 0)
{
physics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->id);
physics->velocityMax = self->velocityMax;
}
return;
}
senderPhysics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->senderID);
physics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->id);
angle = ATAN(physics->position[0], senderPhysics->position[0], physics->position[1], senderPhysics->position[1]);
physics->velocity[0] += cos(angle) * self->speed;
physics->velocity[1] += sin(angle) * self->speed;
}

View File

@ -0,0 +1,36 @@
#pragma once
#include "../../../GAME_COMMON.h"
#include "../../ecs_entity.h"
#include "../component_physics.h"
typedef struct ComponentReturn
{
u32 id;
f32 speed;
f32 velocityMax;
u32 lifetime;
u32 senderID;
} ComponentReturn;
void component_return_init(ComponentReturn* self, f32 speed, f32 velocityMax, u32 lifetime, u32 senderID);
void component_return_tick(ComponentReturn* self, ECS* ecs);
static const ECSComponentInfo COMPONENT_RETURN_INFO =
{
.system =
{
.functions =
{
NULL,
NULL,
(ECSFunction)component_return_tick,
NULL
}
},
.type = ECS_COMPONENT_RETURN,
.size = sizeof(ComponentReturn)
};

View File

@ -7,7 +7,7 @@ void
component_shoot_init
(
ComponentShoot* self,
EntityGameObjectInit projectileInit,
ProjectileInit projectileInit,
f32 speed,
f32 offset
)
@ -23,20 +23,28 @@ component_shoot_tick(ComponentShoot* self, ECS* ecs)
{
if (self->isFire)
{
//ComponentGameObject* gameObject;
ComponentPhysics* physics;
ComponentPhysics* projectilePhysics;
u32 projectile;
vec3 position;
//vec3 velocity;
//gameObject = ecs_component_get(ecs, ECS_COMPONENT_GAME_OBJECT, self->id);
physics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->id);
glm_vec3_copy(physics->position, position);
projectile = ecs_entity_add(ecs);
self->projectileInit(ecs, projectile, position);
physics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->id);
position[0] += -cos(physics->angle) * self->offset;
position[1] += -sin(physics->angle) * self->offset;
glm_vec3_copy(physics->position, position);
self->projectileInit(ecs, projectile, position, self->id);
projectilePhysics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, projectile);
projectilePhysics->angle = physics->angle;
projectilePhysics->velocity[0] = -cos(projectilePhysics->angle) * self->speed;
projectilePhysics->velocity[1] = -sin(projectilePhysics->angle) * self->speed;
self->isFire = false;
}

View File

@ -1,20 +1,22 @@
#pragma once
#include "../../GAME_COMMON.h"
#include "../ecs_entity.h"
#include "../../../GAME_COMMON.h"
#include "../../ecs_entity.h"
#include "component_game_object.h"
#include "../component_game_object.h"
typedef void (*ProjectileInit)(ECS*, u32, vec3, u32);
typedef struct ComponentShoot
{
u32 id;
EntityGameObjectInit projectileInit;
ProjectileInit projectileInit;
f32 offset;
f32 speed;
bool isFire;
} ComponentShoot;
void component_shoot_init(ComponentShoot* self, EntityGameObjectInit projectileInit, f32 speed, f32 offset);
void component_shoot_init(ComponentShoot* self, ProjectileInit projectileInit, f32 speed, f32 offset);
void component_shoot_tick(ComponentShoot* self, ECS* ecs);
static const ECSComponentInfo COMPONENT_SHOOT_INFO =

View File

@ -1,130 +0,0 @@
#include "component_control_move.h"
/* DEPENDENCIES: Physics */
/* Ticks control_move component. */
void
component_control_move_init(ComponentControlMove* self, f32 speed)
{
self->speed = speed;
}
/* Ticks control_move component. */
void
component_control_move_tick(ComponentControlMove* self, ECS* ecs)
{
if
(
input_held(&ecs->game->input, INPUT_LEFT) ||
input_held(&ecs->game->input, INPUT_RIGHT) ||
input_held(&ecs->game->input, INPUT_UP) ||
input_held(&ecs->game->input, INPUT_DOWN)
)
{
ComponentPhysics* physics;
f32 angle;
vec2 velocity;
angle = 0.0f;
physics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->id);
glm_vec2_zero(velocity);
self->previousDirection = self->direction;
self->direction = DIRECTION_NONE;
velocity[0] = 1.0f;
velocity[1] = 0.0f;
glm_vec2_norm(velocity);
glm_vec2_scale(velocity, self->speed, velocity);
if
(
input_held(&ecs->game->input, INPUT_LEFT) &&
input_held(&ecs->game->input, INPUT_UP)
)
{
angle = PI + PI_FOURTH;
self->direction = DIRECTION_NORTH_WEST;
}
else if
(
input_held(&ecs->game->input, INPUT_RIGHT) &&
input_held(&ecs->game->input, INPUT_UP)
)
{
angle = TAU - PI_FOURTH;
self->direction = DIRECTION_NORTH_EAST;
}
else if
(
input_held(&ecs->game->input, INPUT_DOWN) &&
input_held(&ecs->game->input, INPUT_LEFT)
)
{
angle = PI - PI_FOURTH;
self->direction = DIRECTION_SOUTH_WEST;
}
else if
(
input_held(&ecs->game->input, INPUT_DOWN) &&
input_held(&ecs->game->input, INPUT_RIGHT)
)
{
angle = PI_FOURTH;
self->direction = DIRECTION_SOUTH_EAST;
}
else if
(
input_held(&ecs->game->input, INPUT_LEFT) &&
input_held(&ecs->game->input, INPUT_RIGHT)
)
{
if
(
self->direction =
self->previousDirection == INPUT_LEFT
)
{
self->direction = DIRECTION_
}
}
else if (input_held(&ecs->game->input, INPUT_LEFT))
{
angle = PI;
self->direction = DIRECTION_WEST;
}
else if (input_held(&ecs->game->input, INPUT_RIGHT))
{
angle = 0.0f;
self->direction = DIRECTION_EAST;
}
else if (input_held(&ecs->game->input, INPUT_UP))
{
angle = PI + PI_HALF;
self->direction = DIRECTION_NORTH;
}
else if (input_held(&ecs->game->input, INPUT_DOWN))
{
angle = PI - PI_HALF;
self->direction = DIRECTION_SOUTH;
}
if (self->direction == DIRECITON_NORTH)
{
}
else if (self->direction == DIRECTION
glm_vec2_rotate(velocity, angle, velocity);
physics->velocity[0] += velocity[0];
physics->velocity[1] += velocity[1];
}
}

View File

@ -1,17 +0,0 @@
#include "component_control_shoot.h"
/* DEPENDENCIES: Shoot */
/* Ticks control_shoot component. */
void
component_control_shoot_tick(ComponentControlShoot* self, ECS* ecs)
{
if (input_press(&ecs->game->input, INPUT_SHOOT))
{
ComponentShoot* shoot;
shoot = ecs_component_get(ecs, ECS_COMPONENT_SHOOT, self->id);
shoot->isFire = true;
}
}

View File

@ -25,8 +25,6 @@ component_game_object_init
frameSize[0] = (s32)texture.size[0];
frameSize[1] = (s32)texture.size[1];
self->angle = 0.0f;
glm_ivec2_one(atlasSize);
component_game_object_atlas_init
@ -78,12 +76,8 @@ component_game_object_atlas_init
void
component_game_object_add(ComponentGameObject* self, ECS* ecs)
{
ComponentSprite* sprite;
ecs_component_add(ecs, ECS_COMPONENT_PHYSICS, self->id);
sprite = ecs_component_add(ecs, ECS_COMPONENT_SPRITE, self->id);
sprite = ecs_component_get(ecs, ECS_COMPONENT_SPRITE, self->id);
ecs_component_add(ecs, ECS_COMPONENT_SPRITE, self->id);
}
/* Runs on game object add. */

View File

@ -7,12 +7,10 @@
#include "component_sprite.h"
#include "component_physics.h"
typedef void (*EntityGameObjectInit)(ECS*, u32 id, vec3);
typedef struct ComponentGameObject
{
u32 id;
f32 angle;
} ComponentGameObject;
void

View File

@ -10,6 +10,7 @@ typedef struct ComponentPhysics
f32 velocityMax;
vec3 velocity;
vec3 position;
f32 angle;
} ComponentPhysics;
void component_physics_init

View File

@ -0,0 +1,24 @@
#include "component_control_aim.h"
/* DEPENDENCIES: Physics */
/* Ticks control_aim component. Sets facing angle to that of the mouse. */
void
component_control_aim_tick(ComponentControlAim* self, ECS* ecs)
{
ComponentPhysics* physics;
f32 angle;
vec2 position;
mouse_world_position_get(&ecs->game->input.mouse, &ecs->game->renderer, position);
physics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->id);
angle = ATAN(position[0], physics->position[0], position[1], physics->position[1]);
printf("MOUSE POSITION: %f %f\n", position[0], position[1]);
printf("PHYSICS POSITION: %f %f\n", physics->position[0], physics->position[1]);
printf("ANGLE: %f\n", angle);
physics->angle = angle;
}

View File

@ -0,0 +1,31 @@
#pragma once
#include "../../../GAME_COMMON.h"
#include "../../ecs_entity.h"
#include "../../../input/input.h"
#include "../component_physics.h"
typedef struct ComponentControlAim
{
u32 id;
} ComponentControlAim;
void component_control_aim_tick(ComponentControlAim* self, ECS* ecs);
static const ECSComponentInfo COMPONENT_CONTROL_AIM_INFO =
{
.system =
{
.functions =
{
NULL,
NULL,
(ECSFunction)component_control_aim_tick,
NULL
}
},
.type = ECS_COMPONENT_CONTROL_AIM,
.size = sizeof(ComponentControlAim)
};

View File

@ -0,0 +1,77 @@
#include "component_control_move.h"
/* DEPENDENCIES: Physics */
static void _direction_update(ComponentControlMove* self, ECS* ecs);
/* Updates current direction. */
static void
_direction_update(ComponentControlMove* self, ECS* ecs)
{
if
(
input_held(&ecs->game->input, INPUT_LEFT) &&
input_held(&ecs->game->input, INPUT_UP)
)
self->direction = DIRECTION_NORTH_WEST;
else if
(
input_held(&ecs->game->input, INPUT_RIGHT) &&
input_held(&ecs->game->input, INPUT_UP)
)
self->direction = DIRECTION_NORTH_EAST;
else if
(
input_held(&ecs->game->input, INPUT_DOWN) &&
input_held(&ecs->game->input, INPUT_LEFT)
)
self->direction = DIRECTION_SOUTH_WEST;
else if
(
input_held(&ecs->game->input, INPUT_DOWN) &&
input_held(&ecs->game->input, INPUT_RIGHT)
)
self->direction = DIRECTION_SOUTH_EAST;
else if (input_held(&ecs->game->input, INPUT_UP))
self->direction = DIRECTION_NORTH;
else if (input_held(&ecs->game->input, INPUT_DOWN))
self->direction = DIRECTION_SOUTH;
else if (input_held(&ecs->game->input, INPUT_LEFT))
self->direction = DIRECTION_WEST;
else if (input_held(&ecs->game->input, INPUT_RIGHT))
self->direction = DIRECTION_EAST;
}
/* Ticks control_move component. */
void
component_control_move_init(ComponentControlMove* self, f32 speed)
{
self->speed = speed;
}
/* Ticks control_move component. */
void
component_control_move_tick(ComponentControlMove* self, ECS* ecs)
{
if
(
input_held(&ecs->game->input, INPUT_LEFT) ||
input_held(&ecs->game->input, INPUT_RIGHT) ||
input_held(&ecs->game->input, INPUT_UP) ||
input_held(&ecs->game->input, INPUT_DOWN)
)
{
ComponentPhysics* physics;
vec2 delta;
physics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->id);
_direction_update(self, ecs);
delta[0] = -cos(DIRECTION_ANGLES[self->direction]) * self->speed;
delta[1] = -sin(DIRECTION_ANGLES[self->direction]) * self->speed;
physics->velocity[0] += delta[0];
physics->velocity[1] += delta[1];
}
}

View File

@ -1,18 +1,18 @@
#pragma once
#include "../../GAME_COMMON.h"
#include "../ecs_entity.h"
#include "../../../GAME_COMMON.h"
#include "../../ecs_entity.h"
#include "../../../input/input.h"
#include "../../input/input.h"
#include "component_physics.h"
#include "../component_physics.h"
typedef struct ComponentControlMove
{
u32 id;
f32 speed;
Direction direction;
Direction oldDirection;
bool directionInput[DIRECTION_COUNT];
bool previousDirectionInput[DIRECTION_COUNT];
} ComponentControlMove;
void component_control_move_init(ComponentControlMove* self, f32 speed);

View File

@ -0,0 +1,39 @@
#include "component_control_shoot.h"
/* DEPENDENCIES: Shoot, Ammo */
/* Initializes control shoot component. */
void
component_control_shoot_init(ComponentControlShoot* self, u32 delay)
{
self->delayMax = delay;
self->delay = self->delayMax;
}
/* Ticks control_shoot component. */
void
component_control_shoot_tick(ComponentControlShoot* self, ECS* ecs)
{
ComponentAmmo* ammo;
if (self->delay > 0)
{
self->delay--;
return;
}
ammo = ecs_component_get(ecs, ECS_COMPONENT_AMMO, self->id);
if (input_held(&ecs->game->input, INPUT_SHOOT) && !ammo->isOut)
{
ComponentShoot* shoot;
shoot = ecs_component_get(ecs, ECS_COMPONENT_SHOOT, self->id);
shoot->isFire = true;
self->delay = self->delayMax;
ammo->value--;
}
}

View File

@ -1,17 +1,19 @@
#pragma once
#include "../../GAME_COMMON.h"
#include "../ecs_entity.h"
#include "../../input/input.h"
#include "component_shoot.h"
#include "../../../GAME_COMMON.h"
#include "../../ecs_entity.h"
#include "../../../input/input.h"
#include "../action/component_shoot.h"
#include "../stat/component_ammo.h"
typedef struct ComponentControlShoot
{
u32 id;
u32 delayMax;
u32 delay;
} ComponentControlShoot;
void component_control_shoot_init(ComponentControlShoot* self, u32 delay);
void component_control_shoot_tick(ComponentControlShoot* self, ECS* ecs);
static const ECSComponentInfo COMPONENT_CONTROL_SHOOT_INFO =

View File

@ -2,16 +2,18 @@
/* Sets ammo component info. */
void
component_ammo_init(ComponentAmmo* self, u32 ammo)
component_ammo_init(ComponentAmmo* self, u32 max)
{
self->ammoMax = ammo;
self->ammo = self->ammoMax;
self->max = max;
self->value = self->max;
}
/* Ticks ammo component. If ammo is depleted, marks as out. */
void
component_ammo_tick(ComponentAmmo* self, ECS* ecs)
{
if (self->ammo <= 0)
if (self->value <= 0)
self->isOut = true;
else
self->isOut = false;
}

View File

@ -1,17 +1,17 @@
#pragma once
#include "../../GAME_COMMON.h"
#include "../ecs_entity.h"
#include "../../../GAME_COMMON.h"
#include "../../ecs_entity.h"
typedef struct ComponentAmmo
{
u32 id;
u32 ammoMax;
u32 ammo;
u32 max;
u32 value;
bool isOut;
} ComponentAmmo;
void component_ammo_init(ComponentAmmo* self, u32 ammo);
void component_ammo_init(ComponentAmmo* self, u32 max);
void component_ammo_tick(ComponentAmmo* self, ECS* ecs);
static const ECSComponentInfo COMPONENT_AMMO_INFO =

View File

@ -2,16 +2,16 @@
/* Sets health component info. */
void
component_health_init(ComponentHealth* self, u32 health)
component_health_init(ComponentHealth* self, u32 max)
{
self->healthMax = health;
self->health = self->healthMax;
self->max = max;
self->value = self->max;
}
/* Ticks health component. If health is depleted, marked dead. */
void
component_health_tick(ComponentHealth* self, ECS* ecs)
{
if (self->health <= 0)
if (self->value <= 0)
self->isDead = true;
}

View File

@ -1,17 +1,17 @@
#pragma once
#include "../../GAME_COMMON.h"
#include "../ecs_entity.h"
#include "../../../GAME_COMMON.h"
#include "../../ecs_entity.h"
typedef struct ComponentHealth
{
u32 id;
u32 healthMax;
u32 health;
u32 max;
u32 value;
bool isDead;
} ComponentHealth;
void component_health_init(ComponentHealth* self, u32 health);
void component_health_init(ComponentHealth* self, u32 max);
void component_health_tick(ComponentHealth* self, ECS* ecs);
static const ECSComponentInfo COMPONENT_HEALTH_INFO =

View File

@ -1,7 +1,7 @@
#pragma once
#include "../../GAME_COMMON.h"
#include "../ecs_entity.h"
#include "../../../GAME_COMMON.h"
#include "../../ecs_entity.h"
typedef struct ComponentLifetime
{

View File

@ -1,14 +1,16 @@
#pragma once
#include "component/component_ammo.h"
#include "component/component_shoot.h"
#include "component/component_control_shoot.h"
#include "component/component_control_move.h"
#include "component/action/component_shoot.h"
#include "component/action/component_return.h"
#include "component/component_game_object.h"
#include "component/component_health.h"
#include "component/component_lifetime.h"
#include "component/component_physics.h"
#include "component/component_sprite.h"
#include "component/control/component_control_aim.h"
#include "component/control/component_control_move.h"
#include "component/control/component_control_shoot.h"
#include "component/stat/component_ammo.h"
#include "component/stat/component_health.h"
#include "component/stat/component_lifetime.h"
#include "ecs_component.h"
@ -16,8 +18,10 @@ static const ECSComponentInfo ECS_COMPONENT_INFO[ECS_COMPONENT_COUNT] =
{
COMPONENT_PHYSICS_INFO,
COMPONENT_SHOOT_INFO,
COMPONENT_RETURN_INFO,
COMPONENT_CONTROL_MOVE_INFO,
COMPONENT_CONTROL_SHOOT_INFO,
COMPONENT_CONTROL_AIM_INFO,
COMPONENT_HEALTH_INFO,
COMPONENT_AMMO_INFO,
COMPONENT_SPRITE_INFO,

View File

@ -4,15 +4,21 @@
void
entity_player_init(ECS* ecs, u32 id, vec3 position)
{
ComponentGameObject* gameObject;
ComponentAmmo* ammo;
ComponentControlMove* controlMove;
ComponentControlShoot* controlShoot;
ComponentGameObject* gameObject;
ComponentHealth* health;
ComponentShoot* shoot;
gameObject = ecs_component_add(ecs, ECS_COMPONENT_GAME_OBJECT, id);
ammo = ecs_component_add(ecs, ECS_COMPONENT_AMMO, id);
controlMove = ecs_component_add(ecs, ECS_COMPONENT_CONTROL_MOVE, id);
controlShoot = ecs_component_add(ecs, ECS_COMPONENT_CONTROL_SHOOT, id);
gameObject = ecs_component_add(ecs, ECS_COMPONENT_GAME_OBJECT, id);
health = ecs_component_add(ecs, ECS_COMPONENT_HEALTH, id);
shoot = ecs_component_add(ecs, ECS_COMPONENT_SHOOT, id);
ecs_component_add(ecs, ECS_COMPONENT_CONTROL_SHOOT, id);
ecs_component_add(ecs, ECS_COMPONENT_CONTROL_AIM, id);
component_game_object_init
(
@ -33,8 +39,13 @@ entity_player_init(ECS* ecs, u32 id, vec3 position)
component_shoot_init
(
shoot,
(EntityGameObjectInit)entity_snake_init,
(ProjectileInit)entity_snake_init,
PLAYER_SHOOT_SPEED,
PLAYER_SHOOT_OFFSET
);
component_control_shoot_init(controlShoot, PLAYER_CONTROL_SHOOT_DELAY);
component_health_init(health, PLAYER_HEALTH_MAX);
component_ammo_init(ammo, PLAYER_AMMO_MAX);
}

View File

@ -1,11 +1,14 @@
#pragma once
#include "../../ecs_component.h"
#include "../../component/action/component_shoot.h"
#include "../../component/component_game_object.h"
#include "../../component/component_control_move.h"
#include "../../component/component_control_shoot.h"
#include "../../component/component_shoot.h"
#include "../../component/component_lifetime.h"
#include "../../component/control/component_control_aim.h"
#include "../../component/control/component_control_move.h"
#include "../../component/control/component_control_shoot.h"
#include "../../component/stat/component_ammo.h"
#include "../../component/stat/component_health.h"
#include "../../component/stat/component_lifetime.h"
#include "../../ecs_component.h"
#include "entity_snake.h"
@ -14,6 +17,9 @@
#define PLAYER_VELOCITY_MAX 6
#define PLAYER_SHOOT_SPEED 5
#define PLAYER_SHOOT_OFFSET 32
#define PLAYER_CONTROL_SHOOT_DELAY 15
#define PLAYER_AMMO_MAX 1
#define PLAYER_HEALTH_MAX 3
static const vec2 PLAYER_SIZE = {50.0f, 100.0f};
void entity_player_init(ECS* ecs, u32 id, vec3 position);

View File

@ -2,11 +2,13 @@
/* Initializes a snake entity. */
void
entity_snake_init(ECS* ecs, u32 id, vec3 position)
entity_snake_init(ECS* ecs, u32 id, vec3 position, u32 sender)
{
ComponentGameObject* gameObject;
ComponentReturn* returnComponent;
gameObject = ecs_component_add(ecs, ECS_COMPONENT_GAME_OBJECT, id);
returnComponent = ecs_component_add(ecs, ECS_COMPONENT_RETURN, id);
component_game_object_init
(
@ -21,4 +23,13 @@ entity_snake_init(ECS* ecs, u32 id, vec3 position)
SNAKE_FRICTION,
SNAKE_VELOCITY_MAX
);
component_return_init
(
returnComponent,
SNAKE_RETURN_SPEED,
SNAKE_RETURN_VELOCITY_MAX,
SNAKE_RETURN_LIFETIME,
sender
);
}

View File

@ -2,10 +2,14 @@
#include "../../ecs_component.h"
#include "../../component/component_game_object.h"
#include "../../component/action/component_return.h"
#define SNAKE_SPEED 1
#define SNAKE_FRICTION 1
#define SNAKE_VELOCITY_MAX 50
#define SNAKE_RETURN_SPEED 1
#define SNAKE_RETURN_VELOCITY_MAX 100
#define SNAKE_RETURN_LIFETIME 20
static const vec2 SNAKE_SIZE = {25.0f, 25.0f};
void entity_snake_init(ECS* ecs, u32 id, vec3 position);
void entity_snake_init(ECS* ecs, u32 id, vec3 position, u32 sender);

View File

@ -34,18 +34,6 @@ _game_tick(Game* self)
if (event_press(&self->input.event, EVENT_QUIT))
_game_quit(self);
if (self->isFullscreen)
{
if (keyboard_press(&self->input.keyboard, KEYBOARD_KEY_F))
fullscreen_exit(&self->window, &self->renderer);
}
else
{
if (keyboard_press(&self->input.keyboard, KEYBOARD_KEY_F))
fullscreen_set(&self->window, &self->renderer);
}
vec2 position;
vec2 mousePosition;