Skip to content

Commit

Permalink
everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Spaceman1701 committed Jan 23, 2022
1 parent 6a21055 commit ab5811a
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 23 deletions.
4 changes: 2 additions & 2 deletions res/map/testing.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@
<property name="target_map" value="testing"/>
</properties>
</object>
<object id="23" x="392" y="8" width="16" height="16">
<object id="23" x="392" y="616" width="16" height="16">
<properties>
<property name="is_entrance" type="bool" value="true"/>
<property name="target_entrance" type="int" value="2"/>
<property name="target_map" value="dungeon_one"/>
</properties>
</object>
<object id="34" x="392" y="616" width="16" height="16">
<object id="34" x="392" y="8" width="16" height="16">
<properties>
<property name="is_entrance" type="bool" value="true"/>
<property name="target_entrance" type="int" value="17"/>
Expand Down
35 changes: 23 additions & 12 deletions src/impl/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,6 @@ void init_game() {
};
}

void save_game() {
// diskw(&game_state, sizeof(struct GameState));
}

void load_game() {
// struct GameState temp;
// diskr(&temp, sizeof(struct GameState));
// if (temp.valid) {
// game_state = temp;
// }
}

int calc_room_id(struct GameState *game) {
return game->currentRoom.loc.x +
(game->currentRoom.loc.y * (game->overworld->static_map.width / 20));
Expand Down Expand Up @@ -117,3 +105,26 @@ void set_default_room_state(struct GameState *game) {

game->currentRoom.state = new_state;
}

// void load_world(struct GameState *game) {
// int state_array_loc = 0;
// for (uint8_t i = 0; i < 3; i++) {
// if (game->room_states.id[i] == game->world_id) {
// state_array_loc = i;
// }
// }
// uint16_t id = game->room_states.state[state_array_loc];
// switch (id) {
// case TILEMAP_TESTING_ID:
// game->overworld = &testing_tilemap;
// break;
// case TILEMAP_TESTING_ID:
// game->overworld = &testing_tilemap;
// break;
// case TILEMAP_TESTING_ID:
// game->overworld = &testing_tilemap;
// break;
// default:
// break;
// }
// }
11 changes: 4 additions & 7 deletions src/impl/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "text.h"

#include "collision.h"
#include "save.h"

void on_room_enter() {
struct Room *new_room = &game_state.currentRoom;
Expand Down Expand Up @@ -39,24 +40,20 @@ void on_room_enter() {
}
}
game_state.currentRoom.blocks.size = index;

save();
}

void on_room_exit() {
tracef("freeing %d block(s) as I leave room %d %d",
game_state.currentRoom.blocks.size, game_state.player.loc.room.x,
game_state.player.loc.room.y);
game_state.currentRoom.blocks.size = 0;
save_game();

game_state.currentRoom.loc = game_state.player.loc.room;
}

void on_game_launch() {

load_game();

on_room_enter();
}
void on_game_launch() { on_room_enter(); }

struct TerrainMap terrain;

Expand Down
10 changes: 8 additions & 2 deletions src/impl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
#include "../../res/map/dungeon_one.map.h"
#include "../../res/map/dungeon_two.map.h"
#include "../../res/map/testing.map.h"

#include "block.h"
#include "save.h"

#include "wasm4.h"

void start() {
initalize_dungeon_one_tilemap();
initalize_dungeon_two_tilemap();
initalize_testing_tilemap();
init_game();

on_game_launch();
if (load_save_game()) {
trace("game loaded");
}

// on_game_launch();
}

void update() { on_update(); }
29 changes: 29 additions & 0 deletions src/impl/save.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "save.h"

void save() {
struct SaveGame g = (struct SaveGame){
.valid = VALID,
.player = game_state.player,
.inventory = game_state.inventory,
.currentRoom = game_state.currentRoom,
.world_id = game_state.world_id,
};

diskw(&g, sizeof(struct SaveGame));
}

bool load_save_game() {
struct SaveGame g;
diskr(&g, sizeof(struct SaveGame));

if (g.valid == VALID) {
game_state.currentRoom = g.currentRoom;
game_state.player = g.player;
game_state.inventory = g.inventory;
game_state.world_id = g.world_id;

return true;
}

return false;
}
15 changes: 15 additions & 0 deletions src/include/save.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "game.h"
#include "wasm4.h"

#define VALID 0xCAFEBABE

struct SaveGame {
uint32_t valid;
struct Player player;
struct PlayerInventory inventory;
struct Room currentRoom;
uint16_t world_id;
};

void save();
bool load_save_game();

0 comments on commit ab5811a

Please sign in to comment.