Compare commits
2 Commits
a8c6a01422
...
db05e5dc90
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db05e5dc90 | ||
|
|
fdc7a803a4 |
@@ -1,4 +1,5 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
class Enemy
|
class Enemy
|
||||||
{
|
{
|
||||||
@@ -9,7 +10,7 @@ class Enemy
|
|||||||
bool Alive();
|
bool Alive();
|
||||||
int _pos;
|
int _pos;
|
||||||
int _wobble;
|
int _wobble;
|
||||||
int playersSide[4]; // This should be MAX_PLAYERS
|
int playersSide[MAX_PLAYERS];
|
||||||
private:
|
private:
|
||||||
int _dir;
|
int _dir;
|
||||||
int _speed;
|
int _speed;
|
||||||
|
|||||||
@@ -65,8 +65,6 @@
|
|||||||
#define USE_GRAVITY 0 // 0/1 use gravity (LED strip going up wall)
|
#define USE_GRAVITY 0 // 0/1 use gravity (LED strip going up wall)
|
||||||
#define BEND_POINT 550 // 0/1000 point at which the LED strip goes up the wall
|
#define BEND_POINT 550 // 0/1000 point at which the LED strip goes up the wall
|
||||||
|
|
||||||
// Players settings
|
|
||||||
#define MAX_PLAYERS 4
|
|
||||||
// this can become a setting in the future
|
// this can become a setting in the future
|
||||||
#define NUM_PLAYERS 2
|
#define NUM_PLAYERS 2
|
||||||
|
|
||||||
@@ -141,7 +139,7 @@ Conveyor conveyorPool[CONVEYOR_COUNT] = {
|
|||||||
|
|
||||||
Boss boss = Boss();
|
Boss boss = Boss();
|
||||||
|
|
||||||
Player player[NUM_PLAYERS] = {
|
Player players[NUM_PLAYERS] = {
|
||||||
Player(0, LIVES_PER_LEVEL, ATTACK_DURATION),
|
Player(0, LIVES_PER_LEVEL, ATTACK_DURATION),
|
||||||
Player(1, LIVES_PER_LEVEL, ATTACK_DURATION)
|
Player(1, LIVES_PER_LEVEL, ATTACK_DURATION)
|
||||||
};
|
};
|
||||||
@@ -256,9 +254,9 @@ void setup() {
|
|||||||
stageStartTime = millis();
|
stageStartTime = millis();
|
||||||
|
|
||||||
// set players color
|
// set players color
|
||||||
player[0].setColor(0,255,0);
|
players[0].setColor(0,255,0);
|
||||||
player[1].setColor(127,2,255);
|
players[1].setColor(127,2,255);
|
||||||
for (Player& p : player)
|
for (Player& p : players)
|
||||||
p.Lives ( user_settings.lives_per_level );
|
p.Lives ( user_settings.lives_per_level );
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -272,7 +270,7 @@ void loop() {
|
|||||||
|
|
||||||
if(stage == PLAY){
|
if(stage == PLAY){
|
||||||
bool attacking = false;
|
bool attacking = false;
|
||||||
for (const Player& p: player) attacking = attacking || p.attacking;
|
for (const Player& p: players) attacking = attacking || p.attacking;
|
||||||
|
|
||||||
if(attacking){
|
if(attacking){
|
||||||
SFXattacking();
|
SFXattacking();
|
||||||
@@ -331,7 +329,7 @@ void loop() {
|
|||||||
// allow selecting player color during first sec of first level
|
// allow selecting player color during first sec of first level
|
||||||
if (levelNumber == 0) {
|
if (levelNumber == 0) {
|
||||||
if ((stageStartTime + COLOR_SELECT_DUR) > mm) {
|
if ((stageStartTime + COLOR_SELECT_DUR) > mm) {
|
||||||
for (Player& p : player) {
|
for (Player& p : players) {
|
||||||
if (joystickWobble[p.Id()] >= user_settings.attack_threshold) {
|
if (joystickWobble[p.Id()] >= user_settings.attack_threshold) {
|
||||||
random_player_color(p);
|
random_player_color(p);
|
||||||
stageStartTime = mm;
|
stageStartTime = mm;
|
||||||
@@ -342,7 +340,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// real action here
|
// real action here
|
||||||
for (Player& p : player) {
|
for (Player& p : players) {
|
||||||
|
|
||||||
if (p.captured) continue;
|
if (p.captured) continue;
|
||||||
|
|
||||||
@@ -386,16 +384,16 @@ void loop() {
|
|||||||
// exploding players during PLAY stage
|
// exploding players during PLAY stage
|
||||||
tickParticles();
|
tickParticles();
|
||||||
|
|
||||||
for (Player& p : player)
|
for (Player& p : players)
|
||||||
tickConveyors(p);
|
tickConveyors(p);
|
||||||
|
|
||||||
tickSpawners();
|
tickSpawners();
|
||||||
tickBoss();
|
tickBoss();
|
||||||
tickLava();
|
tickLava();
|
||||||
|
|
||||||
for (Player& p : player) if (!p.captured) tickEnemies(p);
|
for (Player& p : players) if (!p.captured) tickEnemies(p);
|
||||||
for (const Player& p : player) if (!p.captured) drawAttack(p);
|
for (const Player& p : players) if (!p.captured) drawAttack(p);
|
||||||
for (const Player& p : player) if (!p.captured) drawPlayer(p);
|
for (const Player& p : players) if (!p.captured) drawPlayer(p);
|
||||||
|
|
||||||
drawExit();
|
drawExit();
|
||||||
}else if(stage == DEAD){
|
}else if(stage == DEAD){
|
||||||
@@ -421,7 +419,7 @@ void loop() {
|
|||||||
// restart from the beginning
|
// restart from the beginning
|
||||||
stage = STARTUP;
|
stage = STARTUP;
|
||||||
stageStartTime = millis();
|
stageStartTime = millis();
|
||||||
for (Player& p : player)
|
for (Player& p : players)
|
||||||
p.Lives ( user_settings.lives_per_level );
|
p.Lives ( user_settings.lives_per_level );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -442,7 +440,7 @@ void loadLevel(){
|
|||||||
|
|
||||||
/// Defaults...OK to change the following items in the levels below
|
/// Defaults...OK to change the following items in the levels below
|
||||||
attack_width = DEFAULT_ATTACK_WIDTH;
|
attack_width = DEFAULT_ATTACK_WIDTH;
|
||||||
for (Player& p : player)
|
for (Player& p : players)
|
||||||
p.Spawn( 0 + p.Id()*10 ); // slightly displace players
|
p.Spawn( 0 + p.Id()*10 ); // slightly displace players
|
||||||
|
|
||||||
/* ==== Level Editing Guide ===============
|
/* ==== Level Editing Guide ===============
|
||||||
@@ -506,7 +504,7 @@ void loadLevel(){
|
|||||||
*/
|
*/
|
||||||
switch(levelNumber){
|
switch(levelNumber){
|
||||||
case 0: // basic introduction
|
case 0: // basic introduction
|
||||||
for (Player& p : player)
|
for (Player& p : players)
|
||||||
p.Spawn( 200 + p.Id()*10 );
|
p.Spawn( 200 + p.Id()*10 );
|
||||||
spawnEnemy(1, 0, 0, 0);
|
spawnEnemy(1, 0, 0, 0);
|
||||||
break;
|
break;
|
||||||
@@ -554,7 +552,7 @@ void loadLevel(){
|
|||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
// lava moving up
|
// lava moving up
|
||||||
for (Player& p : player)
|
for (Player& p : players)
|
||||||
p.Spawn( 200 + p.Id()*10 );
|
p.Spawn( 200 + p.Id()*10 );
|
||||||
spawnLava(10, 180, 2000, 2000, 0, Lava::OFF, 0, 0.5);
|
spawnLava(10, 180, 2000, 2000, 0, Lava::OFF, 0, 0.5);
|
||||||
spawnEnemy(350, 0, 1, 0);
|
spawnEnemy(350, 0, 1, 0);
|
||||||
@@ -658,7 +656,7 @@ void spawnEnemy(int pos, int dir, int speed, int wobble){
|
|||||||
if(!enemyPool[e].Alive()){
|
if(!enemyPool[e].Alive()){
|
||||||
enemyPool[e].Spawn(pos, dir, speed, wobble);
|
enemyPool[e].Spawn(pos, dir, speed, wobble);
|
||||||
// for each player, save if it is above or below
|
// for each player, save if it is above or below
|
||||||
for (const Player& p : player)
|
for (const Player& p : players)
|
||||||
enemyPool[e].playersSide[p.Id()] = pos > p.position?1:-1;
|
enemyPool[e].playersSide[p.Id()] = pos > p.position?1:-1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -711,7 +709,7 @@ void levelComplete(){
|
|||||||
}
|
}
|
||||||
if (levelNumber != 0) // no points for the first level
|
if (levelNumber != 0) // no points for the first level
|
||||||
{
|
{
|
||||||
score = score + (player[0].Lives() * 10); //
|
for (Player& p : players) score = score + (p.Lives() * 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -722,11 +720,11 @@ void nextLevel(){
|
|||||||
stage = STARTUP;
|
stage = STARTUP;
|
||||||
stageStartTime = millis();
|
stageStartTime = millis();
|
||||||
|
|
||||||
for (Player& p : player)
|
for (Player& p : players)
|
||||||
p.Lives ( user_settings.lives_per_level );
|
p.Lives ( user_settings.lives_per_level );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
for (Player& p : player) {
|
for (Player& p : players) {
|
||||||
if (!p.Alive()) p.Lives ( user_settings.lives_per_level );
|
if (!p.Alive()) p.Lives ( user_settings.lives_per_level );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,7 +747,7 @@ void die(Player& p){
|
|||||||
int stillPlaying = 0;
|
int stillPlaying = 0;
|
||||||
// how many players have lives?
|
// how many players have lives?
|
||||||
bool allDead = true;
|
bool allDead = true;
|
||||||
for (const Player& pp : player) {
|
for (const Player& pp : players) {
|
||||||
stillPlaying += !pp.captured;
|
stillPlaying += !pp.captured;
|
||||||
allDead &= !pp.Alive();
|
allDead &= !pp.Alive();
|
||||||
}
|
}
|
||||||
@@ -861,7 +859,7 @@ void tickBoss(){
|
|||||||
leds[i] %= 100;
|
leds[i] %= 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Player& p : player)
|
for (Player& p : players)
|
||||||
{
|
{
|
||||||
// CHECK COLLISION
|
// CHECK COLLISION
|
||||||
if(getLED(p.position) > getLED(boss._pos - BOSS_WIDTH/2) && getLED(p.position) < getLED(boss._pos + BOSS_WIDTH)){
|
if(getLED(p.position) > getLED(boss._pos - BOSS_WIDTH/2) && getLED(p.position) < getLED(boss._pos + BOSS_WIDTH)){
|
||||||
@@ -1092,13 +1090,13 @@ void tickGameover(long mm) {
|
|||||||
if(stageStartTime+GAMEOVER_SPREAD_DURATION > mm) // Spread red from player position to top and bottom
|
if(stageStartTime+GAMEOVER_SPREAD_DURATION > mm) // Spread red from player position to top and bottom
|
||||||
{
|
{
|
||||||
// fill to top
|
// fill to top
|
||||||
int n = _max(map(((mm-stageStartTime)), 0, GAMEOVER_SPREAD_DURATION, getLED(player[0].position), user_settings.led_count), 0);
|
int n = _max(map(((mm-stageStartTime)), 0, GAMEOVER_SPREAD_DURATION, getLED(killPos), user_settings.led_count), 0);
|
||||||
for(int i = getLED(player[0].position); i<= n; i++){
|
for(int i = getLED(killPos); i<= n; i++){
|
||||||
leds[i] = CRGB(255, 0, 0);
|
leds[i] = CRGB(255, 0, 0);
|
||||||
}
|
}
|
||||||
// fill to bottom
|
// fill to bottom
|
||||||
n = _max(map(((mm-stageStartTime)), 0, GAMEOVER_SPREAD_DURATION, getLED(player[0].position), 0), 0);
|
n = _max(map(((mm-stageStartTime)), 0, GAMEOVER_SPREAD_DURATION, getLED(killPos), 0), 0);
|
||||||
for(int i = getLED(player[0].position); i>= n; i--){
|
for(int i = getLED(killPos); i>= n; i--){
|
||||||
leds[i] = CRGB(255, 0, 0);
|
leds[i] = CRGB(255, 0, 0);
|
||||||
}
|
}
|
||||||
SFXgameover();
|
SFXgameover();
|
||||||
@@ -1149,7 +1147,7 @@ void drawLives()
|
|||||||
SFXcomplete(); // stop any sounds
|
SFXcomplete(); // stop any sounds
|
||||||
FastLED.clear();
|
FastLED.clear();
|
||||||
|
|
||||||
for (const Player& p : player) {
|
for (const Player& p : players) {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (int i = 0; i < p.Lives(); i++)
|
for (int i = 0; i < p.Lives(); i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,9 @@
|
|||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
|
// Players settings
|
||||||
|
#define MAX_PLAYERS 4
|
||||||
|
|
||||||
/* Uncomment below to use the accelerometer base joystic of original implementation */
|
/* Uncomment below to use the accelerometer base joystic of original implementation */
|
||||||
//#define USE_GYRO_JOYSTICK
|
//#define USE_GYRO_JOYSTICK
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ void ap_setup() {
|
|||||||
* @param ssid_hidden Network cloaking (0 = broadcast SSID, 1 = hide SSID)
|
* @param ssid_hidden Network cloaking (0 = broadcast SSID, 1 = hide SSID)
|
||||||
*/
|
*/
|
||||||
ret = WiFi.softAP(ssid, passphrase, 2, 0);
|
ret = WiFi.softAP(ssid, passphrase, 2, 0);
|
||||||
|
// workaround for c3_super_mini design flaw
|
||||||
|
// https://www.reddit.com/r/esp32/comments/1dsh3b5/warning_some_c3_super_mini_boards_have_a_design/
|
||||||
|
// https://github.com/luc-github/ESP3D/issues/1009#issuecomment-1985395716
|
||||||
|
// https://forum.arduino.cc/t/no-wifi-connect-with-esp32-c3-super-mini/1324046/21
|
||||||
|
WiFi.setTxPower(WIFI_POWER_8_5dBm);
|
||||||
server.begin();
|
server.begin();
|
||||||
|
|
||||||
Serial.print("\r\nWiFi SSID: ");
|
Serial.print("\r\nWiFi SSID: ");
|
||||||
|
|||||||
Reference in New Issue
Block a user