Skip to content

Commit

Permalink
Change buttons and joystick input to work with HW
Browse files Browse the repository at this point in the history
  • Loading branch information
mrskoog committed Sep 26, 2017
1 parent dbf7814 commit 4e4e84d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion game.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
/*Game*/
#define ROTSPEED 0.1
#define STEP_SIZE 0.2
#define SHOOT_BUTTON 10
#define SHOOT_BUTTON 12
#define SHOOT_BUTTON2 9
#define RIGHT 0
#define LEFT 1

Expand Down
8 changes: 4 additions & 4 deletions game.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stdlib.h>
#include <stdio.h>

#define D(x)
#define D(x) x

const uint8_t level_map[][35] PROGMEM =
{
Expand Down Expand Up @@ -86,7 +86,7 @@ void drawHUD(Player *player) {
/*Sets player in shooting state.
Collision detection happens in drawSprite function*/
void playerShoot(Player *player) {
if (digitalRead(SHOOT_BUTTON) == 0) {
if (digitalRead(SHOOT_BUTTON) == 0 || digitalRead(SHOOT_BUTTON2) == 0) {
player->shooting = 1;
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ void movePlayer(Player *player) {
double nextStepX = player->dirX * STEP_SIZE;
double nextStepY = player->dirY * STEP_SIZE;

if ( analogRead(A1) < 200) {
if ( analogRead(A1) > 200) {

if (pgm_read_byte(&level_map[int(player->y)][int(player->x + nextStepX)]) != 1) {
player->x += nextStepX;
Expand All @@ -163,7 +163,7 @@ void movePlayer(Player *player) {
}
}

if (analogRead(A1) > 700) {
if (analogRead(A1) < 700) {

if (pgm_read_byte(&level_map[int(player->y)][int(player->x - nextStepX)]) != 1) {
player->x -= nextStepX;
Expand Down
3 changes: 2 additions & 1 deletion ray-gfx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "game.h"
#include "gfx_engine.h"

#define D(x)
#define D(x) x

#define I2C_ADDRESS 0x3C
#define OLED_RESET 3 //not used but needed by lib
Expand All @@ -22,6 +22,7 @@ void setup() {
D(Serial.begin(9600));

pinMode(SHOOT_BUTTON, INPUT_PULLUP);
pinMode(SHOOT_BUTTON2, INPUT_PULLUP);

Timer1.initialize(50000);
Timer1.attachInterrupt(timer_IRQ);
Expand Down

0 comments on commit 4e4e84d

Please sign in to comment.