added options screen with resolution-changer widget
--HG-- branch : vssg
This commit is contained in:
parent
88a70248b3
commit
e0f1909b56
2 changed files with 142 additions and 40 deletions
|
@ -12,4 +12,6 @@ button.topleft = (10, 10)
|
|||
re.add_widget (button)
|
||||
|
||||
# Start the main rendering loop.
|
||||
re.start()
|
||||
|
||||
re.start()
|
180
vssg.py
180
vssg.py
|
@ -8,6 +8,9 @@ import math
|
|||
import random
|
||||
import starmap
|
||||
import starmap_gen
|
||||
from ocempgui.widgets import *
|
||||
from ocempgui.widgets.Constants import *
|
||||
|
||||
|
||||
pygame.init()
|
||||
|
||||
|
@ -58,15 +61,147 @@ bounce = True
|
|||
speed_player = 5.0
|
||||
trails = False
|
||||
|
||||
scr.fill((0,0,0))
|
||||
#scr.fill((0,0,0))
|
||||
|
||||
keys = []
|
||||
do_quit = False
|
||||
|
||||
map = starmap_gen.starmap_generate()
|
||||
map = None
|
||||
pygame.event.set_allowed((KEYDOWN, KEYUP, QUIT))
|
||||
|
||||
|
||||
sg = False
|
||||
def btn_start_game():
|
||||
global guiscreen, map
|
||||
guiscreen = None
|
||||
map = starmap_gen.starmap_generate()
|
||||
|
||||
def btn_quit_game():
|
||||
pygame.event.post(pygame.event.Event(QUIT, {}))
|
||||
def btn_game_options():
|
||||
global guiscreen
|
||||
guiscreen = screen_options()
|
||||
|
||||
def screen_mainmenu():
|
||||
re = Renderer()
|
||||
re.screen = scr
|
||||
re.title = "vssg 0.1 - Very Simple Space Game"
|
||||
re.color = (40,0,70)
|
||||
|
||||
b_start = Button("Start Game")
|
||||
b_options = Button("Options")
|
||||
b_quit = Button("Quit")
|
||||
blist = [b_start, b_options, b_quit]
|
||||
totheight = (b_start.height * len(blist)) + (5 * (len(blist) - 1))
|
||||
maxwidth = 0
|
||||
for button in blist:
|
||||
if maxwidth == None or button.width > maxwidth:
|
||||
maxwidth = button.width
|
||||
b_start.connect_signal(SIG_CLICKED, btn_start_game)
|
||||
b_quit.connect_signal(SIG_CLICKED, btn_quit_game)
|
||||
b_options.connect_signal(SIG_CLICKED, btn_game_options)
|
||||
|
||||
for i, button in enumerate(blist):
|
||||
x = scr.get_rect().w / 2
|
||||
y = scr.get_rect().h / 2
|
||||
y = y - (totheight / 2) + (b_start.height / 2)
|
||||
y = y + (i * 5) + (i * b_start.height)
|
||||
button.set_minimum_size(maxwidth, b_start.height)
|
||||
button.center = (x, y)
|
||||
re.add_widget(button)
|
||||
|
||||
return re
|
||||
|
||||
def screen_options():
|
||||
def slider_set_resolution():
|
||||
global resolution_list, s_res, l_res
|
||||
new_res = resolution_list[int(s_res.value)]
|
||||
l_res.set_text("%s x %s" % (new_res[0], new_res[1]))
|
||||
def btn_ok():
|
||||
global guiscreen, s_res, resolution_list, scr
|
||||
guiscreen = None
|
||||
new_res = resolution_list[int(s_res.value)]
|
||||
scr = pygame.display.set_mode(new_res)
|
||||
guiscreen = screen_mainmenu()
|
||||
|
||||
def btn_apply():
|
||||
global s_res, resolution_list, scr, guiscreen
|
||||
guiscreen = None
|
||||
new_res = resolution_list[int(s_res.value)]
|
||||
scr = pygame.display.set_mode(new_res)
|
||||
guiscreen = screen_options()
|
||||
|
||||
def btn_cancel():
|
||||
global guiscreen
|
||||
guiscreen = screen_mainmenu()
|
||||
|
||||
def set_resolution():
|
||||
global guiscreen
|
||||
|
||||
|
||||
global resolution_list, l_res, s_res
|
||||
re = Renderer()
|
||||
re.screen = scr
|
||||
re.color = (40,0,70)
|
||||
optframe = VFrame()
|
||||
optframe.spacing = 10
|
||||
|
||||
resolution_list = pygame.display.list_modes()
|
||||
resolution_list.reverse()
|
||||
cur_res = (scr.get_rect().w, scr.get_rect().h)
|
||||
try:
|
||||
cur_res_idx = resolution_list.index(cur_res)
|
||||
except ValueError:
|
||||
cur_res_idx = None
|
||||
|
||||
s_res = HScale(0, len(resolution_list) - 1)
|
||||
s_res.set_minimum_size(300, s_res.size[1])
|
||||
#s_res.center = (cur_res[0] / 2, (cur_res[1] / 2) - (s_res.size[1] / 2) - 2)
|
||||
if cur_res_idx != None:
|
||||
s_res.value = cur_res_idx
|
||||
s_res.connect_signal(SIG_VALCHANGED, slider_set_resolution)
|
||||
l_res = Label("%s x %s" % (cur_res[0], cur_res[1]))
|
||||
#l_res.center = (cur_res[0] / 2, (cur_res[1] / 2) + (l_res.size[1] / 2) + 2)
|
||||
optframe.add_child(s_res)
|
||||
optframe.add_child(l_res)
|
||||
|
||||
|
||||
btnframe = HFrame()
|
||||
btnframe.border = BORDER_NONE
|
||||
btnframe.spacing = 5
|
||||
b_ok = Button("OK")
|
||||
b_apply = Button("Apply")
|
||||
b_cancel = Button("Cancel")
|
||||
b_ok.connect_signal(SIG_CLICKED, btn_ok)
|
||||
b_apply.connect_signal(SIG_CLICKED, btn_apply)
|
||||
b_cancel.connect_signal(SIG_CLICKED, btn_cancel)
|
||||
btnframe.add_child(b_ok)
|
||||
btnframe.add_child(b_apply)
|
||||
btnframe.add_child(b_cancel)
|
||||
optframe.add_child(btnframe)
|
||||
|
||||
optframe.center = (cur_res[0] / 2, cur_res[1] / 2)
|
||||
re.add_widget(optframe)
|
||||
return re
|
||||
|
||||
|
||||
guiscreen = screen_mainmenu()
|
||||
|
||||
while True:
|
||||
events = pygame.event.get((KEYDOWN, KEYUP, QUIT))
|
||||
events = pygame.event.get()
|
||||
|
||||
if guiscreen != None:
|
||||
for ev in events:
|
||||
if ev.type == QUIT:
|
||||
do_quit = True
|
||||
break
|
||||
if do_quit:
|
||||
break
|
||||
guiscreen.distribute_events(*events)
|
||||
continue
|
||||
scr.fill((0,0,0))
|
||||
|
||||
|
||||
for ev in events:
|
||||
if ev.type == QUIT:
|
||||
do_quit = True
|
||||
|
@ -76,49 +211,14 @@ while True:
|
|||
del keys[keys.index(ev.key)]
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
elif ev.type == KEYDOWN:
|
||||
keys += [ev.key]
|
||||
|
||||
if do_quit:
|
||||
break
|
||||
|
||||
handle_keys(keys)
|
||||
pygame.event.pump()
|
||||
"""
|
||||
loc_new = move(loc_player, dir_player, speed_player)
|
||||
|
||||
if loc_new[0] < 5:
|
||||
if not bounce:
|
||||
loc_new[0] = width-6
|
||||
else:
|
||||
dir_player = bouncedir(math.pi*0.5, dir_player)
|
||||
elif loc_new[1] < 5:
|
||||
if not bounce:
|
||||
loc_new[1] = height-6
|
||||
else:
|
||||
dir_player = bouncedir(math.pi, dir_player)
|
||||
elif loc_new[0] > width - 5:
|
||||
if not bounce:
|
||||
loc_new[0] = 6
|
||||
else:
|
||||
dir_player = bouncedir(math.pi*1.5, dir_player)
|
||||
elif loc_new[1] > height - 5:
|
||||
if not bounce:
|
||||
loc_new[1] = 6
|
||||
else:
|
||||
dir_player = bouncedir(0, dir_player)
|
||||
|
||||
if bounce:
|
||||
loc_new = move(loc_player, dir_player, speed_player)
|
||||
|
||||
if not trails:
|
||||
pygame.draw.circle(scr, (0,0,0), loc_player, 2, 1)
|
||||
pygame.draw.circle(scr, color_player, loc_new, 2, 1)
|
||||
handle_keys(keys)
|
||||
|
||||
|
||||
loc_player = loc_new
|
||||
"""
|
||||
|
||||
for star in map.get_all_stars():
|
||||
star.draw(scr)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue