Skip to content

Commit

Permalink
added btn enum
Browse files Browse the repository at this point in the history
  • Loading branch information
m4reko committed Dec 6, 2018
1 parent 0890c27 commit 1523e6b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/game_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ void move_dino(Dino *dino) {
// If in jump and jump button not pressed, high down accel.
if (round(dino->y_pos) != DINO_BASE_POS) {
// If duck button pressed even higher down accel.
if ((getbtns() & 0x2) >> 1) {
if ((is_pressed(BTN3)) >> 1) {
dino->y_accel = DINO_DUCK_ACCEL;
} else {
dino->y_accel = DINO_REG_ACCEL;
}
}
// If jump button pressed, low down accel.
if ((getbtns() & 0x4) >> 2) {
if ((is_pressed(BTN4) & 0x4) >> 2) {
jump_dino(dino);
if (round(dino->y_pos) != DINO_BASE_POS) {
dino->y_accel = DINO_JUMP_ACCEL;
}
}
// If duck button pressed point graphic to duck graphic
if ((getbtns() & 0x2) >> 1) {
if ((is_pressed(BTN3) & 0x2) >> 1) {
dino->sprite.graphic = &dino_graphic_duck;
} else {
dino->sprite.graphic = &dino_graphic;
Expand Down
11 changes: 11 additions & 0 deletions src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ int getbtns(void){
input &= 0x7;
return input;
}

int is_pressed(Button btn) {
switch (btn) {
case BTN2:
return getbtns() & 0x1;
case BTN3:
return (getbtns() & 0x2) >> 1;
case BTN4:
return (getbtns() & 0x4) >> 2;
}
}
6 changes: 5 additions & 1 deletion src/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
For copyright and licensing, see file COPYING
*/

int getbtns();
typedef enum Button {
BTN2, BTN3, BTN4
} Button;

int is_pressed();
int getsw();
13 changes: 6 additions & 7 deletions src/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,20 @@ void loop() {
pixelbuffer_to_buffer();
clear_pixelbuffer();
display_buffer();
if (is_pressed(BTN2)) {
GAME_STATE = 1;
srand(seed);
}
/*
display_string(0, "Dinosaur Run");
display_string(0, "Dino Run");
display_string(1, "by M.Wesslen");
display_string(2, "and A.Elmarsson");
display_string(3, "Press any button");
display_textbuffer();*/
} else {
} else if (GAME_STATE == 2){
update_game_state();
update_graphics();
}

if (getbtns() & 0x1) {
GAME_STATE = 1;
srand(seed);
}
quicksleep(150000);
}

Expand Down

0 comments on commit 1523e6b

Please sign in to comment.