Compare commits
No commits in common. "ac6d93565b2639033644258a0eeb3a1e6993a0ed" and "d01a6772ec5f2eb08e66d7f775ec0ea3adb06403" have entirely different histories.
ac6d93565b
...
d01a6772ec
|
@ -14,22 +14,18 @@ int main(void)
|
||||||
|
|
||||||
Texture2D* tex = add_texture(&assets, "testtex", "res/test_tex.png");
|
Texture2D* tex = add_texture(&assets, "testtex", "res/test_tex.png");
|
||||||
|
|
||||||
add_sprite(&assets, "testspr1", tex);
|
Sprite_t* spr = add_sprite(&assets, "testspr1", tex);
|
||||||
Sprite_t* spr = get_sprite(&assets, "testspr1");
|
|
||||||
spr->origin = (Vector2){0, 0};
|
spr->origin = (Vector2){0, 0};
|
||||||
spr->frame_size = (Vector2){32, 32};
|
spr->frame_size = (Vector2){32, 32};
|
||||||
|
|
||||||
add_sprite(&assets, "testspr2", tex);
|
Sprite_t* spr2 = add_sprite(&assets, "testspr2", tex);
|
||||||
Sprite_t* spr2 = get_sprite(&assets, "testspr2");
|
|
||||||
spr2->frame_count = 4;
|
spr2->frame_count = 4;
|
||||||
spr2->origin = (Vector2){0, 0};
|
spr2->origin = (Vector2){0, 0};
|
||||||
spr2->frame_size = (Vector2){32, 32};
|
spr2->frame_size = (Vector2){32, 32};
|
||||||
spr2->speed = 15;
|
spr2->speed = 15;
|
||||||
|
|
||||||
add_sound(&assets, "testsnd", "res/sound.ogg");
|
Sound* snd = add_sound(&assets, "testsnd", "res/sound.ogg");
|
||||||
Sound* snd = get_sound(&assets, "testsnd");
|
Font* fnt = add_font(&assets, "testfont", "res/test_font.ttf");
|
||||||
add_font(&assets, "testfont", "res/test_font.ttf");
|
|
||||||
Font* fnt = get_font(&assets, "testfont");
|
|
||||||
|
|
||||||
while(!WindowShouldClose())
|
while(!WindowShouldClose())
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
// TODO: Look at sc to use macros to auto generate functions
|
// TODO: Look at sc to use macros to auto generate functions
|
||||||
|
|
||||||
#define N_COMPONENTS 10
|
#define N_COMPONENTS 9
|
||||||
typedef enum ComponentEnum
|
enum ComponentEnum
|
||||||
{
|
{
|
||||||
CBBOX_COMP_T,
|
CBBOX_COMP_T,
|
||||||
CTRANSFORM_COMP_T,
|
CTRANSFORM_COMP_T,
|
||||||
|
@ -16,8 +16,8 @@ typedef enum ComponentEnum
|
||||||
CCONTAINER_T,
|
CCONTAINER_T,
|
||||||
CHITBOXES_T,
|
CHITBOXES_T,
|
||||||
CHURTBOX_T,
|
CHURTBOX_T,
|
||||||
CSPRITE_T,
|
};
|
||||||
}ComponentEnum_t;
|
typedef enum ComponentEnum ComponentEnum_t;
|
||||||
|
|
||||||
typedef struct _CBBox_t
|
typedef struct _CBBox_t
|
||||||
{
|
{
|
||||||
|
@ -112,25 +112,6 @@ typedef struct _CHurtbox_t
|
||||||
bool fragile;
|
bool fragile;
|
||||||
}CHurtbox_t;
|
}CHurtbox_t;
|
||||||
|
|
||||||
// Credits to bedroomcoders.co.uk for this
|
|
||||||
typedef struct Sprite
|
|
||||||
{
|
|
||||||
Texture2D* texture;
|
|
||||||
Vector2 frame_size;
|
|
||||||
Vector2 origin;
|
|
||||||
int frame_count;
|
|
||||||
int current_frame;
|
|
||||||
int elapsed;
|
|
||||||
int speed;
|
|
||||||
char* name;
|
|
||||||
}Sprite_t;
|
|
||||||
|
|
||||||
typedef struct _CSprite_t
|
|
||||||
{
|
|
||||||
Sprite_t* sprite;
|
|
||||||
Vector2 offset;
|
|
||||||
}CSprite_t;
|
|
||||||
|
|
||||||
static inline void set_bbox(CBBox_t* p_bbox, unsigned int x, unsigned int y)
|
static inline void set_bbox(CBBox_t* p_bbox, unsigned int x, unsigned int y)
|
||||||
{
|
{
|
||||||
p_bbox->size.x = x;
|
p_bbox->size.x = x;
|
||||||
|
|
|
@ -14,8 +14,13 @@ static CPlayerState_t cplayerstate_buffer[1]; // Only player is expected to have
|
||||||
static CContainer_t ccontainer_buffer[MAX_COMP_POOL_SIZE];
|
static CContainer_t ccontainer_buffer[MAX_COMP_POOL_SIZE];
|
||||||
static CHitBoxes_t chitboxes_buffer[MAX_COMP_POOL_SIZE];
|
static CHitBoxes_t chitboxes_buffer[MAX_COMP_POOL_SIZE];
|
||||||
static CHurtbox_t churtbox_buffer[MAX_COMP_POOL_SIZE];
|
static CHurtbox_t churtbox_buffer[MAX_COMP_POOL_SIZE];
|
||||||
static CSprite_t csprite_buffer[MAX_COMP_POOL_SIZE];
|
|
||||||
|
|
||||||
|
// Use hashmap as a Set
|
||||||
|
// Use list will be used to check if an object exist
|
||||||
|
// The alternative method to check the free list if idx is not there
|
||||||
|
// requires bound checking
|
||||||
|
// It's just easier on the mind overall
|
||||||
|
// If need to optimise memory, replace free_list with set and remove use_list
|
||||||
typedef struct MemPool
|
typedef struct MemPool
|
||||||
{
|
{
|
||||||
void * const buffer;
|
void * const buffer;
|
||||||
|
@ -37,7 +42,6 @@ static MemPool_t comp_mempools[N_COMPONENTS] =
|
||||||
{ccontainer_buffer, MAX_COMP_POOL_SIZE, sizeof(CContainer_t), NULL, {0}},
|
{ccontainer_buffer, MAX_COMP_POOL_SIZE, sizeof(CContainer_t), NULL, {0}},
|
||||||
{chitboxes_buffer, MAX_COMP_POOL_SIZE, sizeof(CHitBoxes_t), NULL, {0}},
|
{chitboxes_buffer, MAX_COMP_POOL_SIZE, sizeof(CHitBoxes_t), NULL, {0}},
|
||||||
{churtbox_buffer, MAX_COMP_POOL_SIZE, sizeof(CHurtbox_t), NULL, {0}},
|
{churtbox_buffer, MAX_COMP_POOL_SIZE, sizeof(CHurtbox_t), NULL, {0}},
|
||||||
{csprite_buffer, MAX_COMP_POOL_SIZE, sizeof(CSprite_t), NULL, {0}},
|
|
||||||
};
|
};
|
||||||
static MemPool_t ent_mempool = {entity_buffer, MAX_COMP_POOL_SIZE, sizeof(Entity_t), NULL, {0}};
|
static MemPool_t ent_mempool = {entity_buffer, MAX_COMP_POOL_SIZE, sizeof(Entity_t), NULL, {0}};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,21 @@
|
||||||
#ifndef __ASSETS_H
|
#ifndef __ASSETS_H
|
||||||
#define __ASSETS_H
|
#define __ASSETS_H
|
||||||
#include "sc/map/sc_map.h"
|
#include "sc/map/sc_map.h"
|
||||||
#include "components.h"
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
|
// Credits to bedroomcoders.co.uk for this
|
||||||
|
typedef struct Sprite
|
||||||
|
{
|
||||||
|
Texture2D* texture;
|
||||||
|
Vector2 frame_size;
|
||||||
|
Vector2 origin;
|
||||||
|
int frame_count;
|
||||||
|
int current_frame;
|
||||||
|
int elapsed;
|
||||||
|
int speed;
|
||||||
|
char* name;
|
||||||
|
}Sprite_t;
|
||||||
|
|
||||||
typedef struct Assets
|
typedef struct Assets
|
||||||
{
|
{
|
||||||
struct sc_map_s64 m_textures;
|
struct sc_map_s64 m_textures;
|
||||||
|
|
|
@ -92,12 +92,6 @@ static void level_scene_render_func(Scene_t* scene)
|
||||||
};
|
};
|
||||||
DrawRectangleLinesEx(rec, 1.5, PURPLE);
|
DrawRectangleLinesEx(rec, 1.5, PURPLE);
|
||||||
}
|
}
|
||||||
CSprite_t* p_cspr = get_component(&scene->ent_manager, p_ent, CSPRITE_T);
|
|
||||||
if (p_cspr != NULL)
|
|
||||||
{
|
|
||||||
Vector2 pos = Vector2Add(p_ct->position, p_cspr->offset);
|
|
||||||
draw_sprite(p_cspr->sprite, pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i=0; i<tilemap.n_tiles;++i)
|
for (size_t i=0; i<tilemap.n_tiles;++i)
|
||||||
|
@ -210,8 +204,6 @@ static void spawn_player(Scene_t *scene)
|
||||||
.width = p_bbox->size.x + 2,
|
.width = p_bbox->size.x + 2,
|
||||||
.height = p_bbox->size.y - 1,
|
.height = p_bbox->size.y - 1,
|
||||||
};
|
};
|
||||||
CSprite_t* p_cspr = add_component(&scene->ent_manager, p_ent, CSPRITE_T);
|
|
||||||
p_cspr->sprite = get_sprite(&scene->engine->assets, "plr_stand");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void toggle_block_system(Scene_t *scene)
|
static void toggle_block_system(Scene_t *scene)
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
#include "entManager.h"
|
#include "entManager.h"
|
||||||
#include "actions.h"
|
#include "actions.h"
|
||||||
#include "sc/array/sc_array.h"
|
#include "sc/array/sc_array.h"
|
||||||
#include "assets.h"
|
|
||||||
|
|
||||||
typedef struct Scene Scene_t;
|
typedef struct Scene Scene_t;
|
||||||
|
|
||||||
typedef struct GameEngine
|
typedef struct GameEngine
|
||||||
|
@ -12,7 +10,6 @@ typedef struct GameEngine
|
||||||
Scene_t **scenes;
|
Scene_t **scenes;
|
||||||
unsigned int max_scenes;
|
unsigned int max_scenes;
|
||||||
unsigned int curr_scene;
|
unsigned int curr_scene;
|
||||||
Assets_t assets;
|
|
||||||
}GameEngine_t;
|
}GameEngine_t;
|
||||||
void change_scene(GameEngine_t *engine, unsigned int idx);
|
void change_scene(GameEngine_t *engine, unsigned int idx);
|
||||||
|
|
||||||
|
|
26
scene_test.c
26
scene_test.c
|
@ -6,40 +6,14 @@
|
||||||
// Maintain own queue to handle key presses
|
// Maintain own queue to handle key presses
|
||||||
struct sc_queue_32 key_buffer;
|
struct sc_queue_32 key_buffer;
|
||||||
|
|
||||||
Scene_t *scenes[1];
|
|
||||||
static GameEngine_t engine =
|
|
||||||
{
|
|
||||||
.scenes = scenes,
|
|
||||||
.max_scenes = 1,
|
|
||||||
.curr_scene = 0,
|
|
||||||
.assets = {0}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
sc_queue_init(&key_buffer);
|
sc_queue_init(&key_buffer);
|
||||||
InitWindow(1280, 640, "raylib");
|
InitWindow(1280, 640, "raylib");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
init_memory_pools();
|
init_memory_pools();
|
||||||
|
|
||||||
init_assets(&engine.assets);
|
|
||||||
Texture2D* tex = add_texture(&engine.assets, "plr_tex", "res/test_tex.png");
|
|
||||||
Sprite_t* spr = add_sprite(&engine.assets, "plr_stand", tex);
|
|
||||||
spr->origin = (Vector2){0, 0};
|
|
||||||
spr->frame_size = (Vector2){32, 32};
|
|
||||||
|
|
||||||
spr = add_sprite(&engine.assets, "plr_run", tex);
|
|
||||||
spr->frame_count = 4;
|
|
||||||
spr->origin = (Vector2){0, 0};
|
|
||||||
spr->frame_size = (Vector2){32, 32};
|
|
||||||
spr->speed = 15;
|
|
||||||
|
|
||||||
LevelScene_t scene;
|
LevelScene_t scene;
|
||||||
scene.scene.engine = &engine;
|
|
||||||
init_level_scene(&scene);
|
init_level_scene(&scene);
|
||||||
scenes[0] = &scene.scene;
|
|
||||||
change_scene(&engine, 0);
|
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue