menu - VPython startMenu -
my main program bloxorz-type program working fine. issue have having implement system game shows message on screen if block falls off map, , gamefinished message on screen when block hits hole vertically. i'm thinking way work match coordinates of hole , if coordinates of hole match square-bases of block, show message. first real issue being able display startmenu message, display "press s start" , "press q quit". know how use scene.kb.getkey(), problem displaying text on screen, implement main while true loop. here code:
from __future__ import division, print_function visual import * import math, sys visual.graph import * sys import exit """necessary python libraries""" # top, left, bottom, right, front, tlbrfb = ( 2.0, -0.5, 0.0, 0.5, 0.5, -0.5 ) #the area block covers (dimensions) top = 0 left = 1 bottom = 2 right = 3 front = 4 = 5 """modules defining movement of block""" def moveright(): global tlbrfb r in range(0, 9): rate(30) block.rotate( angle = pi/18, axis = vector( 0, 0, -1), origin = vector(tlbrfb[right], 0, 0) ) #pi/18 = 10degrees, tlbrfb = (tlbrfb[right]-tlbrfb[left], tlbrfb[right], 0, tlbrfb[right]+tlbrfb[top], tlbrfb[front], tlbrfb[back]) #update block's state of stance def movedown(): global tlbrfb r in range(0, 9): rate(30) block.rotate( angle = pi/18, axis = vector( +1, 0, 0), origin = vector(0, 0, tlbrfb[front]) ) tlbrfb = (tlbrfb[front]-tlbrfb[back], tlbrfb[left], 0, tlbrfb[right], tlbrfb[front]+tlbrfb[top], tlbrfb[front]) def moveleft(): global tlbrfb r in range(0, 9): rate(30) block.rotate( angle = pi/18, axis = vector( 0, 0, +1), origin = vector(tlbrfb[left], 0, 0) ) tlbrfb = (tlbrfb[right]-tlbrfb[left], tlbrfb[left]-tlbrfb[top], 0, tlbrfb[left], tlbrfb[front], tlbrfb[back] ) def moveup(): global tlbrfb r in range(0, 9): rate(30) block.rotate( angle = pi/18, axis = vector( -1, 0, 0), origin = vector(0, 0, tlbrfb[back]) ) tlbrfb = (tlbrfb[front]-tlbrfb[back], tlbrfb[left], 0, tlbrfb[right], tlbrfb[back], tlbrfb[back]-tlbrfb[top]) level1 = [ #array on tile placement [1,1,1,0,0,0,0,0,0,0], [1,1,1,1,1,0,0,0,0,0], [1,1,1,1,1,1,1,1,1,0], [0,0,0,0,0,1,1,0,1,1], [0,0,0,0,0,0,1,1,1,0] ] def draw_level(array): y in range(0, len(array)): x in range(0, len(array[y])): if array[y][x] == 1: box( pos=vector(x, -0.1, y), length=0.9, width = 0.9, height = 0.2, color = vector(0.9, 0.8, 0.8)) block = box( pos=vector(0,1,0), length = 1, width = 1, height = 2, color = vector(0.9, 0.9, 0.5)) def handle_events(): key = scene.kb.getkey() if key =="up": moveup() elif key =="down": movedown() elif key == "left": moveleft() elif key == "right": moveright() elif key == "q": quit() elif key == "escape": quit() def maingameloop(): while true: scene.center = vector(4.5, 0, 2) scene.forward = scene.center - vector(2, 6, 10) scene.background = vector(0.57, 0.2, 0.2) draw_level(level1) #draw mapout handle_events() while true: maingameloop() handle_events() print(block.pos)
Comments
Post a Comment