cleanup and refactor
This commit is contained in:
+4
-59
@@ -5,57 +5,8 @@
|
||||
#include "collision.h"
|
||||
#include "actor.h"
|
||||
|
||||
//! Hierher gehören noch weiter Attribute. is_moving, direction, hitpoints, etc.
|
||||
//! Oder besser: den Actor struct kann ich als Basis nehmen und evtl. extenden für verschiedene types (Player, Enemy, Pickup etc.)
|
||||
|
||||
// A structure of the actor
|
||||
/* typedef struct Actor
|
||||
{
|
||||
uint8_t sprite_id; // The starting ID of the sprite for this actor. Remaining sprites should follow in sequency
|
||||
uint8_t sprite_tile_width; // The number of tiles wide this sprite is
|
||||
uint8_t sprite_tile_height; // The number tiles high this sprite is
|
||||
uint8_t sprite_frame; // The total number of animated sprites
|
||||
uint8_t sprite_current_frame; // The current frame the sprite is on
|
||||
uint8_t tilemap_start; // The start index where the tiles start for this sprite
|
||||
uint8_t x; // The sprite x position (top left)
|
||||
uint8_t y; // The sprite y position (top left)
|
||||
uint8_t next_x; // The future sprite x position (top left)
|
||||
uint8_t next_y; // The future sprite y position (top left)
|
||||
int8_t dx; // The sprite x moving direction
|
||||
int8_t dy; // The sprite y moving direction
|
||||
uint8_t velocity_x; // The current speed of travel in the X direction
|
||||
uint8_t velocity_y; // The current speed of travel in the y direction
|
||||
bool is_facing_right; // The direction the player sprite is facing
|
||||
bool is_moving; // Is the actor moving or not
|
||||
const unsigned char *tilemap; // A pointer to the tilemap (may be obsolete with metasprite)
|
||||
const metasprite_t *metasprite; // A pointer to the metasprite
|
||||
} Actor; */
|
||||
|
||||
//! die load_sprite_frame wird mit dem move_metasprite_ex gar nicht mehr benutzt!
|
||||
/* void load_sprite_frame(Actor *actor, uint8_t frame)
|
||||
{
|
||||
// Set current frame
|
||||
actor->sprite_current_frame = frame;
|
||||
|
||||
// Get total sprites
|
||||
uint8_t spriteCount = actor->sprite_tile_width * actor->sprite_tile_height;
|
||||
|
||||
for (uint8_t i = 0; i != spriteCount; i++)
|
||||
{
|
||||
set_sprite_tile(actor->sprite_id + i, actor->tilemap[actor->tilemap_start + i + (frame * spriteCount)]);
|
||||
}
|
||||
} */
|
||||
|
||||
void move_actor(Actor *actor, uint8_t x, uint8_t y) // Evtl. sollte is_moving hier mit übergeben werden
|
||||
{
|
||||
|
||||
// Set actors new position
|
||||
// actor->x = x;
|
||||
// actor->y = y;
|
||||
|
||||
// actor->x = actor->next_x;
|
||||
// actor->y = actor->next_y;
|
||||
|
||||
// Move the metasprite
|
||||
if (actor->is_facing_right)
|
||||
{
|
||||
@@ -70,15 +21,10 @@ void move_actor(Actor *actor, uint8_t x, uint8_t y) // Evtl. sollte is_moving hi
|
||||
|
||||
void scroll_actor(Actor *actor)
|
||||
{
|
||||
uint8_t actorIsMoving = actor->dx != 0 || actor->dy != 0;
|
||||
|
||||
uint8_t playerIsMoving = actor->dx != 0 || actor->dy != 0;
|
||||
|
||||
// If the player is moving at all
|
||||
// We'll handle horizontall and vertical movement separately
|
||||
// Handling them separately enables a sliding motion against walls
|
||||
if (playerIsMoving)
|
||||
if (actorIsMoving)
|
||||
{
|
||||
|
||||
actor->x = actor->next_x;
|
||||
actor->y = actor->next_y;
|
||||
|
||||
@@ -202,7 +148,8 @@ void move_actor_with_joypad(Actor *actor, uint8_t framecount)
|
||||
actor->is_moving = FALSE;
|
||||
}
|
||||
|
||||
scroll_actor(actor);
|
||||
//! moved scroll function to update() in main
|
||||
// scroll_actor(actor);
|
||||
}
|
||||
|
||||
void setup_actor(Actor *actor, uint8_t sprite_id, uint8_t tile_width, uint8_t tile_height, uint8_t tilemap_start, uint8_t total_frames, bool is_facing_right, uint8_t x, uint8_t y, const unsigned char *tilemap, const metasprite_t *metasprite)
|
||||
@@ -222,7 +169,5 @@ void setup_actor(Actor *actor, uint8_t sprite_id, uint8_t tile_width, uint8_t ti
|
||||
actor->sprite_current_frame = 0; // Make sure to start at frame 1
|
||||
actor->metasprite = metasprite; // Store pointer to metasprite
|
||||
|
||||
// move_metasprite_ex(actor->metasprite, 0, 0, actor->sprite_id, x + 8, y + 16);
|
||||
|
||||
move_actor(actor, x, y);
|
||||
}
|
||||
+13
-7
@@ -61,6 +61,7 @@ void update_two_frame_counter(void)
|
||||
|
||||
//! Switch metasprite on certain frames. Could be heavily improved to take props for actor->spriteFrames and more
|
||||
//! Should be called in some UpdateActor(&actor) Function
|
||||
//! Hier kann ich stattdessen ein metasprite array übergeben
|
||||
void animate_actor(Actor *actor, int8_t two_frame_counter)
|
||||
{
|
||||
if (actor->is_moving)
|
||||
@@ -216,11 +217,6 @@ void init(void)
|
||||
|
||||
//! Prüfen, welche variables für das metasprite überhaupt noch benötigt werden
|
||||
setup();
|
||||
// uint8_t startingSprite = 0;
|
||||
|
||||
// startingSprite += move_metasprite_ex(squid_metasprite, 0, 0, startingSprite, 20 + 8, 80 + 16);
|
||||
// startingSprite += move_metasprite_ex(submarine_metasprite, 0, 0, startingSprite, 80 + 8, 90 + 16);
|
||||
// MoveCharacter(&submarine, 80, 90);
|
||||
|
||||
// Show the HUD
|
||||
// show_hud();
|
||||
@@ -229,8 +225,17 @@ void init(void)
|
||||
SHOW_SPRITES;
|
||||
// SPRITES_8x16;
|
||||
DISPLAY_ON;
|
||||
}
|
||||
|
||||
// move_metasprite_ex(submarine_metasprite, 0, 0, 0, 80, 80);
|
||||
void render(void)
|
||||
{
|
||||
animate_actor(&submarine, two_frame_counter);
|
||||
}
|
||||
|
||||
void update(void)
|
||||
{
|
||||
scroll_actor(&submarine);
|
||||
render();
|
||||
}
|
||||
|
||||
void main(void)
|
||||
@@ -243,10 +248,11 @@ void main(void)
|
||||
{
|
||||
|
||||
update_two_frame_counter();
|
||||
animate_actor(&submarine, two_frame_counter);
|
||||
|
||||
// animate_actor(&squid, two_frame_counter);
|
||||
|
||||
move_actor_with_joypad(&submarine, framecount);
|
||||
update();
|
||||
|
||||
animcounter(96); // I picked 96 because of how many factors it has. Easy to have different spaced timings that don't stutter when the counter loops.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user