Skyfahren 1.1
skifahren 1.0.py — text/python-source, 6 KB (6694 bytes)
Dateiinhalt
from visual import * from threading import Thread import Image name = "hintergrund" width, height = 2048, 1024 im = Image.open(name+".tga") materials.saveTGA(name,im) pano = materials.texture(data=im, mapping="spherical") scene.userzoom = False # User darf zoomen? scene.userspin = False # User darf rotieren? scene.forward = (0,-5,10) # Kameraposition scene.autoscale = False # Autoskalierung aktiv? scene.range = 70 # Kameraabstand von scene.center scene.center = (0,0,0) # Kamerablickpunkt: norm. (0,0,0) scene.up = (0,1,0) # Rotationsachse Kamera: norm. (0,1,0) scene.background = color.black # Hintergrundfarbe scene.fov = 1.1 # Kamerawinkeloeffnung: norm. 1 scene.fullscreen = False # Vollbild? norm. False scene.title = "SKYFAHREN" # Fenstertitel scene.width = 800 # Fensterbreite: scene.height = 800 # Fensterhoehe: scene.x = 50 # x-Koordinate d. Fensters: norm. 0 scene.y = 25 # y-Koordinate d. Fensters: norm. 0 class kiste(Thread,frame): def __init__(self,pos=(0,0,0)): Thread.__init__(self) frame.__init__(self,pos=pos) self.kiste = box(pos=(self.x,self.y,self.z),height=10,length=10,width=10,material=materials.earth,frame=self) self.vkiste = vector(self.x,self.y,self.z) self.respawnpos=0 def Entgegenkommen(self): if self.z<=-100: self.z=self.respawnpos self.vkiste = vector(self.x,self.y,self.z) else: self.z-=1.5 self.vkiste = vector(self.x,self.y,self.z) class baum(Thread, frame): def __init__(self,pos=(0,0,0)): Thread.__init__(self) frame.__init__(self,pos=pos) self.stamm = cylinder(axis=(0,35,0),pos=(self.x,self.y-5,self.z),radius=(4),length=(50),frame=self,material=materials.wood) self.busch = sphere(radius=(20),pos=(self.x,self.y+52,self.z),material=materials.marble,color=color.green,frame=self) self.vstamm = vector(self.stamm.x,0,self.stamm.z) def baumBewegtSich(self): if self.z<=-45: self.z=100 self.vstamm = vector(self.x,0,self.z) else: self.z-=1 self.vstamm = vector(self.x,0,self.z) class skifahrer(Thread, frame): def __init__(self, pos=()): Thread.__init__(self) frame.__init__(self,pos=pos) self.arm1 = cylinder(radius=(1),length=(4),axis=(-1,0,5),pos=(self.x-5,self.y+10,self.z-35),color=color.red,frame=self) self.arm2 = cylinder(radius=(1),length=(4),axis=(1,0,5),pos=(self.x+5,self.y+10,self.z-35),color=color.red,frame=self) self.ski1 = box(pos=(self.x+3,self.y-5,self.z-25),height=(0.5),length=(15),axis=(0,0,5),width=(2),color=color.green,frame=self) self.ski2 = box(pos=(self.x-3,self.y-5,self.z-25),height=(0.5),length=(15),axis=(0,0,5),width=(2),color=color.green,frame=self) self.ich = sphere(pos=(self.x,self.y,self.z-25),radius=8,opacity=0.5,frame=self) self.vich = vector(self.ich.x,self.ich.y,self.ich.z) self.gesundheit=121 def einsLinksFahren(self): self.x+=3 self.vich = vector(self.x,self.y,self.ich.z) scene.center.x+=3 def einsRechtsFahren(self): self.x-=3 self.vich = vector(self.x,self.y,self.ich.z) scene.center.x-=3 class haus (Thread,frame): def __init__(self,pos=(0,0,0)): Thread.__init__(self) frame.__init__(self,pos=pos) tri=Polygon([(-50,0),(0,50),(50,0)]) straight = [(0,43,175),(0,43,115)] haus = box(width=(50),length=(100),height=(50),color=color.green,material=materials.glass,z=150,y=19,opacity=1,frame=self) dach = extrusion(shape=tri,pos=straight,material=materials.wood,frame=self) if __name__ == "__main__": timer=0 wand1 = box(length=100,height=10,pos=(0,-5,200)) himmel = sphere(radius=200,color=color.orange,material=pano,opacity=0.6) s1 = skifahrer(pos=(0,0,0)) anzeige = label(pos=(40,-10,-50),text=str(s1.gesundheit)) time = label(pos=(-40,-10,-50),text="Punkte: "+str(timer)) h= haus() h.start() h1=kiste(pos=(15,0,50)) h2=kiste(pos=(-15,0,30)) h3=kiste(pos=(-7,0,50)) h4=kiste(pos=(7,0,60)) h2.start() s1.start() h1.start() b1 = baum() b1.start() h3.start() h4.start() h1.respawnpos=100 h2.respawnpos=50 h3.respawnpos=75 h4.respawnpos=90 k=1 while True: anzeige.text="Leben: "+str(s1.gesundheit) time.text="Punkte: "+str(timer) #pause=label(text="'p' = Pause -- 'o' = Weiter",x=-50,z=-55) rate(50) h4.Entgegenkommen() h3.Entgegenkommen() h1.Entgegenkommen() h2.Entgegenkommen() b1.baumBewegtSich() timer+=k if mag(s1.vich-b1.vstamm) <= 10 or(2<=(s1.x-h1.x)<=28 and 65<=(s1.z-h1.z)<=85) or (-27<=(s1.x-h2.x)<=-1 and 40<=(s1.z-h2.z)<=70) or (-20<=(s1.x-h3.x)<=6 and 65<=(s1.z-h3.z)<=85) or (-6<=(s1.x-h4.x)<=20 and 75<=(s1.z-h4.z)<=95): if s1.gesundheit == 0: k=0 anzeige2 = label(pos=(0,0,0),text="---Du hast leider verloren :/---") print ("you lost") exit() #while i<=20: # \n \n ---Press 'n' for Restart---",heigth = 1000) # i+=1 else: s1.gesundheit-=1 print ("Leben: "+ str(s1.gesundheit)) if scene.kb.keys: skk = scene.kb.getkey() if skk=="left": if (s1.x != 42): s1.einsLinksFahren() anzeige.x+=3 time.x+=3 elif skk=="right": if (s1.x != -42): s1.einsRechtsFahren() anzeige.x-=3 time.x-=3 elif skk=="p": while skk!="o": pause=label(text="PAUSE 'o' = Weiter",line=False) skk = scene.kb.getkey() pause.visible=False del(pause) elif skk=="n": del(anzeige2) if s1.gesundheit== 0: timer=0 s1.gesundheit=100 k=1 elif skk=="esc": exit()