Modifiers are working. Ice is completely broken though.
This commit is contained in:
parent
e1f6d108e2
commit
9dcf3c732a
|
@ -1 +1 @@
|
|||
Subproject commit 9fa29497dadf8f5546b6606aa2cd60cbe1f1b8ee
|
||||
Subproject commit 27095913e303824ad216da61f29836ced2f6a365
|
|
@ -1,6 +1,8 @@
|
|||
/* tile modifiers on player vars */
|
||||
#ifndef _DEF_PLAYER_MODIFIERS
|
||||
#define _DEF_PLAYER_MODIFIERS
|
||||
#include "player.h"
|
||||
|
||||
void player_mod_ice(Player *player);
|
||||
void player_mod_glue(Player *player);
|
||||
#endif
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
typedef struct Player_vars {
|
||||
float friction;
|
||||
int acceleration;
|
||||
int gravity;
|
||||
int jump_spd;
|
||||
} Player_vars;
|
||||
|
||||
|
|
|
@ -16,11 +16,16 @@ typedef unsigned char Tile_flags; /* the tile properties (bitmask) */
|
|||
#define P_AIR (0)
|
||||
#define P_BASE (F_SOLID)
|
||||
#define P_SPIKE (F_SPIKY)
|
||||
#define P_ICE (F_SOLID | F_ICE)
|
||||
#define P_GLUE (F_SOLID | F_GLUE)
|
||||
#define P_UNKNOWN (0)
|
||||
|
||||
enum {
|
||||
ID_AIR = TILE_AT(0, 0),
|
||||
ID_CHAIN = TILE_AT(0, 1),
|
||||
ID_SPIKE = TILE_AT(0, 4),
|
||||
ID_CHAIN = TILE_AT(7, 2),
|
||||
ID_ICE = TILE_AT(0, 5),
|
||||
ID_GLUE = TILE_AT(0, 6),
|
||||
ID_BASE_0 = TILE_AT(1, 0),
|
||||
ID_BASE_1 = TILE_AT(2, 0),
|
||||
ID_BASE_2 = TILE_AT(3, 0),
|
||||
|
|
File diff suppressed because one or more lines are too long
40
src/player.c
40
src/player.c
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "player.h"
|
||||
#include "player_vars.h"
|
||||
#include "player_modifiers.h"
|
||||
#include "vec.h"
|
||||
#include "conf.h"
|
||||
#include "camera.h"
|
||||
|
@ -25,11 +26,16 @@
|
|||
#define PLAYER_COLLIDE_SOLID(pos) (player_collide_or(player, pos, level) & F_SOLID)
|
||||
|
||||
void player_init(Player *player, const Level *level) {
|
||||
player->pos = (Vec){TILE_SIZE * 2, TILE_SIZE * 2};
|
||||
player->spd = (Vec){0, 0};
|
||||
player->hbox = (Vec){TILE_SIZE - 1, TILE_SIZE - 1};
|
||||
player->vbox = (Vec){7, 7};
|
||||
player->origin = (Vec){0 * VEC_PRECISION, 0 * VEC_PRECISION};
|
||||
player->pos.x = TILE_SIZE;
|
||||
player->pos.y = TILE_SIZE;
|
||||
player->spd.x = 0;
|
||||
player->spd.y = 0;
|
||||
player->hbox.x = TILE_SIZE - 1;
|
||||
player->hbox.y = TILE_SIZE - 1;
|
||||
player->vbox.x = 7;
|
||||
player->vbox.y = 7;
|
||||
player->origin.x = 0;
|
||||
player->origin.y = 0;
|
||||
player->grace = 0;
|
||||
player->jump_held = false;
|
||||
player->dead = false;
|
||||
|
@ -38,10 +44,9 @@ void player_init(Player *player, const Level *level) {
|
|||
void player_set_vars(Player *player, const Level *level) {
|
||||
player->vars.friction = FRICTION;
|
||||
player->vars.acceleration = ACCELERATION;
|
||||
player->vars.gravity = GRAVITY;
|
||||
player->vars.jump_spd = JUMP_SPD;
|
||||
/* apply modifiers */
|
||||
Vec pos = (Vec){ player->pos.x, player->pos.y + 1 };
|
||||
Vec pos = { player->pos.x, player->pos.y + 1 };
|
||||
Tile_flags flags = player_collide_or(player, pos, level);
|
||||
pos.y -= 2;
|
||||
flags |= player_collide_or(player, pos, level);
|
||||
|
@ -50,6 +55,21 @@ void player_set_vars(Player *player, const Level *level) {
|
|||
flags |= player_collide_or(player, pos, level);
|
||||
pos.x -= 2;
|
||||
flags |= player_collide_or(player, pos, level);
|
||||
/* test for each flag */
|
||||
for (int i = 0; i < sizeof(Tile_flags) * 8; i++) {
|
||||
if (flags & 1) {
|
||||
switch (1 << i) {
|
||||
case F_ICE:
|
||||
player_mod_ice(player);
|
||||
break;
|
||||
case F_GLUE:
|
||||
player_mod_glue(player);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
flags >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
void player_move(Player *player, const Level *level) {
|
||||
|
@ -116,9 +136,9 @@ void player_step(Player *player, Input *input, const Level *level, uint step) {
|
|||
if (player->spd.y < 0 && !player->jump_held) {
|
||||
/* The player is rising and let go the jump key,
|
||||
* accelerate gravity until they reach 0. */
|
||||
player->spd.y += player->vars.gravity * FAST_FALL_FACTOR;
|
||||
player->spd.y += GRAVITY * FAST_FALL_FACTOR;
|
||||
} else {
|
||||
player->spd.y += player->vars.gravity;
|
||||
player->spd.y += GRAVITY;
|
||||
}
|
||||
/* Grace frames allow the player to jump a short
|
||||
* time after leaving a platform. */
|
||||
|
@ -129,7 +149,7 @@ void player_step(Player *player, Input *input, const Level *level, uint step) {
|
|||
* them to do it again and assign them the
|
||||
* corresponding y speed. */
|
||||
player->grace = 0;
|
||||
player->spd.y = JUMP_SPD;
|
||||
player->spd.y = player->vars.jump_spd;
|
||||
player->jump_held = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#include "player_modifiers.h"
|
||||
#include "player.h"
|
||||
|
||||
void player_mod_ice(Player *player) {
|
||||
player->vars.acceleration /= 2;
|
||||
player->vars.friction /= 2;
|
||||
player->vars.acceleration *= 2;
|
||||
float *friction = &player->vars.friction;
|
||||
*friction = 1 - ((1 - *friction) / 2);
|
||||
}
|
||||
|
||||
void player_mod_glue(Player *player) {
|
||||
player->vars.acceleration = 0;
|
||||
player->vars.friction = 1;
|
||||
player->vars.friction = 0;
|
||||
}
|
||||
|
|
|
@ -3,11 +3,18 @@
|
|||
Tile_flags tile_get_flags(Tile tile) {
|
||||
switch (tile) {
|
||||
case ID_AIR:
|
||||
case ID_CHAIN:
|
||||
return P_AIR;
|
||||
break;
|
||||
case ID_CHAIN:
|
||||
case ID_SPIKE:
|
||||
return P_SPIKE;
|
||||
break;
|
||||
case ID_ICE:
|
||||
return P_ICE;
|
||||
break;
|
||||
case ID_GLUE:
|
||||
return P_GLUE;
|
||||
break;
|
||||
case ID_BASE_0:
|
||||
case ID_BASE_1:
|
||||
case ID_BASE_2:
|
||||
|
|
Reference in New Issue