For this example we'll mainly be editing the files for our HUD, Cycle, MachineGun
, and Cannon
classes.
GunClasses_03.py
. First, we have a few small edits to make here. __init__
method of the MachineGun
class, right under the line that says self.cycle = cycle:
self.name = "JR Martin J59 Jabber"
Cannon
class:self.name = "Virtue X-A9 Equalizer"
MachineGun
class, right beneath the line that says self.damage = 10:
self.energyCost = 1.25
Cannon
class:self.energyCost = 5
fire()
method in both the classes, right beneath the line that starts fireSeq:
self.cycle.energy -= self.energyCost
GunClasses_04.py
and open CycleClass_04.py
. Update the gun classes import line to use the new file. setupVarsNPs()
method, right under the line that says self.handling = 25:
self.maxEnergy = 100 self.energy = self.maxEnergy
CycleClass_05.py
and open HUDClass_01.py
. It's time to do the real work. __init__
method of the HUD
class, right after the line that calls the createLLHUD()
method:self.createURHUD(fonts)
setupCycle
and add the following lines to the bottom of that method:self.guns = [self.cycle.LMG, self.cycle.RMG, self.cycle.cannon] self.gunNames[0]["text"] = self.guns[0].name self.gunNames[1]["text"] = self.guns[1].name self.gunNames[2]["text"] = self.guns[2].name
createLLHUD()
method. It's a lot of code, but there's nothing in it that we haven't done before.def createURHUD(self, fonts): self.urFrame = DirectFrame(frameSize = (-.6, 0, -.4, 0), frameColor = (1,1,1,0), parent = base.a2dTopRight) energyEgg = loader.loadModel("../Models/EnergyBar.egg") self.energyBG = energyEgg.find("**/EnergyBG") self.energyBar = energyEgg.find("**/EnergyBar") self.energyFrame = energyEgg.find("**/EnergyFrame") self.energyBG.reparentTo(self.urFrame) self.energyBar.reparentTo(self.energyBG) self.energyFrame.reparentTo(self.energyBG) self.energyBG.setPos(-.35, 0, -.0375) alpha = loader.loadTexture("../Images/ReloadAlpha.png") alpha.setFormat(Texture.FAlpha) alpha.setWrapU(Texture.WMClamp) self.energyBar.setTexture(self.modTS, alpha) self.energyText = DirectLabel(text = "100", text_font = fonts["orange"], text_scale = .05, pos = (-.65, 0, -.0525), text_fg = (1,1,1,1), relief = None, text_align = TextNode.ARight, self.reloadGreen = loader.loadTexture( "../Images/ReloadGreen.png") self.reloadRed = loader.loadTexture( "../Images/ReloadRed.png"). self.reloadBars = [] self.gunNames = [] for N in range(3): self.reloadBars.append(loader.loadModel( "../Models/ReloadBar.egg")) self.reloadBars[N].reparentTo(self.urFrame) self.reloadBars[N].setPos(-.6, 0, -.1125 + (N * -.05)) self.reloadBars[N].setScale(.1, 0, .1) self.reloadBars[N].setTexture(self.modTS, alpha) self.reloadBars[N].setTexOffset(self.modTS, .015, 0) self.gunNames.append(DirectLabel(text = "Gun Name", text_font = fonts["orange"], text_scale = .035, pos = (-.55, 0, -.125 + (N * -.05)), text_fg = (1,1,1,1), relief = None, text_align = TextNode.ALeft, parent = self.urFrame)) return
updateLLHUD()
method:def updateURHUD(self): energyRatio = self.cycle.energy / self.cycle.maxEnergy self.energyBar.setTexOffset(self.modTS, -(1 - energyRatio) + .015, 0) self.energyText["text"] = str(int(self.cycle.energy)) for N in range(3): if(self.guns[N].fireSeq.isPlaying() == True): if(self.reloadBars[N].getTexture != self.reloadRed): self.reloadBars[N].setTexture(self.reloadRed, 1) reloadRatio = (self.guns[N].fireSeq.getT() / self.guns[N].fireSeq.getDuration()) self.reloadBars[N].setTexOffset(self.modTS, -(1 - reloadRatio) + .015, 0) elif(self.reloadBars[N].getTexture() != self.reloadGreen): self.reloadBars[N].setTexture(self.reloadGreen, 1) self.reloadBars[N].setTexOffset(self.modTS, .015, 0) return
updateHUD()
method and add this line in, right after the call to updateLLHUD():
self.updateURHUD()
hide()
method, add the following line right beneath the one that hides the lower left DirectFrame:
self.urFrame.hide()
show()
method as well. It belongs right after the line that shows the lower-left DirectFrame:
self.urFrame.show()
HUDClass_02.py
. RaceClass_03.py
to use CycleClass_05.py
, and then resave it as RaceClass_04.py
. WorldClass_03.py
to use RaceClass_04.py
and HUDClass_02.py
then resave it as WorldClass_04.py
. WorldClass_04.py
from the command prompt and fire some of the guns to see the new HUD pieces in action.