Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/unstable' into gfx-rdp
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Sep 1, 2024
2 parents 33e62f3 + 7d3f445 commit 6ec65f8
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 159 deletions.
2 changes: 1 addition & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EXAMPLES += pixelshader
EXAMPLES += rdpqdemo
EXAMPLES += rspqdemo
EXAMPLES += rtctest
EXAMPLES += spritemap
EXAMPLES += spriteanim
EXAMPLES += test
EXAMPLES += timers
EXAMPLES += videoplayer
Expand Down
1 change: 1 addition & 0 deletions examples/spriteanim/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
filesystem/
31 changes: 31 additions & 0 deletions examples/spriteanim/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
BUILD_DIR=build
include $(N64_INST)/include/n64.mk

src = spriteanim.c
assets_png = $(wildcard assets/*.png)

assets_conv = $(addprefix filesystem/,$(notdir $(assets_png:%.png=%.sprite)))


AUDIOCONV_FLAGS ?=
MKSPRITE_FLAGS ?=

all: spriteanim.z64

filesystem/%.sprite: assets/%.png
@mkdir -p $(dir $@)
@echo " [SPRITE] $@"
@$(N64_MKSPRITE) $(MKSPRITE_FLAGS) -o filesystem "$<"

$(BUILD_DIR)/spriteanim.dfs: $(assets_conv)
$(BUILD_DIR)/spriteanim.elf: $(src:%.c=$(BUILD_DIR)/%.o)

spriteanim.z64: N64_ROM_TITLE="Sprite Anim Demo"
spriteanim.z64: $(BUILD_DIR)/spriteanim.dfs

clean:
rm -rf $(BUILD_DIR) spriteanim.z64

-include $(wildcard $(BUILD_DIR)/*.d)

.PHONY: all clean
Binary file added examples/spriteanim/assets/knight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions examples/spriteanim/spriteanim.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include "libdragon.h"
#include <malloc.h>
#include <math.h>

//Animation frame size defines
#define ANIM_FRAME_W 120
#define ANIM_FRAME_H 80

//Animation frame timing defines
#define ANIM_FRAME_DELAY 3
#define ANIM_FRAME_MAX 6

#define KNIGHT_MAX 2

//Structure for knight sprite
typedef struct {
float x;
float y;
bool attack;
bool flip;
int time;
} knight_data;

static knight_data knights[2];
static sprite_t *sheet_knight;

void render(void)
{
// Attach and clear the screen
surface_t *disp = display_get();
rdpq_attach_clear(disp, NULL);
//Set render mode to the standard render mode
rdpq_set_mode_standard();
rdpq_mode_alphacompare(1); // colorkey (draw pixel with alpha >= 1)
for(int i=0; i<KNIGHT_MAX; i++) {
int frame = knights[i].time/ANIM_FRAME_DELAY; //Calculate knight frame
//Draw knight sprite
rdpq_sprite_blit(sheet_knight, knights[i].x, knights[i].y, &(rdpq_blitparms_t){
.s0 = frame*ANIM_FRAME_W, //Extract correct sprite from sheet
//Set sprite center to bottom-center
.cx = ANIM_FRAME_W/2,
.cy = ANIM_FRAME_H,
.width = ANIM_FRAME_W, //Extract correct width from sheet
.flip_x = knights[i].flip
});
}
//Detach the screen
rdpq_detach_show();
}

void update(void)
{
for(int i=0; i<KNIGHT_MAX; i++) {
if(knights[i].attack) {
knights[i].time++; //Increment time
//Stop attack at end of animation
if(knights[i].time >= ANIM_FRAME_DELAY*ANIM_FRAME_MAX) {
knights[i].time = 0;
knights[i].attack = false;
}
}
}
}

int main()
{
//Init logging
debug_init_isviewer();
debug_init_usblog();

//Init display
display_init(RESOLUTION_320x240, DEPTH_16_BPP, 3, GAMMA_NONE, FILTERS_RESAMPLE);
//Init DragonFS
dfs_init(DFS_DEFAULT_LOCATION);
//Init RDPQ
rdpq_init();
//Init joypad
joypad_init();
//Load Sprite Sheet
sheet_knight = sprite_load("rom:/knight.sprite");
//Initialize left knight
knights[0].x = (display_get_width()/2)-25;
knights[0].y = display_get_height()-30;
//Initialize right knight
knights[1].x = (display_get_width()/2)+25;
knights[1].y = knights[0].y;
knights[1].flip = true;
while (1)
{
render();
update();

//Read joypad
joypad_poll();
joypad_buttons_t ckeys = joypad_get_buttons_pressed(JOYPAD_PORT_1);
//Set attack for left knight
if(ckeys.a) {
knights[0].attack = true;
}
//Set attack for right knight
if(ckeys.b) {
knights[1].attack = true;
}
}
}
19 changes: 0 additions & 19 deletions examples/spritemap/Makefile

This file was deleted.

Binary file removed examples/spritemap/filesystem/earthbound.sprite
Binary file not shown.
Binary file removed examples/spritemap/filesystem/mudkip.sprite
Binary file not shown.
Binary file removed examples/spritemap/filesystem/plane.sprite
Binary file not shown.
139 changes: 0 additions & 139 deletions examples/spritemap/spritemap.c

This file was deleted.

0 comments on commit 6ec65f8

Please sign in to comment.