mirror of
https://github.com/CTurt/dsgmLib.git
synced 2025-06-18 22:55:33 -04:00
Saving example
This commit is contained in:
parent
765bb7b450
commit
29b0bdd102
2
examples/Saving/Makefile
Normal file
2
examples/Saving/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
DSGMLIB := $(DEVKITPRO)/dsgmLib
|
||||
include $(DSGMLIB)/DSGM_Makefile
|
BIN
examples/Saving/Saving.nds
Normal file
BIN
examples/Saving/Saving.nds
Normal file
Binary file not shown.
57
examples/Saving/include/project.h
Normal file
57
examples/Saving/include/project.h
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#define DSGM_SOUND_STREAM_COUNT 0
|
||||
#define DSGM_SOUND_EFFECT_COUNT 0
|
||||
#define DSGM_SOUND_COUNT (DSGM_SOUND_STREAM_COUNT + DSGM_SOUND_EFFECT_COUNT)
|
||||
#define DSGM_BACKGROUND_COUNT 0
|
||||
#define DSGM_PALETTE_COUNT 1
|
||||
#define DSGM_SPRITE_COUNT 2
|
||||
#define DSGM_OBJECT_COUNT 1
|
||||
#define DSGM_ROOM_COUNT 1
|
||||
|
||||
// Include backgrounds, palettes and sprites to be loaded from RAM
|
||||
|
||||
// No sounds, no enum
|
||||
//typedef enum {
|
||||
//} DSGM_SoundNames;
|
||||
|
||||
// No backgrounds, no enum
|
||||
//typedef enum {
|
||||
//} DSGM_BackgroundNames;
|
||||
|
||||
typedef enum {
|
||||
DSGMPal0,
|
||||
} DSGM_PaletteNames;
|
||||
|
||||
typedef enum {
|
||||
taptapman,
|
||||
ballSprite,
|
||||
} DSGM_SpriteNames;
|
||||
|
||||
typedef enum {
|
||||
ball,
|
||||
} DSGM_ObjectNames;
|
||||
|
||||
typedef struct {
|
||||
DSGM_ObjectInstanceBase;
|
||||
struct {
|
||||
} *variables;
|
||||
} ballObjectInstance;
|
||||
|
||||
typedef enum {
|
||||
Room_1,
|
||||
} DSGM_RoomNames;
|
||||
|
||||
extern DSGM_Sound DSGM_Sounds[DSGM_SOUND_COUNT];
|
||||
extern DSGM_Background DSGM_Backgrounds[DSGM_BACKGROUND_COUNT];
|
||||
extern DSGM_Palette DSGM_Palettes[DSGM_PALETTE_COUNT];
|
||||
extern DSGM_Sprite DSGM_Sprites[DSGM_SPRITE_COUNT];
|
||||
extern DSGM_Object DSGM_Objects[DSGM_OBJECT_COUNT];
|
||||
extern DSGM_Room DSGM_Rooms[DSGM_ROOM_COUNT];
|
||||
|
||||
extern int DSGM_currentRoom;
|
||||
|
||||
void DSGM_SetupRooms(int room);
|
||||
|
||||
void ball_create(ballObjectInstance *me);
|
||||
void ball_loop(ballObjectInstance *me);
|
0
examples/Saving/music/.gitkeep
Normal file
0
examples/Saving/music/.gitkeep
Normal file
BIN
examples/Saving/nitrofiles/DSGMPal0_Pal.bin
Normal file
BIN
examples/Saving/nitrofiles/DSGMPal0_Pal.bin
Normal file
Binary file not shown.
BIN
examples/Saving/nitrofiles/ball_Sprite.bin
Normal file
BIN
examples/Saving/nitrofiles/ball_Sprite.bin
Normal file
Binary file not shown.
BIN
examples/Saving/nitrofiles/taptapman_Sprite.bin
Normal file
BIN
examples/Saving/nitrofiles/taptapman_Sprite.bin
Normal file
Binary file not shown.
235
examples/Saving/source/project.c
Normal file
235
examples/Saving/source/project.c
Normal file
@ -0,0 +1,235 @@
|
||||
#include "DSGM.h"
|
||||
|
||||
#include "DSGM_projectHelper.h"
|
||||
|
||||
// User variables / declarations
|
||||
int timer = 0;
|
||||
|
||||
// Resources
|
||||
DSGM_Sound DSGM_Sounds[DSGM_SOUND_COUNT] = {
|
||||
};
|
||||
|
||||
DSGM_Background DSGM_Backgrounds[DSGM_BACKGROUND_COUNT] = {
|
||||
};
|
||||
|
||||
DSGM_Palette DSGM_Palettes[DSGM_PALETTE_COUNT] = {
|
||||
DSGM_FORM_NITRO_PALETTE(DSGMPal0),
|
||||
};
|
||||
|
||||
DSGM_Sprite DSGM_Sprites[DSGM_SPRITE_COUNT] = {
|
||||
DSGM_FORM_NITRO_SPRITE(taptapman, DSGMPal0, SpriteSize_32x32, 9),
|
||||
DSGM_FORM_NITRO_SPRITE(ball, DSGMPal0, SpriteSize_32x32, 1),
|
||||
};
|
||||
|
||||
DSGM_Object DSGM_Objects[DSGM_OBJECT_COUNT] = {
|
||||
// ball
|
||||
{
|
||||
&DSGM_Sprites[ballSprite],
|
||||
(DSGM_Event)ball_create,
|
||||
(DSGM_Event)ball_loop,
|
||||
DSGM_NO_EVENT,
|
||||
DSGM_NO_EVENT,
|
||||
NULL, 0,
|
||||
|
||||
sizeof(*((ballObjectInstance *)0)->variables)
|
||||
},
|
||||
};
|
||||
|
||||
DSGM_Room DSGM_Rooms[DSGM_ROOM_COUNT] = {
|
||||
// Room_1
|
||||
{
|
||||
// Backgrounds
|
||||
{
|
||||
// Bottom screen
|
||||
{
|
||||
// Layer 0
|
||||
{
|
||||
DSGM_NO_BACKGROUND, // Background
|
||||
DSGM_BOTTOM, // Screen
|
||||
0, // Layer
|
||||
false, // Attached to view system
|
||||
0, // Map base
|
||||
0, // Tile base
|
||||
0, 0, 0
|
||||
},
|
||||
|
||||
// Layer 1
|
||||
{
|
||||
DSGM_NO_BACKGROUND, // Background
|
||||
DSGM_BOTTOM, // Screen
|
||||
1, // Layer
|
||||
true, // Attached to view system
|
||||
0, // Map base
|
||||
0, // Tile base
|
||||
0, 0, 0
|
||||
},
|
||||
|
||||
// Layer 2
|
||||
{
|
||||
DSGM_NO_BACKGROUND, // Background
|
||||
DSGM_BOTTOM, // Screen
|
||||
2, // Layer
|
||||
true, // Attached to view system
|
||||
0, // Map base
|
||||
0, // Tile base
|
||||
0, 0, 0
|
||||
},
|
||||
|
||||
// Layer 3
|
||||
{
|
||||
DSGM_NO_BACKGROUND, // Background
|
||||
DSGM_BOTTOM, // Screen
|
||||
3, // Layer
|
||||
true, // Attached to view system
|
||||
0, // Map base
|
||||
0, // Tile base
|
||||
0, 0, 0
|
||||
},
|
||||
},
|
||||
|
||||
// Top screen
|
||||
{
|
||||
// Layer 0
|
||||
{
|
||||
DSGM_DEFAULT_FONT, // Background
|
||||
DSGM_TOP, // Screen
|
||||
0, // Layer
|
||||
false, // Attached to view system
|
||||
7, // Map base
|
||||
0, // Tile base
|
||||
0, 0, 0
|
||||
},
|
||||
|
||||
// Layer 1
|
||||
{
|
||||
DSGM_NO_BACKGROUND, // Background
|
||||
DSGM_TOP, // Screen
|
||||
1, // Layer
|
||||
true, // Attached to view system
|
||||
0, // Map base
|
||||
0, // Tile base
|
||||
0, 0, 0
|
||||
},
|
||||
|
||||
// Layer 2
|
||||
{
|
||||
DSGM_NO_BACKGROUND, // Background
|
||||
DSGM_TOP, // Screen
|
||||
2, // Layer
|
||||
true, // Attached to view system
|
||||
0, // Map base
|
||||
0, // Tile base
|
||||
0, 0, 0
|
||||
},
|
||||
|
||||
// Layer 3
|
||||
{
|
||||
DSGM_NO_BACKGROUND, // Background
|
||||
DSGM_TOP, // Screen
|
||||
3, // Layer
|
||||
true, // Attached to view system
|
||||
0, // Map base
|
||||
0, // Tile base
|
||||
0, 0, 0
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
// Initial views
|
||||
{
|
||||
// Bottom screen
|
||||
{
|
||||
0, 0
|
||||
},
|
||||
|
||||
// Top screen
|
||||
{
|
||||
0, 0
|
||||
}
|
||||
},
|
||||
|
||||
// Views
|
||||
{
|
||||
// Bottom screen
|
||||
{
|
||||
0, 0
|
||||
},
|
||||
|
||||
// Top screen
|
||||
{
|
||||
0, 0
|
||||
}
|
||||
},
|
||||
|
||||
NULL, // Room handler
|
||||
|
||||
// Object groups are dynamic, so must be set up at run time, see DSGM_SetupRooms.
|
||||
{
|
||||
NULL,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
0,
|
||||
0
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
int DSGM_currentRoom = Room_1;
|
||||
|
||||
void DSGM_SetupRooms(int room) {
|
||||
if(room != DSGM_ALL_ROOMS) {
|
||||
switch(room) {
|
||||
case Room_1: goto Room_1; break;
|
||||
}
|
||||
}
|
||||
|
||||
Room_1:
|
||||
DSGM_Debug("Room_1 reset\n");
|
||||
DSGM_LeaveRoom(&DSGM_Rooms[Room_1]);
|
||||
|
||||
DSGM_SetupViews(&DSGM_Rooms[Room_1]);
|
||||
|
||||
DSGM_SetupObjectGroups(&DSGM_Rooms[Room_1], DSGM_TOP, 0);
|
||||
|
||||
DSGM_SetupObjectGroups(&DSGM_Rooms[Room_1], DSGM_BOTTOM, 1);
|
||||
|
||||
DSGM_SetupObjectInstances(&DSGM_Rooms[Room_1].objectGroups[DSGM_BOTTOM][0], &DSGM_Objects[ball], DSGM_BOTTOM, 1,
|
||||
64, 64
|
||||
);
|
||||
|
||||
if(room != DSGM_ALL_ROOMS) return;
|
||||
}
|
||||
|
||||
void ball_create(ballObjectInstance *me) {
|
||||
DSGM_DrawText(DSGM_TOP, 1, 1, "Stylus to move");
|
||||
DSGM_DrawText(DSGM_TOP, 1, 2, "R to save");
|
||||
DSGM_DrawText(DSGM_TOP, 1, 3, "L to load");
|
||||
}
|
||||
|
||||
void ball_loop(ballObjectInstance *me) {
|
||||
if(DSGM_held.Stylus) {
|
||||
me->x = DSGM_stylus.x - 16;
|
||||
me->y = DSGM_stylus.y - 16;
|
||||
}
|
||||
|
||||
if(DSGM_newpress.R) {
|
||||
if(DSGM_StartSaving()) {
|
||||
fwrite(&me->x, sizeof(int), 2, DSGM_save);
|
||||
DSGM_FinishSaving();
|
||||
}
|
||||
else {
|
||||
DSGM_DrawText(DSGM_TOP, 1, 5, "Can't save! DLDI patch, or use hbmenu.");
|
||||
}
|
||||
}
|
||||
|
||||
if(DSGM_newpress.L) {
|
||||
if(DSGM_StartSaving()) {
|
||||
fread(&me->x, sizeof(int), 2, DSGM_save);
|
||||
DSGM_FinishSaving();
|
||||
}
|
||||
else {
|
||||
DSGM_DrawText(DSGM_TOP, 1, 5, "Can't load! DLDI patch, or use hbmenu.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user