FANDOM


programmed with: Panda3D 1.8.1, Python 2.7.3, Notepad, and various online tutorials and resources.
picture saving/editing software: MS Paint and Photoshop CS3.

FlyingRoadster_v2_pub1.py

'''
FlyingRoadster_v2_pub1
formerly MascotPlatformerTT_v2-2

author: Dyna/[REDACTED]
date started: 2018_12_29_December
(using code from 2018_12_28_December and 2018_03_11_March)
latest big changes: 2019_04_04_April
latest changes: 2019_04_18_April
Python programming

purpose: 
This flying roadster is fantastic for exploring 3D environments!
Make a character move around on the screen controlable with the keyboard in third-person view.
Aids in finding glitches and oddities in model gemotry.


controls:
up arrow/down arrow:		move kart forward/backward
left arrow/right arrow:		spin kart and camera left/right
1/2: 		spin camera to the left/right of the kart
page up/page down:	fly kart up/down
home:		move kart to the height it started at

hold left and right mouse buttons
while moving the mouse forward and back:
		make the camera look up/down



tutorials:
-How to make this comment at the top of a program.
http://www.afterhoursprogramming.com/tutorial/Python/Comments/

-Keyboard interface for moving a character and a camera.
https://www.panda3d.org/manual/?title=Keyboard_Support#Polling_interface

-Doing tasks every frame and using sine and cosine to spin a camera around a central point
https://www.panda3d.org/manual/index.php/Loading_and_Animating_the_Panda_Model

-Sine and cosine fact check.
https://www.youtube.com/watch?v=etQUCWyvfMM
How to make a car racing game in flash part 1
Game Development Tutorials
Published on Dec 3, 2012

-Getting coordinate values for and moving things around.
https://www.panda3d.org/manual/?title=Common_State_Changes

-Attaching things to an actor so it can be used as one uniform entity. Don't worry, the dual lasers are currently just for show.
https://www.youtube.com/watch?v=XcAeDddqAdo
Panda3D Tutorial Ep. 4: Actors
Sam's Gaming
Published on Oct 14, 2016

-Repurposed Toon colors as colors on a race kart.
https://www.reddit.com/r/Toontown/comments/54mpfh/toontown_toon_model_export_with_clothes/
http://xdar1d.tumblr.com/post/83997644958/panda3d-dog-tutorial-pype

-Changing the configuration, like the gray background to make it blue like the sky.
https://www.youtube.com/watch?v=wIbMV31_87o
Panda3D Tutorial Ep. 3: The Config
Sam's Gaming
Published on May 10, 2016
https://www.panda3d.org/manual/index.php/List_of_All_Config_Variables

-What value to give the sky if I want the sky to be blue.
(135, 206, 235)
https://en.wikipedia.org/wiki/Sky_blue

-Perfect for when you want For Those About to Rock (We Salute You) by AC/DC to loop on your "radio" when you're "driving" in the sky.
https://www.panda3d.org/manual/?title=Manipulating_Sounds

-Modulo operation for getting the modulus of a variable mod 360.
https://www.journaldev.com/15651/python-modulo

-other
https://www.panda3d.org/manual/?title=Collision_Solids

'''



from panda3d.core import loadPrcFile, loadPrcFileData
if __debug__:
	loadPrcFile("config/TestConfig.prc")
#	loadPrcFileData("", "show-frame-rate-meter false")
#	loadPrcFileData("", "compressed-textures 1")
#	loadPrcFileData("", "driver-compress-textures 1")
	loadPrcFileData("", "background-color 0.53 0.81 0.92 0.0")
#	loadPrcFileData("", "background-color 0 0 0 0")
#	loadPrcFileData("", "background-color 1 1 1 1")
	loadPrcFileData("", "window-title DinoDisplay")
	loadPrcFileData("", "icon-filename phase_3/etc/icon.ico")
	loadPrcFileData("", "cursor-filename phase_3/etc/toonmono.cur")
#	loadPrcFileData("", "win-size 40 40")
	loadPrcFileData("", "win-size 640 360")
	loadPrcFileData("", "win-origin 50 80")


#(135, 206, 235) https://en.wikipedia.org/wiki/Sky_blue

from direct.showbase.ShowBase import ShowBase
from direct.actor.Actor import Actor
from panda3d.core import *
from direct.gui.OnscreenText import OnscreenText
from direct.task import Task
from math import pi, sin, cos, tan

#from panda3d.core import Vec3,Vec4,BitMask32

#self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
#self.taskMgr.add(self.MovementAndCameraTask, "MovementAndCameraTask")

class Window(ShowBase):

	def __init__(self):
		ShowBase.__init__(self)
		self.elevationstart = 20.75
		self.elevation = self.elevationstart
		self.camdistance = 20
		self.herospin = 0
		self.startingPlace = (1, 1, 1)
		self.loadAudio()
		self.loadHero()
		self.inputsystem()
		self.modifyHero(int)
	#	self.taskMgr.add(self.MovementAndCameraTask, "MovementAndCameraTask")
		
	
	def spinCameraTask(self, task):
		
		herospin = 0
		#print("MovementAndspinCameraTask is working.")
		#angleDegrees = task.time * 6.0
		angleDegrees = self.hero.getH() + 180 + self.herospin
		angleRadians = angleDegrees * (pi / 180.0)
	#	self.camera.setPos(self.hero.getX(), self.hero.getY() -20, self.hero.getZ()+2)
		
		self.camera.setPos(self.hero.getX() + self.camdistance * sin(angleRadians), self.hero.getY() +0 -self.camdistance * cos(angleRadians), self.hero.getZ() + 2)
		self.camera.setH(angleDegrees)
		self.camera.setR(0)
		
		#self.shadow.setZ(self.setting.getZ(self.setting.find('**/collision')))
		
		
#		#Make the camera follow the player character. Obsolete Code.
#	#	base.cam.setZ(22.75)
#		self.hero.setZ(20.75)
#		#base.cam.setH(self.hero.getH())
#		#base.camera.lookAt(self.hero)
#	#	base.cam.setX(self.hero.getX())
#	#	base.cam.setY(self.hero.getY()-20)
		
		return Task.cont
	
	def inputsystem(self):
		self.accept("arrow_up", self.modifyHero, [1])
		self.accept("arrow_up-repeat", self.modifyHero, [1])
		self.accept("arrow_down", self.modifyHero, [2])
		self.accept("arrow_down-repeat", self.modifyHero, [2])
		self.accept("arrow_left", self.modifyHero, [3])
		self.accept("arrow_left-repeat", self.modifyHero, [3])
		self.accept("arrow_right", self.modifyHero, [4])
		self.accept("arrow_right-repeat", self.modifyHero, [4])
		self.accept("1", self.modifyHero, [21])
		self.accept("1-repeat", self.modifyHero, [21])
		self.accept("2", self.modifyHero, [22])
		self.accept("2-repeat", self.modifyHero, [22])
		self.accept("page_up", self.modifyHero, [31])
		self.accept("page_up-repeat", self.modifyHero, [31])
		self.accept("page_down", self.modifyHero, [32])
		self.accept("page_down-repeat", self.modifyHero, [32])
		self.accept("home", self.modifyHero, [33])

		
#	"shift-control-alt-a-up"
#	"a-d-b-y-n-m-o-up"
#	https://www.panda3d.org/manual/index.php/Keyboard_Support
	
	
	
	def modifyHero(self, int):
		speed = 0
		turnspeed = 10
		heromove = "idle"
		if int == 1:
			speed = 10
			self.hero.set_y(self.hero, -speed)
			heromove = "run"
		if int == 2:
			speed = 10
			print("down")
			self.hero.set_y(self.hero, speed)
			heromove = 'walk'
			print(self.herospin)
		if int == 3:
			speed = 10
			#self.hero.set_x(self.hero, -speed)
			heromove = "run"
			self.hero.set_h(self.hero, turnspeed)
		if int == 4:
			speed = 10
			#self.hero.set_x(self.hero, speed)
			heromove = "run"
			self.hero.set_h(self.hero, -turnspeed)
		if int == 21:
			#swivel the camera to the left of the character
			self.herospin -=5
			self.herospin = self.herospin%360
			if self.herospin <=-500000000000000000000:
				self.herospin += 500000000000000000040
			
		if int == 22:
			#swivel the camera to the right of the character
			self.herospin +=5
			self.herospin = self.herospin%360
			#self.herospin +=500000000000000000000 #Two of these cause a crash.
			if self.herospin >=500000000000000000000:
				self.herospin -= 500000000000000000040
			
		if int == 31:
			self.elevation += 5
			self.shadow.setZ(self.shadow.getZ() - 5)
		if int == 32:
			self.elevation -= 5
			self.shadow.setZ(self.shadow.getZ() + 5)
		if int == 33:
			self.shadow.setZ(self.shadow.getZ() - (self.elevationstart - self.elevation))
			self.elevation = self.elevationstart
		else:
			speed = 0
		
		
		
		
		#Make the camera follow the player character. (Originally. Not anymore.)
	#	base.cam.setZ(22.75)
		self.hero.setZ(self.elevation)
		#base.cam.setH(self.hero.getH())
		#base.camera.lookAt(self.hero)
	#	base.cam.setX(self.hero.getX())
	#	base.cam.setY(self.hero.getY()-20)
		
		#self.hero.place()
	
	
	def loadAudio(self):
		music=self.loader.loadMusic("tto/phase_11/audio/bgm/LB_juryBG.mid")
#		music=self.loader.loadMusic("other/acdc_for_those_about_to_rock_with_lyrics_fKhTk0IynHM.mp3")
		sfx = self.loader.loadSfx("phase_3/audio/bgm/create_a_toon.ogg")
#		music.play()
#		music.stop()
		music.setVolume(.5)
		self.enableMusic(True)
		self.enableSoundEffects(True)
		music.setLoop(True)
#		music.setPlayRate(1)
	
	def loadHero(self):
		
	#	self.hero = Actor("phase_3/models/char/mickey-1200.bam",
	#		{
	#		"run": "phase_3/models/char/mickey-run.bam",
	#		"walk": "phase_3/models/char/mickey-walk.bam",
	#		"idle": "phase_3/models/char/mickey-wait.bam"
	#		})
#		heromove = 'idle'
	#	self.hero.reparentTo(self.render)
	#	self.hero.loop('walk')
#		self.hero.setPlayRate(0.5, 'run')
		#base.cam.setY()
		#base.cam.getH()
		#base.cam.getH()
	#	ears = self.hero.find('**/sphere3')
	#	ears.setH(base.cam.getH())
	#	#ears.setZ(3)
		
		
		self.setting = loader.loadModel("phase_6/models/karting/RT_SpeedwayA.bam")
#		self.setting.setAlphaScale(.5)
		self.setting.reparentTo(self.render)
		
		sky = loader.loadModel("phase_3.5/models/props/TT_sky.bam")
		sky.setSx(10)
		sky.setSy(10)
		sky.setSz(10)
		sky.reparentTo(render)
		'''
#The following are other things to fly around.
#Comes with Panda3D:
environment.egg.pz
panda-model.egg.pz
panda.egg.pz


#The following are from the Disney's Toontown Online (TTO) and/or Toontown Rewritten (TTR) phase files.

#Top 6 models that I recomend:
phase_6/models/karting/RT_SpeedwayA.bam
phase_3.5/models/props/TT_sky.bam
phase_12/models/bossbotHQ/BossbotMazex1_C.bam
phase_12/models/bossbotHQ/CogGolfExterior.bam
phase_5/models/cogdominium/tt_m_ara_crg_penthouse.bam
phase_5/models/cogdominium/tt_m_ara_cmg_quadrant3.bam


#TTO/TTR models likely starting from 2003/2002. Pretty universal.
phase_8/models/minigames/tag_arena_DG.bam
phase_4/models/minigames/tug_of_war_dock.bam
phase_4/models/minigames/matching_room.bam

phase_6/models/neighborhoods/minnies_melody_land.bam
phase_8/models/neighborhoods/the_burrrgh.bam


phase_3.5/models/props/TT_sky.bam
phase_3.5/models/props/BR_sky.bam
phase_6/models/props/MM_sky.bam
phase_8/models/props/DL_sky.bam


#TTO/TTR  models likely starting from 2003-2008.
phase_9/models/cogHQ/BossRoomHQ.bam
phase_9/models/cogHQ/SelbotLegFactory.bam

phase_9/models/cogHQ/cog_sky.bam

phase_6/models/karting/RT_SpeedwayA.bam

phase_4/models/minigames/ice_game.bam

phase_12/models/bossbotHQ/BossbotMazex1_C.bam
phase_12/models/bossbotHQ/CogGolfHub.bam
phase_12/models/bossbotHQ/CogGolfCourtyard.bam


#TTO/TTR  models likely starting from 2011.
phase_5/models/cogdominium/tt_m_ara_ccg_rooftop.bam
phase_5/models/cogdominium/tt_m_ara_crg_penthouse.bam
phase_5/models/cogdominium/tt_m_ara_cmg_quadrant3.bam

#Unused TTO model from 2011, removed before closure in 2013.
#Model restored in TTR but still unused some time between 2014 and 2015.
phase_5/models/cogdominium/tt_m_ara_cfg_quadrant6.bam

#TTR exlusive models. TTR models starting from 2014-May 2015
phase_6/models/events/ttr_m_ww_grounds.bam

phase_12/models/bossbotHQ/CogGolfLobby.bam
phase_12/models/bossbotHQ/CogGolfExterior.bam
phase_12/models/bossbotHQ/ttr_m_bossbothq_sky.bam


#The code after these coments makes "self.hero" a roadster from the Toontown game files.
#If you don't have unpacked TT phase files in Panda3D's "models" folder,
#then "panda.egg.pz" could be used for self.hero instead. T-poses are aerodynamic too, right?
#Careful when throwing t-poses like boomerangs as they are much heavier.
		'''
		self.hero = Actor("phase_6/models/karting/Kart2_Final.bam")
		self.lwing = loader.loadModel("phase_6/models/karting/accessory_rear_ww_8.bam")
		self.rwing = loader.loadModel("phase_6/models/karting/accessory_rear_ww_8.bam")
		self.lmetallazer = loader.loadModel("phase_6/models/karting/accessory_frontMiddle_6.bam")
		self.rmetallazer = loader.loadModel("phase_6/models/karting/accessory_frontMiddle_6.bam")
		
#		self.kart1.setZ(10.75)
		
		self.hero.find('**/chasse').setColor(0.3, 0.3, 0.35, 1.0)
		self.hero.find('**/accessoryGeometry').setColor(0.996094, 0.898438, 0.320312, 1.0)
		
		
	#	lwingplace = self.hero.find('**/leftFWWNode_2')
	#	rwingplace = self.hero.find('**/rightFWWNode_2')
	#	lmetallazerplace = self.hero.find('**/rightFWWNode_0')
	#	rmetallazerplace = self.hero.find('**/leftFWWNode_0')
		
	#	self.hero.attach(self.hero, self.lwing, 'rightFWWNode_2')
	#	self.hero.attach(self.rwing, self.hero, 'rightFWWNode_2')
		
	#	self.lwing.reparentTo(lwingplace)
	#	self.rwing.reparentTo(rwingplace)
	#	self.hero.attach(self.hero, self.rwing, "rwingplace")
	#	self.lmetallazer.reparentTo(lmetallazerplace)
	#	self.rmetallazer.reparentTo(rmetallazerplace)
		self.hero.reparentTo(self.render)
		self.lwing.reparentTo(self.render)
		self.rwing.reparentTo(self.render)
		self.lmetallazer.reparentTo(self.render)
		self.rmetallazer.reparentTo(self.render)
		
		
		self.lwing.reparentTo(self.hero.find('**/leftFWWNode_2'))
		self.lwing.setSx(20)
		self.lwing.setSy(10)
		self.lwing.setSz(30)
		self.lwing.setR(90)
		self.lwing.setX(-5)
		
		
		#rightFWWNode_2
		self.rwing.reparentTo(self.hero.find('**/rightFWWNode_2'))
		self.rwing.setSx(20)
		self.rwing.setSy(10)
		self.rwing.setSz(30)
		self.rwing.setH(180)
		self.rwing.setR(90)
		self.rwing.setP(180)
		self.rwing.setZ(7.85)
		self.rwing.setX(5)
		
		self.lmetallazer.reparentTo(self.hero.find('**/leftFWWNode_0'))
		self.lmetallazer.setSx(10)
		self.lmetallazer.setSy(10)
		self.lmetallazer.setSz(9.83)
		self.lmetallazer.setR(70)
		self.lmetallazer.setZ(1)
		self.lmetallazer.setY(5)
		
		self.rmetallazer.reparentTo(self.hero.find('**/rightFWWNode_0'))
		self.rmetallazer.setSx(10)
		self.rmetallazer.setSy(10)
		self.rmetallazer.setSz(9.83)
		self.rmetallazer.setR(-70)
		self.rmetallazer.setZ(1)
		self.rmetallazer.setY(5)
		
		
		self.shadow = loader.loadModel("phase_3/models/props/drop_shadow.bam")
		self.shadow.reparentTo(self.render)
		#self.shadow.setPos(self.hero.getPos())
		self.shadow.reparentTo(self.hero)
		self.shadow.setZ(self.hero.getZ() - self.elevation + 0.2)
		
		#self.shadow.setScale(.5, .5, .5)
		
		
		base.disableMouse()
		base.useDrive()
		base.useTrackball()
		print ("Initializing. Elevation nominal. Hammerspace thrusters operational. Lasers offline, but still cool.")
		print ("Delta Yankee November Alpha requesting permission to use a cup holder.")
		
		self.hero.setH(180)
		
		self.taskMgr.add(self.spinCameraTask, "spinCameraTask")


game = Window()
game.run()

Output

Controls

  • up arrow/down arrow:
    • move kart forward/backward
  • left arrow/right arrow:
    • spin kart and camera left/right
  • 1/2:
    • spin camera to the left/right of the kart
  • page up/page down:
    • fly kart up/down
  • home:
    • move kart to the height it started at
  • hold left and right mouse buttons while moving the mouse forward and back:
    • make the camera look up/down

Resources

  • phase_3\etc\icon.ico
  • phase_6\models\karting\Kart2_Final.bam
  • phase_6\models\karting\accessory_rear_ww_8.bam
  • phase_6\models\karting\accessory_frontMiddle_6.bam
  • phase_3\models\props\drop_shadow.bam
  • phase_6\models\karting\RT_SpeedwayA.bam
  • phase_3.5\models\props\TT_sky.bam

Tutorials

How to make a comment like the one at the top of the program.

Keyboard interface for moving a character and a camera.

Doing tasks every frame and using sine and cosine to spin a camera around a central point

Sine and cosine fact check.

Getting coordinate values for and moving things around.

Attaching things to an actor so it can be used as one uniform entity. Don't worry, the dual lasers are currently just for show.

Repurposed Toon colors as colors on a race kart.

Changing the configuration, like the gray background to make it blue like the sky.

What value to give the sky if I want the sky to be blue.

Perfect for when you want For Those About to Rock (We Salute You) by AC/DC to loop on your "radio" when you're "driving" in the sky.

Modulo operation for getting the modulus of a variable mod 360.

Community content is available under CC-BY-SA unless otherwise noted.