stickman_content.py
stickman_fails.py — Python Source, 7 KB (8101 bytes)
Dateiinhalt
from visual import * scene = display(title="Stickman", width=1000, height=800, center=(0,20,0), fullscreen=False) scene.select() #scene.title="Just Baum" scene.autoscale=False scene.userzoom= False scene.userspin= False scene.cursor.visible = False #scene.center=(0,20,0) tex1 = materials.texture(data=materials.loadTGA("Nadel"),mapping = "rectangular") tex2 = materials.texture(data=materials.loadTGA("Gras"),mapping = "sign") #scene.forward=(0.0,-0.5,-1.0) Kliste = [] Eliste = [] def richtung(x): return { 0: (0.0,-0.2,-3.0), 1: (3.0,-0.2,0.0), 2: (0.0,-0.2,3.0), 3: (-3.0,-0.2,0.0), }[x] def brichtung(x): return { 0: (0,0,-1), 1: (1,0,0), 2: (0,0,1), 3: (-1,0,0), }[x] #Klassen class Man(frame): def __init__ (self,pos=(0,0,0)): frame.__init__(self) self.koerper=cone (frame=self,pos=(0,0,0),radius=3,length=15,color=color.blue,axis=(0,1,0)) self.kopf=sphere(frame=self,pos=(0,12,0),radius=3) #self.front=arrow(frame=self,pos=(0,8,0),axis=(1,0,0),shaftwidth=10) self.pos=pos self.richtung=0 self.muni=0 self.anzeige=label(frame=self ,pos=(0,15,0),text="Pfeile" + str (self.muni)) def bewegen (self,schritt): self.pos +=schritt for obj in Kliste: if obj.kollision (self.pos.x,self.pos.z): self.pos -=schritt for obj in Eliste: if obj.kollision (self.pos.x,self.pos.z,self.pos.y): if obj.geschossen: from time import sleep time.sleep(4) self.pos = (0,0,0) else: obj.pos.y=-20 self.muni+=1 def update(self): if scene.kb.keys: zeichen = scene.kb.getkey() if zeichen == "up": self.bewegen(brichtung(x=self.richtung)) #print "up", self.pos if zeichen == "down": if self.richtung <= 1: self.bewegen(brichtung(x=self.richtung+2)) else: self.bewegen(brichtung(x=self.richtung-2)) #print "down", self.pos if zeichen == "right": self.richtung += 1 if self.richtung > 3: self.richtung=0 scene.forward=(richtung(x=self.richtung)) if zeichen == "left": self.richtung += -1 if self.richtung < 0: self.richtung=3 scene.forward=(richtung(x=self.richtung)) scene.center=self.kopf.pos+self.pos+(0,8,0) if zeichen == "x" and self.muni > 0: for pfeil in Eliste: if pfeil.pos.y == -20: pfeil.schiessen(self.richtung, self.pos+self.kopf.pos) self.muni -= 1 break for pfeil in Eliste: pfeil.update() self.anzeige.text="Pfeile" + str (self.muni) class Baum (frame): def __init__(self,pos=(0,0,0)): frame.__init__(self) self.stamm=cylinder(frame=self,pos=(0,0,0),radius=2,axis=(0,5,0),length=10,material=materials.wood) self.krone=cone (frame=self,pos=(0,8,0),axis=(0,5,0),radius=6,length=20,material=tex1) self.pos=pos def kollision (self,x,z): if x < self.pos.x +4 and x > self.pos.x -4 and z < self.pos.z +4 and z > self.pos.z -4: return True else: return False class Haus (frame): def __init__(self,pos=(0,0,0)): frame.__init__(self) self.mauern=box (frame=self,pos=(0,0,0),length=60,height=40,width=30,color=color.white) self.dach=pyramid (frame=self,pos=(0,20,0),size=(15,65,35),axis=(0,5,0),color=color.red) self.pos=pos def kollision (self,x,z): if x < self.pos.x +30 and x > self.pos.x -30 and z < self.pos.z +15 and z > self.pos.z -15: return True else: return False class Zaun (frame): def __init__(self,pos=(0,0,0)): frame.__init__(self) self.latte1=arrow(frame=self,pos=(-5,0,0),axis=(0,5,0),length=15,color=(0,0,0)) self.latte1=arrow(frame=self,pos=(0,0,0),axis=(0,5,0),length=15,color=(0,0,0)) self.latte1=arrow(frame=self,pos=(5,0,0),axis=(0,5,0),length=15,color=(0,0,0)) self.latte1=arrow(frame=self,pos=(-10,0,0),axis=(0,5,0),length=15,color=(0,0,0)) self.latte1=arrow(frame=self,pos=(10,0,0),axis=(0,5,0),length=15,color=(0,0,0)) self.balken=box(frame=self,pos=(0,6,0),length=20,height=2,width=1,color=(0,0,0)) self.pos=pos def kollision (self,x,z): if x < self.pos.x +10 and x > self.pos.x -10 and z < self.pos.z +2 and z > self.pos.z -2: return True else: return False class PfeilD (frame): def __init__(self,pos=(0,0,0)): frame.__init__(self) self.balken=box(frame=self,pos=(5,6,0),length=10,height=2,width=1,material=materials.wood) self.spitze=pyramid (frame=self,pos=(10,6,0),size=(6,3,3),material=materials.rough) self.federn=pyramid (frame=self,pos=(0,6,0),size=(6,3,3),color=color.red) self.pos=pos self.geschossen = False self.richtung = (0,0,0) def kollision (self,x,z,y): if x < self.pos.x +10 and x > self.pos.x -10 and z < self.pos.z +10 and z > self.pos.z -10 and y < self.pos.y +10 and y > self.pos.y -10: return True else: return False def schiessen(self, richtung, startpos): self.richtung = brichtung(richtung) + (0.0,-0.5,0.0) self.axis = brichtung(richtung) self.pos = startpos self.geschossen = True def update(self): if self.geschossen: self.pos = (self.richtung[0]*2+self.pos.x, self.pos.y-0.1, self.richtung[2]*2+self.pos.z) if self.pos.y <=-1: self.geschossen = False def generate(V): Boden = box (pos=(0,0,0),length=1,height=500,width=500,material=tex2) Boden.rotate(angle=pi/2, axis=(0,0,1)) Baum1=Baum (pos=(V[0],0,V[1])) Baum2=Baum (pos=(V[2],0,V[3])) Baum3=Baum (pos=(V[4],0,V[5])) Baum4=Baum (pos=(V[6],0,V[7])) Baum5=Baum (pos=(V[8],0,V[9])) Baum6=Baum (pos=(V[10],0,V[11])) Baum7=Baum (pos=(V[48],0,V[49])) Baum8=Baum (pos=(V[50],0,V[51])) Baum9=Baum (pos=(V[52],0,V[53])) Baum10=Baum (pos=(V[54],0,V[55])) Baum11=Baum (pos=(V[56],0,V[57])) Baum12=Baum (pos=(V[58],0,V[59])) Haus1=Haus (pos=(V[12],0,V[13])) Haus2=Haus (pos=(V[14],0,V[15])) Haus3=Haus (pos=(V[16],0,V[17])) Haus4=Haus (pos=(V[18],0,V[19])) Haus5=Haus (pos=(V[20],0,V[21])) Haus6=Haus (pos=(V[22],0,V[23])) Zaun1=Zaun (pos=(V[24],0,V[25])) Zaun2=Zaun (pos=(V[26],0,V[27])) Zaun3=Zaun (pos=(V[28],0,V[29])) Zaun4=Zaun (pos=(V[30],0,V[31])) Zaun5=Zaun (pos=(V[32],0,V[33])) Zaun6=Zaun (pos=(V[34],0,V[35])) PfeilD1=PfeilD (pos=(V[36],0,V[37])) PfeilD2=PfeilD (pos=(V[38],0,V[39])) PfeilD3=PfeilD (pos=(V[40],0,V[41])) PfeilD4=PfeilD (pos=(V[42],0,V[43])) PfeilD5=PfeilD (pos=(V[44],0,V[45])) PfeilD6=PfeilD (pos=(V[46],0,V[47])) Kliste.append(Baum1) Kliste.append(Baum2) Kliste.append(Baum3) Kliste.append(Baum4) Kliste.append(Baum5) Kliste.append(Baum6) Kliste.append(Baum7) Kliste.append(Baum8) Kliste.append(Baum9) Kliste.append(Baum10) Kliste.append(Baum11) Kliste.append(Baum12) Kliste.append(Haus1) Kliste.append(Haus2) Kliste.append(Haus3) Kliste.append(Haus4) Kliste.append(Haus5) Kliste.append(Haus6) Kliste.append(Zaun1) Kliste.append(Zaun2) Kliste.append(Zaun3) Kliste.append(Zaun4) Kliste.append(Zaun5) Kliste.append(Zaun6) Eliste.append(PfeilD1) Eliste.append(PfeilD2) Eliste.append(PfeilD3) Eliste.append(PfeilD4) Eliste.append(PfeilD5) Eliste.append(PfeilD6)