def drawUpdate(s, timeElapsed): s.velo = HelperVec2.add(s.velo, (s.force[0] / s.mass, s.force[1] / s.mass)) s.pos = HelperVec2.add( s.pos, HelperVec2.mult(s.velo, (timeElapsed, timeElapsed))) s.force = (0.0, 0.0) pass
def initIcnFuels(s, list, screenSize): pos = (73 / 800.0 * screenSize[0], 205 / 600.0 * screenSize[1]) size = (94 / 800.0 * screenSize[0], 243 / 600.0 * screenSize[1]) barPos = (10 / 800.0 * screenSize[0], 10 / 600.0 * screenSize[1]) barSize = (74 / 800.0 * screenSize[0], 223 / 600.0 * screenSize[1]) labelSize = HelperVec2.mult(barSize, (.3, .3)) s.textureIdFuelBG = TextureLoader.load( os.path.join('assets', 'screenGame', 'fuelBG.png')) s.textureIdFuelWave = TextureLoader.load( os.path.join('assets', 'screenGame', 'wave.png')) s.textureIdFuelDiv = TextureLoader.load( os.path.join('assets', 'screenGame', 'fuelDiv.png')) s.textureIdFuelFill = TextureLoader.load( os.path.join('assets', 'screenGame', 'fuelFill.png')) s.arrIcnFuelLabelFraction = [] for i in range(0, 3): posNew = (pos[0] + .155 * screenSize[0] * i, pos[1]) posLabel = HelperVec2.add(posNew, (size[0] + 10, -labelSize[1])) icn = IcnFuel(posNew, size, s.textureIdFuelBG) icn.registerEvent_static(s.EVENT_STTAIC_DRAWN) icn.setRenderStatic(s.myBackground) list.append(icn) s.arrIcnFuelLabelFraction.append( IcnTextFraction(posLabel[0], posLabel[1], labelSize[0], labelSize[1]))
def initLines(s, screenSize): s.arrLines = [] for i in range(0, 3): objA = s.arrIcnFuels[i] objB =s.arrIcnFuelLabelFraction[i] pointA = HelperVec2.add(objA.pos, (objA.size[0] *.5,0) ) pointB = HelperVec2.add(objB.pos,( 0, objB.size[1]*.5 ) ) s.arrLines.append(EasyLine( pointA,pointB, (255,255,255) , 2) ) s.arrLines.append(EasyLine( (660/800.0*screenSize[0],220/600.0*screenSize[1]),(700/800.0*screenSize[0],220/600.0*screenSize[1]), (255,255,255) , 3) ) s.arrLines.append(EasyLine( (700/800.0*screenSize[0],220/600.0*screenSize[1]), HelperVec2.add(s.icnRocketLabelFraction.pos,(0,s.icnRocketLabelFraction.size[1] *.5) ) , (255,255,255) , 2) )
def __init__(self,pos,size, \ textureMe=-1,textureDiv=-1, textureBar =-1,textureIdFuelWave = -1): IcnBasic.__init__(self,pos[0],pos[1], size[0], size[1], textureMe, True) self.isRendered = False barPos = HelperVec2.mult(size, (.073,.0308)) barSize = HelperVec2.mult(size, (.878,.940)) self.myBars = IcnBars(barPos[0],barPos[1],barSize[0],barSize[1],10,True) self.posBars = barPos self.numNuno = 0 self.numDeno = 1 self.isChanged = True self.displayPercentage = 0
def setContent(s, c, color = (255,255,255) ): s.content = str(c) s.mySurface = IcnTextBox.FONT.render(s.content , 1, color) size = (s.mySurface.get_width(),s.mySurface.get_height()) ratio_1 = s.size[0] / s.mySurface.get_width() ratio_2 = s.size[1] / s.mySurface.get_height() ratio = ratio_1 if ratio_1 < ratio_2 else ratio_2 s.mySurface= HelperTexture.scale(s.mySurface ,HelperVec2.mult( size,(ratio,ratio) )) size = (s.mySurface.get_width(),s.mySurface.get_height()) extraSpace = HelperVec2.mult(HelperVec2.sub(s.size, size),(.5,.5) ) s.pos = HelperVec2.add(s.posInit , extraSpace)
def setContent(s, c, color=(255, 255, 255)): s.content = str(c) s.mySurface = IcnTextBox.FONT.render(s.content, 1, color) size = (s.mySurface.get_width(), s.mySurface.get_height()) ratio_1 = s.size[0] / s.mySurface.get_width() ratio_2 = s.size[1] / s.mySurface.get_height() ratio = ratio_1 if ratio_1 < ratio_2 else ratio_2 s.mySurface = HelperTexture.scale( s.mySurface, HelperVec2.mult(size, (ratio, ratio))) size = (s.mySurface.get_width(), s.mySurface.get_height()) extraSpace = HelperVec2.mult(HelperVec2.sub(s.size, size), (.5, .5)) s.pos = HelperVec2.add(s.posInit, extraSpace)
def __init__(self,pos,size, \ textureMe=-1,textureDiv=-1, textureBar =-1,textureIdFuelWave = -1): IcnBasic.__init__(self, pos[0], pos[1], size[0], size[1], textureMe, True) self.isRendered = False barPos = HelperVec2.mult(size, (.073, .0308)) barSize = HelperVec2.mult(size, (.878, .940)) self.myBars = IcnBars(barPos[0], barPos[1], barSize[0], barSize[1], 10, True) self.posBars = barPos self.numNuno = 0 self.numDeno = 1 self.isChanged = True self.displayPercentage = 0
def initButtons(s,screenSize): size = HelperVec2.mult(screenSize, (.1 ,.1 )) sizeMenu = (119/800.0*screenSize[0],43/600.0*screenSize[1]) s.textureIdButtonMenu = TextureLoader.load( os.path.join('assets', 'screenGame','bttnBack.png'),sizeMenu) s.bttnMenu = KButton(0, 554/600.0*screenSize[1], sizeMenu[0],sizeMenu[1], s.textureIdButtonMenu,True) s.arrButtons = [s.bttnMenu]
def initButtons(s,resolution): center = HelperVec2.mult(resolution, (.5,.5) ) # Main menu buttons s.bttnPlay = s.helperInitKButton ((center[0],center[1]-60),s.textureIdBttnStart)# KButton(center[0]-100, center[1] - 100, 200, 75,s.textureIdBttnStart) s.bttnHow = s.helperInitKButton ((center[0],center[1]), s.textureIdBttnHelp) s.bttnQuit = s.helperInitKButton ((center[0],center[1]+60), s.textureIdBttnExit) #KButton(center[0] -100,center[1] + 100, 200, 75,s.textureIdBttnExit) s.buttons = [s.bttnPlay,s.bttnHow,s.bttnQuit]
def initButtons(s, screenSize): size = HelperVec2.mult(screenSize, (.1, .1)) sizeMenu = (119 / 800.0 * screenSize[0], 43 / 600.0 * screenSize[1]) s.textureIdButtonMenu = TextureLoader.load( os.path.join('assets', 'screenGame', 'bttnBack.png'), sizeMenu) s.bttnMenu = KButton(0, 554 / 600.0 * screenSize[1], sizeMenu[0], sizeMenu[1], s.textureIdButtonMenu, True) s.arrButtons = [s.bttnMenu]
def display(s, nume,deno , colorNum = (255,255,255), colorDen = (255,255,255)): s.icnTextNum.setContent(str(nume),colorNum) s.icnTextDen.setContent(str(deno),colorDen) s.icnTextNum.drawUpdate(0) s.icnTextDen.drawUpdate(0) s.mySurface.fill((1,1,1,0)) s.icnTextNum.draw(s.mySurface) s.icnTextDen.draw(s.mySurface) pygame.draw.line(s.mySurface, (255,255,255) , (0,s.size[1]*.5) , HelperVec2.mult(s.size, (1,.5) ) ,2)
def drawUpdate(s, timeElapsed): #s.mySurface.fill((1,1,1,1), special_flags=pygame.BLEND_ADD) ratio = s.myFuel.getPercentage() if(s.isFlying ): s.pos = HelperVec2.add(s.pos, (0,-2200 *timeElapsed) ) else : s.updateVibrate(3.0*ratio,8.0*ratio) if(ratio >0):s.updateVibrateSound(timeElapsed,1-.3* ratio) #s.myFuel.pos = HelperVec2.add(s.pos, s.posFuel) if(s.myFuel.drawUpdate(timeElapsed)):s.myFuel.draw(s.mySurface)
def renderUpdate(s, timeElapsed): s.time += timeElapsed move = (math.cos(20 * s.time) * 10, math.sin(20 * s.time) * 10) s.icnRocket.pos = HelperVec2.add(s.posInit, (move)) for e in s.icnParticleStars: e.drawUpdate(timeElapsed) if (s.time > 10): print "Next frame now" s.helperRaiseEvent(s.EVENT_FINISHED) pass
def drawUpdate(s, timeElapsed): #s.mySurface.fill((1,1,1,1), special_flags=pygame.BLEND_ADD) ratio = s.myFuel.getPercentage() if (s.isFlying): s.pos = HelperVec2.add(s.pos, (0, -2200 * timeElapsed)) else: s.updateVibrate(3.0 * ratio, 8.0 * ratio) if (ratio > 0): s.updateVibrateSound(timeElapsed, 1 - .3 * ratio) #s.myFuel.pos = HelperVec2.add(s.pos, s.posFuel) if (s.myFuel.drawUpdate(timeElapsed)): s.myFuel.draw(s.mySurface)
def initIcnFuels(s,list,screenSize): pos = (73/800.0*screenSize[0],205/600.0*screenSize[1]) size = (94/800.0*screenSize[0],243/600.0*screenSize[1]) barPos = (10/800.0*screenSize[0],10/600.0*screenSize[1]) barSize = (74/800.0*screenSize[0], 223/600.0*screenSize[1]) labelSize = HelperVec2.mult( barSize , (.3, .3) ) s.textureIdFuelBG = TextureLoader.load( os.path.join('assets', 'screenGame','fuelBG.png' )) s.textureIdFuelWave = TextureLoader.load( os.path.join('assets', 'screenGame','wave.png')) s.textureIdFuelDiv = TextureLoader.load( os.path.join('assets', 'screenGame','fuelDiv.png')) s.textureIdFuelFill = TextureLoader.load( os.path.join('assets', 'screenGame','fuelFill.png')) s.arrIcnFuelLabelFraction = [] for i in range(0,3): posNew = ( pos[0] + .155*screenSize[0] * i, pos[1]) posLabel = HelperVec2.add(posNew, (size[0] +10, -labelSize[1] )) icn = IcnFuel(posNew, size,s.textureIdFuelBG ) icn.registerEvent_static(s.EVENT_STTAIC_DRAWN) icn.setRenderStatic(s.myBackground) list.append(icn) s.arrIcnFuelLabelFraction.append(IcnTextFraction (posLabel[0],posLabel[1],labelSize[0],labelSize[1]) )
def initButtons(self, resolution): center = HelperVec2.mult(resolution, (.5, .5)) # Main menu buttons self.bttnPlay = self.helperInitKButton( (center[0], center[1] - 60), self.textureIdBttnStart ) # KButton(center[0]-100, center[1] - 100, 200, 75,s.textureIdBttnStart) self.bttnHow = self.helperInitKButton((center[0], center[1]), self.textureIdBttnHelp) self.bttnQuit = self.helperInitKButton( (center[0], center[1] + 60), self.textureIdBttnExit ) # KButton(center[0] -100,center[1] + 100, 200, 75,s.textureIdBttnExit) self.buttons = [self.bttnPlay, self.bttnHow, self.bttnQuit]
def display(s, nume, deno, colorNum=(255, 255, 255), colorDen=(255, 255, 255)): s.icnTextNum.setContent(str(nume), colorNum) s.icnTextDen.setContent(str(deno), colorDen) s.icnTextNum.drawUpdate(0) s.icnTextDen.drawUpdate(0) s.mySurface.fill((1, 1, 1, 0)) s.icnTextNum.draw(s.mySurface) s.icnTextDen.draw(s.mySurface) pygame.draw.line(s.mySurface, (255, 255, 255), (0, s.size[1] * .5), HelperVec2.mult(s.size, (1, .5)), 2)
def respawn(s): ratio = 1.2 + 3.5 * random.random() s.pos = (random.random() * 1.5 * s.boundry[0], -100) s.velo = HelperVec2.mult(s.veloInit, (ratio, ratio)) pass
def updateVibrate(s, w, h): s.pos = HelperVec2.add( s.posInit, HelperVec2.mult((w, h), (-.5 + random.random(), -.5 + random.random()))) pass
def helperGetIcnFuel(self, pos,size, ratioPos,ratioSize,textureBG,textureDiv, textureFill,textureWave): return IcnFuel(pos, size,HelperVec2.mult(size,ratioPos), HelperVec2.mult(size, ratioSize ),textureBG,textureDiv,textureFill,textureWave )
def drawUpdate(s, timeElapsed): s.velo =HelperVec2.add(s.velo, (s.force[0]/s.mass ,s.force[1]/s.mass )) s.pos = HelperVec2.add(s.pos, HelperVec2.mult (s.velo ,(timeElapsed,timeElapsed) )) s.force = (0.0, 0.0) pass
def updateVibrate(s, w,h): s.pos = HelperVec2.add(s.posInit, HelperVec2.mult ( (w,h), ( -.5 +random.random(), -.5+ random.random())) ) pass
def respawn(s): ratio = 1.2+ 3.5*random.random() s.pos = (random.random() *1.5* s.boundry[0],-100) s.velo = HelperVec2.mult(s.veloInit ,(ratio,ratio)) pass