collision
skifahrer.py — text/python-source, 3 KB (3101 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,-5,-25),height=(0.5),length=(15),axis=(0,0,5),width=(2),color=color.green,frame=self) self.ski2 = box(pos=(-3.5,-5,-25),height=(0.5),length=(15),axis=(0,0,5),width=(2),color=color.green,frame=self) self.rahmen = sphere(pos=(0,-5,-25),radius=10,opacity=1,frame=self) self.vrahmen = vector(0,0,-25) def vektoranpassen(self): self.vrahmen = vector(self.x,0,-25) def einsLinksFahren(self): self.x+=1 def einsRechtsFahren(self): self.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=(3),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 mag(s1.vrahmen-b1.vstamm) b1.baumBewegtSich() if mag(s1.vrahmen-b1.vstamm)<=10: print ("Collision") if scene.kb.keys: skk = scene.kb.getkey() if skk=="left": s1.einsLinksFahren() elif skk=="right": s1.einsRechtsFahren()