polarity
This commit is contained in:
parent
21e2a088dc
commit
14e7c15326
|
@ -16,6 +16,7 @@ set(SOURCES
|
|||
src/input.c
|
||||
src/level.c
|
||||
src/player.c
|
||||
src/polarity.c
|
||||
)
|
||||
|
||||
set(ASSETS
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
enum Key { K_LEFT, K_RIGHT, K_UP, K_DOWN, K_JUMP, K_EXIT, K_COUNT };
|
||||
enum Key { K_LEFT, K_RIGHT, K_UP, K_DOWN, K_JUMP, K_POLARITY, K_EXIT, K_COUNT };
|
||||
enum KeyState { KS_UP, KS_DOWN, KS_PRESS };
|
||||
|
||||
struct Input {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
int polarity(void);
|
||||
void polarity_invert(void);
|
|
@ -3,6 +3,8 @@
|
|||
enum Tile {
|
||||
TILE_AIR,
|
||||
TILE_SOLID,
|
||||
TILE_RED,
|
||||
TILE_BLUE,
|
||||
TILE_SPAWN,
|
||||
TILE_EXIT,
|
||||
TILE_BURN,
|
||||
|
|
BIN
res/bounce.kble
BIN
res/bounce.kble
Binary file not shown.
BIN
res/burn.kble
BIN
res/burn.kble
Binary file not shown.
BIN
res/test.kble
BIN
res/test.kble
Binary file not shown.
BIN
res/tileset.png
BIN
res/tileset.png
Binary file not shown.
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.0 KiB |
|
@ -2,8 +2,8 @@
|
|||
#include <gint/keyboard.h>
|
||||
|
||||
static struct Input input;
|
||||
static const int default_map[K_COUNT] = {KEY_LEFT, KEY_RIGHT, KEY_UP,
|
||||
KEY_DOWN, KEY_SHIFT, KEY_EXIT};
|
||||
static const int default_map[K_COUNT] = {
|
||||
KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, KEY_SHIFT, KEY_ALPHA, KEY_EXIT};
|
||||
|
||||
void
|
||||
input_init(void)
|
||||
|
|
11
src/level.c
11
src/level.c
|
@ -1,6 +1,7 @@
|
|||
#include "level.h"
|
||||
#include "conf.h"
|
||||
#include "player.h"
|
||||
#include "polarity.h"
|
||||
#include "tile.h"
|
||||
#include "vec.h"
|
||||
#include "visual_data.h"
|
||||
|
@ -79,6 +80,16 @@ level_regen_visual_data(void)
|
|||
vd->img_x = tile % tileset_width * TILE_SIZE;
|
||||
vd->img_y = (int)(tile / tileset_width) * TILE_SIZE;
|
||||
vd->visible = tile != 0;
|
||||
switch (tile) {
|
||||
case TILE_RED:
|
||||
vd->img_y += polarity() ? TILE_SIZE : 0;
|
||||
break;
|
||||
case TILE_BLUE:
|
||||
vd->img_y += polarity() ? 0 : TILE_SIZE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
src/player.c
14
src/player.c
|
@ -3,6 +3,7 @@
|
|||
#include "draw.h"
|
||||
#include "input.h"
|
||||
#include "level.h"
|
||||
#include "polarity.h"
|
||||
#include "tile.h"
|
||||
#include "util.h"
|
||||
|
||||
|
@ -35,8 +36,12 @@ player_update(struct Player *p)
|
|||
// const int k_down = input_down(K_DOWN);
|
||||
const int k_jump = input_down(K_JUMP);
|
||||
const int kp_jump = input_pressed(K_JUMP);
|
||||
const int kp_polarity = input_pressed(K_POLARITY);
|
||||
const int dir_x = k_right - k_left;
|
||||
|
||||
/* polarity swap */
|
||||
if (kp_polarity) polarity_invert();
|
||||
|
||||
/* horizontal friction & acceleration */
|
||||
p->spd.x *= on_ground ? (1 - GROUND_FRICTION) : (1 - AIR_FRICTION);
|
||||
p->spd.x +=
|
||||
|
@ -116,6 +121,11 @@ player_move(struct Player *p, struct Vec spd)
|
|||
const int sign_y = sign(spd.y);
|
||||
if (!sign_x && !sign_y) sign_x = 1.0f;
|
||||
|
||||
if (collide_solid(p->pos.x, p->pos.y)) {
|
||||
reset_speed(p, 1, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
p->pos.x += spd.x;
|
||||
if (collide_solid(p->pos.x, p->pos.y)) reset_speed(p, 1, 0);
|
||||
while (collide_solid(p->pos.x, p->pos.y))
|
||||
|
@ -170,5 +180,7 @@ collide(int x, int y, int tile)
|
|||
static int
|
||||
collide_solid(int x, int y)
|
||||
{
|
||||
return collide(x, y, TILE_SOLID);
|
||||
return collide(x, y, TILE_SOLID) ||
|
||||
(!polarity() && collide(x, y, TILE_RED)) ||
|
||||
(polarity() && collide(x, y, TILE_BLUE));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#include "polarity.h"
|
||||
#include "level.h"
|
||||
|
||||
static int pol = 0;
|
||||
|
||||
int
|
||||
polarity(void)
|
||||
{
|
||||
return pol;
|
||||
}
|
||||
|
||||
void
|
||||
polarity_invert(void)
|
||||
{
|
||||
pol = !pol;
|
||||
level_regen_visual_data();
|
||||
}
|
Loading…
Reference in New Issue