Top Gun (Beta-Build 2)
2.Fenster
2. Jet bewegt sich
beide Beschleunigung und Bremsung
Top Gun Singleplayer.py — text/python-source, 6 KB (6579 bytes)
Dateiinhalt
# -*- coding: utf-8 -*- from visual import * from threading import Thread projectname = 'Top Gun für Arme' projectstatus = 'Singleplayer 0.1' scene.title = projectname+' '+projectstatus # Fenstertitel scene.x = 0 # Fensterpos v. links scene.y = 0 # Fensterpos v. oben scene.height = 480 # Fensterhöhe scene.width = 640 # Fensterbreite scene.range = (1,1,1) # Abstand scene.center = (0,5,10) # Festlegung Blickziel scene.userspin = True scene.userzoom = True scene.background = (0.8,0.85,1) # Farbe Hintergrund scene.stereodepth = 2 # Stereotiefe scene.show_rendertime = True # Anzeige der Berechnungszeiten scene.fullscreen = False # Vollbildmodus b1=box(pos=(10,0,-100),color=color.red) #Boxen im 1.Fenster b2=box(pos=(-10,0,-500),color=color.red) scene2 = display(title = projectname+' '+projectstatus, x=640, y=0, width =640, height =480, userzoom= scene.userzoom, userspin= scene.userspin, range=scene.range, stereodepth= scene.stereodepth, sichtx = scene.x, sichty=scene.y, center = scene.center, background=(0,0,0)) b3=box(pos=(10,0,-100)) #Boxen im 2.Fenster b4=box(pos=(-10,0,-500)) def xgeben (frame, local): x_axis = norm(frame.axis) z_axis = norm(cross(frame.axis, frame.up)) y_axis = norm(cross(z_axis, x_axis)) return x_axis def ygeben (frame, local): x_axis = norm(frame.axis) z_axis = norm(cross(frame.axis, frame.up)) y_axis = norm(cross(z_axis, x_axis)) return y_axis def zgeben (frame, local): x_axis = norm(frame.axis) z_axis = norm(cross(frame.axis, frame.up)) y_axis = norm(cross(z_axis, x_axis)) return z_axis class Bullet(Thread, frame): def __init__(self, p=(0,0,0), axis=(0,0,0)): Thread.__init__(self) frame.__init__(self, pos=p, axis = (0,0,1)) self.jacket = sphere(radius=(0.1), pos=self.pos+vector(0,5,0), frame=self) self.v = vector(0,0,-1) def fly (self): self.pos = self.pos+self.v class Jet (Thread, frame): def __init__(self, p=(0,0,0), axis=(0,0,0), c=color.white, leading=true): Thread.__init__(self) frame.__init__(self, pos=p, axis = (0,0,1)) self.achse = vector(0,0,1) self.body = cylinder(radius = 2, axis=(-10,0,0), pos=(0,0,0), material=materials.wood, color=c, frame=self) self.wing = box (length=3, height=1, width=15, pos=(-6,0,0), material=materials.wood, color=c, frame=self) self.bullets = [Bullet] self.bulletMax = 40 self.health = 100 self.ztest = zgeben(self, self.body) self.xchange = 0 self.ychange = 0 self.zchange = 0 self.v = vector(0,0,-1) self.t = 0.0 def fly (self): vvec = vector(self.xchange,self.ychange,self.zchange) self.pos = self.pos+self.v+vvec # Jet-Bewegung print self.pos def nose (self, positive): self.t = self.t+0.1 if positive == True: self.ychange = sin(self.t) self.rotate(angle = -0.1*(pi/3), axis = zgeben(self, self.body), origin = self.body.pos+vector(0,0,6)) else: self.ychange = -sin(self.t) self.rotate(angle = 0.1*(pi/3), axis = self.ztest, origin = self.body.pos+vector(0,0,6)) print self.ztest def roll(self, vturn): self.rotate(angle = vturn, axis=self.axis) def shoot (self): if len(self.bullets) < self.bulletMax: self.bullets.append(Bullet(axis=self.axis)) else: print 'LADE NACH!' del self.bullets self.bullets = [Bullet] if __name__ == "__main__": print 'Initializing "',projectname,' ', projectstatus print 'By Darko Jankovic & Felix Schneider' print 'LMU Probestudium Informatik 2012' print '-------------------------------------------' print 'Initializing scene 1...' scene.select() j1 = Jet() j2 = Jet(p=(0,0,-12), c=(0.5,0.5,0.5)) print '...successful! Initializing scene 2...' scene2.select() j1b = Jet() j2b = Jet(p=(0,0,-12), c=(0.5,0.5,0.5)) scene.select() print '...successful!' print '-------------------------------------------' print 'Press the any key to start the game!' if scene.kb.getkey() > 0: # hier Abfrage nach dem Any-Key running = True while running == True: key = scene.kb.getkey() rate(50) print 'Leben: ',str(j1.health),'| Munition: ',str(j1.bulletMax-(len(j1.bullets)-1)) if key == '.' and mag(j1.v)<4.0: #Beschleunigung Jet1 j1.v = j1.v*1.1 j1b.v = j1.v elif key == ',' and mag(j1.v)>0.5: #Bremsung Jet1 j1.v = j1.v*0.9 j1b.v = j1.v elif key == 'm' and mag(j1.v)<4.0 and mag(j1.v)>0.5: j1.v = 1.0 j1b.v= 1.0 elif key == 'n': j2.v = 1.0 j2b.v = 1.0 elif key == 'left': #Rollen Jet1 nach links j1.roll(vturn=pi/90) j1b.roll(vturn=pi/90) elif key == 'right': #Rollen Jet1 nach rechts j1.roll(vturn=-pi/90) j1b.roll(vturn=-pi/90) #if key == 'up': # j1.nose(-0.1) # j1b.nose(-0.1) elif key == 'c': j1.shoot() #Beschleunigung Jet2 elif key == 'u' and mag(j2b.v)<4.0: #Beschleunigung Jet2 j2.v=j2.v*1.1 j2b.v=j2.v elif key== 'j' and mag(j2b.v)>0.5: #Bremse Jet2 j2.v = j2.v*0.9 j2b.v = j2.v elif key == 'h': # Rollen Jet2 nach links j2.roll(vturn=pi/90) j2b.roll(vturn=pi/90) elif key == 'k': #Rollen Jet2 nach rechts j2.roll(vturn=-pi/90) j2b.roll(vturn=-pi/90) scene.center+=j1.v scene2.center+=j2.v j1.pos = j1.pos+j1.v j2.pos = j2.pos+j2.v j1b.pos = j1b.pos+j1b.v j2b.pos = j2b.pos+j2b.v print mag(j1.v), mag(j2.v)