zentrieren
Mensch-ärger-dich.py — Python Source, 4 KB (4749 bytes)
Dateiinhalt
from visual import * class Spielbrett (frame): def __init__(self): frame.__init__(self) feld1=Feld((0,0,0),1) feld2=Feld((1.25,0,0),2) feld3=Feld((2.5,0,0),3) feld4=Feld((2.5,0,1.25),4) feld5=Feld((2.5,0,2.5),5) feld6=Feld((2.5,0,3.75),6) feld7=Feld((2.5,0,5),7) feld8=Feld((3.75,0,5),8) feld9=Feld((5,0,5),9) feld10=Feld((6.25,0,5),10) feld11=Feld((7.5,0,5),11) feld12=Feld((7.5,0,6.25),12) feld13=Feld((7.5,0,7.5),13) feld14=Feld((6.25,0,7.5),14) feld15=Feld((5,0,7.5),15) feld16=Feld((3.75,0,7.5),16) feld17=Feld((2.5,0,7.5),17) feld18=Feld((2.5,0,8.75),18) feld19=Feld((2.5,0,10),19) feld20=Feld((2.5,0,11.25),20) feld21=Feld((2.5,0,12.5),21) feld22=Feld((1.25,0,12.5),22) feld23=Feld((0,0,12.5),23) feld24=Feld((0,0,11.25),24) feld25=Feld((0,0,10),25) feld26=Feld((0,0,8.75),26) feld27=Feld((0,0,7.5),27) feld28=Feld((-1.25,0,7.5),28) feld29=Feld((-2.5,0,7.5),29) feld30=Feld((-3.75,0,7.5),30) feld31=Feld((-5,0,7.5),31) feld32=Feld((-5,0,6.25),32) feld33=Feld((-5,0,5),33) feld34=Feld((-3.75,0,5),34) feld35=Feld((-2.5,0,5),35) feld36=Feld((-1.25,0,5),36) feld37=Feld((0,0,5),37) feld38=Feld((0,0,3.75),38) feld39=Feld((0,0,2.5),39) feld40=Feld((0,0,1.25),40) garage1=Feld((1.25,0,1.25),41) garage2=Feld((1.25,0,2.5),42) garage3=Feld((1.25,0,3.75),43) garage4=Feld((1.25,0,5),44) garage5=Feld((-3.75,0,6.25),45) garage6=Feld((-2.5,0,6.25),46) garage7=Feld((-1.25,0,6.25),47) garage8=Feld((0,0,6.25),48) garage9=Feld((2.5,0,6.25),49) garage10=Feld((3.75,0,6.25),50) garage11=Feld((5,0,6.25),51) garage12=Feld((6.25,0,6.25),52) garage13=Feld((1.25,0,7.5),53) garage14=Feld((1.25,0,8.75),54) garage15=Feld((1.25,0,10),55) garage16=Feld((1.25,0,11.25),56) anfang1=Feld((6.25,0,11.25),57) anfang2=Feld((7.5,0,11.25),58) anfang3=Feld((6.25,0,12.5),59) anfang4=Feld((7.5,0,12.5),60) anfang5=Feld((6.25,0,0),61) anfang6=Feld((7.5,0,0),62) anfang7=Feld((6.25,0,1.25),63) anfang8=Feld((7.5,0,1.25),64) anfang9=Feld((-5,0,0),65) anfang10=Feld((-3.75,0,0),66) anfang11=Feld((-5,0,1.25),67) anfang12=Feld((-3.75,0,1.25),68) anfang13=Feld((-5,0,11.25),69) anfang14=Feld((-3.75,0,11.25),70) anfang15=Feld((-5,0,12.5),71) anfang16=Feld((-3.75,0,12.5),72) spielfeld = box (height=0.1, length=15, width=15, color=color.black, pos=(1.25,0,6.25)) self.liste = [feld1,feld2,feld3,feld4,feld5,feld6,feld7,feld8,feld9,feld10,feld11,feld12,feld13,feld14,feld15,feld16,feld17,feld18,feld19,feld20,feld21,feld22,feld23,feld24,feld25,feld26,feld27,feld28,feld29,feld30,feld31,feld32,feld33,feld34,feld35,feld36,feld37,feld38,feld39,feld40,garage1,garage2,garage3,garage4,garage5,garage6,garage7,garage8,garage9,garage10,garage11,garage12,garage13,garage14,garage15,garage16,anfang1,anfang2,anfang3,anfang4,anfang5,anfang6,anfang7,anfang8,anfang9,anfang10,anfang11,anfang12,anfang13,anfang14,anfang15,anfang16] def run(self): radius = 0.5 ball = sphere(pos=(-3,0,0),radius=(0.25),color=color.red) pick = None while True: if scene.mouse.events: m1 = scene.mouse.getevent() if m1.drag and m1.pick ==ball: pick = m1.pick elif m1.drop: if pick != None: #print(pick.pos) for n in self.liste: #print(mag(pick.pos - n.pos)) if mag(pick.pos - n.pos) <= radius: ball.pos = n.pos #print(n.pos) break else: pass pick = None if pick: new_pos = scene.mouse.project(normal=(0,1,0)) if new_pos != m1.pick.pos: pick.pos += new_pos - m1.pick.pos m1.pick.pos = new_pos class Feld (frame): def __init__(self, ort, nummer): frame.__init__(self,pos=ort) self.nummer=nummer feld=cylinder(radius=0.5,axis=(0,0.1,0), pos=ort) spiel=Spielbrett() spiel.run()