Ballschießen komplett (nur a bisserl komisch)
bogenschiesen2.py — text/python-source, 8 KB (8752 bytes)
Dateiinhalt
# -*- coding: utf-8 -*-
from visual import * # das 3D-Modul
from random import *
from sys import *
#from visual.text import *
from time import sleep
scene.title = "Bogenschiessen!"
#-- Panamorama-Auskleidung einer Kugel ---------------------
import Image
name = "pano_olympia_aussen"
#name = "pano_solarberg"
#name = "pano_siegburg"
#name = "pano_waldeck"
#name = "siegwehr"
#name = "pano_notting-hill"
width = 2048 # Breite und Hoehe an Original anpassen
height = 1024
im = Image.open(name+".tga") # Oeffnen des Bildes
materials.saveTGA(name,im) # Speichern des Bildes intern
pano = materials.texture(data=im, mapping="spherical") # Darstellungsart
#-- Neutrale Umleuchtung mit 8 Lichtern --------------------
scene.lights = [distant_light(direction=( 10, 10, 10), color=color.gray(0.5)),\
distant_light(direction=(-10, 10, 10), color=color.gray(0.5)),\
distant_light(direction=( 10,-10, 10), color=color.gray(0.5)),\
distant_light(direction=( 10, 10,-10), color=color.gray(0.5)),\
distant_light(direction=(-10,-10, 10), color=color.gray(0.5)),\
distant_light(direction=( 10,-10,-10), color=color.gray(0.5)),\
distant_light(direction=(-10, 10,-10), color=color.gray(0.5)),\
distant_light(direction=(-10,-10,-10), color=color.gray(0.5))]
#-- Kameraposition im Zentrum ------------------------------
scene.fov=pi/2 # Blickwinkel 90° (statt 60°)
scene.range=0.001 # Entfernung zum Blickzentrum
zufallszahlX = random()*10+3
zufallszahlZ = random()*10+3
zufallszahlY = random()*10+3
scene.center=(0,3.5,0)
scene.range=(3.5,3.5,3.5)
scene.forward=(0,-0.5,-1)
#scene.width=700
#scene.hight=320
#scene.userzoom=False
#scene.userspin=False
drehung = 0
#for i in range(1):
# rate(50)
# kugel.rotate(angle=radians(260), axis=(0,1,0), origin=(0,0,0))
kugel = sphere(radius=90, material=pano)
#kugel2 = sphere (radius=19.99, opacity=0.3)
ZielrohrundMensch=frame()
Zielrohr = frame(frame=ZielrohrundMensch)
pfeil=frame(frame=Zielrohr)
Mensch = frame(frame=ZielrohrundMensch)
Kopf = sphere(frame=Mensch, pos=(0,3,0),radius = 0.5, color=(.9,.8,.2))
Hals = ellipsoid(frame=Mensch, pos=(0,2.5,0), height=1.3, length=0.5, width=0.5)
Oberkoerper = ellipsoid(frame=Mensch, pos=(0,0.8,0), height=3, length=1.5, width=1, color=(.3,.2,.1))
rechtesBein = cylinder(frame=Mensch, axis=(0,-2,0), pos=(0.2,0,0), radius=0.25, color=color.green)
linkesBein = cylinder(frame=Mensch, axis=(0,-2,0), pos=(-0.2,0,0), radius=0.25, color=color.green)
rechterFuss = ellipsoid(frame=Mensch, pos=(-0.25,-2.1,-0.15), height=0.5, length=0.5, width=1, color=color.blue)
linkerFuss = ellipsoid(frame=Mensch, pos=(0.25,-2.1,-0.15), height=0.5, length=0.5, width=1, color=color.blue)
linkerArm = ellipsoid(frame=Mensch, pos=(-0.75,1.3,-0.1), height=2, length=0.5, width=0.5, axis=(-1,1,-0.3), color=(.3,.2,.1))
linkerArm = ellipsoid(frame=Mensch, pos=(0.75,1.3,-0.1), height=2, length=0.5, width=0.5, axis=(1,1,-0.3), color=(.3,.2,.1))
#pfeilschaft=cylinder(frame=pfeil,pos=(0,2.95,-0.7),material=materials.wood,color=(0.3157,.2029,.1008),length=2.01,radius=0.025,axis=(scene.forward))
#pfeilspitze=cone(frame=pfeil,pos=(0,2.05,-2.5),length=0.1,radius=0.0275,color=(.4196,.4,.38823),axis=(scene.forward))
#feder1=cylinder(frame=pfeil,pos=(0.123,2.95,-0.7),length=0.1,axis=(-5,-2,5),radius=0.01)
#feder2=cylinder(frame=pfeil,pos=(0.25,2.95,-0.7),length=0.1,axis=(-1,1,0),radius=0.01)
#feder3=cylinder(frame=pfeil,pos=(0.35,2.95,-0.7),length=0.1,axis=(-1,1,0),radius=0.01)
#feder4=cylinder(frame=pfeil,pos=(0.45,2.95,-0.7),length=0.1,axis=(-1,1,0),radius=0.01)
#feder5=cylinder(frame=pfeil,pos=(0.15,2.95,-0.7),length=0.1,axis=(-1,-1,0),radius=0.01)
#feder6=cylinder(frame=pfeil,pos=(0.25,2.95,-0.7),length=0.1,axis=(-1,-1,0),radius=0.01)
#feder7=cylinder(frame=pfeil,pos=(0.35,2.95,-0.7),length=0.1,axis=(-1,-1,0),radius=0.01)
#feder8=cylinder(frame=pfeil,pos=(0.45,2.95,-0.7),length=0.1,axis=(-1,-1,0),radius=0.01)
#feder9=cylinder(frame=pfeil,pos=(0.15,2.95,-0.7),length=0.1,axis=(-80,0,50),radius=0.01)
#feder10=cylinder(frame=pfeil,pos=(0.25,2.95,-0.7),length=0.1,axis=(-80,0,50),radius=0.01)
#feder11=cylinder(frame=pfeil,pos=(0.35,2.95,-0.7),length=0.1,axis=(-80,0,50),radius=0.01)
#feder12=cylinder(frame=pfeil,pos=(0.45,2.95,-0.7),length=0.1,axis=(-80,0,50),radius=0.01)
#feder13=cylinder(frame=pfeil,pos=(0.15,2.95,-0.7),length=0.1,axis=(-80,0,50),radius=0.01)
#feder14=cylinder(frame=pfeil,pos=(0.25,2.95,-0.7),length=0.1,axis=(-80,0,-50),radius=0.01)
#feder15=cylinder(frame=pfeil,pos=(0.35,2.95,-0.7),length=0.1,axis=(-80,0,-50),radius=0.01)
#feder16=cylinder(frame=pfeil,pos=(0.45,2.95,-0.7),length=0.1,axis=(-80,0,-50),radius=0.01)
#Untergrund=box(material=materials.rough, pos=(0,-2.4,0), length=100, height=0.0005, width=100)
ball = sphere(frame=Zielrohr, pos=(0,2.95,-2.7), radius=0.05,color=color.blue)
ausseresZielrohr = cylinder(frame=Zielrohr, pos=(0,2.95,-0.7), axis=(0,0,-1), radius=0.07, length=2, material=materials.wood)
inneresZielrohr = cylinder(frame=Zielrohr, pos=(0,2.95,-0.7), axis=(0,0,-1), radius=0.06, length=2, color=color.black)
Zielscheibe = frame()
nutzlosesDing = sphere(opacity=0, radius=2, pos=(zufallszahlX-0.01, 0, zufallszahlZ-0.01))
Ring1 = cylinder(frame = Zielscheibe, pos=(zufallszahlX-0.04, 0, zufallszahlZ-0.04), length=0.17, radius=0.5, color=color.red)
Ring2 = cylinder(frame = Zielscheibe, pos=(zufallszahlX-0.03, 0, zufallszahlZ-0.03), length=0.15, radius=1)
Ring3 = cylinder(frame = Zielscheibe, pos=(zufallszahlX-0.02, 0, zufallszahlZ-0.02), length=0.13, radius=1.5, color=color.red)
Ring4 = cylinder(frame = Zielscheibe, pos=(zufallszahlX-0.01, 0, zufallszahlZ-0.01), length=0.11, radius=2)
ende=False
drehungpfeil = 0
drehungMensch = 0
dt = 0.01
vGesamt = 10
vY = sin(radians(drehungpfeil))*vGesamt
vEbene = cos(radians(drehungpfeil))*vGesamt
vX = sin(radians(drehungMensch))*vEbene
vZ = cos(radians(drehungMensch))*vEbene
schussAnzahl=2
trefferAnzahl=0
while ende==False:
rate(50)
if schussAnzahl<0:
ende=True
spielendetext = label(frame=ZielrohrundMensch,text='Game over!',pos=(0,3,-5))
spielendetext2 = label(frame=ZielrohrundMensch,text='Sie haben '+str(trefferAnzahl)+'-mal getroffen!',pos=(0,3,Kopf.pos[2]-2.5))
Zielscheibe.rotate(angle=radians(1), axis=(0,1,0), origin=(zufallszahlX, 0, zufallszahlZ))
#Ring1.rotate(angle=radians(1), axis=(0,1,0))
#Ring2.rotate(angle=radians(1), axis=(0,1,0))
#Ring3.rotate(angle=radians(1), axis=(0,1,0))
#Ring4.rotate(angle=radians(1), axis=(0,1,0))
if scene.kb.keys:
s = scene.kb.getkey()
#print s
if s == 'left': # links
ZielrohrundMensch.rotate(angle=radians(3), axis=(0,1,0))
newforward = rotate(scene.forward, axis=(0,1,0), angle=radians(3))
scene.forward=newforward
drehungMensch = drehungMensch -3
elif s == 'right':
ZielrohrundMensch.rotate(angle=radians(-3), axis=(0,1,0))
newforward = rotate(scene.forward, axis=(0,1,0), angle=radians(-3))
scene.forward=newforward
drehungMensch = drehungMensch + 3
elif s == 'up':
if drehungpfeil<=44:
Zielrohr.rotate(angle=radians(2), axis=(Hals.axis), origin=(ausseresZielrohr.pos))
drehungpfeil = drehungpfeil + 2
newforward = rotate(scene.forward, axis=(ZielrohrundMensch.axis), angle=radians(2))
scene.forward=newforward
elif s == 'down':
if drehungpfeil>=0:
Zielrohr.rotate(angle=radians(-2), axis=(Hals.axis), origin=(ausseresZielrohr.pos))
drehungpfeil = drehungpfeil - 2
newforward = rotate(scene.forward, axis=(ZielrohrundMensch.axis), angle=radians(-2))
scene.forward=newforward
elif s == ' ':
schussAnzahl=schussAnzahl-1
i =0
while i<100:
print( mag(Zielscheibe.pos-ball.pos))
vY = vY - 9.81*dt
i= i+1
sleep(0.025)
ball.pos=(ball.pos[0] + vX*dt, ball.pos[1]+vY*dt, ball.pos[2] - vZ*dt)
Zielscheibe.rotate(angle=radians(2), axis=(0,1,0), origin=(zufallszahlX, 0, zufallszahlZ))
if mag(Zielscheibe.pos-ball.pos)<9:
print "getroffen"
trefferAnzahl=trefferAnzahl+1
schussAnzahl=schussAnzahl+1
i=100
ball.pos=(0,2.95,-2.7)
vY=sin(radians(drehungpfeil))*vGesamt
#fast fertig