Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
glitchcore committed Oct 3, 2020
2 parents 40383c6 + f15cc9e commit 4f84e3c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
18 changes: 11 additions & 7 deletions floopper-bloopper.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ void render_graphics(GameState* state, u8g2_t* fb) {
}

void render_player(GameState* state, u8g2_t* fb) {
u8g2_DrawBox(
fb, state->player_x / 1000, state->player_y / 1000, PLAYER_WIDTH, PLAYER_HEIGHT
);
if (state->player_x < BONDARIES_X_LEFT * SCALE) {
state->player_x = BONDARIES_X_LEFT * SCALE;
} else if (state->player_x > (BONDARIES_X_RIGHT - PLAYER_WIDTH) * SCALE) {
state-> player_x = (BONDARIES_X_RIGHT - PLAYER_WIDTH) * SCALE;
}

u8g2_DrawBox(fb, state->player_x / SCALE, state->player_y / SCALE, PLAYER_WIDTH, PLAYER_HEIGHT);
}

void render_world(GameState* state, u8g2_t* fb) {
Expand All @@ -37,9 +41,9 @@ void handle_key(GameState* state, InputEvent* input) {

if(input->state) {
if (input->input == InputRight) {
state->player_vx = 50;
state->player_vx = SPEED_X;
} else if (input->input == InputLeft) {
state->player_vx = -50;
state->player_vx = -SPEED_X;
}
} else {
if (input->input == InputRight || input->input == InputLeft) {
Expand All @@ -59,11 +63,11 @@ void handle_tick(GameState* state, uint32_t t, uint32_t dt) {

// gravity
if(state->player_jump) {
state->player_y -= 1000;
state->player_y -= 1 * SCALE;
state->player_vy = -60;
state->player_jump = false;
} else {
if(state->player_y > ((SCREEN_HEIGHT - 5 - PLAYER_HEIGHT) * 1000)) {
if(state->player_y > ((SCREEN_HEIGHT - 5 - PLAYER_HEIGHT) * SCALE)) {
state->player_vy = 0;
} else {
state->player_vy += 5;
Expand Down
5 changes: 5 additions & 0 deletions floopper-bloopper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ typedef struct {

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define BONDARIES_X_LEFT 20
#define BONDARIES_X_RIGHT 108

#define PLAYER_WIDTH 6
#define PLAYER_HEIGHT 6
#define SCALE 1000
#define SPEED_X 50
4 changes: 2 additions & 2 deletions game-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void floopper_bloopper(void* p) {
digitalWrite(green, HIGH);

GameState state = {
.player_x = (SCREEN_WIDTH/2 - PLAYER_WIDTH/2) * 1000,
.player_y = (SCREEN_HEIGHT - 5 - PLAYER_HEIGHT) * 1000,
.player_x = (SCREEN_WIDTH/2 - PLAYER_WIDTH/2) * SCALE,
.player_y = (SCREEN_HEIGHT - 5 - PLAYER_WIDTH) * SCALE,
.player_vx = 0,
.player_vy = 0,
.player_jump = false,
Expand Down

0 comments on commit 4f84e3c

Please sign in to comment.