Spielfigur.py
Spielfigur.py — Python Source, 6 KB (7151 bytes)
Dateiinhalt
from visual import * from random import choice class Br(frame): def __init__(self,farbe=color.cyan,stoff=materials.wood,x=0,y=0,z=0): frame.__init__(self) self.stein=box(frame=self,color=farbe,material=stoff,length=1,height=0.25,width=1,pos=(x,y,z)) class Ri(frame): def __init__(self, farbe=color.blue,x=0,z=0): frame.__init__(self) self.Ringe=ring(frame=self,pos=(x,0.2,z),radius=0.45,axis=(0,1,0),thickness=0.05,color=farbe,material=materials.plastic) class Sp: def __init__(self): self.R1=Ri(x=-2,z=-2) self.R2=Ri(x=-3,z=-3) self.R3=Ri(x=-3,z=-1) self.R4=Ri(x=-2,z=0) self.R5=Ri(x=-1,z=0) self.R6=Ri(x=0,z=-2,farbe=color.red) self.R7=Ri(x=0,z=-1,farbe=color.red) self.R8=Ri(x=1,z=-3,farbe=color.red) self.R9=Ri(x=3,z=-3,farbe=color.red) self.R10=Ri(x=2,z=-2,farbe=color.red) self.R11=Ri(x=1,z=0,farbe=color.orange) self.R12=Ri(x=2,z=0,farbe=color.orange) self.R13=Ri(x=3,z=1,farbe=color.orange) self.R14=Ri(x=3,z=3,farbe=color.orange) self.R15=Ri(x=2,z=2,farbe=color.orange) self.R16=Ri(x=0,z=1,farbe=color.yellow) self.R17=Ri(x=0,z=2,farbe=color.yellow) self.R18=Ri(x=-1,z=3,farbe=color.yellow) self.R19=Ri(x=-3,z=3,farbe=color.yellow) self.R20=Ri(x=-2,z=2,farbe=color.yellow) self.b1=Br(x=-4,z=-4) self.b2=Br(x=-3,z=-4) self.b3=Br(x=-2,z=-4) self.b4=Br(x=-1,z=-4) self.b5=Br(x=0,z=-4) self.b6=Br(x=1,z=-4) self.b7=Br(x=2,z=-4) self.b8=Br(x=3,z=-4) self.b9=Br(x=4,z=-4) self.b10=Br(x=-4,z=-3) self.b11=Br(x=-3,z=-3) self.b12=Br(x=-2,z=-3,) self.b13=Br(x=-1,z=-3,farbe=color.black,stoff=materials.plastic) self.b14=Br(x=0,z=-3,farbe=color.white,stoff=materials.plastic) self.b15=Br(x=1,z=-3,farbe=color.black,stoff=materials.plastic) self.b16=Br(x=2,z=-3) self.b17=Br(x=3,z=-3) self.b18=Br(x=4,z=-3) self.b19=Br(x=-4,z=-2) self.b20=Br(x=-3,z=-2) self.b21=Br(x=-2,z=-2) self.b22=Br(x=-1,z=-2,farbe=color.white,stoff=materials.plastic) self.b23=Br(x=0,z=-2) self.b24=Br(x=1,z=-2,farbe=color.white,stoff=materials.plastic) self.b25=Br(x=2,z=-2) self.b26=Br(x=3,z=-2) self.b27=Br(x=4,z=-2) self.b28=Br(x=-4,z=-1) self.b29=Br(x=-3,z=-1,farbe=color.black,stoff=materials.plastic) self.b30=Br(x=-2,z=-1,farbe=color.white,stoff=materials.plastic) self.b31=Br(x=-1,z=-1,farbe=color.black,stoff=materials.plastic) self.b32=Br(x=0,z=-1) self.b33=Br(x=1,z=-1,farbe=color.black,stoff=materials.plastic) self.b34=Br(x=2,z=-1,farbe=color.white,stoff=materials.plastic) self.b35=Br(x=3,z=-1,farbe=color.black,stoff=materials.plastic) self.b36=Br(x=4,z=-1) self.b37=Br(x=-4,z=0) self.b38=Br(x=-3,z=0,farbe=color.white,stoff=materials.plastic) self.b39=Br(x=-2,z=0) self.b40=Br(x=-1,z=0) self.b41=Br(x=0,z=0) self.b42=Br(x=1,z=0) self.b43=Br(x=2,z=0) self.b44=Br(x=3,z=0,farbe=color.white,stoff=materials.plastic) self.b45=Br(x=4,z=0) self.b46=Br(x=-4,z=1) self.b47=Br(x=-3,z=1,farbe=color.black,stoff=materials.plastic) self.b48=Br(x=-2,z=1,farbe=color.white,stoff=materials.plastic) self.b49=Br(x=-1,z=1,farbe=color.black,stoff=materials.plastic) self.b50=Br(x=0,z=1) self.b51=Br(x=1,z=1,farbe=color.black,stoff=materials.plastic) self.b52=Br(x=2,z=1,farbe=color.white,stoff=materials.plastic) self.b53=Br(x=3,z=1,farbe=color.black,stoff=materials.plastic) self.b54=Br(x=4,z=1) self.b55=Br(x=-4,z=2) self.b56=Br(x=-3,z=2) self.b57=Br(x=-2,z=2) self.b58=Br(x=-1,z=2,farbe=color.white,stoff=materials.plastic) self.b59=Br(x=0,z=2) self.b60=Br(x=1,z=2,farbe=color.white,stoff=materials.plastic) self.b61=Br(x=2,z=2) self.b62=Br(x=3,z=2) self.b63=Br(x=4,z=2) self.b64=Br(x=-4,z=3) self.b65=Br(x=-3,z=3) self.b66=Br(x=-2,z=3) self.b67=Br(x=-1,z=3,farbe=color.black,stoff=materials.plastic) self.b68=Br(x=0,z=3,farbe=color.white,stoff=materials.plastic) self.b69=Br(x=1,z=3,farbe=color.black,stoff=materials.plastic) self.b70=Br(x=2,z=3) self.b71=Br(x=3,z=3) self.b72=Br(x=4,z=3) self.b73=Br(x=-4,z=4) self.b74=Br(x=-3,z=4) self.b75=Br(x=-2,z=4) self.b76=Br(x=-1,z=4) self.b77=Br(x=0,z=4) self.b78=Br(x=1,z=4) self.b79=Br(x=2,z=4) self.b80=Br(x=3,z=4) self.b81=Br(x=4,z=4) x= Sp() class Spielfigur(frame) : def __init__ (self,farbe1 = color.orange,farbe2=color.red,pos = (0,0,0)): frame.__init__(self,pos = pos) self.pos = pos self.figur = cone(frame=self,pos=(0,0,0),axis =(0,1,0),color = farbe1,radius = (0.4),material = (materials.chrome)) self.kopf = sphere(frame=self,pos = (0,1.2,0),radius = (0.3),color = farbe1,material = (materials.chrome)) self.ring1 = ring(frame=self,pos =(0,0,0),axis = (0,1,0),color = farbe2,radius = (0.4),material = (materials.wood)) self.ring2 = ring(frame=self,pos =(0,0.7,0) ,axis = (0,1,0),color = farbe2, radius = (0.3),material = (materials.wood)) self.punkt = sphere(frame=self,pos = (0,1.58,0),color = farbe2,radius = (0.1),material = (materials.wood)) zufallszahl=(1,2,3,4,5,6) class wuerfeln(frame): def __init__(self): self.aus = label(pos=(0,1.2,0),color=color.white,text=(str(choice(zufallszahl)))) Wuerfel=box(pos=(0,1.15,0),color=color.magenta) r1 = Spielfigur(farbe1 = color.red, farbe2 = color.green,pos = (3,0.15,-3)) r2 = Spielfigur(farbe1 = color.red, farbe2 = color.green, pos = (2,0.15,-2)) b1 = Spielfigur(farbe1 = color.blue, farbe2 = color.magenta, pos = (-2,0.15,-2)) b2 = Spielfigur(farbe1 = color.blue, farbe2 = color.magenta, pos = (-3,0.15,-3)) y1 = Spielfigur(farbe1 = color.yellow, farbe2 = color.black, pos = (-2,0.15,2)) y2 = Spielfigur(farbe1 = color.yellow, farbe2 = color.black, pos = (-3,0.15,3)) o1 = Spielfigur(farbe1 = color.orange, farbe2 = color.blue, pos = (2,0.15,2)) o2 = Spielfigur(farbe1 = color.orange, farbe2 = color.blue, pos = (3,0.15,3)) pick=None while True: rate(30) if scene.mouse.events: m1=scene.mouse.getevent() if m1.drag and m1.pick: for i in [r1,r2,b1,b2,y1,y2,o1,o2]: if m1.pick in i.objects: drag_pos = i.pos pick = m1.pick break if m1.pick==Wuerfel: w=wuerfeln() elif m1.drop: pick = None if pick: new_pos = scene.mouse.project(normal=(0,1,0)) if new_pos != drag_pos : drag_pos = new_pos i.pos = drag_pos + vector(0,0.15,0)