-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
executable file
·69 lines (55 loc) · 2.19 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python2
import collections
import sys
import pygame
import pygame.locals
import cairo
import numpy
import math
import Image
import graphics
GAME_NAME = 'A Hobo\'s Quest'
class Window(object):
def __init__(self, name = GAME_NAME, size=(800,600)):
# initialize pygame
pygame.init()
self._size = size
self._window = pygame.display.set_mode(size)
pygame.display.set_caption(name)
# data to talk between pygame and cairo
self._data = numpy.empty(size[0] * size[1] * 4, dtype=numpy.int8)
# initialize cairo
self._surface = cairo.ImageSurface.create_for_data(self._data, cairo.FORMAT_ARGB32, size[0], size[1], size[0] * 4)
def run(self, callback):
# test rendering
while True:
ctx = cairo.Context(self._surface)
ctx.set_source_rgb(0, 0, 0)
ctx.paint()
if not callback(ctx, self._size):
pygame.quit()
return
img = Image.frombuffer('RGBA', (self._surface.get_width(),
self._surface.get_height()),
self._surface.get_data(), 'raw', 'BGRA', 0, 1)
img = img.tostring('raw', 'RGBA', 0, 1)
psurf = pygame.image.frombuffer(img, self._size, 'RGBA')
self._window.blit(psurf, (0, 0))
pygame.display.flip()
if __name__ == '__main__':
from stateframe import FrameUpdate, stack
from menuframe import MenuFrame
from boardframe import BoardFrame
def InitGame():
def SetCaffeine(vis):
graphics.CAFFEINE = vis
submenu_list = collections.OrderedDict()
submenu_list['CAFFEINE'] = lambda: SetCaffeine(True)
submenu_list['Sane'] = lambda: SetCaffeine(False)
main_menu_list = {'Start Game':(lambda : BoardFrame()), 'Menu Skin': submenu_list, 'Exit': (lambda : exit(0))}
mainMenu = MenuFrame(main_menu_list, GAME_NAME, fontSizeTitle=50, fontSize=30, displayItems = 4)
stack.append(mainMenu)
sprite = graphics.Sprite('test')
win = Window()
InitGame() #Places the main menu in the stack
win.run(FrameUpdate)