diff options
author | BoredGuy <osome3717@gmail.com> | 2025-08-26 12:33:32 +0300 |
---|---|---|
committer | BoredGuy <osome3717@gmail.com> | 2025-08-26 12:33:32 +0300 |
commit | 87d07175058ee4ae18fce608de81c68d7d9bb178 (patch) | |
tree | 1eb459ff40aded29f6433bcd413d47ff870fd4e0 /include | |
parent | 978c543891af8dbe9e95b27c4e2c46645d45138c (diff) |
Player Improvements
Diffstat (limited to 'include')
-rw-r--r-- | include/assets.h | 1 | ||||
-rw-r--r-- | include/game.h | 28 | ||||
-rw-r--r-- | include/player_data.h | 31 | ||||
-rw-r--r-- | include/utils.h | 4 |
4 files changed, 63 insertions, 1 deletions
diff --git a/include/assets.h b/include/assets.h index 61b198e..6761d51 100644 --- a/include/assets.h +++ b/include/assets.h @@ -16,4 +16,5 @@ typedef struct Asset { void LoadAssets(); Asset* GetMatchingAssetWithType(const char* targetName, AssetType targetType); +Asset* GetMatchingAssetExitOnFail(const char* targetName, AssetType targetType); void UnloadAssets(); diff --git a/include/game.h b/include/game.h index ec44b3e..99529bf 100644 --- a/include/game.h +++ b/include/game.h @@ -37,6 +37,9 @@ typedef struct Sprite { DrawLayer layer; Rectangle destRect; //Destination rectangle relative to player position + bool flipX; + bool flipY; + int numAnimations; //Zero for static spritesx Animation animations[MAX_ANIMATIONS]; int currentAnimation; @@ -64,6 +67,9 @@ typedef struct Entity { //Debug information Color physicsColliderColor; #endif + + //Human entity information + int bodySpriteIndex; } Entity; typedef struct Game { @@ -77,15 +83,37 @@ typedef struct Game { #endif } Game; +//Entity Stuff void AddEntity(Entity* e); void AddWall(float xpos, float ypos, float width, float height); +//Game Stuff void InitGame(); void UpdateGame(float deltaTime); void DrawGame(); +//Sprite Stuff void UpdateCurrentSpriteAnimation(Sprite* sprite, float dt); void DrawEntitySprite(const Entity* e, int spriteIndex); +Rectangle GetSrcRectFromIndex +( + Texture texture, + int framesX, + int framesY, + int index +); + +typedef struct { + Texture texture; + int framesX; + int framesY; + int numFrames; + bool isLooping; + int* indices; + float* frameTimes; +} AnimationFromIndicesParams; + +Animation AnimationFromIndices(AnimationFromIndicesParams params); #ifdef BEATEMUP_DEBUG void DebugHighlights(const Entity* e); diff --git a/include/player_data.h b/include/player_data.h new file mode 100644 index 0000000..d9d45a1 --- /dev/null +++ b/include/player_data.h @@ -0,0 +1,31 @@ +#ifndef PLAYER_DATA_H_ +#define PLAYER_DATA_H_ + +#include "game.h" + +#define PLAYER_SPEED 300.0f + +const Rectangle shadowDestRect = (Rectangle) { + .x = -30, + .y = 100, + .width = 140, + .height = 40 +}; + +const Rectangle physicsCollider = (Rectangle) { + .x = NO_OFFSET, + .y = NO_OFFSET, + .width = 100, + .height = 100 +}; + +const Rectangle bodyDestRect = (Rectangle) { + .x = -160, + .y = -280, + .width = 400, + .height = 400 +}; + +#define IDLE_FTIME 0.1f + +#endif // PLAYER_DATA_H_ diff --git a/include/utils.h b/include/utils.h index 0ba8c32..3381828 100644 --- a/include/utils.h +++ b/include/utils.h @@ -16,10 +16,12 @@ static inline bool SameEntity(const Entity* a, const Entity* b) { return a->id == b->id; } -static inline void AddSpriteToEntity(Entity* e, Sprite s) { +static inline int AddSpriteToEntity(Entity* e, Sprite s) { if (e->numSprites < MAX_SPRITE_COUNT) { e->sprites[e->numSprites++] = s; } + + return e->numSprites - 1; } static inline bool IsAnimated(const Sprite* s) { |