Highendgameversion
rotation2.py — text/python-source, 41 KB (42712 bytes)
Dateiinhalt
# -*- coding: utf-8 -*- from visual import * import math from threading import Thread from random import * import time # Szene-Einstellungen house_size =5 #Hausgröße map_size = 50 #Mapgröße world_size = 10*map_size class Camera(Thread): def __init__(self): Thread.__init__(self) scene.forward = (0,-1, 1) # Kameraposition: Vogel scene.userspin = True # Sitzt in Flugzeug scene.userzoom = True # Spezielles Key-Event zuständig scene.range = 65 # Ausgangsposition in y scene.fullscreen = True # Fullscreen-Mode scene.title = "SimplePlane" # Titel des Spiels self.camera = (0,0,0) # Cameraposition zu Anfang, wird anfangs neu berechnet self.radius = 50 # Anfangsradius der Kamerabewegung self.geschwindigkeit = .01 # Geschwindigkeit der Kamera self.beschleunigung = 1.01 # Beschleunigung um 1% self.y = 40 # Höhe self.geschoss = 0 # Geschosszähler self.treffer = 0 # Treffer scene.show_rendertime = True self.endgegner = False self.endgegner_treffer = 10 self.endgegner_killed = False self.geschossZaehler = label(pos = (3*map_size, 10, 3*map_size)) self.zeitanzeige = label(pos = (3*map_size, 20, 3*map_size)) self.frame = [] # Alle Frames self.objects = [] # Liste aller abschießbaren Objekte self.framenumber = 0 self.timer = Zeitanzeige(self) # Zeitanzeige initialisieren def run(self): x = 0 ControlScrolling(self, 150) # User darf nicht unendlich rauszoomen self.timer.start() # Timer Anzeige self.anzahlframes = self.framenumber # Framenumber um das Ende des Spiels zu erkennen self.refreshGeschossZaehler() # Geschosszähler erneuern while self.endgegner_killed == False: rate(50) if self.framenumber <= 0 and self.endgegner_killed == False: self.releaseTheKraken() self.newCameraPosition(x) # Neue Kameraposition ermitteln x += self.geschwindigkeit def newCameraPosition(self, i): # Berechnung der Kameraposition auf einem Kreis mit Radius scene.center = (self.radius * sin(i), self.y,self.radius * cos(i)) self.center = scene.center scene.forward = (-1 * self.center.x, -self.y, -2 * self.center.z) def schiessen(self, sme): if self.framenumber > 0 and self.endgegner == False: # Schießen s = Schuss(self, sme) s.start() if self.endgegner != False: s = Schuss(self, sme, True) s.start() def releaseTheKraken(self): self.framenumber += 1 self.endgegner_instance = Teufel(c, (random()*map_size, 10, random()* map_size), 10) def frameSetzen(self, f): self.framenumber += 1 for o in f.objects: if isinstance(o, frame): # Wenn ein Frame übergeben ist -> rekursiv self.frameSetzen(o) else: self.objects.append(o) # Alle Objekte des Frames def refreshGeschossZaehler(self): self.geschossZaehler.text = "Bisher "+ str(self.geschoss) +" mal geschossen bei "+ str(self.anzahlframes) +" erzeugten Objekten." def remove(self, f): for n in f.objects: if isinstance(n, frame): # Wenn ein Frame übergeben ist -> rekursiv self.framenumber -= 1 self.remove(n) else: self.objects.remove(n) # Alle Objekte des Frames entfernen def alert(self, text, wait): Alert(text, wait) class ControlScrolling(Thread): def __init__(self, camera, limit = 150): Thread.__init__(self) self.camera = camera self.limit = 150 # Höhenlimit für Scrolling self.start() # Thread starten def run(self): while True: if scene.kb.keys: s = scene.kb.getkey() if s == 'up' and self.camera.y < self.limit: self.camera.y += 1 elif s == 'down' and self.camera.y > 10: self.camera.y -= 1 class Alert(Thread): def __init__(self, text, wait): Thread.__init__(self) self.text = text # Alert Text self.wait = wait # Wartezeit des Alerts self.label = label(text = text, pos = scene.mouse.pos) self.run() def run(self): self.started = time.time() while (time.time()-self.started) <= self.wait: self.label.pos = scene.mouse.pos self.label.visible = false class Schuss(Thread): def __init__(self, camera, sme, endgegner_active = False): Thread.__init__(self) self.camera = camera self.sme = sme self.endgegner_active = endgegner_active def run(self): geschoss = cone(pos = scene.mouse.camera - (0,3,0), axis = (-scene.mouse.camera + self.sme.pickpos)*0.1, radius = 1) self.camera.geschoss += 1 # Geschosszähler self.camera.refreshGeschossZaehler() # Geschosszähler refresh explosion = Explosion(self.sme, geschoss) explosion.start() # Explosions Thread if self.endgegner_active == False: for x in range(1,10): geschoss.axis = (-self.sme.pickpos + scene.mouse.camera)*0.1*x geschoss.opacity -= 0.1 time.sleep(0.05) for o in self.camera.objects: if o == self.sme.pick: step = 0.1 self.camera.framenumber -= 1 self.camera.remove(o.frame) # Gesamtes Frame versinken lassen und anschließend löschen for n in range(0,100): o.frame.pos.y = o.frame.pos.y - step time.sleep(0.01) o.frame.visible = False self.camera.treffer += 1 # Beschleunigung um 5% self.camera.geschwindigkeit *= self.camera.beschleunigung time.sleep(0.1) elif self.endgegner_active == True and self.camera.endgegner_killed == False: self.camera.endgegner_treffer -= 1 if(self.camera.endgegner_treffer <= 0): step = 0.1 self.camera.endgegner_killed = True self.camera.framenumber -= 1 self.camera.remove(self.camera.endgegner) # Gesamtes Frame versinken lassen und anschließend löschen for n in range(0,1000): self.camera.endgegner.pos.y = self.camera.endgegner.pos.y - step time.sleep(0.01) self.camera.endgegner.visible = False self.camera.treffer += 1 time.sleep(0.1) class Explosion(Thread): def __init__(self, sme, geschoss): Thread.__init__(self) self.sme = sme self.geschoss = geschoss def run(self): explosion = sphere(pos = self.sme.pickpos, radius = 3, color = color.red, opacity = 0.8) for j in range(0,10): explosion.radius += j explosion.opacity -= 0.1 time.sleep(0.05) explosion.visible = false self.geschoss.visible = false class Zeitanzeige(Thread): def __init__(self, camera): Thread.__init__(self) self.camera = camera self.started = int(round(time.time())) self.camera.zeitanzeige.text = "O Sekunden" def run(self): while self.camera.framenumber > 0 and self.camera.endgegner_killed == False: self.camera.zeitanzeige.text = str(int(round(time.time()-self.started))) +" Sekunden" time.sleep(1) class Baum (): def __init__ (self,x,y,z,camera): baum = frame() cylinder(radius=0.5, pos= (0,0,0),frame=baum, axis=(0,7,0),color=(0.5,0.25,0.1)) sphere(radius=3, pos=(0,7,0),frame=baum,color=(0.1,0.5,0.1), material = materials.marble) baum.pos = (x,y,z) camera.frameSetzen(baum) class Fass (): def __init__ (self,x,y,z, camera): fass = frame() cylinder (frame = fass, radius=2,pos= (x,y,z), axis=(0,3.5,0),material=materials.earth) camera.frameSetzen(fass) class Haus (): def __init__(self,h,x,y,z, camera): f = frame() f.pos = (x,y,z) box(length=h,height= h,width = h,pos = (0,0.5*h,0),color = (0.7,0.4,0.1),frame=f, material=materials.bricks) extrusion(pos=[(0,0,0),(0,0,-0.5*h)],shape=Polygon( [(-0.5*h,h), (0,1.5*h), (h*0.5,h)] ),frame=f, material=materials.rough,color=color.red) extrusion(pos=[(0,0,0),(0,0,0.5*h)],shape=Polygon( [(-h*0.5,h), (0,1.5*h), (h*0.5,h)] ),material=materials.rough,frame=f,color=color.red) camera.frameSetzen(f) class Schneemann (): def __init__ (self, camera, pos = (0,1,0)): schneemann = frame() kugel = sphere(pos=(0,1,0),frame=schneemann,radius=1,color= color.white) kugel = sphere(pos=(0,2.6,0),frame=schneemann,radius=0.75,color = color.white) kugel = sphere(pos=(0,3.7,0),frame=schneemann,radius=0.5,color = color.white) arm = sphere(pos=(0.75,2.75,0),frame=schneemann,radius=0.33,color = color.white) armr= sphere(pos=(-0.75,2.75,0),frame=schneemann,radius=0.33,color = color.white) riing= ring (pos=(0,4.2,0),frame=schneemann,axis=(0,0.1,0),radius=0.27,thickness=0.1,color=color.black) hut= cylinder (pos=(0,4.2,0),frame=schneemann,axis=(0,0.6,0),radius=0.2,color=color.black) nase= cone (pos=(0,3.7,0.5),frame=schneemann,axis=(0,0,0.15),radius=0.09,color=color.orange) knopf = sphere(pos=(0,0.6,0.9),frame=schneemann,radius=0.05,color= color.black) knopf = sphere(pos=(0,1,1),frame=schneemann,radius=0.05,color= color.black) knopf = sphere(pos=(0,1.4,0.9),frame=schneemann,radius=0.05,color= color.black) knopf = sphere(pos=(0,2.2,0.65),frame=schneemann,radius=0.05,color= color.black) knopf = sphere(pos=(0,2.6,0.75),frame=schneemann,radius=0.05,color= color.black) knopf = sphere(pos=(0,3.0,0.65),frame=schneemann,radius=0.05,color= color.black) auge = sphere(pos=(0.25,3.8,0.5),frame=schneemann,radius=0.05,color= color.black) auge = sphere(pos=(-0.25,3.8,0.5),frame=schneemann,radius=0.05,color= color.black) schneemann.pos = pos camera.frameSetzen(schneemann) class Ente (Thread): def __init__(self, camera, pos = (0,1,0)): Thread.__init__(self) self.frame = frame() kopf = sphere(pos=(0,2.5,1),radius=0.5,frame=self.frame,color=color.gray(0.7),material=materials.rough) koerper = sphere(pos=(0,1.5,0),radius=1,color=color.gray(0.7),material=materials.rough, frame = self.frame) fluegel=ellipsoid(pos=(0,1.5,0),axis=(1,0,0),length=4, height=0.5, width=1,frame=self.frame,color=color.gray(0.7),material=materials.rough) bein1=ellipsoid(pos=(0.3,0.4,0),axis=(0,1,0),length=0.7, height=0.25, width=0.25,frame=self.frame ,color=color.gray(0.7),material=materials.rough) bein2=ellipsoid(pos=(-0.3,0.4,0),axis=(0,1,0),length=0.7, height=0.25, width=0.25,frame=self.frame ,color=color.gray(0.7),material=materials.rough) fuss1=ellipsoid(pos=(0.3,0,0.3),axis=(0,0,1),length=1, height=0.2, width=0.5,frame=self.frame,color=color.orange) fuss2=ellipsoid(pos=(-0.3,0,0.3),axis=(0,0,1),length=1, height=0.2, width=0.5,frame=self.frame,color=color.orange) hinten=ellipsoid(pos=(0,1.3,-1),axis=(0,0.5,1),length=2, height=0.2, width=1,frame=self.frame,color=color.gray(0.7)) schnabel=ellipsoid(pos=(0,2.4,1.5),axis=(0,0,1),length=1, height=0.2, width=0.5,frame=self.frame,color=color.orange) auge1=sphere(pos=(-0.15,2.7,1.4),radius=0.1,frame=self.frame,color=color.black,material=materials.plastic) auge2=sphere(pos=(0.15,2.7,1.4),radius=0.1,frame=self.frame,color=color.black,material=materials.plastic) self.frame.pos = pos camera.frameSetzen(self.frame) self.start() def run(self): z = 1 while True: y = 100 timer = 1.0/y step = 5.0/y geschwindigkeit = random() * 5 axis = norm(-cross((0,1,0), self.frame.axis)) * geschwindigkeit step_x = axis.x / y step_z = axis.z / y # Bewegen in x und z for i in range(0,y): self.frame.pos.z += step_z self.frame.pos.x += step_x self.frame.pos.y += step time.sleep(timer) for i in range(0,y): self.frame.pos.y -= step self.frame.pos.x += step_x self.frame.pos.z += step_z time.sleep(timer) time.sleep(1) # Drehen in x und z y = 100 r = random() * math.pi timer = r/y step = r/y for i in range(0,y): self.frame.rotate(angle = step, axis = (0,1,0), origin = self.frame.pos) time.sleep(timer) time.sleep(5) z += 1 class Flugzeug (Thread): def __init__ (self, camera): Thread.__init__(self) flugzeug= frame() flugzeug= frame() mitte= box(pos=(0,10,0),frame=flugzeug, length=5, heigth=8, width=3,color=(0.5,1,0.5),material=materials.marble) mitte= cylinder(pos=(-2.5,9.5,0),frame=flugzeug, axis=(5,0,0),radius=0.5,color=color.black,material=materials.marble) schnauze= cylinder(pos=(2.5,10,0),frame=flugzeug, axis=(3,0,0),radius=1.5,color=color.black) schnauze= helix(pos=(2.5,10,0),frame=flugzeug,axis=(3,0,0),radius=1.6,thickness=0.2,material=materials.chrome) schnauze= cylinder(pos=(5.5,10,0),frame=flugzeug, axis=(0.5,0,0),radius=0.5,color=color.red) propeller= ellipsoid (pos=(5.9,10,0.1),frame=flugzeug, length=0.2,heigth=0.2, width=5,material=materials.wood) propeller= ellipsoid (pos=(5.9,10,-0.1),frame=flugzeug, length=0.2,heigth=0.2, width=5,material=materials.wood) kuppel= ellipsoid (pos=(0,11,0),frame=flugzeug, length=4.5,heigth=2, width=2,material=materials.ice) kuppel= ellipsoid (pos=(0,10.5,0),frame=flugzeug, length=4.5,heigth=2, width=2,material=materials.ice) kuppel= ellipsoid (pos=(0,10.6,0),frame=flugzeug, length=4.5,heigth=2, width=2,color=color.black) kuppel= ellipsoid (pos=(0,10.7,0),frame=flugzeug, length=4.5,heigth=2, width=2,material=materials.ice) kuppel= ellipsoid (pos=(0,10.8,0),frame=flugzeug, length=4.5,heigth=2, width=2,material=materials.ice) kuppel= ellipsoid (pos=(0,10.9,0),frame=flugzeug, length=4.5,heigth=2, width=2,material=materials.ice) fluegel= ellipsoid (pos=(0,10,0),frame=flugzeug, length=2,heigth=2, width=16,color=(0.6,1,0.6),material=materials.marble) kanone= cylinder (pos=(-2.5,10,5),frame=flugzeug, axis=(5,0,0),radius=0.5,color=color.gray(0.5)) kanone= cylinder (pos=(-2.5,10,-5),frame=flugzeug, axis=(5,0,0),radius=0.5,color=color.gray(0.5)) kanone= cylinder (pos=(-2.5,10,5),frame=flugzeug, axis=(5.5,0,0),radius=0.25,material=materials.chrome) kanone= cylinder (pos=(-2.5,10,-5),frame=flugzeug, axis=(5.5,0,0),radius=0.25,material=materials.chrome) heck= cone (pos=(-2,10,0),frame=flugzeug, axis=(-5,0,0),radius=1,color=color.black) heck= cylinder (pos=(-6,10,0),frame=flugzeug, axis=(-1,0,0),radius=0.2,color=color.black) senkrechterheckfluegel= ellipsoid (pos=(-6,10.5,0),frame=flugzeug, length=2,heigth=0.2, width=0.2,color=color.red) heckfluegel= ellipsoid (pos=(-6,10,0),frame=flugzeug, length=1,heigth=0.2, width=4,color=(0.6,1,0.6),material=materials.marble) propeller= ring (pos=(5.9,10,0),frame=flugzeug, axis=(0.1,0,0),radius=1.25,thickness=0.01,material=materials.ice) propeller= ring (pos=(5.9,10,0),frame=flugzeug, axis=(0.1,0,0),radius=2.5,thickness=0.01,material=materials.ice) spitze= cone (pos=(5.9,10,0),frame=flugzeug, axis=(1,0,0),radius=0.3,color=color.black) self.frame = flugzeug camera.frameSetzen(self.frame) self.geschwindigkeit = 0.05 self.radius = 20 self.start() def run(self): x = 0 while True: rate(50) self.newFlugzeugPosition(x) x += self.geschwindigkeit def newFlugzeugPosition(self, i): self.frame.pos = (self.radius * sin(i), self.frame.y ,self.radius * cos(i)) self.frame.axis = -cross(self.frame.pos-(0,0,0), vector(0,1,0)) class Hubschrauber (Thread): def __init__ (self, camera, pos = (0,0,0)): Thread.__init__(self) self.camera = camera hubschrauber=frame() self.propeller = frame() kugel = sphere(pos=(0,15,0),frame=hubschrauber,radius=3,material=materials.ice,opacity=0.1) kugel = sphere(pos=(0,14.95,0),frame=hubschrauber,radius=3,color=color.orange,material=materials.marble) kugel = sphere(pos=(0.05,15,0),frame=hubschrauber,radius=3,color=color.black,material=materials.marble) kugellampe= local_light(pos=(0,15,0),frame=hubschrauber,radius=3,color=color.green) heck= cone (pos=(0,15,0),frame=hubschrauber,axis=(6,0,0),radius=2.9,color=color.orange,material=materials.marble) heck=cylinder (pos=(0,16.5,0),frame=hubschrauber,axis=(9,0,0),radius=0.25,color=color.black) heck=cylinder (pos=(5,15,0),frame=hubschrauber,axis=(2.5,1.5,0),radius=0.1,color=color.black) heck=cylinder (pos=(4,15,0),frame=hubschrauber,axis=(2.5,1.5,0),radius=0.09,color=color.black) heck=cylinder (pos=(3,15,0),frame=hubschrauber,axis=(2.5,1.5,0),radius=0.08,color=color.black) heck=cylinder (pos=(2,15,0),frame=hubschrauber,axis=(2.5,1.5,0),radius=0.07,color=color.black) heck=cylinder (pos=(1,15,0),frame=hubschrauber,axis=(2.5,1.5,0),radius=0.06,color=color.black) bein=cylinder (pos=(-1,13.5,1.5),frame=hubschrauber,axis=(-2,-2,0),radius=0.1,color=color.black) bein=cylinder (pos=(-1,13.5,-1.5),frame=hubschrauber,axis=(-2,-2,0),radius=0.1,color=color.black) bein=cylinder (pos=(-1,13.5,1.5),frame=hubschrauber,axis=(2,-2,0),radius=0.1,color=color.black) bein=cylinder (pos=(-1,13.5,-1.5),frame=hubschrauber,axis=(2,-2,0),radius=0.1,color=color.black) bein=cylinder (pos=(-3.5,11.5,1.5),frame=hubschrauber,axis=(8,0,0),radius=0.3,color=color.black) bein=cylinder (pos=(-3.5,11.5,-1.5),frame=hubschrauber,axis=(8,0,0),radius=0.3,color=color.black) bein= sphere(pos=(-3.5,11.5,-1.5),frame=hubschrauber,radius=0.3,color= color.orange,material=materials.marble) bein= sphere(pos=(-3.5,11.5,1.5),frame=hubschrauber,radius=0.3,color= color.orange,material=materials.marble) bein= sphere(pos=(4.5,11.5,-1.5),frame=hubschrauber,radius=0.3,color= color.orange,material=materials.marble) bein= sphere(pos=(4.5,11.5,1.5),frame=hubschrauber,radius=0.3,color= color.orange,material=materials.marble) hecknase= cone (pos=(8.5,16.5,0),frame=hubschrauber,axis=(0,0,1),radius=0.5,color=color.orange,material=materials.marble) hecknase= cone (pos=(8.5,16.5,0),frame=hubschrauber,axis=(0,0,-0.5),radius=0.5,color=color.orange,material=materials.marble) ellipsoid (pos=(9,16.5,0.7),frame=hubschrauber,axis=(0,0.2,0), length=0.2,heigth=2, width=0.2,color=color.black) ellipsoid (pos=(8,16.5,0.7),frame=hubschrauber,axis=(0,0.2,0), length=0.2,heigth=2, width=0.2,color=color.black) self.propeller_origin = propellernase= cone (pos=(0,18,0),frame=hubschrauber,axis=(0,1,0),radius=0.5,color=color.orange,material=materials.marble) self.propeller1= ellipsoid (pos=(0,18.6,3.5),frame=self.propeller,axis=(-0.2,0.5,0), length=0.2,heigth=0.2, width=7,color=color.black) self.propeller2= ellipsoid (pos=(0,18.6,-3.5),frame=self.propeller,axis=(0.2,0.5,0), length=0.2,heigth=0.2, width=7,color=color.black) lampe=cylinder (pos=(0,13.5,0),frame=hubschrauber,axis=(-1.8,-2,0),radius=0.1,color=color.black) lampe= sphere(pos=(-1.8,11.5,0),frame=hubschrauber,radius=0.25,color=color.orange,material=materials.marble,opacity=0.5) lampe=cylinder (pos=(-1.8,11.5,0),frame=hubschrauber,axis=(-0.25,-0.1,0),radius=0.25,color=color.black) #lampe= local_light(pos=(-2.05,11.4,0),frame=hubschrauber,radius=0.25,color=color.yellow) #lampe= local_light(pos=(-1.8,1.5,0),frame=hubschrauber,radius=0.25,color=color.yellow) lampe= sphere(pos=(-2.05,11.4,0),frame=hubschrauber,radius=0.25,color=color.yellow,opacity=0.5) self.frame = hubschrauber self.propeller.frame = self.frame self.frame.pos = pos self.radius = 60 self.geschwindigkeit = 0.005 camera.frameSetzen(self.frame) self.start() propeller = Propeller(self.propeller, self.propeller_origin) propeller.start() def run(self): x = 0 while True: rate(50) self.newHubschrauberPosition(x) x += self.geschwindigkeit def newHubschrauberPosition(self, i): self.frame.pos = (self.radius * sin(i), self.frame.y ,self.radius * cos(i)) self.frame.axis = cross(self.frame.pos-(0,0,0), vector(0,1,0)) class Propeller(Thread): def __init__(self, propeller, propeller_origin): Thread.__init__(self) self.propeller = propeller self.propeller_origin = propeller_origin def run(self): while True: y = 100 r = 2*math.pi timer = r/(y*10) step = r/y for i in range(0,y): self.propeller.rotate(angle=step, axis=(0,1,0), origin=self.propeller_origin.pos) time.sleep(timer) class Raketenbatterie (Thread): def __init__(self,camera, pos = (0, 2, 0)): Thread.__init__(self) raketenbatterie=frame() self.camera = camera self.raketen=frame() boden=box(pos=(0,0,0),length=4,width=4,height=0.2,color=(0.5,0.5,0.5),frame=raketenbatterie) halterung=box(pos=(0,0.3,0),width=1,lenght=1,height=1,axis=(0,0.5,0),frame=raketenbatterie) stange=cylinder(pos=(0,0.3,0),axis=(0,1.2,0),radius=0.2,frame=raketenbatterie) raketenb=box(pos=(0.5,1.5,0),axis=(2,0,0),length=1.9,width=2,material=materials.rough,frame=self.raketen) self.rak1 = arrow(pos=(1,1.5,0.5),axis=(1,0,0),color=color.black,material=materials.plastic,frame=self.raketen) self.rak2 = arrow(pos=(1,1.5,0),axis=(1,0,0),color=color.black,material=materials.plastic,frame=self.raketen) self.rak3 = arrow(pos=(1,1.5,-0.5),axis=(1,0,0),radius=0.3,color=color.black,material=materials.plastic,frame=self.raketen) self.raketen.frame=raketenbatterie self.frame = raketenbatterie self.sleeping = 30 self.frame.pos = pos self.start() abschuss = RaketenAbschuss(self) abschuss.start() def run(self): while True: self.raketen.axis = scene.mouse.camera - self.raketen.pos def startNewRocket(self, rocket): timer = 0.005 visible_rocket = arrow(pos = self.frame.pos, axis = rocket.axis, color = color.black, material = materials.plastic, make_trail = True) visible_rocket.trail_object.color = color.red while (rocket.visible and round(mag(scene.mouse.camera - rocket.pos)) > 10) and self.camera.framenumber > 0 and self.camera.endgegner_killed == False: axis = scene.mouse.camera - rocket.pos rocket.axis = norm(axis)*5 step_z = axis.z / 40 step_x = axis.x / 40 step_y = axis.y / 40 rocket.pos.y += step_y rocket.pos.x += step_x rocket.pos.z += step_z rocket.opacity = 0 visible_rocket.pos = rocket.pos visible_rocket.axis = rocket.axis time.sleep(timer) visible_rocket.trail_object.visible = False rocket.visible = False visible_rocket.visible = False Alert("Du wurdest getroffen!", 3) class RaketenAbschuss(Thread): def __init__(self, raketenbatterie): Thread.__init__(self) self.raketenbatterie = raketenbatterie def run(self): # Erste Rakete time.sleep(self.raketenbatterie.sleeping) self.raketenbatterie.camera.alert("Das Boden-Luft-Geschuetz hat soeben eine Rakete auf dich gestartet.", 5) self.raketenbatterie.startNewRocket(self.raketenbatterie.rak1) # Zweite Rakete time.sleep(self.raketenbatterie.sleeping) self.raketenbatterie.camera.alert("Eine weitere Rakete. Versuche das Geschuetz abzuschiessen!", 5) self.raketenbatterie.startNewRocket(self.raketenbatterie.rak2) # Raketenbatterie kann abgeschossen werden self.raketenbatterie.camera.frameSetzen(self.raketenbatterie.frame) time.sleep(self.raketenbatterie.sleeping*1.2) # Dritte Rakete self.raketenbatterie.startNewRocket(self.raketenbatterie.rak3) class Schiff (): def __init__ (self, camera, pos = (20, 2, 30), axis = (1,0,0)): schiff=frame() self.camera = camera haupt= box(pos=(10,1,10),frame=schiff, length=5, width=10,material=materials.wood) mast=cylinder (pos=(10,1,10),frame=schiff,axis=(0,8,0),radius=0.5,material=materials.wood) mast=cylinder (pos=(6,7,10),frame=schiff,axis=(8,2,0),radius=0.25,material=materials.wood) mast=cylinder (pos=(4,6.5,10),frame=schiff,axis=(12 ,3,0),radius=0.15,material=materials.wood) mast=cylinder (pos=(10,1,10),frame=schiff,axis=(0,12,0),radius=0.25,material=materials.wood) mast=cylinder (pos=(10,1,10),frame=schiff,axis=(0,14,0),radius=0.1,material=materials.wood) vordermast=cylinder (pos=(10,1,15),frame=schiff,axis=(0,7,0),radius=0.3,material=materials.wood) vordermast=cylinder (pos=(10,4,15),frame=schiff,axis=(0,1,6),radius=0.15,material=materials.wood) vordermast=cylinder (pos=(10,1,15),frame=schiff,axis=(0,9,0),radius=0.15,material=materials.wood) korb=cylinder (pos=(10,9,10),frame=schiff,axis=(0,2,0),radius=1.5,material=materials.wood) korb=cylinder (pos=(11.5,9.25,10),frame=schiff,axis=(0,1.5,0),radius=0.25,color=color.black) korb=cylinder (pos=(8.5,9.25,10),frame=schiff,axis=(0,1.5,0),radius=0.25,color=color.black) korb=cylinder (pos=(10,9.25,11.5),frame=schiff,axis=(0,1.5,0),radius=0.25,color=color.black) korb=cylinder (pos=(10,9.25,8.5),frame=schiff,axis=(0,1.5,0),radius=0.25,color=color.black) reling= box(pos=(12.5,2,9.5),frame=schiff, length=2, width=11,axis=(0,5,0),material=materials.wood) reling= box(pos=(7.5,2,9.5),frame=schiff, length=2, width=11,axis=(0,5,0),material=materials.wood) reling=cylinder (pos=(7.5,3,5),frame=schiff,axis=(0,0,10),radius=0.1,color=color.black) reling=cylinder (pos=(12.5,3,5),frame=schiff,axis=(0,0,10),radius=0.1,color=color.black) reling=cylinder (pos=(7.5,1,4),frame=schiff,axis=(0,0,11),radius=0.5,material=materials.wood) reling=cylinder (pos=(12.5,1,4),frame=schiff,axis=(0,0,11),radius=0.5,material=materials.wood) heck= box(pos=(10,1,5),frame=schiff, length=2, width=10,axis=(0,5,0),material=materials.wood) heck= box(pos=(10,1,15),frame=schiff, length=2, width=10,axis=(0,5,0),material=materials.wood) heck= box(pos=(10,1,5),frame=schiff, length=2, width=10,axis=(5,0,0),material=materials.wood) heck= box(pos=(10,2,2),frame=schiff, length=6, width=5,axis=(0,-2,5),material=materials.wood) heck= box(pos=(10,4.5,2),frame=schiff, length=6, height=5, width=6,axis=(0,-2,5),material=materials.wood) heck= box(pos=(10,3.5,5),frame=schiff, length=6, height=5, width=1,axis=(0,-2,0),material=materials.wood) heckreling=cylinder (pos=(12.5,1,5),frame=schiff,axis=(0,6,0),radius=0.5,material=materials.wood) heckreling=cylinder (pos=(7.5,1,5),frame=schiff,axis=(0,6,0),radius=0.5,material=materials.wood) heckrelinglampe=cylinder (pos=(12.5,1,5),frame=schiff,axis=(0,7.2,0),radius=0.1,color=color.black) heckrelinglampe=cylinder (pos=(7.5,1,5),frame=schiff,axis=(0,7.2,0),radius=0.1,color=color.black) #heckrelinglampe=local_light (pos=(12.5,7.3,5),frame=schiff,axis=(0,0,0),radius=1,color=color.yellow) #heckrelinglampe=local_light (pos=(7.5,7.3,5),frame=schiff,axis=(0,0,0),radius=1,color=color.yellow) heckrelinglampe=cylinder (pos=(12.5,7.3,5),frame=schiff,axis=(0,0.5,0),radius=0.5,color=color.yellow,opacity=0.25) heckrelinglampe=cylinder (pos=(7.5,7.3,5),frame=schiff,axis=(0,0.5,0),radius=0.5,color=color.yellow,opacity=0.25) heckrelinglampe=cylinder (pos=(12.5,7.8,5),frame=schiff,axis=(0,0.1,0),radius=0.5,color=color.black) heckrelinglampe=cylinder (pos=(7.5,7.8,5),frame=schiff,axis=(0,0.1,0),radius=0.5,color=color.black) heckrelinglampe=cylinder (pos=(12.5,7.2,5),frame=schiff,axis=(0,0.1,0),radius=0.5,color=color.black) heckrelinglampe=cylinder (pos=(7.5,7.2,5),frame=schiff,axis=(0,0.1,0),radius=0.5,color=color.black) spitzereling=cylinder (pos=(7.5,3,15),frame=schiff,axis=(2.5,0,5),radius=0.1,color=color.black) spitzereling=cylinder (pos=(12.5,3,15),frame=schiff,axis=(-2.5,0,5),radius=0.1,color=color.black) spitzereling=cylinder (pos=(7.5,1,15),frame=schiff,axis=(2.5,0,5),radius=0.5,material=materials.wood) spitzereling=cylinder (pos=(12.5,1,15),frame=schiff,axis=(-2.5,0,5),radius=0.5,material=materials.wood) spitzereling= box(pos=(11.4,2,17),frame=schiff, length=1, width=5,height=2,axis=(2.5,0,1.5),material=materials.wood) spitzereling= box(pos=(8.6,2,17),frame=schiff, length=1, width=5,height=2,axis=(-2.5,0,1.5),material=materials.wood) spitzereling= box(pos=(10,2,20),frame=schiff, length=1.5, width=1,height=1,axis=(0,1,1),material=materials.wood) spitzeboden= box(pos=(10,1,15),frame=schiff, length=4, width=4,height=1,axis=(-2.5,0,2.5),material=materials.wood) spitzenmast=cylinder (pos=(10,2.75,19),frame=schiff,axis=(0,0,2),radius=0.5,material=materials.wood) spitzenmast=cylinder (pos=(10,3,19),frame=schiff,axis=(0,0,6),radius=0.25,material=materials.wood) self.camera.frameSetzen(schiff) schiff.pos = pos schiff.axis = axis class Uboot (Thread): def __init__ (self, camera, pos = (0,0,0), axis = (1,0,0)): Thread.__init__(self) uboot=frame() self.camera = camera haupt= ellipsoid(pos=(0,-2.5,0),frame=uboot,length=20, height=4, width=4,material=materials.marble,color=color.gray(0.6)) mast=cylinder (pos=(0,-2.5,0),frame=uboot,axis=(0,2,0),radius=2,material=materials.marble,color=color.gray(0.6)) mast=sphere(pos=(0,-1,0),frame=uboot,radius=1.8,material=materials.marble,color=color.gray(0.6)) mast=cylinder (pos=(0,-2,0),frame=uboot,axis=(0,4.5,0),radius=0.25,material=materials.marble,color=color.gray(0.6)) mast=sphere(pos=(0,2.5,0),frame=uboot,radius=0.25,material=materials.marble,color=color.gray(0.6)) mast=cylinder (pos=(0,2.5,0),frame=uboot,axis=(1,0,0),radius=0.25,material=materials.marble,color=color.gray(0.6)) flosse= ellipsoid(pos=(9.5,-2.5,0),frame=uboot,length=1, height=0.2, width=3,material=materials.marble,color=color.gray(0.6)) flosse= ellipsoid(pos=(-9,-2.5,0),frame=uboot,length=1, height=0.5, width=6,material=materials.marble,color=color.gray(0.6)) flosse= ellipsoid(pos=(-9,-2.5,0),frame=uboot,length=1, height=3, width=0.5,material=materials.marble,color=color.gray(0.6)) flosse= ellipsoid(pos=(0,-2.5,0),frame=uboot,length=2, height=0.5, width=10,material=materials.marble,color=color.gray(0.6)) motor=cylinder (pos=(-9.5,-2.5,0),frame=uboot,axis=(3,0,0),radius=1,material=materials.marble,color=color.gray(0.6)) uboot.pos = pos uboot.axis = axis self.frame = uboot self.camera.frameSetzen(uboot) self.start() def run(self): z = 1 while True: y = 100 timer = 3.0/y step = 3.0/y geschwindigkeit = random() * 20 axis = self.frame.axis * geschwindigkeit #axis = norm(-cross((0,1,0), self.frame.axis)) * geschwindigkeit step_x = axis.x/ y step_z = axis.z / y # Bewegen in x und z for i in range(0,y): self.frame.pos.z += step_z self.frame.pos.x += step_x self.frame.pos.y += step time.sleep(timer) for i in range(0,y): self.frame.pos.y -= step self.frame.pos.x += step_x self.frame.pos.z += step_z time.sleep(timer) time.sleep(1) # Drehen in x und z y = 100 r = random() * math.pi timer = r/y step = r/y for i in range(0,y): self.frame.rotate(angle = step, axis = (0,1,0), origin = self.frame.pos) time.sleep(timer) z += 1 time.sleep(5) class Teufel (Thread): def __init__ (self, camera, pos = (0,0,0), k = 1): Thread.__init__(self) self.camera = camera self.k = k teufel=frame () kopf=sphere(pos=(0,3.5*self.k,0),frame=teufel,radius=0.5*self.k,color=color.red) augen=sphere(pos=(0.25*self.k,3.5*self.k,0.45*self.k),frame=teufel,radius=0.05*self.k,color=color.black) augen=sphere(pos=(-0.25*self.k,3.5*self.k,0.45*self.k),frame=teufel,radius=0.05*self.k,color=color.black) horn= arrow(pos=(-0.4*self.k,3.7*self.k,0),frame=teufel, axis=(-0.5*self.k,0.5*self.k,0), shaftwidth=0.25*self.k,color=color.black) horn= arrow(pos=(0.4*self.k,3.7*self.k,0), frame=teufel,axis=(0.5*self.k,0.5*self.k,0), shaftwidth=0.25*self.k,color=color.black) nase= cone(pos=(0,3.5*self.k,0.5*self.k),frame=teufel, axis=(0,0,0.15*self.k),radius=0.1*self.k,color=color.black) bart= cone(pos=(0,3.1*self.k,0.25*self.k),frame=teufel, axis=(0,-0.1*self.k,0.1*self.k),radius=0.01*self.k,color=color.black) mund= cylinder(pos=(-0.2*self.k,3.3*self.k,0.42*self.k),frame=teufel, axis=(0.4*self.k,0,0),radius=0.05*self.k,color=color.black) braue= cylinder(pos=(-0.3*self.k,3.6*self.k,0.42*self.k),frame=teufel, axis=(0.1*self.k,0,0),radius=0.02*self.k,color=color.black) braue= cylinder(pos=(0.2*self.k,3.6*self.k,0.42*self.k),frame=teufel, axis=(0.1*self.k,0,0),radius=0.02*self.k,color=color.black) ohr= cylinder(pos=(-0.5*self.k,3.5*self.k,0),frame=teufel, axis=(0.1*self.k,0,0.05*self.k),radius=0.05*self.k,color=color.red) ohr= cylinder(pos=(0.4*self.k,3.5*self.k,0),frame=teufel, axis=(0.1*self.k,0,0.05*self.k),radius=0.05*self.k,color=color.red) koerper= cylinder(pos=(0,2.7*self.k,0),frame=teufel, axis=(0,-0.8*self.k,0),radius=0.5*self.k,color=color.red) koerper=sphere(pos=(0,2.7*self.k,0),frame=teufel,radius=0.5*self.k,color=color.red) koerper=sphere(pos=(0,2*self.k,0),frame=teufel,radius=0.5*self.k,color=color.black) arm=sphere(pos=(0.5*self.k,2.6*self.k,0),frame=teufel,radius=0.1*self.k,color=color.red) arm=sphere(pos=(-0.5*self.k,2.6*self.k,0),frame=teufel,radius=0.1*self.k,color=color.red) arm= cylinder(pos=(0.5*self.k,2.6*self.k,0),frame=teufel, axis=(0.3*self.k,-0.3*self.k,0),radius=0.1*self.k,color=color.red) arm= cylinder(pos=(-0.5*self.k,2.6*self.k,0),frame=teufel, axis=(-0.3*self.k,0.3*self.k,0),radius=0.1*self.k,color=color.red) arm=sphere(pos=(0.8*self.k,2.3*self.k,0),frame=teufel,radius=0.1*self.k,color=color.red) arm=sphere(pos=(-0.8*self.k,2.9*self.k,0),frame=teufel,radius=0.1*self.k,color=color.red) arm= cylinder(pos=(0.8*self.k,2.3*self.k,0),frame=teufel, axis=(0.2*self.k,-0.2*self.k,0),radius=0.1*self.k,color=color.red) arm= cylinder(pos=(-0.8*self.k,2.9*self.k,0),frame=teufel, axis=(-0.1*self.k,0.3*self.k,0),radius=0.1*self.k,color=color.red) arm=sphere(pos=(1*self.k,2.1*self.k,0),frame=teufel,radius=0.1*self.k,color=color.red) arm=sphere(pos=(-0.9*self.k,3.2*self.k,0),frame=teufel,radius=0.1*self.k,color=color.red) lanze= arrow(pos=(0.8*self.k,1*self.k,0),frame=teufel, axis=(0.5*self.k,3*self.k,0), shaftwidth=0.05*self.k,color=color.black) lanze= cylinder(pos=(0.95*self.k,3.3*self.k,0),frame=teufel, axis=(0.5*self.k,-0.05*self.k,0),radius=0.05,color=color.black) lanze= arrow(pos=(0.95*self.k,3.3*self.k,0),frame=teufel, axis=(0.05*self.k,0.5*self.k,0), shaftwidth=0.05*self.k,color=color.black) lanze= arrow(pos=(1.45*self.k,3.25*self.k,0),frame=teufel, axis=(0.05*self.k,0.5*self.k,0), shaftwidth=0.05*self.k,color=color.black) lanze= helix(pos=(0.8*self.k,1*self.k,0),frame=teufel,axis=(0.5*self.k,3*self.k,0),radius=0.06*self.k,thickness=0.02*self.k,color=color.red) lanze= helix(pos=(0.95*self.k,3.3*self.k,0),frame=teufel,axis=(0.5*self.k,-0.05,0),radius=0.06*self.k,thickness=0.02*self.k,color=color.red) lanze= helix(pos=(0.95*self.k,3.3*self.k,0),frame=teufel,axis=(0.05*self.k,0.5*self.k,0),radius=0.06*self.k,thickness=0.02*self.k,color=color.red) lanze= helix(pos=(1.45*self.k,3.25*self.k,0),frame=teufel,axis=(0.05*self.k,0.5*self.k,0),radius=0.06*self.k,thickness=0.02*self.k,color=color.red) bein= cylinder(pos=(0.4*self.k,2*self.k,0),frame=teufel, axis=(0,-1*self.k,0),radius=0.1*self.k,color=color.red) bein= cylinder(pos=(-0.4*self.k,2*self.k,0),frame=teufel, axis=(0,-1*self.k,0),radius=0.1*self.k,color=color.red) fuss=sphere(pos=(0.4*self.k,1*self.k,0),frame=teufel,radius=0.2*self.k,color=color.black) fuss=sphere(pos=(-0.4*self.k,1*self.k,0),frame=teufel,radius=0.2*self.k,color=color.black) fuss= cylinder(pos=(0.4*self.k,1*self.k,0),frame=teufel, axis=(0,0,0.4*self.k),radius=0.2*self.k,color=color.black) fuss= cylinder(pos=(-0.4*self.k,1*self.k,0),frame=teufel, axis=(0,0,0.4*self.k),radius=0.2*self.k,color=color.black) fuss= cone(pos=(0.4*self.k,1*self.k,0.4*self.k),frame=teufel, axis=(0,0,0.15*self.k),radius=0.2*self.k,color=color.black) fuss= cone(pos=(-0.4*self.k,1*self.k,0.4*self.k),frame=teufel, axis=(0,0,0.15*self.k),radius=0.2*self.k,color=color.black) schweif=sphere(pos=(0,2*self.k,-0.5*self.k),frame=teufel,radius=0.1*self.k,color=color.red) schweif= cylinder(pos=(0,2*self.k,-0.5*self.k),frame=teufel, axis=(0,-0.5*self.k,-0.4*self.k),radius=0.1*self.k,color=color.red) schweif=sphere(pos=(0,1.5*self.k,-0.9*self.k),frame=teufel,radius=0.1*self.k,color=color.red) schweif= arrow(pos=(0,1.5*self.k,-0.9*self.k),frame=teufel, axis=(0,0.5*self.k,-0.5*self.k), shaftwidth=0.1*self.k,color=color.red) guertel= ring (pos=(0,2.5*self.k,0),frame=teufel, axis=(0.5*self.k,0.6*self.k,0),radius=0.55*self.k,thickness=0.1*self.k,color=color.black) armreif= ring (pos=(0.55*self.k,2.6*self.k,0),frame=teufel, axis=(0,0.1*self.k,0),radius=0.07*self.k,thickness=0.1*self.k,color=color.black) armreif= ring (pos=(-0.85*self.k,3.1*self.k,0),frame=teufel, axis=(0,0.1*self.k,0),radius=0.12*self.k,thickness=0.05*self.k,color=color.black) leuchte=local_light (pos=(0,2.5*self.k,0),frame=teufel,axis=(0,0,0),radius=0.0005*self.k,color=color.red) teufel.pos = pos self.frame = teufel self.camera.endgegner = self.frame self.camera.frameSetzen(self.frame) self.start() def run(self): step = math.pi/100 while True: self.frame.rotate(angle = step, axis = (0,1,0), origin = self.frame.pos) time.sleep(0.01) if __name__ == '__main__': c = Camera() Haus(house_size,random()*map_size,0,random()*map_size, c) Haus(house_size,random()*-map_size,0,random()*map_size, c) Haus(house_size,random()*-map_size,0,random()*-map_size, c) Haus(house_size,random()*map_size,0,random()*-map_size, c) Baum(random()*map_size,0,random()*map_size*-1, c) Baum(random()*map_size*-1,0,random()*map_size, c) Baum(random()*map_size*-1,0,random()*map_size*-1, c) Baum(random()*map_size,0,random()*map_size, c) #Baum(random()*map_size,0,random()*map_size*-1, c) #Baum(random()*map_size*-1,0,random()*map_size, c) #Baum(random()*map_size*-1,0,random()*map_size*-1, c) #Baum(random()*map_size,0,random()*map_size, c) Raketenbatterie(c) Flugzeug(c) Hubschrauber(c) Schiff(c,pos=((random()+1)*map_size,2,(random()+1)*map_size), axis = (random(),0,random())) Schiff(c,pos=(-(random()+1)*map_size,2,(random()+1)*map_size), axis = (random(),0,random())) #Schiff(c,pos=((random()+1)*map_size,2,-(random()+1)*map_size), axis = (random(),0,random())) #Schiff(c,pos=(-(random()+1)*map_size,2,-(random()+1)*map_size), axis = (random(),0,random())) #Uboot(c,pos=((random()+1)*map_size,0,(random()+1)*map_size), axis = (random(),0,random())) #Uboot(c,pos=(-(random()+1)*map_size,0,(random()+1)*map_size), axis = (random(),0,random())) Uboot(c,pos=((random()+1)*map_size,0,-(random()+1)*map_size), axis = (random(),0,random())) Uboot(c,pos=(-(random()+1)*map_size,0,-(random()+1)*map_size), axis = (random(),0,random())) #Ente(c, pos=(1,1,7)) #Ente(c, pos=(5,1,5)) Ente(c, pos = (random()*map_size,2,random()*map_size*-1)) Ente(c, pos = (random()*map_size,2,random()*map_size*-1)) Fass(random()*map_size,0,random()*map_size, c) Fass(random()*map_size*-1,0,random()*map_size, c) Schneemann = Schneemann(c, pos = (50,2,30)) boden = cylinder(pos = (0,0.1,0), axis=(0,1,0),radius = 1.5*map_size, material = materials.marble, color = color.yellow) welt = box(pos = (0,0,0), axis=(1,0,0), length = world_size, height = 2, width = world_size, material = materials.silver, color = color.blue) c.start() while True: if scene.mouse.events: sme = scene.mouse.getevent() if sme.pick and sme.click == 'left': c.schiessen(sme)