Prototype yeet
This commit is contained in:
parent
029a7e7e52
commit
6adbc83c86
|
@ -2,9 +2,14 @@
|
|||
#include "grid.h"
|
||||
#include "player.h"
|
||||
|
||||
enum GameState { GameFloor, GameRest };
|
||||
|
||||
struct Game {
|
||||
enum GameState state;
|
||||
struct Grid floor;
|
||||
struct Grid rest;
|
||||
struct Player player;
|
||||
struct Player player_rest;
|
||||
};
|
||||
|
||||
struct Game game_init(void);
|
||||
|
|
|
@ -13,4 +13,5 @@ struct Player {
|
|||
|
||||
struct Player player_init(int x, int y);
|
||||
void player_draw(struct Player, int scr_x, int scr_y);
|
||||
void player_update(struct Player *restrict, struct Grid *restrict);
|
||||
/* return 1 on zone transition */
|
||||
int player_update(struct Player *restrict, struct Grid *restrict);
|
||||
|
|
|
@ -9,5 +9,6 @@ enum Tile {
|
|||
TILE_OBSTACLE_2,
|
||||
TILE_OBSTACLE_3,
|
||||
TILE_SOLID,
|
||||
TILE_ZONE_TRANSITION,
|
||||
};
|
||||
#define TILE_OOB TILE_SOLID
|
||||
|
|
|
@ -5,9 +5,12 @@ struct Game
|
|||
game_init(void)
|
||||
{
|
||||
struct Game game;
|
||||
game.state = GameFloor;
|
||||
game.floor = grid_new(1024, 14);
|
||||
grid_random_walker(&game.floor);
|
||||
game.player = player_init(0, game.floor.height / 2);
|
||||
game.rest = grid_new(25, 14);
|
||||
game.player_rest = player_init(game.rest.width / 2, game.rest.height - 1);
|
||||
return game;
|
||||
}
|
||||
|
||||
|
@ -15,4 +18,5 @@ void
|
|||
game_deinit(struct Game game)
|
||||
{
|
||||
grid_free(game.floor);
|
||||
grid_free(game.rest);
|
||||
}
|
||||
|
|
27
src/main.c
27
src/main.c
|
@ -55,11 +55,32 @@ main_loop(struct Game *restrict game)
|
|||
scroll_x = 99;
|
||||
|
||||
clearevents();
|
||||
player_update(&game->player, &game->floor);
|
||||
switch(game->state) {
|
||||
case GameFloor:
|
||||
if (player_update(&game->player, &game->floor))
|
||||
game->state = GameRest;
|
||||
break;
|
||||
case GameRest:
|
||||
if (player_update(&game->player_rest, &game->rest))
|
||||
game->state = GameFloor;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
dclear(C_BLACK);
|
||||
grid_draw(game->floor, (scroll_x < 0) ? (scroll_x) : (0), 0);
|
||||
player_draw(game->player, (scroll_x < 0) ? (scroll_x) : (0), 0);
|
||||
switch(game->state) {
|
||||
case GameFloor:
|
||||
grid_draw(game->floor, (scroll_x < 0) ? (scroll_x) : (0), 0);
|
||||
player_draw(game->player, (scroll_x < 0) ? (scroll_x) : (0), 0);
|
||||
break;
|
||||
case GameRest:
|
||||
grid_draw(game->rest, -2, 0);
|
||||
player_draw(game->player_rest, -2, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
dupdate();
|
||||
|
||||
scroll_x -= 1;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "player.h"
|
||||
#include <gint/keyboard.h>
|
||||
|
||||
void
|
||||
int
|
||||
player_update(struct Player *restrict player, struct Grid *restrict grid)
|
||||
{
|
||||
int new_x;
|
||||
|
@ -40,13 +40,27 @@ player_update(struct Player *restrict player, struct Grid *restrict grid)
|
|||
if (new_y >= grid->height)
|
||||
new_y = 0;
|
||||
|
||||
if (!grid_get(*grid, new_x, new_y)) {
|
||||
if (new_x == player->x && new_y == player->y)
|
||||
return 0;
|
||||
|
||||
switch (grid_get(*grid, new_x, new_y)) {
|
||||
case TILE_VOID:
|
||||
player->x = new_x;
|
||||
player->y = new_y;
|
||||
} else if (grid_get(*grid, new_x, new_y) != TILE_SOLID) {
|
||||
break;
|
||||
case TILE_ZONE_TRANSITION:
|
||||
return 1;
|
||||
case TILE_OBSTACLE_1:
|
||||
player->cash += 1;
|
||||
/* fallthrough */
|
||||
case TILE_OBSTACLE_2:
|
||||
case TILE_OBSTACLE_3:
|
||||
grid_set(grid, new_x, new_y, grid_get(*grid, new_x, new_y) - 1);
|
||||
/* get rich! */
|
||||
if (!grid_get(*grid, new_x, new_y))
|
||||
player->cash += 1;
|
||||
break;
|
||||
case TILE_SOLID:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue