improve spawning rate and separate behaviour for start and end wall

This commit is contained in:
interfisch 2025-07-18 23:02:37 +02:00
commit e74b258795
2 changed files with 23 additions and 13 deletions

View file

@ -683,7 +683,11 @@ void loop_achterbahn(){
lastCheckspawn=loopmillis;
Serial.print("Checking Spawning, wagons ");
Serial.println(wagoncount);
if (random(0,SPAWNCHANCE)==0 && wagoncount<MAXWAGONS) { //by chance, exclusive SPAWNCHANCE
uint8_t spawnchance=SPAWNCHANCE;
if (wagoncount<=0) { //no wagons present
spawnchance/=2; //double spawnchance
}
if (random(0,spawnchance)==0 && wagoncount<MAXWAGONS) { //by chance, exclusive SPAWNCHANCE
spawnWagon();
if (random(0,SPAWNCHANCEDOUBLE)==0){
spawnWagon();

View file

@ -2,10 +2,16 @@
#define WAGONLENGTH 3
//#define EDGE_KILL
#define EDGE_WALL
//#define EDGE_BOUNCE
//#define EDGE_WRAP
//#define EDGE_KILL_END
#define EDGE_WALL_END
//#define EDGE_BOUNCE_END
//#define EDGE_WRAP_END
#define EDGE_KILL_START
//#define EDGE_WALL_START
//#define EDGE_BOUNCE_START
//#define EDGE_WRAP_START
#define WRAPLEDENDPOS _numpixels //default
//#define WRAPLEDENDPOS (_numpixels-5) //led index which is last led
#define WRAPLEDSTARTPOS 0 //default
@ -171,32 +177,32 @@ void Wagon::updatePhysics(float updatedelayms)
if (_pos>=WRAPLEDENDPOS){
#ifdef EDGE_WRAP
#ifdef EDGE_WRAP_END
_pos-=WRAPLEDENDPOS; //Wrap around edges
#endif
#ifdef EDGE_BOUNCE
#ifdef EDGE_BOUNCE_END
_vel*=-1; //bounce at edges
#endif
#ifdef EDGE_WALL
#ifdef EDGE_WALL_END
//nothing
#endif
#ifdef EDGE_KILL
#ifdef EDGE_KILL_END
if (_pos>=WRAPLEDENDPOS+(_trainlength*WAGONLENGTH)){
_health=0;
}
#endif
}
if (_pos<WRAPLEDSTARTPOS){
#ifdef EDGE_WRAP
#ifdef EDGE_WRAP_START
_pos=WRAPLEDENDPOS+_pos; //warp around edges
#endif
#ifdef EDGE_BOUNCE
#ifdef EDGE_BOUNCE_START
_vel*=-1;; //bounce at edges
#endif
#ifdef EDGE_WALL
#ifdef EDGE_WALL_START
//nothing
#endif
#ifdef EDGE_KILL
#ifdef EDGE_KILL_START
_health=0;
#endif
}