Prototype done! :D
This commit is contained in:
parent
f0001a7809
commit
9bfa3e802a
|
@ -2,7 +2,7 @@
|
|||
#include "grid.h"
|
||||
#include "player.h"
|
||||
|
||||
enum GameState { GameFloor, GameRest };
|
||||
enum GameState { GameFloor, GameRest, GameDead };
|
||||
|
||||
struct Game {
|
||||
enum GameState state;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
struct Player {
|
||||
int x;
|
||||
int y;
|
||||
int cash;
|
||||
int *cash;
|
||||
int left_held;
|
||||
int right_held;
|
||||
int up_held;
|
||||
|
@ -12,6 +12,6 @@ struct Player {
|
|||
};
|
||||
|
||||
struct Player player_init(int x, int y);
|
||||
void player_draw(struct Player, int scr_x, int scr_y);
|
||||
int player_draw(struct Player, int scr_x, int scr_y);
|
||||
/* return 1 on zone transition */
|
||||
int player_update(struct Player *restrict, struct Grid *restrict);
|
||||
|
|
|
@ -10,6 +10,7 @@ enum Tile {
|
|||
TILE_OBSTACLE_3,
|
||||
TILE_SOLID,
|
||||
TILE_ZONE_TRANSITION,
|
||||
TILE_CONTRACTS,
|
||||
TILE_CONTRACTS_SPEED_UP,
|
||||
TILE_CONTRACTS_SLOW_DOWN,
|
||||
};
|
||||
#define TILE_OOB TILE_SOLID
|
||||
|
|
|
@ -10,7 +10,8 @@ game_init(void)
|
|||
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);
|
||||
game.player_rest =
|
||||
player_init(game.rest.width / 2, game.rest.height - 1);
|
||||
return game;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,9 +68,12 @@ tile_draw(enum Tile tile, int x, int y)
|
|||
case TILE_ZONE_TRANSITION:
|
||||
color = C_RGB(0, 31, 31);
|
||||
break;
|
||||
case TILE_CONTRACTS:
|
||||
case TILE_CONTRACTS_SPEED_UP:
|
||||
color = C_RGB(31, 31, 0);
|
||||
break;
|
||||
case TILE_CONTRACTS_SLOW_DOWN:
|
||||
color = C_RED;
|
||||
break;
|
||||
default:
|
||||
color = C_RGB(31, 0, 31);
|
||||
break;
|
||||
|
|
|
@ -58,7 +58,8 @@ grid_random_walker(struct Grid *restrict grid)
|
|||
/* place resting points */
|
||||
for (x = 64; x < grid->width; x += 64) {
|
||||
for (y = 0; y < grid->height; y += 1) {
|
||||
if (!grid_get(*grid, x, y)) break;
|
||||
if (!grid_get(*grid, x, y))
|
||||
break;
|
||||
}
|
||||
grid_set(grid, x, y, TILE_ZONE_TRANSITION);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
#include "grid.h"
|
||||
#include "tiles.h"
|
||||
|
||||
void grid_shop(struct Grid *restrict grid) {
|
||||
void
|
||||
grid_shop(struct Grid *restrict grid)
|
||||
{
|
||||
const int x_middle = grid->width / 2;
|
||||
const int y_middle = grid->height / 2;
|
||||
|
||||
grid_set(grid, x_middle, y_middle, TILE_CONTRACTS);
|
||||
grid_set(grid, x_middle + 4, y_middle, TILE_ZONE_TRANSITION);
|
||||
grid_set(grid, x_middle - 2, y_middle, TILE_CONTRACTS_SPEED_UP);
|
||||
grid_set(grid, x_middle + 2, y_middle, TILE_CONTRACTS_SLOW_DOWN);
|
||||
grid_set(grid, grid->width - 1, grid->height - 1, TILE_ZONE_TRANSITION);
|
||||
}
|
||||
|
|
44
src/main.c
44
src/main.c
|
@ -49,37 +49,61 @@ init_rand(void)
|
|||
static int
|
||||
main_loop(struct Game *restrict game)
|
||||
{
|
||||
static int scroll_x = 1 << 13;
|
||||
|
||||
if (scroll_x == 1 << 13)
|
||||
scroll_x = 99;
|
||||
static float scroll_x = 99.0;
|
||||
static float scroll_speed = 0.6;
|
||||
|
||||
clearevents();
|
||||
switch(game->state) {
|
||||
switch (game->state) {
|
||||
case GameFloor:
|
||||
if (player_update(&game->player, &game->floor)) {
|
||||
game->state = GameRest;
|
||||
grid_shop(&game->rest);
|
||||
}
|
||||
scroll_x -= 1;
|
||||
scroll_x -= scroll_speed;
|
||||
scroll_speed += 0.0003;
|
||||
break;
|
||||
case GameRest:
|
||||
if (player_update(&game->player_rest, &game->rest))
|
||||
switch (player_update(&game->player_rest, &game->rest)) {
|
||||
case -1:
|
||||
scroll_speed += 0.2;
|
||||
break;
|
||||
case -2:
|
||||
scroll_speed -= 0.6;
|
||||
if (scroll_speed < 0.6)
|
||||
scroll_speed = 0.6;
|
||||
break;
|
||||
case 1:
|
||||
game->state = GameFloor;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case GameDead:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
dclear(C_BLACK);
|
||||
switch(game->state) {
|
||||
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);
|
||||
if (!player_draw(game->player,
|
||||
(scroll_x < 0) ? (scroll_x) : (0), 0))
|
||||
game->state = GameDead;
|
||||
break;
|
||||
case GameRest:
|
||||
grid_draw(game->rest, -2, 0);
|
||||
player_draw(game->player_rest, -2, 0);
|
||||
if (!player_draw(game->player_rest, -2, 0))
|
||||
game->state = GameDead;
|
||||
break;
|
||||
case GameDead:
|
||||
dprint(0, 0, C_WHITE, "You died :(");
|
||||
dprint(0, 16, C_WHITE, "Collected $%d", *game->player.cash);
|
||||
dprint(0, 32, C_WHITE, "Survived %d feets",
|
||||
-(int)(scroll_x / 4));
|
||||
dprint(0, 48, C_WHITE, "Thanks for playing :)");
|
||||
dprint(0, 64, C_WHITE, "(Press EXIT)");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
#include "tiles.h"
|
||||
#include <gint/display.h>
|
||||
|
||||
void
|
||||
int
|
||||
player_draw(struct Player player, int scr_x, int scr_y)
|
||||
{
|
||||
const int x = scr_x + player.x * TILE_WIDTH;
|
||||
const int y = scr_y + player.y * TILE_HEIGHT;
|
||||
if (x < -TILE_WIDTH * 4)
|
||||
return 0;
|
||||
drect(x + 2, y + 2, x + TILE_WIDTH - 3, y + TILE_HEIGHT - 3, C_GREEN);
|
||||
dprint(0, 0, C_RGB(31, 31, 0), "$%d", player.cash);
|
||||
dprint(0, 0, C_RGB(31, 31, 0), "$%d", *player.cash);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
struct Player
|
||||
player_init(int x, int y)
|
||||
{
|
||||
static int cash = 0;
|
||||
struct Player player;
|
||||
player.x = x;
|
||||
player.y = y;
|
||||
player.cash = 0;
|
||||
player.cash = &cash;
|
||||
return player;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "grid.h"
|
||||
#include "player.h"
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/std/stdlib.h>
|
||||
|
||||
int
|
||||
player_update(struct Player *restrict player, struct Grid *restrict grid)
|
||||
|
@ -51,11 +52,25 @@ player_update(struct Player *restrict player, struct Grid *restrict grid)
|
|||
case TILE_ZONE_TRANSITION:
|
||||
grid_set(grid, new_x, new_y, TILE_VOID);
|
||||
return 1;
|
||||
case TILE_CONTRACTS:
|
||||
/* start contracts sequence */
|
||||
break;
|
||||
case TILE_CONTRACTS_SPEED_UP:
|
||||
player->x = new_x;
|
||||
player->y = new_y;
|
||||
grid_set(grid, new_x, new_y, TILE_VOID);
|
||||
grid_set(grid, new_x + 4, new_y, TILE_VOID);
|
||||
*player->cash += 50;
|
||||
return -1;
|
||||
case TILE_CONTRACTS_SLOW_DOWN:
|
||||
player->x = new_x;
|
||||
player->y = new_y;
|
||||
if (*player->cash < 50)
|
||||
break;
|
||||
grid_set(grid, new_x, new_y, TILE_VOID);
|
||||
grid_set(grid, new_x - 4, new_y, TILE_VOID);
|
||||
*player->cash -= 50;
|
||||
return -2;
|
||||
case TILE_OBSTACLE_1:
|
||||
player->cash += 1;
|
||||
/* rand between 1 and 4 */
|
||||
*player->cash += 1 + rand() % 4;
|
||||
/* fallthrough */
|
||||
case TILE_OBSTACLE_2:
|
||||
case TILE_OBSTACLE_3:
|
||||
|
|
Loading…
Reference in New Issue