Skifahren BETA 1.0
skifahren beta1.py — text/python-source, 5 KB (5626 bytes)
Dateiinhalt
from visual import * from threading import Thread scene.userzoom = True # User darf zoomen? scene.userspin = True # 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.blue # Hintergrundfarbe scene.fov = 1 # Kamerawinkeloeffnung: norm. 1 scene.fullscreen = False # Vollbild? norm. False scene.title = "TEST" # Fenstertitel scene.width = 800 # Fensterbreite: norm. 200 scene.height = 800 # Fensterhoehe: norm 200 scene.x = 50 # x-Koordinate d. Fensters: norm. 0 scene.y = 25 # y-Koordinate d. Fensters: norm. 0 # Koordinatenachsen in Form von Pfeilen xAchse = arrow(axis=(10,0,0), shaftwidth=0.02, color=color.red) yAchse = arrow(axis=(0,10,0), shaftwidth=0.02, color=(0,0,1)) zAchse = arrow(axis=(0,0,10), shaftwidth=0.02, color=color.green) 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) def Entgegenkommen(self): if self.z<=-100: self.z=100 self.vkiste = vector(self.x,self.y,self.z) else: rate(100) self.z-=1 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=(15),pos=(self.x,self.y+52,self.z),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: rate(80) 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=100 def einsLinksFahren(self): self.x+=1 self.vich = vector(self.x,self.y,self.ich.z) scene.center.x+=1 def einsRechtsFahren(self): self.x-=1 self.vich = vector(self.x,self.y,self.ich.z) scene.center.x-=1 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),z=150,y=19,opacity=0.1,material=materials.bricks,frame=self) dach = extrusion(shape=tri,pos=straight,material=materials.wood,frame=self) #class zaun (Thread,frame): #def __init__(self,pos): # Thread.__init__(self) # frame.__init__(self,pos=pos) # pfahl = box(height=10,width=5,length=5,pos=(5,5,5),frame=self) if __name__ == "__main__": #feld = box(width=100, length =200,pos=(0,-6,50),axis=(0,0,5)) wand1 = box(length=100,height=10,pos=(0,-5,200)) himmel = sphere(radius=200) s1 = skifahrer(pos=(0,0,0)) h= haus() h.start() #z=zaun() #z.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() while True: h4.Entgegenkommen() h3.Entgegenkommen() h1.Entgegenkommen() h2.Entgegenkommen() b1.baumBewegtSich() 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: print ("you lost") exit() else: s1.gesundheit-=1 print ("Leben: "+ str(s1.gesundheit)) if scene.kb.keys: skk = scene.kb.getkey() if skk=="left": if (s1.x != 45): s1.einsLinksFahren() elif skk=="right": if (s1.x != -45): s1.einsRechtsFahren()