collision part 2
(halbwegs) funktionierende collision mit baum
skifahrer.py — text/python-source, 3 KB (3261 bytes)
Dateiinhalt
from visual import * from random import random from threading import Thread # Szene-Einstellungen 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 = 30 # 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 # Kamerawinkeloeffnung: norm. 1 scene.fullscreen = False # Vollbild? norm. False scene.title = "Koordinaten" # Fenstertitel scene.width = 600 # Fensterbreite: norm. 200 scene.height = 600 # Fensterhoehe: norm 200 scene.x = 50 # x-Koordinate d. Fensters: norm. 0 scene.y = 25 # y-Koordinate d. Fensters: norm. 0 class skifahrer(Thread, frame): def __init__(self, pos=(0,10,-35)): Thread.__init__(self) frame.__init__(self) self.arm1 = cylinder(radius=(1),length=(4),axis=(-1,0,5),pos=(-5,10,-35),color=color.red,frame=self) self.arm2 = cylinder(radius=(1),length=(4),axis=(1,0,5),pos=(5,10,-35),color=color.red,frame=self) self.ski1 = box(pos=(3,-5,-25),height=(0.5),length=(15),axis=(0,0,5),width=(2),color=color.green,frame=self) self.ski2 = box(pos=(-3,-5,-25),height=(0.5),length=(15),axis=(0,0,5),width=(2),color=color.green,frame=self) self.vski1 = vector(3,0,-25) self.vski2 = vector(-3,0,-25) def vektoranpassen(self): self.vski1 = vector(self.vski1.x,0,-25) self.vski2 = vector(self.vski2.x,0,-25) def einsLinksFahren(self): self.x+=1 self.vski1.x+=1 self.vski2.x+=1 def einsRechtsFahren(self): self.x-=1 self.vski1.x-=1 self.vski2.x-=1 class baum(Thread, frame): def __init__(self,pos=(5,-5,10)): Thread.__init__(self) frame.__init__(self) self.stamm = cylinder(axis=(0,35,0),pos=(5,-5,10),radius=(4),length=(50),frame=self,material=materials.wood) self.busch = sphere(radius=(15),pos=(5,52,10),color=color.green,frame=self) self.vstamm = vector(0,0,self.stamm.z) def vektoranpassen(self): self.vstamm = vector(0,0,self.z) def baumBewegtSich(self): if self.z<=-45: self.z=30 else: rate(10) self.z-=2 if __name__ == "__main__": s1 = skifahrer() b1 = baum() s1.start() b1.start() while True: s1.vektoranpassen() b1.vektoranpassen() print s1.vski2 b1.baumBewegtSich() if (-8<=s1.vski2.x<= 10) and (s1.vski2.z - b1.vstamm.z >= 0): print ("Collision -> TOD") #exit() if scene.kb.keys: skk = scene.kb.getkey() if skk=="left": s1.einsLinksFahren() elif skk=="right": s1.einsRechtsFahren()