Compare commits
No commits in common. "f20daa9ccefaa725e5a44cc9a19ec544edf6aa84" and "2dbc1f19abb5c9ee20b9dc306a16986f69360f27" have entirely different histories.
f20daa9cce
...
2dbc1f19ab
15
engine/EC.h
15
engine/EC.h
|
@ -192,25 +192,10 @@ typedef struct Sprite {
|
||||||
} Sprite_t;
|
} Sprite_t;
|
||||||
|
|
||||||
typedef unsigned int (*sprite_transition_func_t)(Entity_t *ent); // Transition requires knowledge of the entity
|
typedef unsigned int (*sprite_transition_func_t)(Entity_t *ent); // Transition requires knowledge of the entity
|
||||||
|
|
||||||
typedef enum AnchorPoint {
|
|
||||||
AP_TOP_LEFT,
|
|
||||||
AP_TOP_CENTER,
|
|
||||||
AP_TOP_RIGHT,
|
|
||||||
AP_MID_LEFT,
|
|
||||||
AP_MID_CENTER,
|
|
||||||
AP_MID_RIGHT,
|
|
||||||
AP_BOT_LEFT,
|
|
||||||
AP_BOT_CENTER,
|
|
||||||
AP_BOT_RIGHT,
|
|
||||||
} AnchorPoint_t;
|
|
||||||
|
|
||||||
typedef struct _SpriteRenderInfo
|
typedef struct _SpriteRenderInfo
|
||||||
{
|
{
|
||||||
Sprite_t* sprite;
|
Sprite_t* sprite;
|
||||||
Vector2 offset;
|
Vector2 offset;
|
||||||
AnchorPoint_t src_anchor;
|
|
||||||
AnchorPoint_t dest_anchor;
|
|
||||||
} SpriteRenderInfo_t;
|
} SpriteRenderInfo_t;
|
||||||
|
|
||||||
typedef struct _CSprite_t {
|
typedef struct _CSprite_t {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include "assets.h"
|
#include "assets.h"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "engine_conf.h"
|
#include "engine_conf.h"
|
||||||
#include "raymath.h"
|
|
||||||
|
|
||||||
#define RRES_RAYLIB_IMPLEMENTATION
|
#define RRES_RAYLIB_IMPLEMENTATION
|
||||||
#include "rres.h"
|
#include "rres.h"
|
||||||
|
@ -552,20 +551,15 @@ void draw_sprite_pro(Sprite_t* spr, int frame_num, Vector2 pos, float rotation,
|
||||||
spr->frame_size.x * ((flip & 1) ? -1 : 1),
|
spr->frame_size.x * ((flip & 1) ? -1 : 1),
|
||||||
spr->frame_size.y * ((flip & 2) ? -1 : 1),
|
spr->frame_size.y * ((flip & 2) ? -1 : 1),
|
||||||
};
|
};
|
||||||
|
|
||||||
// The anchor here is only for rotation and scaling.
|
|
||||||
// Translational anchor is expected to be accounted for
|
|
||||||
// So need to offset render position with anchor position
|
|
||||||
Vector2 anchor = spr->anchor;
|
|
||||||
anchor.x *= scale.x;
|
|
||||||
anchor.y *= scale.y;
|
|
||||||
|
|
||||||
Rectangle dest = {
|
Rectangle dest = {
|
||||||
.x = pos.x + anchor.x,
|
.x = pos.x,
|
||||||
.y = pos.y + anchor.y,
|
.y = pos.y,
|
||||||
.width = spr->frame_size.x * scale.x,
|
.width = spr->frame_size.x * scale.x,
|
||||||
.height = spr->frame_size.y * scale.y
|
.height = spr->frame_size.y * scale.y
|
||||||
};
|
};
|
||||||
|
Vector2 anchor = spr->anchor;
|
||||||
|
anchor.x *= scale.x;
|
||||||
|
anchor.y *= scale.y;
|
||||||
DrawTexturePro(
|
DrawTexturePro(
|
||||||
*spr->texture,
|
*spr->texture,
|
||||||
rec,
|
rec,
|
||||||
|
@ -574,73 +568,3 @@ void draw_sprite_pro(Sprite_t* spr, int frame_num, Vector2 pos, float rotation,
|
||||||
rotation, colour
|
rotation, colour
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Vector2 internal_get_anchor_offset(Vector2 bbox, AnchorPoint_t anchor)
|
|
||||||
{
|
|
||||||
Vector2 offset = {0};
|
|
||||||
switch (anchor)
|
|
||||||
{
|
|
||||||
case AP_TOP_LEFT:
|
|
||||||
break;
|
|
||||||
case AP_TOP_CENTER:
|
|
||||||
offset.x = bbox.x / 2;
|
|
||||||
break;
|
|
||||||
case AP_TOP_RIGHT:
|
|
||||||
offset.x = bbox.x;
|
|
||||||
break;
|
|
||||||
case AP_MID_LEFT:
|
|
||||||
offset.x = 0;
|
|
||||||
offset.y = bbox.y / 2;
|
|
||||||
break;
|
|
||||||
case AP_MID_CENTER:
|
|
||||||
offset.x = bbox.x / 2;
|
|
||||||
offset.y = bbox.y / 2;
|
|
||||||
break;
|
|
||||||
case AP_MID_RIGHT:
|
|
||||||
offset.x = bbox.x;
|
|
||||||
offset.y = bbox.y / 2;
|
|
||||||
break;
|
|
||||||
case AP_BOT_LEFT:
|
|
||||||
offset.x = 0;
|
|
||||||
offset.y = bbox.y;
|
|
||||||
break;
|
|
||||||
case AP_BOT_CENTER:
|
|
||||||
offset.x = bbox.x / 2;
|
|
||||||
offset.y = bbox.y;
|
|
||||||
break;
|
|
||||||
case AP_BOT_RIGHT:
|
|
||||||
offset.x = bbox.x;
|
|
||||||
offset.y = bbox.y;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 shift_bbox(Vector2 bbox, Vector2 new_bbox, AnchorPoint_t anchor)
|
|
||||||
{
|
|
||||||
Vector2 p1 = internal_get_anchor_offset(bbox, anchor);
|
|
||||||
Vector2 p2 = internal_get_anchor_offset(new_bbox, anchor);
|
|
||||||
|
|
||||||
return Vector2Subtract(p1, p2);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 get_anchor_offset(Vector2 bbox, AnchorPoint_t anchor, bool flip_x)
|
|
||||||
{
|
|
||||||
if (flip_x)
|
|
||||||
{
|
|
||||||
switch(anchor)
|
|
||||||
{
|
|
||||||
case AP_TOP_LEFT: anchor = AP_TOP_RIGHT; break;
|
|
||||||
case AP_TOP_RIGHT: anchor = AP_TOP_LEFT; break;
|
|
||||||
case AP_MID_LEFT: anchor = AP_MID_RIGHT; break;
|
|
||||||
case AP_MID_RIGHT: anchor = AP_MID_LEFT; break;
|
|
||||||
case AP_BOT_LEFT: anchor = AP_BOT_RIGHT; break;
|
|
||||||
case AP_BOT_RIGHT: anchor = AP_BOT_LEFT; break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return internal_get_anchor_offset(bbox, anchor);
|
|
||||||
}
|
|
||||||
|
|
|
@ -83,8 +83,6 @@ LevelPack_t* get_level_pack(Assets_t* assets, const char* name);
|
||||||
|
|
||||||
void draw_sprite(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, bool flip_x);
|
void draw_sprite(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, bool flip_x);
|
||||||
void draw_sprite_pro(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, uint8_t flip, Vector2 scale, Color colour);
|
void draw_sprite_pro(Sprite_t* spr, int frame_num, Vector2 pos, float rotation, uint8_t flip, Vector2 scale, Color colour);
|
||||||
Vector2 get_anchor_offset(Vector2 bbox, AnchorPoint_t anchor, bool flip_x);
|
|
||||||
Vector2 shift_bbox(Vector2 bbox, Vector2 new_bbox, AnchorPoint_t anchor);
|
|
||||||
|
|
||||||
typedef struct SFX
|
typedef struct SFX
|
||||||
{
|
{
|
||||||
|
|
|
@ -220,7 +220,6 @@ static void render_editor_game_scene(Scene_t* scene)
|
||||||
int y = tile_y * TILE_SIZE;
|
int y = tile_y * TILE_SIZE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//if (!tilemap.tiles[i].moveable)
|
//if (!tilemap.tiles[i].moveable)
|
||||||
//{
|
//{
|
||||||
// // Draw water tile
|
// // Draw water tile
|
||||||
|
@ -433,23 +432,7 @@ static void render_editor_game_scene(Scene_t* scene)
|
||||||
const SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
const SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
||||||
if (spr.sprite != NULL)
|
if (spr.sprite != NULL)
|
||||||
{
|
{
|
||||||
Vector2 pos = p_ent->position;
|
Vector2 pos = Vector2Add(p_ent->position, spr.offset);
|
||||||
if (p_bbox != NULL)
|
|
||||||
{
|
|
||||||
pos = Vector2Add(
|
|
||||||
pos,
|
|
||||||
get_anchor_offset(p_bbox->size, spr.dest_anchor, p_cspr->flip_x)
|
|
||||||
);
|
|
||||||
pos = Vector2Subtract(
|
|
||||||
pos,
|
|
||||||
get_anchor_offset(spr.sprite->frame_size, spr.src_anchor, p_cspr->flip_x)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 offset = spr.offset;
|
|
||||||
if (p_cspr->flip_x) offset.x *= -1;
|
|
||||||
|
|
||||||
pos = Vector2Add(pos, offset);
|
|
||||||
draw_sprite(spr.sprite, p_cspr->current_frame, pos, 0.0f, p_cspr->flip_x);
|
draw_sprite(spr.sprite, p_cspr->current_frame, pos, 0.0f, p_cspr->flip_x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,23 +214,7 @@ static void render_regular_game_scene(Scene_t* scene)
|
||||||
const SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
const SpriteRenderInfo_t spr = p_cspr->sprites[p_cspr->current_idx];
|
||||||
if (spr.sprite != NULL)
|
if (spr.sprite != NULL)
|
||||||
{
|
{
|
||||||
Vector2 pos = p_ent->position;
|
Vector2 pos = Vector2Add(p_ent->position, spr.offset);
|
||||||
if (p_bbox != NULL)
|
|
||||||
{
|
|
||||||
pos = Vector2Add(
|
|
||||||
pos,
|
|
||||||
get_anchor_offset(p_bbox->size, spr.dest_anchor, p_cspr->flip_x)
|
|
||||||
);
|
|
||||||
pos = Vector2Subtract(
|
|
||||||
pos,
|
|
||||||
get_anchor_offset(spr.sprite->frame_size, spr.src_anchor, p_cspr->flip_x)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 offset = spr.offset;
|
|
||||||
if (p_cspr->flip_x) offset.x *= -1;
|
|
||||||
|
|
||||||
pos = Vector2Add(pos, offset);
|
|
||||||
draw_sprite(spr.sprite, p_cspr->current_frame, pos, 0.0f, p_cspr->flip_x);
|
draw_sprite(spr.sprite, p_cspr->current_frame, pos, 0.0f, p_cspr->flip_x);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -12,6 +12,17 @@ bool check_in_water(const ParticleEmitter_t* emitter, float delta_time);
|
||||||
|
|
||||||
static const Vector2 GRAVITY = {0, GRAV_ACCEL};
|
static const Vector2 GRAVITY = {0, GRAV_ACCEL};
|
||||||
static const Vector2 UPTHRUST = {0, -GRAV_ACCEL * 1.1};
|
static const Vector2 UPTHRUST = {0, -GRAV_ACCEL * 1.1};
|
||||||
|
typedef enum AnchorPoint {
|
||||||
|
AP_TOP_LEFT,
|
||||||
|
AP_TOP_CENTER,
|
||||||
|
AP_TOP_RIGHT,
|
||||||
|
AP_MID_LEFT,
|
||||||
|
AP_MID_CENTER,
|
||||||
|
AP_MID_RIGHT,
|
||||||
|
AP_BOT_LEFT,
|
||||||
|
AP_BOT_CENTER,
|
||||||
|
AP_BOT_RIGHT,
|
||||||
|
} AnchorPoint_t;
|
||||||
|
|
||||||
static inline unsigned int get_tile_idx(int x, int y, TileGrid_t gridmap)
|
static inline unsigned int get_tile_idx(int x, int y, TileGrid_t gridmap)
|
||||||
{
|
{
|
||||||
|
@ -149,6 +160,73 @@ collision_end:
|
||||||
return overlap_mode > 0;
|
return overlap_mode > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Vector2 shift_bbox(Vector2 bbox, Vector2 new_bbox, AnchorPoint_t anchor)
|
||||||
|
{
|
||||||
|
Vector2 p1;
|
||||||
|
Vector2 p2;
|
||||||
|
|
||||||
|
Vector2 offset = {0};
|
||||||
|
switch (anchor)
|
||||||
|
{
|
||||||
|
case AP_TOP_LEFT:
|
||||||
|
// When resizing bbox, it is implicitly assumed that to be already in topleft
|
||||||
|
// due to the coordindate system (+ve towards right and downwards)
|
||||||
|
// So do nothing
|
||||||
|
return offset;
|
||||||
|
case AP_TOP_CENTER:
|
||||||
|
p1.x = bbox.x / 2;
|
||||||
|
p1.y = 0;
|
||||||
|
p2.x = new_bbox.x / 2;
|
||||||
|
p2.y = 0;
|
||||||
|
break;
|
||||||
|
case AP_TOP_RIGHT:
|
||||||
|
p1.x = bbox.x;
|
||||||
|
p1.y = 0;
|
||||||
|
p2.x = new_bbox.x;
|
||||||
|
p2.y = 0;
|
||||||
|
break;
|
||||||
|
case AP_MID_LEFT:
|
||||||
|
p1.x = 0;
|
||||||
|
p1.y = bbox.y / 2;
|
||||||
|
p2.x = 0;
|
||||||
|
p2.y = new_bbox.y / 2;
|
||||||
|
break;
|
||||||
|
case AP_MID_CENTER:
|
||||||
|
p1.x = bbox.x / 2;
|
||||||
|
p1.y = bbox.y / 2;
|
||||||
|
p2.x = new_bbox.x / 2;
|
||||||
|
p2.y = new_bbox.y / 2;
|
||||||
|
break;
|
||||||
|
case AP_MID_RIGHT:
|
||||||
|
p1.x = bbox.x;
|
||||||
|
p1.y = bbox.y / 2;
|
||||||
|
p2.x = new_bbox.x;
|
||||||
|
p2.y = new_bbox.y / 2;
|
||||||
|
break;
|
||||||
|
case AP_BOT_LEFT:
|
||||||
|
p1.x = 0;
|
||||||
|
p1.y = bbox.y;
|
||||||
|
p2.x = 0;
|
||||||
|
p2.y = new_bbox.y;
|
||||||
|
break;
|
||||||
|
case AP_BOT_CENTER:
|
||||||
|
p1.x = bbox.x / 2;
|
||||||
|
p1.y = bbox.y;
|
||||||
|
p2.x = new_bbox.x / 2;
|
||||||
|
p2.y = new_bbox.y;
|
||||||
|
break;
|
||||||
|
case AP_BOT_RIGHT:
|
||||||
|
p1.x = bbox.x;
|
||||||
|
p1.y = bbox.y;
|
||||||
|
p2.x = new_bbox.x;
|
||||||
|
p2.y = new_bbox.y;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
offset.x = p1.x - p2.x;
|
||||||
|
offset.y = p1.y - p2.y;
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
void destroy_entity(Scene_t* scene, TileGrid_t* tilemap, Entity_t* p_ent)
|
void destroy_entity(Scene_t* scene, TileGrid_t* tilemap, Entity_t* p_ent)
|
||||||
{
|
{
|
||||||
Vector2 half_size = {0,0};
|
Vector2 half_size = {0,0};
|
||||||
|
|
|
@ -136,30 +136,6 @@ Entity_t* create_dead_player(EntityManager_t* ent_manager)
|
||||||
return p_ent;
|
return p_ent;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AnchorPoint_t parse_anchor_symbol(const char symbol[2])
|
|
||||||
{
|
|
||||||
if (symbol[0] == 't')
|
|
||||||
{
|
|
||||||
if (symbol[1] == 'l') return AP_TOP_LEFT;
|
|
||||||
if (symbol[1] == 'c') return AP_TOP_CENTER;
|
|
||||||
if (symbol[1] == 'r') return AP_TOP_RIGHT;
|
|
||||||
}
|
|
||||||
else if (symbol[0] == 'm')
|
|
||||||
{
|
|
||||||
if (symbol[1] == 'l') return AP_MID_LEFT;
|
|
||||||
if (symbol[1] == 'c') return AP_MID_CENTER;
|
|
||||||
if (symbol[1] == 'r') return AP_MID_RIGHT;
|
|
||||||
}
|
|
||||||
else if (symbol[0] == 'b')
|
|
||||||
{
|
|
||||||
if (symbol[1] == 'l') return AP_BOT_LEFT;
|
|
||||||
if (symbol[1] == 'c') return AP_BOT_CENTER;
|
|
||||||
if (symbol[1] == 'r') return AP_BOT_RIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return AP_TOP_LEFT;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool init_player_file(FILE* in_file, Assets_t* assets)
|
static bool init_player_file(FILE* in_file, Assets_t* assets)
|
||||||
{
|
{
|
||||||
static bool already_init = false;
|
static bool already_init = false;
|
||||||
|
@ -186,23 +162,18 @@ static bool init_player_file(FILE* in_file, Assets_t* assets)
|
||||||
while(*info_str == ' ' || *info_str == '\t') info_str++;
|
while(*info_str == ' ' || *info_str == '\t') info_str++;
|
||||||
|
|
||||||
Vector2 offset;
|
Vector2 offset;
|
||||||
char src_ap_symbol[3];
|
|
||||||
char dest_ap_symbol[3];
|
|
||||||
int data_count = sscanf(
|
int data_count = sscanf(
|
||||||
info_str, "%f,%f,%2s,%2s",
|
info_str, "%f,%f",
|
||||||
&offset.x, &offset.y, src_ap_symbol, dest_ap_symbol
|
&offset.x, &offset.y
|
||||||
);
|
);
|
||||||
if (data_count != 4)
|
if (data_count !=2)
|
||||||
{
|
{
|
||||||
printf("Unable to parse info for player at line %lu\n", line_num);
|
printf("Unable to parse info for player at line %lu\n", line_num);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Sprite_t* spr = get_sprite(assets, name);
|
Sprite_t* spr = get_sprite(assets, name);
|
||||||
spr->anchor = Vector2Scale(spr->frame_size, 0.5f);
|
|
||||||
player_sprite_map[i].sprite = spr;
|
player_sprite_map[i].sprite = spr;
|
||||||
player_sprite_map[i].offset = offset;
|
player_sprite_map[i].offset = offset;
|
||||||
player_sprite_map[i].src_anchor = parse_anchor_symbol(src_ap_symbol);
|
|
||||||
player_sprite_map[i].dest_anchor = parse_anchor_symbol(dest_ap_symbol);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
already_init = true;
|
already_init = true;
|
||||||
|
|
Loading…
Reference in New Issue