kaggge
Jump&Run.py — Python Source, 4 KB (4414 bytes)
Dateiinhalt
from visual import * from threading import Thread import random scene.range = (500) scene.forward = (275,-150,-100) 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): while True: rate(20) self.x += 10 scene.center=self.pos scene.autoscale = False if scene.kb.keys: taste = scene.kb.getkey() if taste == "w" and self.z != -100: self.pos = self.pos + vector(0,20,-50) scene.center=self.pos elif taste == "s" and self.z != 0: self.pos = self.pos + vector(0,-20,50) scene.center=self.pos elif taste == " ": for a in range(5): rate(30) self.y += 12 self.x += 12 scene.center=self.pos rate(20) for b in range(5): rate(30) self.y -= 12 self.x += 12 scene.center=self.pos class hindernis(Thread): def __init__(self, px=0, py=0, pz=0, x=50, y=50, z=50, farbe=color.white, e = None): Thread.__init__(self) self.box = box(pos=(px,py,pz), size=(x,y,z), color = farbe) self.strecke = 0 self.e = e def run(self): while True: rate(20) self.strecke += 10 self.e.hliste.append(hindernis(px=-1000)) if self.strecke%150==0: a = random.randint(0,2) h = hindernis(px=500+self.strecke,py=a*20+35,pz=a*-50, x=50,y=50,z=50, farbe = color.blue) self.e.hliste.append(h) class ebene(Thread): def __init__(self, zahl=0, farbe = color.white): Thread.__init__(self) self.ebene = box(pos=(0,zahl*20,zahl*-50), size=(10000,20,50), color = farbe) self.z = self.ebene.z scene.autoscale = False def run(self): while True: rate(20) self.ebene.x += 10 class strecke(Thread): def __init__(self, f = None): Thread.__init__(self) self.strecke = 0 self.anzeige = label(pos=(1000,-1000,0), text='STRECKE= ' + str(0)) self.hliste = [] self.f = f def run(self): while True: rate(20) self.strecke += 10 self.anzeige.x += 10 self.anzeige.text ='STRECKE= ' + str(self.strecke) hi = self.hliste.pop(0) #print hi print self.f.x print hi.box.x if self.f.x == hi.box.x: print "GAME OVER" class starter(): def __init__(self): self.figur1 = figur(g=1, posx=-450, posy= 65, posz=0, farbe = color.red) self.ebene1 = ebene(zahl =0) self.ebene2 = ebene(zahl =1, farbe=color.gray(0.7)) self.ebene3 = ebene(zahl =2, farbe=color.gray(0.4)) self.strecke = strecke(f = self.figur1) self.hindernis1 = hindernis(px=-1000, e = self.strecke) self.ebene1.start() self.ebene2.start() self.ebene3.start() self.figur1.start() self.hindernis1.start() self.strecke.start() def gameover(): label(pos=(0,50,0), text='Game Over') starter()