Select Git revision
Dashboard.java
-
Shubham Maheshwari authoredShubham Maheshwari authored
cse16238_lab4.py 1.45 KiB
from vpython import *
#GlowScript 2.7 VPython
ball = sphere(pos=vector(-5,0,0), radius=0.5, color=color.cyan, make_trail=True)
wallR = box(pos=vector(6,0,0), size=vector(0.2,12,12), color=color.green)
wallL = box(pos=vector(-6,0,0), size=vector(0.2,12,12), color=color.green)
wallT = box(pos=vector(0,6,0), size=vector(12,0.2,12), color=color.blue)
wallB = box(pos=vector(0,-6,0), size=vector(12,0.2,12), color=color.blue)
wallBa = box(pos=vector(0,0,-6), size=vector(12,12,0.2), color=color.red)
ball.velocity = vector(5,5,0)
deltat = 0.005
t = 0
#ball.pos = ball.pos + ball.velocity*deltat
vscale = 0.1
varr = arrow(pos=ball.pos, axis=vscale*ball.velocity, color=color.yellow)
while t >= 0:
rate(100)
if ball.pos.x > wallR.pos.x or ball.pos.x < wallL.pos.x:
# ball.velocity.x = -ball.velocity.x
print("game over")
break
if ball.pos.y > wallT.pos.y or ball.pos.y < wallB.pos.y:
#ball.velocity.y = -ball.velocity.y
print("game over")
break
if ball.pos.z < wallBa.pos.z:
#ball.velocity.z = -ball.velocity.z
#ball.pos = ball.pos + ball.velocity*deltat
varr.pos = ball.pos
varr.axis = vscale*ball.velocity
t=t+deltat
def onpress(event):
s=event.key
if s='up':
ball.velocity.y+=1
else if s='down':
ball.velocity.y-=1
else if s='left':
ball.velocity.x-=1
else if s='right':
ball.velocity.x+=1
scene.bind('keydown',onpress)