Code cleanup, fixed compilation error and added button based joystick as default
This commit is contained in:
@@ -32,19 +32,21 @@
|
|||||||
#define VERSION "2018-06-28"
|
#define VERSION "2018-06-28"
|
||||||
|
|
||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
#include<Wire.h>
|
#include <Wire.h>
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "RunningMedian.h"
|
#include "RunningMedian.h"
|
||||||
|
|
||||||
// twang files
|
// twang files
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#ifdef USE_GYRO_JOYSTICK
|
||||||
#include "twang_mpu.h"
|
#include "twang_mpu.h"
|
||||||
#include "enemy.h"
|
#endif
|
||||||
#include "particle.h"
|
#include "Enemy.h"
|
||||||
#include "spawner.h"
|
#include "Particle.h"
|
||||||
#include "lava.h"
|
#include "Spawner.h"
|
||||||
#include "boss.h"
|
#include "Lava.h"
|
||||||
#include "conveyor.h"
|
#include "Boss.h"
|
||||||
|
#include "Conveyor.h"
|
||||||
#include "iSin.h"
|
#include "iSin.h"
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
@@ -90,7 +92,9 @@ bool attacking = 0; // Is the attack in progress?
|
|||||||
#define WIN_CLEAR_DURATION 1000
|
#define WIN_CLEAR_DURATION 1000
|
||||||
#define WIN_OFF_DURATION 1200
|
#define WIN_OFF_DURATION 1200
|
||||||
|
|
||||||
|
#ifdef USE_GYRO_JOYSTICK
|
||||||
Twang_MPU accelgyro = Twang_MPU();
|
Twang_MPU accelgyro = Twang_MPU();
|
||||||
|
#endif
|
||||||
CRGB leds[VIRTUAL_LED_COUNT];
|
CRGB leds[VIRTUAL_LED_COUNT];
|
||||||
RunningMedian MPUAngleSamples = RunningMedian(5);
|
RunningMedian MPUAngleSamples = RunningMedian(5);
|
||||||
RunningMedian MPUWobbleSamples = RunningMedian(5);
|
RunningMedian MPUWobbleSamples = RunningMedian(5);
|
||||||
@@ -203,7 +207,9 @@ void setup() {
|
|||||||
settings_init(); // load the user settings from EEPROM
|
settings_init(); // load the user settings from EEPROM
|
||||||
|
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
#ifdef USE_GYRO_JOYSTICK
|
||||||
accelgyro.initialize();
|
accelgyro.initialize();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_NEOPIXEL
|
#ifdef USE_NEOPIXEL
|
||||||
Serial.print("\r\nCompiled for WS2812B (Neopixel) LEDs");
|
Serial.print("\r\nCompiled for WS2812B (Neopixel) LEDs");
|
||||||
@@ -223,12 +229,18 @@ void setup() {
|
|||||||
|
|
||||||
sound_init(DAC_AUDIO_PIN);
|
sound_init(DAC_AUDIO_PIN);
|
||||||
|
|
||||||
|
#ifndef USE_GYRO_JOYSTICK
|
||||||
|
pinMode(upButtonPinNumber, INPUT_PULLUP);
|
||||||
|
pinMode(downButtonPinNumber, INPUT_PULLUP);
|
||||||
|
pinMode(leftButtonPinNumber, INPUT_PULLUP);
|
||||||
|
pinMode(rightButtonPinNumber, INPUT_PULLUP);
|
||||||
|
#endif
|
||||||
|
|
||||||
ap_setup();
|
ap_setup();
|
||||||
|
|
||||||
stage = STARTUP;
|
stage = STARTUP;
|
||||||
stageStartTime = millis();
|
stageStartTime = millis();
|
||||||
lives = user_settings.lives_per_level;
|
lives = user_settings.lives_per_level;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -243,8 +255,6 @@ void loop() {
|
|||||||
SFXattacking();
|
SFXattacking();
|
||||||
}else{
|
}else{
|
||||||
SFXtilt(joystickTilt);
|
SFXtilt(joystickTilt);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}else if(stage == DEAD){
|
}else if(stage == DEAD){
|
||||||
SFXdead();
|
SFXdead();
|
||||||
@@ -349,9 +359,7 @@ void loop() {
|
|||||||
if (stageStartTime+GAMEOVER_FADE_DURATION > mm)
|
if (stageStartTime+GAMEOVER_FADE_DURATION > mm)
|
||||||
{
|
{
|
||||||
tickGameover(mm);
|
tickGameover(mm);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
FastLED.clear();
|
FastLED.clear();
|
||||||
save_game_stats(false); // boss not killed
|
save_game_stats(false); // boss not killed
|
||||||
|
|
||||||
@@ -359,16 +367,11 @@ void loop() {
|
|||||||
stage = STARTUP;
|
stage = STARTUP;
|
||||||
stageStartTime = millis();
|
stageStartTime = millis();
|
||||||
lives = user_settings.lives_per_level;
|
lives = user_settings.lives_per_level;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//FastLED.show();
|
//FastLED.show();
|
||||||
FastLEDshowESP32();
|
FastLEDshowESP32();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
@@ -1144,6 +1147,7 @@ void screenSaverTick(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_GYRO_JOYSTICK
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
// ----------- JOYSTICK ------------
|
// ----------- JOYSTICK ------------
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
@@ -1188,6 +1192,34 @@ void getInput(){
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
void getInput() {
|
||||||
|
// This is responsible for the player movement speed and attacking.
|
||||||
|
// You can replace it with anything you want that passes a -90>+90 value to joystickTilt
|
||||||
|
// and any value to joystickWobble that is greater than ATTACK_THRESHOLD (defined at start)
|
||||||
|
// For example you could use 3 momentary buttons:
|
||||||
|
|
||||||
|
bool up = digitalRead(upButtonPinNumber) == LOW;
|
||||||
|
bool down = digitalRead(downButtonPinNumber) == LOW;
|
||||||
|
bool left = digitalRead(leftButtonPinNumber) == LOW;
|
||||||
|
bool right = digitalRead(rightButtonPinNumber) == LOW;
|
||||||
|
|
||||||
|
joystickTilt = 0;
|
||||||
|
if (up) {
|
||||||
|
joystickTilt = 90 ;
|
||||||
|
} else if (down) {
|
||||||
|
joystickTilt = -90;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (left || right) {
|
||||||
|
joystickWobble = user_settings.attack_threshold;
|
||||||
|
} else {
|
||||||
|
joystickWobble = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
// -------------- SFX --------------
|
// -------------- SFX --------------
|
||||||
|
|||||||
Reference in New Issue
Block a user