Links und Funktionen
Sprachumschaltung

Navigationspfad


Inhaltsbereich

PvPshooter

PvPshooter.py — text/python-source, 5 KB (6039 bytes)

Dateiinhalt

#-*- coding: utf-8 -*-
# Teststadt für Rundgang
# 2010-03-08

from visual import *
from visual.text import *
from random import *



scene.title = "Shooter" # Fenstertitel
scene.x = 0	                    # Fensterpos v. links
scene.y = 0	                    # Fensterpos v. oben
scene.height =1000# Fensterhöhe
scene.width = 1500               # Fensterbreite
scene.range = (1,1,1)           # Abstand
scene.center = (0,5,50)         # Festlegung Blickziel
scene.userspin = False          # Blickwechsel abgeschaltet
scene.userzoom = False         # Benutzerzoom abgeschaltet
scene.fov = 1.5                   # Kamerawinkel
scene.background = (0.8,0.85,1) # Farbe Hintergrund
scene.stereodepth = 2           # Stereotiefe
scene.show_rendertime = True    # Anzeige der Berechnungszeiten
scene.fullscreen = False         # Vollbildmodus
haus_anzahl = 10                # Konstante: Anzahl der Häuser
haeuser=[0,1,2,3,4,5,6,7,8,9]
# graue Bodenplatte
floor = box(pos=(0,0,0), width=200, height=1, length=200, color=color.gray(0.4),material=materials.rough)
Kaefig = box (pos=(0,15,0),width=200,height=30,length=200,material=materials.earth)#Kaefig um Speiler herum
Gebilde=frame()#Zielfläche für Schüsse
Figur=pyramid(pos=(0,5,53.8),axis=(0,0,-1),size=(4, 5, 5),color=color.red, material=materials.emissive)  #Spielfigur =)


    
for i in range(haus_anzahl):    # Häuser durch Zufall generieren
    zufallsvariable = random()
    haeuser[i]=cylinder \
    (pos=(random()*200-100, 0,random()*200-100),\
    axis=(0,30,0),radius=(8) ,\
    color=color.gray(float(i/2)/10),material=materials.marble,\
    frame=Gebilde)
    

rhairs = 0.025 # half-length of crosshairs
dhairs = 2 # how far away the crosshairs are
maxcosine = dhairs/sqrt(rhairs**2+dhairs**2) # if ray inside crosshairs, don't move
haircolor = color.black
roam=False

#-Zweitfenster für topview---
#zweitfenster = display(width=300,height=320, title="Minimap",\
 #                      center=(0,5,0), forward=(0,-5,0), x=700, y=0,\
  #                     background=(0.8,0.85,1))
#zweitfenster.range = 75
#zweitfenster.select()
#for obj in scene.objects:
#    try:
#        obj.__copy__(display=zweitfenster).opacity=0.5
#    except:
 #       pass
#walker = sphere(radius=2, color=color.white, pos=scene.center, material=materials.emissive)
  # walker.trail = curve(opacity=1)#farbe 

Treffer=0


anzeige = label(pos=(30,0,30), text="Abgefeuerte Schuesse", \
    box=False, line=False, yoffset=150, height=10)


while True:
    rate(50) 

    # Toggle roam option
    #if scene.mouse.events:
    #    m = scene.mouse.getevent()
    
    roam = True

    # If in roaming mode, change center and forward according to mouse position
    if roam:
        ray = scene.mouse.ray
        if abs(dot(ray,scene.forward)) < maxcosine: # do something only if outside crosshairs
            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/25)
           # scene.center = scene.mouse.camera+newforward*mag(scene.center-scene.mouse.camera)
            scene.forward = newforward
            #scene.center = scene.center+scene.forward*ray.y/2.
            #zweitfenster.select()
            #walker.pos = scene.center
            #walker.trail.append(pos=walker.pos, retain=5000)

    # Falls Tastatur gedrückt...
    if scene.kb.keys:
        s = scene.kb.getkey()
        
       
        
        if   s == 'w':     # vorwärtsgehen
            naheshaus=haeuser[0]
            for i in range (haus_anzahl):
                if(mag(scene.center-naheshaus.pos)>=mag(scene.center-haeuser[i].pos)):
                    naheshaus=haeuser[i]
            if (mag(scene.center-naheshaus.pos)<12):
                scene.center = scene.center-scene.forward*mag(scene.center-scene.mouse.camera)
            else:
                scene.center = (scene.center+scene.forward*mag(scene.center-scene.mouse.camera))
        elif s == 's':   # rückwärtsgehen
            naheshaus=haeuser[0]
            for i in range (haus_anzahl):
                if(mag(scene.center-naheshaus.pos)>=mag(scene.center-haeuser[i].pos)):
                    naheshaus=haeuser[i]
            if (mag(scene.center-naheshaus.pos)<12):
                scene.center = (scene.center+scene.forward*mag(scene.center-scene.mouse.camera))
            else:
                scene.center = scene.center-scene.forward*mag(scene.center-scene.mouse.camera)
        elif s == 'a':   # links gehen
            naheshaus=haeuser[0]
            for i in range (haus_anzahl):
                if(mag(scene.center-naheshaus.pos)>=mag(scene.center-haeuser[i].pos)):
                    naheshaus=haeuser[i]
            if (mag(scene.center-naheshaus.pos)<12):
                scene.center+=cross(scene.forward,scene.up)#rightbackpush
            else:
                scene.center-=cross(scene.forward,scene.up) 
        elif s == 'd':   # rechtsgehen gehen
            naheshaus=haeuser[0]
            for i in range (haus_anzahl):
                if(mag(scene.center-naheshaus.pos)>=mag(scene.center-haeuser[i].pos)):
                    naheshaus=haeuser[i]
            if (mag(scene.center-naheshaus.pos)<12):
                scene.center-=cross(scene.forward,scene.up)#leftbackpush
            else:
                scene.center+=cross(scene.forward,scene.up) 



#Schuss:!!!!!!!!!!
   
    if scene.mouse.events:
    # Maus-Event in Variable speichern
        Linksklick = scene.mouse.getevent()
    # zielen auf Gebilde
        try:  
            if Linksklick.pick.radius and Linksklick.press:# in haeuser[]:# and Linksklick                 
                Treffer += 1
                #Treffer landen auf Gebilde
                sphere(pos=Gebilde.world_to_frame(Linksklick.pickpos), color=color.blue, \
                radius=0.2, material=materials.emissive)   
                anzeige.text="Du hast"+str(Treffer)+ "Schuesse abgefeuert!! "
            
        except:
            pass


Funktionsleiste