Add a key to toggle the music off, fix little guy's movement speed
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,4 +1,4 @@
|
|||||||
SDLFLAGS_CC:=$(shell pkg-config sdl3 --cflags) $(shell pkg-config sdl3-image --cflags) $(shell pkg-config sdl3game --clfags) $(shell pkg-config akerror --cflags)
|
SDLFLAGS_CC:=$(shell pkg-config sdl3 --cflags) $(shell pkg-config sdl3-image --cflags) $(shell pkg-config sdl3game --cflags) $(shell pkg-config akerror --cflags)
|
||||||
SDLFLAGS_LD:=$(shell pkg-config sdl3 --libs) $(shell pkg-config sdl3-mixer --libs) $(shell pkg-config sdl3-image --libs) $(shell pkg-config sdl3game --libs) $(shell pkg-config akerror --libs) -lasound
|
SDLFLAGS_LD:=$(shell pkg-config sdl3 --libs) $(shell pkg-config sdl3-mixer --libs) $(shell pkg-config sdl3-image --libs) $(shell pkg-config sdl3game --libs) $(shell pkg-config akerror --libs) -lasound
|
||||||
CC:=$(shell which gcc)
|
CC:=$(shell which gcc)
|
||||||
LD:=$(shell which ld)
|
LD:=$(shell which ld)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "little guy",
|
"name": "little guy",
|
||||||
"movementspeed": 30,
|
"movementspeed": 8,
|
||||||
"velocity_x": 0.15,
|
"velocity_x": 1,
|
||||||
"velocity_y": 0.15,
|
"velocity_y": 1,
|
||||||
"sprite_mappings": [
|
"sprite_mappings": [
|
||||||
{
|
{
|
||||||
"state": [
|
"state": [
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <SDL3_mixer/SDL_mixer.h>
|
#include <SDL3_mixer/SDL_mixer.h>
|
||||||
|
|
||||||
#include <sdl3game/assets.h>
|
#include <sdl3game/assets.h>
|
||||||
|
#include <sdl3game/error.h>
|
||||||
#include <sdl3game/iterator.h>
|
#include <sdl3game/iterator.h>
|
||||||
#include <sdl3game/tilemap.h>
|
#include <sdl3game/tilemap.h>
|
||||||
#include <sdl3game/heap.h>
|
#include <sdl3game/heap.h>
|
||||||
@@ -30,6 +31,29 @@ char *spritepaths[] = {
|
|||||||
|
|
||||||
char dirnamebuf[1024];
|
char dirnamebuf[1024];
|
||||||
|
|
||||||
|
akerr_ErrorContext AKERR_NOIGNORE *music_toggle(actor *obj, SDL_Event *event)
|
||||||
|
{
|
||||||
|
SDL_PropertiesID bgmprops = 0;
|
||||||
|
PREPARE_ERROR(errctx);
|
||||||
|
if ( MIX_TrackPlaying(game.tracks[GAME_AUDIO_TRACK_BGM]) ) {
|
||||||
|
FAIL_ZERO_RETURN(
|
||||||
|
errctx,
|
||||||
|
MIX_StopTrack(game.tracks[GAME_AUDIO_TRACK_BGM], 0),
|
||||||
|
AKERR_SDL,
|
||||||
|
"%s",
|
||||||
|
SDL_GetError());
|
||||||
|
} else {
|
||||||
|
SDL_SetNumberProperty(bgmprops, MIX_PROP_PLAY_LOOPS_NUMBER, -1);
|
||||||
|
FAIL_ZERO_RETURN(
|
||||||
|
errctx,
|
||||||
|
MIX_PlayTrack(game.tracks[GAME_AUDIO_TRACK_BGM], bgmprops),
|
||||||
|
AKERR_SDL,
|
||||||
|
"%s",
|
||||||
|
SDL_GetError());
|
||||||
|
}
|
||||||
|
SUCCEED_RETURN(errctx);
|
||||||
|
}
|
||||||
|
|
||||||
akerr_ErrorContext AKERR_NOIGNORE *user_breakpoint(actor *obj, SDL_Event *event)
|
akerr_ErrorContext AKERR_NOIGNORE *user_breakpoint(actor *obj, SDL_Event *event)
|
||||||
{
|
{
|
||||||
PREPARE_ERROR(errctx);
|
PREPARE_ERROR(errctx);
|
||||||
@@ -111,12 +135,16 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
|||||||
controlmap->controls[3].event_off = SDL_EVENT_KEY_UP;
|
controlmap->controls[3].event_off = SDL_EVENT_KEY_UP;
|
||||||
controlmap->controls[3].handler_on = &SDL3GActor_cmhf_right_on;
|
controlmap->controls[3].handler_on = &SDL3GActor_cmhf_right_on;
|
||||||
controlmap->controls[3].handler_off = &SDL3GActor_cmhf_right_off;
|
controlmap->controls[3].handler_off = &SDL3GActor_cmhf_right_off;
|
||||||
|
|
||||||
// Breakpoint
|
// Breakpoint
|
||||||
controlmap->controls[4].key = SDLK_ESCAPE;
|
controlmap->controls[4].key = SDLK_ESCAPE;
|
||||||
controlmap->controls[4].event_on = SDL_EVENT_KEY_DOWN;
|
controlmap->controls[4].event_on = SDL_EVENT_KEY_DOWN;
|
||||||
controlmap->controls[4].handler_on = &user_breakpoint;
|
controlmap->controls[4].handler_on = &user_breakpoint;
|
||||||
|
|
||||||
|
// Toggle the music
|
||||||
|
controlmap->controls[5].key = SDLK_M;
|
||||||
|
controlmap->controls[5].event_on = SDL_EVENT_KEY_DOWN;
|
||||||
|
controlmap->controls[5].handler_on = &music_toggle;
|
||||||
|
|
||||||
} CLEANUP {
|
} CLEANUP {
|
||||||
} PROCESS(errctx) {
|
} PROCESS(errctx) {
|
||||||
|
|||||||
Reference in New Issue
Block a user