Levele exit and next level load
This commit is contained in:
parent
01a3aa59d5
commit
60b374f84e
10
TODO.txt
10
TODO.txt
|
@ -7,7 +7,6 @@ x Add enemies (generated through lua)
|
|||
x Move "clip" from texture to sprite
|
||||
x Hitting enemies
|
||||
x Nicer enemy hits (Text textures, healthbars?)
|
||||
- This could need some love later on.
|
||||
x Add hits to stats
|
||||
x Player hits
|
||||
x Moving enemies
|
||||
|
@ -16,14 +15,15 @@ x Moving enemies
|
|||
x Fleeing enemies
|
||||
x Add hooks to lua
|
||||
x Add movement depending on state (aggro, scared, passive)
|
||||
- Lower dungeon levels
|
||||
x Lower dungeon levels
|
||||
- GUI (lua generated)
|
||||
- Items (lua generated?)
|
||||
- More GUI
|
||||
o XP
|
||||
- Some xp amount logic
|
||||
- Level threshholds
|
||||
- Menus
|
||||
- Statistics
|
||||
- More stuff to count
|
||||
- gui
|
||||
- Items
|
||||
- More gui
|
||||
|
||||
Legend: ( '-' = future) ( 'x' = completed ) ( 'o' = begun )
|
||||
|
|
|
@ -28,6 +28,8 @@ local wall = {
|
|||
horizontal = nil
|
||||
}
|
||||
|
||||
local special = { level_exit = nil }
|
||||
|
||||
local floorDecor = { }
|
||||
local lightDecor = { }
|
||||
|
||||
|
@ -101,14 +103,20 @@ local function load_decor_textures()
|
|||
lightDecor.candle2 = { td0, td1, 32, 8 * 16, true, true }
|
||||
end
|
||||
|
||||
local function load_special_tiles()
|
||||
tt = add_texture(map, "assets/Objects/Tile.png")
|
||||
special.level_exit = { tt, -1, 16, 16, false, true, true }
|
||||
end
|
||||
|
||||
local function repack(data)
|
||||
return {
|
||||
textureIndex0 = data[1],
|
||||
textureIndex1 = data[2],
|
||||
textureIndex1 = data[2] or -1,
|
||||
tileClipX = data[3],
|
||||
tileClipY = data[4],
|
||||
isCollider = data[5] or false,
|
||||
isLightSource = data[6] or false,
|
||||
isLevelExit = data[7] or false,
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -208,6 +216,12 @@ local function add_exit(map, direction)
|
|||
end
|
||||
end
|
||||
|
||||
local function add_level_exit(map)
|
||||
x = random(14)
|
||||
y = random(10)
|
||||
add_tile(map, x, y, repack(special.level_exit));
|
||||
end
|
||||
|
||||
local function build_vert_center_coridoor(map, offset)
|
||||
for j=0,4 do
|
||||
add_tile(map, 6, offset+j, repack(wall.vertical));
|
||||
|
@ -328,6 +342,9 @@ function module.build_square_room(map, room)
|
|||
for exit=1, #room.exits do
|
||||
add_exit(map, room.exits[exit]);
|
||||
end
|
||||
if room.goal then
|
||||
add_level_exit(map);
|
||||
end
|
||||
end
|
||||
|
||||
function module.load_textures(map)
|
||||
|
@ -360,6 +377,7 @@ function module.load_textures(map)
|
|||
wall.horizontal = { t_wall, -1, xo + 16, yo + 0, true }
|
||||
|
||||
load_decor_textures()
|
||||
load_special_tiles()
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef GAMESTATE_H_
|
||||
#define GAMESTATE_H_
|
||||
|
||||
typedef enum GameState_t {
|
||||
MENU,
|
||||
PLAYING,
|
||||
NEXT_LEVEL
|
||||
} GameState;
|
||||
|
||||
#endif // GAMESTATE_H_
|
54
src/main.c
54
src/main.c
|
@ -12,6 +12,7 @@
|
|||
#include "map_lua.h"
|
||||
#include "timer.h"
|
||||
#include "roommatrix.h"
|
||||
#include "gamestate.h"
|
||||
|
||||
static SDL_Window *gWindow = NULL;
|
||||
static SDL_Renderer *gRenderer = NULL;
|
||||
|
@ -19,7 +20,7 @@ static Player *gPlayer = NULL;
|
|||
static LinkedList *gSpriteList = NULL;
|
||||
static Map *gMap = NULL;
|
||||
static RoomMatrix *gRoomMatrix = NULL;
|
||||
|
||||
static GameState gameState;
|
||||
static Camera gCamera;
|
||||
|
||||
static
|
||||
|
@ -30,7 +31,7 @@ bool initSDL(void)
|
|||
//Dimension dim = (Dimension) { 1920, 1080 };
|
||||
double scale = 1.0;
|
||||
|
||||
if (dim.height > 768) {
|
||||
if (dim.height > 1080) {
|
||||
printf("[**] Hi resolution screen detected (%u x %u)\n", dim.width, dim.height);
|
||||
scale = ((double) dim.height)/1080;
|
||||
printf("[**] Scaling by %f\n", scale);
|
||||
|
@ -41,6 +42,19 @@ bool initSDL(void)
|
|||
printf("[!!] Could not initiate SDL2: %s\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( (IMG_Init(imgFlags) & imgFlags) == 0 ) {
|
||||
printf("[!!] Unable to initiate img loading: %s\n",
|
||||
IMG_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( TTF_Init() == -1 ) {
|
||||
printf("[!!] Unable to initiate ttf library: %s\n",
|
||||
TTF_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
gWindow = SDL_CreateWindow("Breakhack",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
|
@ -69,18 +83,6 @@ bool initSDL(void)
|
|||
SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( (IMG_Init(imgFlags) & imgFlags) == 0 ) {
|
||||
printf("[!!] Unable to initiate img loading: %s\n",
|
||||
IMG_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( TTF_Init() == -1 ) {
|
||||
printf("[!!] Unable to initiate ttf library: %s\n",
|
||||
TTF_GetError());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -105,6 +107,8 @@ bool init(void)
|
|||
gRoomMatrix = roommatrix_create();
|
||||
}
|
||||
|
||||
gameState = PLAYING;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -134,6 +138,26 @@ bool handle_events(void)
|
|||
return quit;
|
||||
}
|
||||
|
||||
static void
|
||||
check_next_level(void)
|
||||
{
|
||||
Room *room = gMap->rooms[gMap->currentRoom.x][gMap->currentRoom.y];
|
||||
Position pos = position_to_matrix_coords(&gPlayer->sprite->pos);
|
||||
|
||||
MapTile *tile = room->tiles[pos.x][pos.y];
|
||||
if (!tile) {
|
||||
printf("[!!] Looks like we are out of place\n");
|
||||
return;
|
||||
}
|
||||
if (tile->levelExit) {
|
||||
printf("[**] Building new map\n");
|
||||
map_destroy(gMap);
|
||||
gMap = map_lua_generator_run(gRenderer);
|
||||
gPlayer->sprite->pos = (Position) {
|
||||
TILE_DIMENSION, TILE_DIMENSION };
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void run(void)
|
||||
{
|
||||
|
@ -165,6 +189,8 @@ void run(void)
|
|||
|
||||
SDL_RenderPresent(gRenderer);
|
||||
|
||||
check_next_level();
|
||||
|
||||
int ticks = timer_get_ticks(fpsTimer);
|
||||
if (ticks < 1000/60)
|
||||
SDL_Delay((1000/60) - ticks);
|
||||
|
|
12
src/map.c
12
src/map.c
|
@ -43,7 +43,17 @@ Map* map_create()
|
|||
void map_add_tile(Map *map, Position *tile_pos, MapTile *tile)
|
||||
{
|
||||
const Position *cr = &map->currentRoom;
|
||||
MapTile **oldTile = &map->rooms[cr->x][cr->y]->tiles[tile_pos->x][tile_pos->y];
|
||||
Room *room = map->rooms[cr->x][cr->y];
|
||||
MapTile **oldTile = &room->tiles[tile_pos->x][tile_pos->y];
|
||||
|
||||
// Clear possible decoration
|
||||
if (tile->levelExit && room->tiles[tile_pos->x][tile_pos->y]) {
|
||||
MapTile **decoration = &room->tiles[tile_pos->x][tile_pos->y];
|
||||
free(*decoration);
|
||||
*decoration = NULL;
|
||||
}
|
||||
|
||||
// Clear possible tile
|
||||
if (*oldTile != NULL) {
|
||||
free(*oldTile);
|
||||
*oldTile = NULL;
|
||||
|
|
|
@ -19,6 +19,7 @@ typedef struct MapTile_t {
|
|||
SDL_Rect clip;
|
||||
bool collider;
|
||||
bool lightsource;
|
||||
bool levelExit;
|
||||
} MapTile;
|
||||
|
||||
typedef struct Room_t {
|
||||
|
|
|
@ -94,7 +94,7 @@ extract_tile_data(lua_State *L,
|
|||
Map *map;
|
||||
int tile_x, tile_y;
|
||||
int t_index0, t_index1, tile_clip_x, tile_clip_y;
|
||||
bool collider, lightsource;
|
||||
bool collider, lightsource, levelExit;
|
||||
|
||||
map = luaL_checkmap(L, 1);
|
||||
tile_x = (int) luaL_checkinteger(L, 2);
|
||||
|
@ -111,13 +111,15 @@ extract_tile_data(lua_State *L,
|
|||
lua_getfield(L, 4, "tileClipY");
|
||||
lua_getfield(L, 4, "isCollider");
|
||||
lua_getfield(L, 4, "isLightSource");
|
||||
lua_getfield(L, 4, "isLevelExit");
|
||||
|
||||
t_index0 = (int) luaL_checkinteger(L, -6);
|
||||
t_index1 = (int) luaL_checkinteger(L, -5);
|
||||
tile_clip_x = (int) luaL_checkinteger(L, -4);
|
||||
tile_clip_y = (int) luaL_checkinteger(L, -3);
|
||||
collider = lua_toboolean(L, -2);
|
||||
lightsource = lua_toboolean(L, -1);
|
||||
t_index0 = (int) luaL_checkinteger(L, -7);
|
||||
t_index1 = (int) luaL_checkinteger(L, -6);
|
||||
tile_clip_x = (int) luaL_checkinteger(L, -5);
|
||||
tile_clip_y = (int) luaL_checkinteger(L, -4);
|
||||
collider = lua_toboolean(L, -3);
|
||||
lightsource = lua_toboolean(L, -2);
|
||||
levelExit = lua_toboolean(L, -1);
|
||||
|
||||
// Clear the stack
|
||||
lua_pop(L, 6);
|
||||
|
@ -126,7 +128,12 @@ extract_tile_data(lua_State *L,
|
|||
SDL_Rect clip = (SDL_Rect) { tile_clip_x, tile_clip_y, 16, 16 };
|
||||
|
||||
MapTile *tile = malloc(sizeof(MapTile));
|
||||
*tile = (MapTile) { t_index0, t_index1, clip, collider, lightsource };
|
||||
*tile = (MapTile) { t_index0,
|
||||
t_index1,
|
||||
clip, collider,
|
||||
lightsource,
|
||||
levelExit
|
||||
};
|
||||
|
||||
f_add_tile(map, &tilePos, tile);
|
||||
}
|
||||
|
|
|
@ -27,18 +27,17 @@ void roommatrix_populate_from_map(RoomMatrix *rm, Map *m)
|
|||
|
||||
for (i = 0; i < MAP_ROOM_WIDTH; ++i) {
|
||||
for (j = 0; j < MAP_ROOM_HEIGHT; ++j) {
|
||||
RoomSpace *space = &rm->spaces[i][j];
|
||||
if (r->tiles[i][j]) {
|
||||
rm->spaces[i][j].occupied =
|
||||
space->occupied =
|
||||
r->tiles[i][j]->collider;
|
||||
|
||||
rm->spaces[i][j].lightsource =
|
||||
space->lightsource =
|
||||
r->tiles[i][j]->lightsource;
|
||||
}
|
||||
if (r->decorations[i][j]) {
|
||||
rm->spaces[i][j].occupied |=
|
||||
space->occupied |=
|
||||
r->decorations[i][j]->collider;
|
||||
|
||||
rm->spaces[i][j].lightsource |=
|
||||
space->lightsource |=
|
||||
r->decorations[i][j]->lightsource;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue