Links und Funktionen
Sprachumschaltung

Navigationspfad


Inhaltsbereich

FürJule

Python Source icon Jump&Run.py — Python Source, 4 KB (4593 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,wposy,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 == "a" and self.z != -100:
                    self.pos = self.pos + vector(0,20,-50)
                    scene.center=self.pos
                elif taste == "d" and self.z != 0:
                    self.pos = self.pos + vector(0,-20,50)
                    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, d = None):
        Thread.__init__(self)
        self.box = box(pos=(px,py,pz), size=(x,y,z), color = farbe)
        self.strecke = 0
        self.d = d
    def run(self):
        while True:
            rate(20)
            self.strecke += 10
            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.d.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):
        Thread.__init__(self)
        self.strecke = 0
        self.anzeige = label(pos=(1000,-1000,0), text='STRECKE= ' + str(0))
    def run(self):
        while True:
            rate(20)
            self.strecke += 10
            self.anzeige.x += 10
            self.anzeige.text ='STRECKE= ' + str(self.strecke)
            

class loescher(Thread):
    def __init__(self, f = None, s = None):
        Thread.__init__(self)
        self.hliste = []
        self.f = f
        self.s = s
    def run(self):
        while True:
            if len(self.hliste) > 0:
                world_pos = self.f.frame_to_world(self.f.koerper.pos)
                if self.hliste[0].box.x < world_pos.x:
                    del self.hliste[0]
                elif self.hliste[0].box.x-20 == world_pos.x and self.hliste[0].box.z == world_pos.z:
                    label(pos=(self.s.strecke, 100, 0), text='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()
        self.loescher = loescher(f = self.figur1, s = self.strecke)
        self.hindernis1 = hindernis(px=-10000, d = self.loescher)
        self.ebene1.start()
        self.ebene2.start()
        self.ebene3.start()
        self.figur1.start()
        self.hindernis1.start()
        self.strecke.start()
        self.loescher.start()
    
starter()
         



Funktionsleiste