refactored tilemap stuff and added clear function

This commit is contained in:
DaniTheSkunk 2023-01-22 18:02:48 +00:00
parent 1a6edcd22a
commit c3e93ebe76
6 changed files with 33 additions and 13 deletions

View File

@ -1,4 +1,5 @@
#include "gamepad.h" #include "gamepad.h"
#include "gsa_map.h"
#include "gsa_text.h" #include "gsa_text.h"
#include <gsa.h> #include <gsa.h>
@ -25,10 +26,9 @@ void init() {
} }
maps[1].half_tile = true; maps[1].half_tile = true;
/* maps[1].tiles[1][1] = gsa_get_char_tile(0x1010, 's'); */
font = 0x1010; font = 0x1010;
gsa_write_text(1, 7, 3, "Game Skunk Advance!!! <3"); gsa_write_text(1, 7, 3, "Game Skunk Advance!!! <3");
gsa_map_clear(0);
} }
void tick() { void tick() {

View File

@ -22,30 +22,21 @@
#endif #endif
#include "gsa_input.h" #include "gsa_input.h"
#include "gsa_map.h"
#include "gsa_text.h" #include "gsa_text.h"
#include "skunkworks.h" #include "skunkworks.h"
#include "vec2i.h" #include "vec2i.h"
#include "window.h" #include "window.h"
#define MAX_SPRITES 256 #define MAX_SPRITES 256
#define TILEMAP_MAX_SIZE 1024
#define MAX_TILEMAPS 4
struct gsa_sprite { struct gsa_sprite {
u16 tile; u16 tile;
i32 x, y; i32 x, y;
}; };
struct gsa_map {
u16 tiles[TILEMAP_MAX_SIZE][TILEMAP_MAX_SIZE];
i32 w, h;
i32 scrollx, scrolly;
bool half_tile;
};
extern struct gsa_sprite sprites[MAX_SPRITES]; extern struct gsa_sprite sprites[MAX_SPRITES];
extern struct sw_image8 *_gfx; extern struct sw_image8 *_gfx;
extern struct gsa_map maps[MAX_TILEMAPS];
int gsa_main(int argc, char *argv[]); int gsa_main(int argc, char *argv[]);

20
include/gsa_map.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef GUARD_15F247457902E371E05EB34544CB7598
#define GUARD_15F247457902E371E05EB34544CB7598
#include "types.h"
#define TILEMAP_MAX_SIZE 1024
#define MAX_TILEMAPS 4
struct gsa_map {
u16 tiles[TILEMAP_MAX_SIZE][TILEMAP_MAX_SIZE];
i32 w, h;
i32 scrollx, scrolly;
bool half_tile;
};
extern struct gsa_map maps[MAX_TILEMAPS];
void gsa_map_clear(u8 map);
#endif /* GUARD_15F247457902E371E05EB34544CB7598 */

View File

@ -47,6 +47,7 @@ skunk_sources = [
'src/gamepad.c', 'src/gamepad.c',
'src/gsa.c', 'src/gsa.c',
'src/gsa_input.c', 'src/gsa_input.c',
'src/gsa_map.c',
'src/gsa_text.c', 'src/gsa_text.c',
'src/image32.c', 'src/image32.c',
'src/image8.c', 'src/image8.c',

View File

@ -11,7 +11,6 @@
#include "gsa_input.h" #include "gsa_input.h"
struct gsa_sprite sprites[256]; struct gsa_sprite sprites[256];
struct gsa_map maps[MAX_TILEMAPS];
struct sw_image8 *_gfx; struct sw_image8 *_gfx;
struct sw_window *_win; struct sw_window *_win;

9
src/gsa_map.c Normal file
View File

@ -0,0 +1,9 @@
#include "gsa_map.h"
#include "string.h"
struct gsa_map maps[MAX_TILEMAPS];
void gsa_map_clear(u8 map) {
memset(maps[map].tiles, 0, sizeof(maps[map].tiles));
}