projekt.py
Version 2.0
projekt.py — text/python-source, 2 KB (2960 bytes)
Dateiinhalt
"""Labyrint-mit Hindernissen
Kugel als spielfigur
"""
from visual import *
oberflaeche = frame ()
a=100
b=0.5
c=30
#Grundflaeche und dementsprechend angepasste Aussenwaende
flaeche = box (frame = oberflaeche, pos = (0,0,0),length=(a), high= (b), width= (a), color=color.red)
wand1= box (frame = oberflaeche, pos = (0.5*a-0.5*b,2*b,0),length=(b), width=(a), high=(c))
wand2= box (frame = oberflaeche, pos = (-0.5*a+0.5*b,2*b,0),length=(b), width=(a), high=(c))
wand3= box (frame = oberflaeche, pos = (0,2*b,0.5*a-0.5*b),length=(a), width=(b), high=(c))
wand4= box (frame = oberflaeche, pos = (0,2*b,-0.5*a+0.5*b),length=(a), width=(b), high=(c))
""" if scene.kb.keys:
s = scene.kb.getkey()
print s
if s == 'up': # nach vorne kippen
scene.center = scene.center+scene.forward*mag(scene.center-scene.mouse.camera)
elif s == 'down': # nach hinten kippen
scene.center = scene.center-scene.forward*mag(scene.center-scene.mouse.camera)
elif s == 'ctrl+up': # links kippen
newforward = rotate(scene.forward, axis=scene.up, angle=radians(2))
scene.center = scene.mouse.camera+newforward*mag(scene.center-scene.mouse.camera)
scene.forward = newforward
#scene.center = scene.center+scene.forward*ray.y/2.
elif s == 'alt+up': # rechts kippen
newforward = rotate(scene.forward, axis=scene.up, angle=radians(-2))
scene.center = scene.mouse.camera+newforward*mag(scene.center-scene.mouse.camera)
scene.forward = newforward"""
# Blick auf die Szene
scene.forward=(0,-1,-2)
scene.background=color.white
# Ball mit Geschwindigkeit und repr. Vektorpfeil
ball = sphere(pos=(-a/2,0,a/2), color=color.green, radius=2.5, material=materials.rough, opacity=0.8)
ball.velocity = vector(0, 0, 0)
pfeil = arrow(pos=ball.pos, axis=ball.velocity, color=color.yellow, shaftwidth=0.25)
# Zeit in krement
dt = 0.02
# Endlosschleife
while True:
rate(100)
ball.pos = ball.pos + ball.velocity*dt
# Falls Tastatur gedrueckt...
if scene.kb.keys:
s = scene.kb.getkey()
print s
if s == 'left': # links
ball.velocity.x += -0.1
elif s == 'right': # right
ball.velocity.x += 0.1
elif s == 'up': # vor
ball.velocity.z -= 0.1
elif s == 'down': # zurueck
ball.velocity.z += 0.1
elif s == '0': # zurueck auf Ursprung setzen; Geschw. null; Kamera ran
ball.pos = (-a/2, 0, a/2)
ball.velocity = vector(0,0,0)
scene.range = 3
else:
ball.velocity.y = 10
if ball.y < 1 and ball.velocity.y < 0:
# Reduktion der Geschwindigkeit = Daempfung
ball.velocity.y = -0.65*ball.velocity.y
ball.y = 1
else:
ball.velocity.y = ball.velocity.y - 9.8*dt
pfeil.pos=ball.pos
pfeil.axis=ball.velocity