main() function in the Main_Update.py file was 1683 lines of code long and contained way too many things in it. At the moment, the same function is down to 641 lines of code. This is still way too much stuff in the main() but this is a hell of a lot of reduction.
↩ Reply
main() function by myself and documented some of it on Dani's Race Matrix Chatroom. This is when I moved pretty much the majority of the racing code out of main() and into Racing.py.
↩ Reply
main() into an equally stupid spaghetti code thing in Racing.py. Instead I've broken it up into 13 individual functions, which are now useful to do various interesting things that weren't possible before.
↩ Reply
![Moria sitting in the car in the game. [embedded image]](https://lm.madiator.cloud/pictrs/image/c8b36327-90cf-4e9f-9375-656acd9f53ea.png)
if Story["Moria"].get("driving"): racepos = [-61.7856, 1028, 0] # Moria drive the car to the race if Story["Moria"]["driving"].getDistanceTo(racepos) > 2 and "Moria-Practicing" not in Story: Story["Moria"]["driving"]["npc"] = "story" Story["Moria"]["driving"]["target"] = racepos Vehicle.TargetedNPC(Story["Moria"]["driving"]) # Moria racing the race elif "Moria-Practicing" not in Story: Story["Moria"]["driving"]["race"] = "RacetrackRace" Story["Moria"]["driving"]["npc"] = "racer" Story["Moria"]["driving"]["racing"] = True Story["Moria-Practicing"] = True
StartRace() which can start any race even without Dani being a part of it.
↩ Reply
def StartRace(racename, dani=None): race = Races()[racename] race["started"] = True race["start-time"] = bge.logic.getRealTime() # Deleting starters for starter in race["starters"]: if starter["cylinder"]: DeleteCylinder(starter, ignoreTimer=True) # Making the racers race for racer in race["racers"]: racer["racing"] = True racer["launchtime"] = 100 racer["race"] = racename # Testing racer["npc"] = "racer" racer["active"] = False # Beam of energy racer["beam"] = Reuse.Create("Racer.Indicator") # If the race includes dani. if dani: dani["race"] = racename dani["checkpoint"] = 0 dani["lap"] = 0 # Make the racing UI visible scene = bge.logic.getCurrentScene() pointer = scene.objects["PointingArrow"] posindicator = scene.objects["Dani_Pos_Indicator"] timeindicator = scene.objects["Dani_Time_Indicator"] lapindicator = scene.objects["Dani_Lap_Indicator"] posindicator.visible = True pointer.visible = True timeindicator.visible = True lapindicator.visible = True # Play the start the race sound. bge.logic.globalDict["SoundDevice"].play(bge.logic.globalDict["sounds"]["active"]["sound"]) # Play a Ding
![Racing cars spawned for racing. [embedded image]](https://files.mastodon.online/media_attachments/files/113/688/641/706/220/431/original/c1affecd02c6c233.png)
main() actually helped the game be a bit less buggy, since I saw all those mistakes and fixed them along the way.
↩ Reply
main(). Here is the recording of that stream:
↩ Reply
main() itself into a few functions, separating it into main(), Init() which runs in the first frame of the game and OnExit() which runs when you close the game. The Init() itself is also not just a copy-paste from what there was in the main() but rather I broken off some of the initialization into Racing.py, Doors.py, Elevators.py and Opt.py. Leaving only just a few if statements in the Init():
↩ Reply
for object in scene.objects: if "spawn" in object: Vehicle.RegisterSpawnPoint(object) if str(object.name).startswith("Crate"): crates = bge.logic.globalDict["garage-crates"] crates.append(object) if "LightSpawn" in object: Opt.RegisterObjects(object, spawnAtDistance, "LightSpawn") elif type(object.blenderObject.data) == bpy.types.AreaLight: Opt.RegisterObjects(object, spawnAtDistance, "AreaLamp") elif "Tree" in object.name: Opt.RegisterObjects(object, spawnAtDistance, "Tree") elif "Palm" in object.name: Opt.RegisterObjects(object, spawnAtDistance, "Palm") elif "Elevator" in object: Elevators.RegisterElevator(object) elif "Door" in object: Doors.RegisterDoor(object) elif "ambiance-sound" in object: bge.logic.globalDict["sound-ambiances"].append(object)
Init():
↩ Reply
Opt.Precalculate() Doors.Precalculate() Elevators.Precalculate()
Init() and call functions based of the object type from there.
↩ Reply
main() function in the Main_Update.py file was 1683 lines of code long and contained way too many things in it. At the moment, the same function is down to 641 lines of code. This is still way too much stuff in the main() but this is a hell of a lot of reduction.