Last active
May 22, 2024 15:28
-
-
Save horstjens/0f38f0710d1ef4545959dab0b2f6271b to your computer and use it in GitHub Desktop.
linus rogue
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
import random | |
import vpython as vp | |
class Game: | |
scene = vp.canvas(width=1024, | |
height=600, | |
title="linus rogue") | |
fps = 30 | |
dt = 1/fps | |
def create_stuff(): | |
vp.arrow(axis=vp.vector(1,0,0), color=vp.color.red) | |
vp.arrow(axis=vp.vector(0,1,0), color=vp.color.green) | |
vp.arrow(axis=vp.vector(0,0,1), color=vp.color.blue) | |
vp.text(text="Hallo Linus", | |
pos=vp.vector(1,0,0), | |
color=vp.color.green, | |
) | |
def main(): | |
create_stuff() | |
while True: | |
vp.rate(Game.fps) | |
if __name__ == "__main__": | |
main() |
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
import random | |
import vpython as vp | |
level1 = """ | |
####################################### | |
#@....................................# | |
#.....................................# | |
#..................>..................# | |
#.....................................# | |
####################################### | |
""" | |
level2 = """ | |
####################################### | |
#.....................................# | |
#.....................................# | |
#..................<..................# | |
#................................>....# | |
####################################### | |
""" | |
class Game: | |
scene = vp.canvas(width=1024, | |
height=600, | |
title="linus rogue") | |
fps = 30 | |
dt = 1/fps | |
levels = [] | |
player = None | |
def create_level(multi_line_string, y): | |
level = [] | |
lines = [list(line) for line in multi_line_string.splitlines() if len(line.strip()) > 0 ] | |
print(lines) | |
for z, line in enumerate(lines): | |
row = [] | |
for x, char in enumerate(line): | |
match char: | |
case ".": # platte | |
row.append(vp.box(pos=vp.vec(x,y - 0.1 ,z), size=vp.vec(0.9, 0.05, 0.9), color=vp.color.gray(0.4) )) | |
case "#": # wall | |
row.append(vp.box(pos=vp.vec(x,y + 0.5, z), size=vp.vec(0.9,0.9,0.9), color=vp.color.gray(0.6))) | |
case "@": # player | |
Game.player = vp.label(text="@", color=vp.color.yellow,pos=vp.vec(x,y,z),box=False, opacity=0, | |
align="center",height=20) | |
row.append(vp.box(pos=vp.vec(x, y - 0.1, z), size=vp.vec(0.9, 0.05, 0.9), color=vp.color.gray(0.4))) | |
print(z, row) | |
level.append(row) | |
return level | |
def create_stuff(): | |
vp.arrow(axis=vp.vector(1,0,0), color=vp.color.red) | |
vp.arrow(axis=vp.vector(0,1,0), color=vp.color.green) | |
vp.arrow(axis=vp.vector(0,0,1), color=vp.color.blue) | |
#vp.text(text="Hallo Linus", | |
# pos=vp.vector(1,0,0), | |
# color=vp.color.green, | |
# ) | |
Game.levels.append(create_level(level1, 0)) | |
def main(): | |
create_stuff() | |
while True: | |
vp.rate(Game.fps) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment