Created
October 28, 2023 09:35
-
-
Save horstjens/1540fec5f37cc2f761fa052eedbe2e1d to your computer and use it in GitHub Desktop.
surfer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gist.github.com/horstjens | |
import vpython as vp | |
import random | |
class Game: | |
dt = 0.1 | |
xlimit = 20 | |
ylimit = 10 | |
ball = vp.sphere(color=vp.color.blue) | |
def f(): | |
return 1*Game.ball.pos | |
for z in range(-1000,0,25): | |
for x in range(0, Game.xlimit+1, 5): | |
for y in range(0, Game.ylimit+1,5): | |
if random.random() < 0.8: | |
vp.box(pos=vp.vector(x,y,z), | |
size=vp.vector(3,3,1)) | |
Game.ball.speed = 1.4 | |
# | |
vp.scene.camera.follow(f) | |
#vp.scene.camera.follow(Game.ball) | |
vp.scene.autoscaling = False | |
while True: | |
Game.ball.move = vp.vector(0,0,-2) # | |
vp.rate(30) | |
keys = vp.keysdown() | |
if "w" in keys: | |
Game.ball.move.y = Game.ball.speed | |
if "s" in keys: | |
Game.ball.move.y = -Game.ball.speed | |
if "a" in keys: | |
Game.ball.move.x = -Game.ball.speed # | |
if "d" in keys: | |
Game.ball.move.x = Game.ball.speed # | |
Game.ball.pos += Game.ball.move * Game.dt | |
#ball.move *= 0.999 | |
if Game.ball.pos.x < 0: | |
Game.ball.pos.x = 0 | |
if Game.ball.pos.y < 0: | |
Game.ball.pos.y = 0 | |
if Game.ball.pos.x > Game.xlimit: | |
Game.ball.pos.x = Game.xlimit | |
if Game.ball.pos.y > Game.ylimit: | |
Game.ball.pos.y = Game.ylimit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment