Links und Funktionen
Sprachumschaltung

Navigationspfad


Inhaltsbereich

Wüste005

aktuelle Version der Wüste mit rotierenden Ufos und Gegnern

WüsteWüste.py — text/python-source, 18 KB (18929 bytes)

Dateiinhalt

# -*- coding: utf-8 -*-
from visual import *
from random import*
from threading import Thread

scene.x = 0	                                # Fensterpos v. links
scene.y = 0	                                # Fensterpos v. oben
scene.height =1050                              # Fensterhöhe
scene.width = 1280                              # Fensterbreite
scene.range = (6,6,6)                           # Abstand
scene.center = (-4,10,-7)                        # Festlegung Blickziel
scene.userspin = True                          # Blickwechsel abgeschaltet
scene.userzoom = True                         # Benutzerzoom abgeschaltet
scene.fov = 1                   # Kamerawinkel
scene.background = (0.8,0.85,1) # Farbe Hintergrund
scene.stereodepth = 2           # Stereotiefe
scene.show_rendertime = True    # Anzeige der Berechnungszeiten
scene.fullscreen = True         # Vollbildmodus                                 # Kamerawinkel

kakteen_zahl = 20               # Konstante: Anzahl der Kakteen
raumschiff_zahl = 5	        # Konstsnte: Anzahl der Raumschiffe

raumschiffe = []

class raumschiff(Thread, frame):        # Raumschiffe
    def __init__(self,x,y,z):
        Thread.__init__(self)
        frame.__init__(self)
        self.raum = ellipsoid(pos=(x,y,z), color=color.black, length=70, height=20, width=70, material=materials.plastic, frame=self) 
        self.raums = sphere(pos=(x,y+10,z), radius=20, opacity=.4, color=color.blue, material=materials.plastic, frame=self) 
        self.raump1 = sphere(pos=(x+25,y+5,z), radius=5, frame=self) 
        self.raump2 = sphere(pos=(x,y+5,z+25), radius=5, frame=self) 
        self.raump3 = sphere(pos=(x,y+5,z-25), radius=5, frame=self) 
        self.raump4 = sphere(pos=(x-25,y+5,z), radius=5, frame=self) 
        self.raump5 = sphere(pos=(x+18,y+5,z+18), radius=5, frame=self) 
        self.raump6 = sphere(pos=(x+18,y+5,z-18), radius=5, frame=self) 
        self.raump7 = sphere(pos=(x-18,y+5,z+18), radius=5, frame=self) 
        self.raump8 = sphere(pos=(x-18,y+5,z-18), radius=5, frame=self) 
        self.raumpk1 = sphere(pos=(x+25,y+9,z), radius=2, color=color.yellow, material=materials.plastic, frame=self) 
        self.raumpk2 = sphere(pos=(x,y+9,z+25), radius=2, color=color.yellow, material=materials.plastic, frame=self) 
        self.raumpk3 = sphere(pos=(x,y+9,z-25), radius=2, color=color.yellow, material=materials.plastic, frame=self) 
        self.raumpk4 = sphere(pos=(x-25,y+9,z), radius=2, color=color.yellow, material=materials.plastic, frame=self) 
        self.raumpk5 = sphere(pos=(x+18,y+9,z+18), radius=2, color=color.yellow, material=materials.plastic, frame=self) 
        self.raumpk6 = sphere(pos=(x+18,y+9,z-18), radius=2, color=color.yellow, material=materials.plastic, frame=self) 
        self.raumpk7 = sphere(pos=(x-18,y+9,z+18), radius=2, color=color.yellow, material=materials.plastic, frame=self) 
        self.raumpk8 = sphere(pos=(x-18,y+9,z-18), radius=2, color=color.yellow, material=materials.plastic, frame=self) 
        self.rauma = ellipsoid(pos=(x,y-10,z), color=color.red, length=30, width=30, height=5, frame=self) 
        self.raumss = sphere(pos=(x,y,z), radius=45, color=color.green, opacity=.1, material=materials.plastic, frame=self) 

        self.winkel = 2

    def run(self):
        "Thread starten"
        while True:
            rate(50)
            # Rotation um y-Achse durch Mittelpunkt
            self.rotate(angle=radians(self.winkel), axis=(0,1,0))


class kaktus(frame):            # Kakteen
    def __init__(self,x,z):
        frame.__init__(self)
        self.ht = cylinder(length=20, color=color.green, radius=2, axis=(0,1,0), pos=(x,0,z), frame=self) 
        self.o1 = sphere(pos=(x,20,z), radius=2, color=color.green, frame=self)
        self.m1 = cylinder(length=6, color=color.green, radius=1.5, pos=(x,8,z), frame=self)
        self.m2 = cylinder(length=6, color=color.green, radius=1.5, pos=(x-6,10,z), frame=self)
        self.m3 = cylinder(length=5, color=color.green, radius=1.5, pos=(x,9,z-5), axis=(0,0,1), frame=self)
        self.m4 = cylinder(length=6, color=color.green, radius=1.5, pos=(x,7,z), axis=(0,0,1), frame=self)
        self.k1 = sphere(pos=((x+6),8,z), color=color.green, radius=1.5, frame=self)
        self.k2 = sphere(pos=((x-6),10,z), color=color.green, radius=1.5, frame=self)
        self.a1 = cylinder(pos=((x+6),8,z), color=color.green, radius=1.5, length=7, axis=(0,1,0), frame=self)
        self.k3 = sphere(pos=((x+6),15,z), color=color.green, radius=1.5, frame=self)
        self.d1 = cylinder(pos=(x,0,z), radius=10, length=22, axis=(0,1,0), opacity=.1, frame=self)
        self.k4 = sphere(pos=(x,9,z-5), color=color.green, radius=1.5, frame=self)
        self.k5 = sphere(pos=(x,7,z+6), color=color.green, radius=1.5, frame=self)
        self.a2 = cylinder(length=5, color=color.green, radius=1.5, pos=(x,9,z-5), axis=(0,1,0), frame=self)
        self.k6 = sphere(pos=(x,14,z-5), color=color.green, radius=1.5, frame=self)
        self.o2 = sphere(pos=(x,21,z), color=color.red, radius=1.5, frame=self)
        self.pos=(x,0,z)

    def drehen(self):
        self.rotate(axis=(0,1,0), angle=random()*2*pi)



# Wüstenlandschaft
boden = box(pos=(0,-1,0), width=350, height=1, length=350, color=(.9,.6,.2))
wand1 = box(pos=(175,25,0), width=350, height=50, length=1, color=(.9,.6,.2), opacity=.5)
wand2 = box(pos=(-175,25,0), width=350, height=50, length=1, color=(.9,.6,.2), opacity=.5)
wand3 = box(pos=(0,25,175), width=1, height=50, length=350, color=(.9,.6,.2), opacity=.5)
wand4 = box(pos=(0,25,-175), width=1, height=50, length=350, color=(.9,.6,.2), opacity=.5)
sonne = sphere(pos=(150,250,150), color=color.yellow, radius=50, opacity=.5, material=materials.plastic)

# Raumschiffe werden erzeugt
for j in range(raumschiff_zahl):
    r1 = raumschiff(((random()*350)-175),((random()*50)+100),((random()*350)-175))
    r1.start()
    raumschiffe.append(r1)
    

# Kakteenliste
liste=[]

# Zufallskakteen
liste.append(kaktus(0,0))
while len(liste) < kakteen_zahl:
    liste.append(kaktus(((random()*150)-75),((random()*150)-75)))
    for i in liste[:-1]:
        if mag(i.pos - liste[-1].pos)<20:
            liste[-1].visible=False
            del liste[-1]
            break
            

# Spieler
class ego(frame):
    def __init__(self):
        frame.__init__(self)
        
        
        #ArmRechts:
        self.OberarmRechts  = cylinder (frame = self, pos = (-11.7, 5.8, 0), radius = (0.7), color = color.white, axis = (0,-2.5,0))
        self.EllbogenRechts = sphere   (frame = self, pos = (-11.7, 3.3, 0), radius = (0.7))
        self.UnterArmRechts = cylinder (frame = self, pos = (-11.7, 3.3,0), radius = (0.7), axis = (1, 0, 3))
        self.HandRechts     = sphere   (frame = self, pos = (-10.7, 3.3, 3), radius = (0.72))

        #ArmLinks:
        self.OberarmLinks   = cylinder(frame = self, pos = (-8.4, 5.8, 0), radius = (0.7), color = color.white, axis = (-1.5,-2.5,4))
        self.HandLinks  = sphere  (frame = self, pos = (-9.9, 3.3, 4), radius = (0.72))
                
        #Waffe
        self.WAFFE = cylinder (frame = self, pos = (-11.4, 4, -1), axis = (1.3, 1.5,7), radius = 0.4, color = color.black, opacity = (1))
        self.Waffenkugel = sphere (frame = self, pos = (-10.1, 5.4, 6), radius= 0.2, color= color.red)
        self.Waffengriffhinten = cylinder (frame = self, pos =(-10.6, 5.1, 3), radius = (0.3),axis = (0,-2.7,0), color = color.black)
        self.Waffengriffvorne = cylinder (frame = self, pos =(-10.5, 3.9, 4), length = (2), radius = (0.3),axis = (0.2, 0.3, 1), color = color.black)
        self.visier = ring (frame = self, pos = (-10.3,5.9,5), axis = (1.3, 1.5, 7), radius = 0.3, color = color.black)

        #Koerper

        self.kopf = sphere(frame = self, pos = (-10, 10,0), radius = (2.5),opacity = (1))
        self.haare = sphere(frame = self, pos = (-10, 10.1,-0.1), radius = (2.5), color= color.black, opacity = (1))
        self.rechtesA = sphere (frame = self, pos = (-11,11,2.2), radius = (0.3), color = color.black)
        self.linkesA  = sphere (frame = self, pos = (-9,11,2.2), radius = (0.3), color = color.black)
        self.Mund = ring (frame = self, pos =(-10,9.3,2.1), radius = (0.8), color = color.red, axis= (0,0,1))

        self.Tshirt = cylinder(frame = self, pos = (-10, 2.5,0), radius = 1.2, color = (0.3,0.6,1), axis = (0,5,0))
        self.Guertel = ring(frame = self, pos = (-10, 2.5, 0), radius = 1, axis = (0,1,0), color = color.black, thickness = 0.3)
        self.SchulterRechts = sphere(frame = self, pos =(-11.3, 6.1, 0), radius = 1.2, color = (0.3,0.6,1) )
        self.SchulterLinks = sphere(frame = self, pos =(-8.7, 6, 0), radius = 1.2, color = (0.3,0.6,1), axis = (0,1.5,0))

        self.hueftelinks = sphere(frame = self, pos =(-11.3, 0.5, 0), radius = 1.2, color = color.blue)
        self.huefterechts = sphere(frame = self, pos =(-8.7, 0.5, 0), radius = 1.2, color = color.blue, axis = (0,1.5,0))
        self.Hosenbund = cylinder(frame = self, pos = (-10,1,0), radius = 1.2, color = color.blue, axis = (0,1.5,0))
        self.HoseRechts = cylinder(frame = self, pos =(-11.3,0.5,0), axis = (0,-1.5,0), radius = 1.2, color = color.blue)
        self.HoseLinks = cylinder(frame = self, pos =(-8.7,0.5,0), axis = (0,-1.5,0), radius = 1.2, color = color.blue)
        self.BreinRechts = cylinder(frame = self, pos =(-11.3,-0.7,0), axis = (0,-4,0), radius = 1.1, color = color.white)
        self.BreinLinks = cylinder(frame = self, pos =(-8.7,-0.7,0), axis = (0,-4,0), radius = 1.1, color = color.white)  

        self.Rucksack = box(frame = self, pos = (-10, 5.7, -1.2), color = color.black, length = 1.6, height = 2.2)
        self.ArmLinks = cylinder(frame = self, pos =(8.7,0.5,0), axis = (0,0,0), radius = 1.2, color = color.red)


class enemy(Thread, frame):
    def __init__(self, x = 0, z = 0, lives = 10):
        Thread.__init__(self)
        frame.__init__(self, pos = (x, 0, z))
        self.x = x
        self.z = z
        self.kopf = sphere(frame = self, pos  = (self.x,10, self.z), radius = (3), color = color.white)
        self.kbody = sphere(frame = self, pos = (self.x, 5, self.z), radius =(4))
        self.zbody = cylinder(frame = self, pos= (self.x, 0, self.z), axis= (0,5,0), radius = (4))
        self.Ring1 = ring(frame = self, pos = (self.x,5,self.z), radius= (4), axis = (0,1,0), color = color.black, thickness = (0.1))
        self.Ring2 = ring(frame = self, pos = (self.x,0,self.z), radius= (4), axis = (0,1,0), color = color.black, thickness = (0.1))
        self.Ring3 = ring(frame = self, pos = (self.x,1,self.z), radius= (4), axis = (0,1,0), color = color.black, thickness = (0.1))
        self.Ring4 = ring(frame = self, pos = (self.x,2,self.z), radius= (4), axis = (0,1,0), color = color.black, thickness = (0.1))
        self.Ring5 = ring(frame = self, pos = (self.x,3,self.z), radius= (4), axis = (0,1,0), color = color.black, thickness = (0.1))
        self.Ring6 = ring(frame = self, pos = (self.x,4,self.z), radius= (4), axis = (0,1,0), color = color.black, thickness = (0.1))
        self.Scheibe = cylinder (frame = self, pos = (self.x,-4,self.z), radius = (4), axis = (0,0.1,0), color = color.red) # Scheibe
        self.RechterArm  = cylinder (frame = self, pos = (self.x-3, 6, self.z), axis = (0,0,6.5))
        self.LinkerArm   = cylinder (frame = self, pos = (self.x+3, 6, self.z), axis = (0,0,6.5))
        self.rechteSchulter  = sphere (frame = self, pos = (self.x-1.7, 5.3, self.z), radius = (2.9))
        self.linkeSchulter = sphere (frame = self, pos = (self.x+1.7, 5.3, self.z),   radius = (2.9))
        self.rechteHand = sphere (frame = self, pos = (self.x+3,6,self.z+6.4),  radius = (1.3))
        self.rechteHand = sphere (frame = self, pos = (self.x-3,6,self.z+6.4), radius = (1.3))
        self.rechtesA = sphere (frame = self, pos = (self.x+1.3,11,self.z+2.6), radius = (0.3), color = color.red)
        self.linkesA  = sphere (frame = self, pos = (self.x-1.3,11,self.z+2.6), radius = (0.3), color = color.red)
        self.speer = arrow (frame = self, pos = (self.x+3, 2.4, self.z+6.4), color= color.black, axis =(0,11,0), shaftwidth = 0.6, material = materials.rough)
        self.Mund = ellipsoid(frame = self, pos=(self.x+0,9.4,self.z+3),length=3, height=1, width=1, color =(0.8,0.3,0.4))
        distant_light(direction=(self.x,2,self.z), color=color.red)

        self.winkel = 1
        self.shots = []
        self.chasingPlayer = false
        self.lives = lives
        self.anzeige = label(pos=(self.x, 5, self.z), \
                            box=False, line=False, yoffset=50, height=10)
        self.anzeige.visible = false

    def run(self):
        "Thread starten"
        while len(self.shots)<self.lives+1:
            rate(50)
            # Rotation um y-Achse durch Mittelpunkt
            self.rotate(angle=radians(self.winkel), axis=(1,1,1))

            if self.chasingPlayer == true:
                abstandEnemyPlayer = vector(player.pos.x - self.x, 0, player.pos.z - self.z)
                self.x += abstandEnemyPlayer.x * 0.02
                self.z += abstandEnemyPlayer.z * 0.02
                self.anzeige.pos = (self.x, 10, self.z)

    def shoot(self,sme):
        "Gegner via Mausevent (sme) beschossen"
        # wurde der Gegner am Kopf abgeschossen?
        if sme.pick == self.kopf and len(self.shots) < self.lives:
            # erzeuge Schüsse und fuegt in Liste ein
            self.shots.append(sphere(pos=self.world_to_frame(sme.pickpos), \
                                color=color.red, \
                                radius=0.5, material=materials.plastic, \
                                frame=self) )
            self.anzeige.visible = true
            self.anzeige.text="Leben: "+str((self.lives+1)-len(self.shots))
            # Erhoehung der Drehgeschwindigkeit
            self.winkel*=1.4
            self.chasingPlayer = true

        elif len(self.shots) >= self.lives:
            self.visible = false
            self.anzeige.visible = false
        
        
player = ego()  

# Donutliste
donuts = []

# Enemyliste
enemies = []

roam=False

class RandomDonut(Thread, frame):
    "Klasse modelliert Donut"
    def __init__(self, pos=(0,0,0), axis=(0,1,0), streuselMax = 10, size=0.5, glasurColor = (.3,.2,.1)):
        # Aufruf der Oberklassenkonstruktoren fuer Nebenlaeufigkeit und Objektcontainer
        Thread.__init__(self)
        frame.__init__(self, pos=pos)
        self.size = size
        self.teig = ring(thickness=self.size, color=(.9,.8,.2), axis=(0,1,0), frame=self, radius = self.size*2)
        self.glasur = ring(thickness=self.size+(self.size/50.0), color=glasurColor,\
                     material=materials.plastic, y=(self.size/5), axis=(0,1,0), frame=self, radius = self.size*2)
        self.streusel = []
        self.winkel = 1
        self.speed = 0.01
        self.movingUp = true
        self.chasingPlayer = false
        self.streuselMax = streuselMax
        self.anzeige = label(pos=self.pos, \
                            box=False, line=False, yoffset=50, height=10)
        self.anzeige.visible = false

    def run(self):
        "Thread starten"
        while len(self.streusel)<self.streuselMax+1:
            rate(50)
            # Rotation um y-Achse durch Mittelpunkt
            self.rotate(angle=radians(self.winkel), axis=(1,1,1))

            if self.chasingPlayer == true:

                abstandDonutPlayer = vector(player.pos.x - self.pos.x, 0, player.pos.z - self.pos.z)
                #print ("abstandDonutPlayer: ", abstandDonutPlayer.x, abstandDonutPlayer.y, abstandDonutPlayer.z)
                self.pos += (abstandDonutPlayer.x*0.02, 0, abstandDonutPlayer.z*0.02)
                
                    
    def garnieren(self,sme):
        "Donut via Mausevent (sme) mit Streuseln versehen"
        # ist die Schokoglasur angeklickt worden?
        if sme.pick == self.glasur and len(self.streusel) < self.streuselMax:
            # erzeuge Streusel und f� Liste ein
            self.streusel.append(sphere(pos=self.world_to_frame(sme.pickpos), \
                                color=color.hsv_to_rgb((random(),1,1)), \
                                radius=(self.size/10), material=materials.plastic, \
                                frame=self) )
            self.anzeige.visible = true
            self.anzeige.text="Leben: "+str((self.streuselMax+1)-len(self.streusel))+" Streusel"
            # Erhoehung der Drehgeschwindigkeit
            self.winkel*=1.4
            self.teig.thickness -= self.size/12
            self.glasur.thickness -= self.size/12+(self.size/50/12)
            self.teig.radius -= self.size/6
            self.glasur.radius -= self.size/6
            self.glasur.y -= (self.size/60)
            self.chasingPlayer = true
            # Streuselprotokoll
            print len(self.streusel)

        elif len(self.streusel) >= self.streuselMax:
            self.visible = false
            self.anzeige.visible = false


if __name__ == "__main__":

     for i in range(20):
        size = random()*3+1
        d1 = RandomDonut(pos=(random()*350-175, size,random()*350-175), size = size, glasurColor = (random(), random(), random()))
        
        d1.start()
        donuts.append(d1)

        """e1 = enemy(random()*350-175, random()*350-175)
        e1.start()
        enemies.append(e1)"""


while True:
    rate(200) 
    
    player.pos=scene.center-(0,15,0)
    
    roam = True

    # If in roaming mode, change center and forward according to mouse position
    if roam:
        ray = scene.mouse.ray
        newray = norm(vector(ray.x, 0, ray.z))
        angle = arcsin(dot(cross(scene.forward,newray),scene.up))
        newforward = rotate(scene.forward, axis=scene.up, angle=angle/150)
        scene.forward = newforward

    
    # Falls Tastatur gedrückt...
    player.pos=scene.center-(0,15,0)
    if scene.kb.keys:
        s = scene.kb.getkey()
        if   s == 'up' or s=='w':     # vor
             scene.center += scene.forward*mag(scene.center-scene.mouse.camera)/12

        elif s == 'down' or s=='s':   # hinter 
             scene.center -= scene.forward*mag(scene.center-scene.mouse.camera)/12
    
        elif s == 'left' or s=='a':   # links 
             scene.center -= cross(scene.forward,scene.up)/6
    
        elif s == 'right' or s=='d':  # rechts 
             scene.center += cross(scene.forward,scene.up)/6
                
                
    player.pos=scene.center-(0-4,10,0)

    #Schuss:!!!!!!!!!!
    
    # falls Maus-Taste gedrueckt...
    if scene.mouse.events:
        # Maus-Event in Variable speichern
            sme = scene.mouse.getevent()     
           # Verarbeitung des Maus-Events: Maus auf Objekt gedrueckt?
            if sme.pick and sme.press:
                for i in donuts:
                    i.garnieren(sme)
                    #i.shoot(sme)

Funktionsleiste