Clang format sprite (#262)
This commit is contained in:
@@ -20,6 +20,7 @@ jobs:
|
|||||||
run: >
|
run: >
|
||||||
clang-format --dry-run -Werror
|
clang-format --dry-run -Werror
|
||||||
include/bitset.h source/bitset.c
|
include/bitset.h source/bitset.c
|
||||||
|
include/sprite.h source/sprite.c
|
||||||
include/splash_screen.h source/splash_screen.c
|
include/splash_screen.h source/splash_screen.c
|
||||||
# Currently contains only the code that has been formatted to conform
|
# Currently contains only the code that has been formatted to conform
|
||||||
# When all existing code conforms, change to this:
|
# When all existing code conforms, change to this:
|
||||||
|
|||||||
+9
-9
@@ -1,14 +1,13 @@
|
|||||||
#ifndef SPRITE_H
|
#ifndef SPRITE_H
|
||||||
#define SPRITE_H
|
#define SPRITE_H
|
||||||
|
|
||||||
#include <tonc.h>
|
|
||||||
#include <maxmod.h>
|
#include <maxmod.h>
|
||||||
|
#include <tonc.h>
|
||||||
|
|
||||||
#define CARD_SPRITE_SIZE 32
|
#define CARD_SPRITE_SIZE 32
|
||||||
#define MAX_SPRITES 128
|
#define MAX_SPRITES 128
|
||||||
#define MAX_SPRITE_OBJECTS 16
|
#define MAX_SPRITE_OBJECTS 16
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
OBJ_ATTR* obj;
|
OBJ_ATTR* obj;
|
||||||
@@ -40,13 +39,6 @@ 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);
|
Sprite* affine_sprite_new(u16 a0, u16 a1, u32 tid, u32 pb);
|
||||||
void sprite_destroy(Sprite** sprite);
|
void sprite_destroy(Sprite** sprite);
|
||||||
int sprite_get_layer(Sprite* sprite);
|
int sprite_get_layer(Sprite* sprite);
|
||||||
INLINE void sprite_position(Sprite *sprite, int x, int y)
|
|
||||||
{
|
|
||||||
sprite->pos.x = x;
|
|
||||||
sprite->pos.y = y;
|
|
||||||
|
|
||||||
obj_set_pos(sprite->obj, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sprite functions
|
// Sprite functions
|
||||||
void sprite_init();
|
void sprite_init();
|
||||||
@@ -67,4 +59,12 @@ Sprite* sprite_object_get_sprite(SpriteObject* sprite_object);
|
|||||||
void sprite_object_set_focus(SpriteObject* sprite_object, bool focus);
|
void sprite_object_set_focus(SpriteObject* sprite_object, bool focus);
|
||||||
bool sprite_object_is_focused(SpriteObject* sprite_object);
|
bool sprite_object_is_focused(SpriteObject* sprite_object);
|
||||||
|
|
||||||
|
INLINE void sprite_position(Sprite* sprite, int x, int y)
|
||||||
|
{
|
||||||
|
sprite->pos.x = x;
|
||||||
|
sprite->pos.y = y;
|
||||||
|
|
||||||
|
obj_set_pos(sprite->obj, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // SPRITE_H
|
#endif // SPRITE_H
|
||||||
|
|||||||
+26
-15
@@ -1,13 +1,14 @@
|
|||||||
#include "game.h"
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "util.h"
|
|
||||||
#include "audio_utils.h"
|
|
||||||
#include "soundbank.h"
|
|
||||||
#include "pool.h"
|
|
||||||
|
|
||||||
#include <tonc.h>
|
#include "audio_utils.h"
|
||||||
#include <stdlib.h>
|
#include "game.h"
|
||||||
|
#include "pool.h"
|
||||||
|
#include "soundbank.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#include <maxmod.h>
|
#include <maxmod.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <tonc.h>
|
||||||
|
|
||||||
#define MAX_SPRITES 128
|
#define MAX_SPRITES 128
|
||||||
#define MAX_AFFINES 32
|
#define MAX_AFFINES 32
|
||||||
@@ -77,7 +78,8 @@ Sprite *sprite_new(u16 a0, u16 a1, u32 tid, u32 pb, int sprite_index)
|
|||||||
|
|
||||||
void sprite_destroy(Sprite** sprite)
|
void sprite_destroy(Sprite** sprite)
|
||||||
{
|
{
|
||||||
if (*sprite == NULL) return;
|
if (*sprite == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
obj_hide((*sprite)->obj);
|
obj_hide((*sprite)->obj);
|
||||||
|
|
||||||
@@ -95,7 +97,8 @@ void sprite_destroy(Sprite **sprite)
|
|||||||
|
|
||||||
int sprite_get_layer(Sprite* sprite)
|
int sprite_get_layer(Sprite* sprite)
|
||||||
{
|
{
|
||||||
if (sprite == NULL || sprite->obj == NULL) return UNDEFINED;
|
if (sprite == NULL || sprite->obj == NULL)
|
||||||
|
return UNDEFINED;
|
||||||
return sprite->obj - obj_buffer;
|
return sprite->obj - obj_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +137,8 @@ SpriteObject* sprite_object_new()
|
|||||||
|
|
||||||
void sprite_object_destroy(SpriteObject** sprite_object)
|
void sprite_object_destroy(SpriteObject** sprite_object)
|
||||||
{
|
{
|
||||||
if (*sprite_object == NULL) return;
|
if (*sprite_object == NULL)
|
||||||
|
return;
|
||||||
sprite_destroy(&(*sprite_object)->sprite);
|
sprite_destroy(&(*sprite_object)->sprite);
|
||||||
POOL_FREE(SpriteObject, *sprite_object);
|
POOL_FREE(SpriteObject, *sprite_object);
|
||||||
*sprite_object = NULL;
|
*sprite_object = NULL;
|
||||||
@@ -169,13 +173,16 @@ void sprite_object_update(SpriteObject* sprite_object)
|
|||||||
sprite_object->vx += ((sprite_object->tx - sprite_object->x) * get_game_speed()) / 8;
|
sprite_object->vx += ((sprite_object->tx - sprite_object->x) * get_game_speed()) / 8;
|
||||||
sprite_object->vy += ((sprite_object->ty - sprite_object->y) * get_game_speed()) / 8;
|
sprite_object->vy += ((sprite_object->ty - sprite_object->y) * get_game_speed()) / 8;
|
||||||
|
|
||||||
sprite_object->vscale += (sprite_object->tscale - sprite_object->scale) / 8; // Scale up the card when it's played
|
// Scale up the card when it's played
|
||||||
|
sprite_object->vscale += (sprite_object->tscale - sprite_object->scale) / 8;
|
||||||
|
|
||||||
sprite_object->vrotation += (sprite_object->trotation - sprite_object->rotation) / 8; // Rotate the card when it's played
|
// Rotate the card when it's played
|
||||||
|
sprite_object->vrotation += (sprite_object->trotation - sprite_object->rotation) / 8;
|
||||||
|
|
||||||
// set velocity to 0 if it's close enough to the target
|
// set velocity to 0 if it's close enough to the target
|
||||||
const FIXED epsilon = float2fx(0.01f);
|
const FIXED epsilon = float2fx(0.01f);
|
||||||
if (sprite_object->vx < epsilon && sprite_object->vx > -epsilon && sprite_object->vy < epsilon && sprite_object->vy > -epsilon)
|
if (sprite_object->vx < epsilon && sprite_object->vx > -epsilon && sprite_object->vy < epsilon &&
|
||||||
|
sprite_object->vy > -epsilon)
|
||||||
{
|
{
|
||||||
sprite_object->vx = 0;
|
sprite_object->vx = 0;
|
||||||
sprite_object->vy = 0;
|
sprite_object->vy = 0;
|
||||||
@@ -216,7 +223,10 @@ void sprite_object_update(SpriteObject* sprite_object)
|
|||||||
sprite_object->rotation += sprite_object->vrotation;
|
sprite_object->rotation += sprite_object->vrotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
obj_aff_rotscale(sprite_object->sprite->aff, sprite_object->scale, sprite_object->scale, -sprite_object->vx + sprite_object->rotation); // Apply rotation and scale to the sprite
|
obj_aff_rotscale(sprite_object->sprite->aff,
|
||||||
|
sprite_object->scale,
|
||||||
|
sprite_object->scale,
|
||||||
|
-sprite_object->vx + sprite_object->rotation); // Apply rotation and scale to the sprite
|
||||||
sprite_position(sprite_object->sprite, fx2int(sprite_object->x), fx2int(sprite_object->y));
|
sprite_position(sprite_object->sprite, fx2int(sprite_object->x), fx2int(sprite_object->y));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +235,8 @@ void sprite_object_shake(SpriteObject* sprite_object, mm_word sound_id)
|
|||||||
sprite_object->vscale = float2fx(0.3f);
|
sprite_object->vscale = float2fx(0.3f);
|
||||||
sprite_object->vrotation = float2fx(8.0f); // Rotate the card when it's scored
|
sprite_object->vrotation = float2fx(8.0f); // Rotate the card when it's scored
|
||||||
|
|
||||||
if (sound_id == UNDEFINED) return; // If no sound ID is provided, do nothing
|
if (sound_id == UNDEFINED)
|
||||||
|
return; // If no sound ID is provided, do nothing
|
||||||
|
|
||||||
play_sfx(sound_id, MM_BASE_PITCH_RATE);
|
play_sfx(sound_id, MM_BASE_PITCH_RATE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user