Extracted JokerObject and CardObject common functionalities to SpriteObject, removing duplicate code and dangerous casts.
This commit is contained in:
+6
-12
@@ -45,17 +45,7 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
Card *card;
|
||||
Sprite *sprite;
|
||||
FIXED tx, ty; // target position
|
||||
FIXED x, y; // position
|
||||
FIXED vx, vy; // velocity
|
||||
FIXED tscale;
|
||||
FIXED scale;
|
||||
FIXED vscale;
|
||||
FIXED trotation; // this never gets used so i might remove it later
|
||||
FIXED rotation;
|
||||
FIXED vrotation;
|
||||
bool selected;
|
||||
SpriteObject *sprite_object;
|
||||
} CardObject;
|
||||
|
||||
// Card functions
|
||||
@@ -71,6 +61,10 @@ CardObject *card_object_new(Card *card);
|
||||
void card_object_destroy(CardObject **card_object);
|
||||
void card_object_update(CardObject *card_object); // Update the card object position and scale
|
||||
void card_object_set_sprite(CardObject *card_object, int layer);
|
||||
void card_object_shake(CardObject *card_object, mm_word sound_id); // This doesn't actually score anything, it just performs an animation and plays a sound effect
|
||||
void card_object_shake(CardObject* card_object, mm_word sound_id);
|
||||
|
||||
void card_object_set_selected(CardObject* card_object, bool selected);
|
||||
bool card_object_is_selected(CardObject* card_object);
|
||||
Sprite* card_object_get_sprite(CardObject* card_object);
|
||||
|
||||
#endif // CARD_H
|
||||
@@ -50,8 +50,6 @@ typedef struct
|
||||
int bottom;
|
||||
} Rect;
|
||||
|
||||
#define UNDEFINED -1
|
||||
|
||||
/* Gets the screenblock tile for the given coordinates (x, y).
|
||||
* x and y are in number of tiles.
|
||||
* Returns the screenblock tile.
|
||||
|
||||
+6
-15
@@ -42,22 +42,8 @@ typedef struct
|
||||
|
||||
typedef struct // copy of CardObject in card.h
|
||||
{
|
||||
/* Note that since JokerObject is cast to CardObject in joker_object_update(),
|
||||
* they have to have the exact same structure to have
|
||||
* the exact same field offsets in memory
|
||||
*/
|
||||
Joker *joker;
|
||||
Sprite *sprite;
|
||||
FIXED tx, ty;
|
||||
FIXED x, y;
|
||||
FIXED vx, vy;
|
||||
FIXED tscale;
|
||||
FIXED scale;
|
||||
FIXED vscale;
|
||||
FIXED trotation;
|
||||
FIXED rotation;
|
||||
FIXED vrotation;
|
||||
bool selected;
|
||||
SpriteObject* sprite_object;
|
||||
} JokerObject;
|
||||
|
||||
typedef struct // These jokers are triggered after the played hand has finished scoring.
|
||||
@@ -84,4 +70,9 @@ void joker_object_update(JokerObject *joker_object);
|
||||
void joker_object_shake(JokerObject *joker_object, mm_word sound_id); // This doesn't actually score anything, it just performs an animation and plays a sound effect
|
||||
bool joker_object_score(JokerObject *joker_object, Card* scored_card, int *chips, int *mult, int *xmult, int *money, bool *retrigger); // This scores the joker and returns true if it was scored successfully (Card = NULL means the joker is independent and not scored by a card)
|
||||
|
||||
void joker_object_set_selected(JokerObject* joker_object, bool selected);
|
||||
bool joker_object_is_selected(JokerObject* joker_object);
|
||||
|
||||
Sprite* joker_object_get_sprite(JokerObject* joker_object);
|
||||
|
||||
#endif // JOKER_H
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SPRITE_H
|
||||
|
||||
#include <tonc.h>
|
||||
#include <maxmod.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -11,6 +12,22 @@ typedef struct
|
||||
POINT pos;
|
||||
} Sprite;
|
||||
|
||||
// A sprite object is a sprite that is selectable and movable in animation
|
||||
typedef struct
|
||||
{
|
||||
Sprite* sprite;
|
||||
FIXED tx, ty; // target position
|
||||
FIXED x, y; // position
|
||||
FIXED vx, vy; // velocity
|
||||
FIXED tscale;
|
||||
FIXED scale;
|
||||
FIXED vscale;
|
||||
FIXED trotation; // this never gets used so i might remove it later
|
||||
FIXED rotation;
|
||||
FIXED vrotation;
|
||||
bool selected;
|
||||
} SpriteObject;
|
||||
|
||||
// Sprite methods
|
||||
Sprite *sprite_new(u16 a0, u16 a1, u32 tid, u32 pb, int sprite_index);
|
||||
Sprite *affine_sprite_new(u16 a0, u16 a1, u32 tid, u32 pb);
|
||||
@@ -28,4 +45,17 @@ INLINE void sprite_position(Sprite *sprite, int x, int y)
|
||||
void sprite_init();
|
||||
void sprite_draw();
|
||||
|
||||
// SpriteObject methods
|
||||
SpriteObject *sprite_object_new();
|
||||
void sprite_object_destroy(SpriteObject **sprite_object);
|
||||
void sprite_object_set_sprite(SpriteObject* sprite_object, Sprite* sprite);
|
||||
void sprite_object_reset_transform(SpriteObject* sprite_object);
|
||||
void sprite_object_update(SpriteObject *sprite_object);
|
||||
void sprite_object_shake(SpriteObject* sprite_object, mm_word sound_id);
|
||||
|
||||
void sprite_object_set_selected(SpriteObject* sprite_object, bool selected);
|
||||
bool sprite_object_is_selected(SpriteObject* sprite_object);
|
||||
Sprite* sprite_object_get_sprite(SpriteObject* sprite_object);
|
||||
|
||||
|
||||
#endif // SPRITE_H
|
||||
@@ -33,4 +33,6 @@ static inline int get_digits_even(int n)
|
||||
return 5;
|
||||
}
|
||||
|
||||
#define UNDEFINED -1
|
||||
|
||||
#endif // UTIL_H
|
||||
Reference in New Issue
Block a user