kakke
Jump&Run.py — Python Source, 3 KB (3834 bytes)
Dateiinhalt
from visual import * from threading import Thread import random STRECKE = 0 # class figur(frame, Thread): def __init__(self,g=1,posx=0, posy=0, posz=0, farbe=color.white): frame.__init__(self) Thread.__init__(self) self.kopf=sphere(frame=self, pos=(posx,44*g+posy,posz), radius=15*g, color = farbe) self.koerper=box(frame=self, pos=(posx,0+posy,posz), size=(25*g,60*g,40*g), color = farbe) self.beinr=box(frame=self, pos=(posx,-40*g+posy,posz+10*g), size=(15*g,30*g,15*g), color= farbe) self.beinl=box(frame=self, pos=(posx,-40*g+posy,posz-10*g), size=(15*g,30*g,15*g), color= farbe) self.auger=sphere(frame=self, pos=(posx+15*g, 44*g+posy, posz+7.5*g), radius=2.5*g, color = (0.5,0,0)) self.augel=sphere(frame=self, pos=(posx+15*g, 44*g+posy, posz-7.5*g), radius=2.5*g, color = (0.5,0,0)) def run(self): self.laufen() self.ausweichen() def laufen(self): while True: rate(20) self.x += 10 scene.center=self.pos scene.autoscale = False def ausweichen(self): if scene.kb.keys: taste = scene.kb.getkey() if taste == "w" and self.z != ebene3.z: self.pos = self.pos + vector(0,20,-50) scene.center=self.pos elif taste == "s" and self.z != ebene1.z: self.pos = self.pos + vector(0,-20,50) scene.center=self.pos elif taste == " ": for a in range(5): rate(30) self.y += 6 self.x += 6 scene.center=self.pos rate(20) for b in range(5): rate(30) self.y -= 6 self.x += 6 scene.center=self.pos class hindernis(frame, Thread): def __init__(self, px=0, py=0, pz=0, x=0, y=0, z=0, farbe=color.white): frame.__init__(self) Thread.__init__(self) self.box = box(pos=(px,py,pz), size=(x,y,z), color = farbe) def run(self): self.hinderniserzeugen() def hinderniserzeugen(self): # rate(1) a = random.randint(0,2) hindernis = hindernis(px=random.randint(0,20)*50,py=a*20+35,pz=a*-50, x=50,y=50,z=50) # class ebene(frame, Thread): def __init__(self, zahl=0, farbe=color.white): frame.__init__(self) Thread.__init__(self) self.ebene = box(frame = self, pos=(0,zahl*20,zahl*-50), size=(1000,20,50), color = farbe) def run(self): while True: rate(20) self.x += 10 #STRECKE += 10 # def gameover(): label(pos=(0,50,0), text='Game Over') figur1 = figur(g=1, posx=0, posy= 65, posz=0, farbe = color.red) ebene1 = ebene(zahl=0, farbe=color.white) ebene2 = ebene(zahl=1, farbe=color.rgb_to_hsv((0.7,0.7,0.7))) ebene3 = ebene(zahl=2, farbe=color.blue) for x in range(5): a = random.randint(0,2) hindernis(px=random.randint(0,20)*50,py=a*20+35,pz=a*-50, x=50,y=50,z=50) if __name__ == "__main__": ebene1.start() ebene2.start() ebene3.start() figur1.start() #hindernis1 = hindernis() #hindernis1.start()