Code cleanup, fixed compilation error and added button based joystick as default

This commit is contained in:
Phew
2025-12-20 10:48:05 +01:00
parent 91cb3ef098
commit e5f7e1ba84

View File

@@ -32,19 +32,21 @@
#define VERSION "2018-06-28"
#include <FastLED.h>
#include<Wire.h>
#include <Wire.h>
#include "Arduino.h"
#include "RunningMedian.h"
// twang files
#include "config.h"
#ifdef USE_GYRO_JOYSTICK
#include "twang_mpu.h"
#include "enemy.h"
#include "particle.h"
#include "spawner.h"
#include "lava.h"
#include "boss.h"
#include "conveyor.h"
#endif
#include "Enemy.h"
#include "Particle.h"
#include "Spawner.h"
#include "Lava.h"
#include "Boss.h"
#include "Conveyor.h"
#include "iSin.h"
#include "sound.h"
#include "settings.h"
@@ -90,7 +92,9 @@ bool attacking = 0; // Is the attack in progress?
#define WIN_CLEAR_DURATION 1000
#define WIN_OFF_DURATION 1200
#ifdef USE_GYRO_JOYSTICK
Twang_MPU accelgyro = Twang_MPU();
#endif
CRGB leds[VIRTUAL_LED_COUNT];
RunningMedian MPUAngleSamples = RunningMedian(5);
RunningMedian MPUWobbleSamples = RunningMedian(5);
@@ -203,7 +207,9 @@ void setup() {
settings_init(); // load the user settings from EEPROM
Wire.begin();
#ifdef USE_GYRO_JOYSTICK
accelgyro.initialize();
#endif
#ifdef USE_NEOPIXEL
Serial.print("\r\nCompiled for WS2812B (Neopixel) LEDs");
@@ -223,12 +229,18 @@ void setup() {
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();
stage = STARTUP;
stageStartTime = millis();
lives = user_settings.lives_per_level;
}
void loop() {
@@ -243,8 +255,6 @@ void loop() {
SFXattacking();
}else{
SFXtilt(joystickTilt);
}
}else if(stage == DEAD){
SFXdead();
@@ -349,9 +359,7 @@ void loop() {
if (stageStartTime+GAMEOVER_FADE_DURATION > mm)
{
tickGameover(mm);
}
else
{
} else {
FastLED.clear();
save_game_stats(false); // boss not killed
@@ -359,16 +367,11 @@ void loop() {
stage = STARTUP;
stageStartTime = millis();
lives = user_settings.lives_per_level;
}
}
//FastLED.show();
FastLEDshowESP32();
}
}
// ---------------------------------
@@ -1144,6 +1147,7 @@ void screenSaverTick(){
}
#ifdef USE_GYRO_JOYSTICK
// ---------------------------------
// ----------- JOYSTICK ------------
// ---------------------------------
@@ -1188,6 +1192,34 @@ void getInput(){
#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 --------------