Menu

[r17]: / main.py  Maximize  Restore  History

Download this file

157 lines (119 with data), 6.5 kB

  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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!usr/bin/env/ python
#
# Filename : main.py
# Author : Juhana Kammonen for JukiWeb Merseine
# Purpose : MitoBlaster v0.1 main program file
import sys, pygame # brings on your system and your pygame module
import os.path # imports your operational system path
from pygame.locals import *
from sprites import * # import all sprites to the main file
selections = ["START", "OPTIONS", "STORY", "EXIT GAME"]
slct = 0 #idx of selection state
selection = selections[slct]
slct_changed = False
global event
def gimmeMain():
global initialPositions, selections, slct, slct_changed
nonePressed = True
if pygame.mixer:
pygame.mixer.set_num_channels(1)
music = pygame.mixer.Sound('data/main.ogg')
music.play(-1)
newFont = pygame.font.Font('data/font/DOWN.TTF', 12)
startText = newFont.render("START GAME", 1, (152, 251, 152))
optionsText = newFont.render("OPTIONS", 1, (152, 251, 152))
storyText = newFont.render("STORY", 1, (152, 251, 152))
exitText = newFont.render("EXIT GAME", 1, (152, 251, 152))
startTextPos = startText.get_rect(centerx=background.get_width()/2, centery=background.get_width()/2)
optionsTextPos = optionsText.get_rect(centerx=background.get_width()/2, centery=background.get_width()/2 + 25)
storyTextPos = storyText.get_rect(centerx=background.get_width()/2, centery=(background.get_width()/2 + 50))
exitTextPos = storyText.get_rect(centerx=(background.get_width()/2)-16, centery=(background.get_width()/2 + 75))
background.blit(startText, startTextPos)
background.blit(optionsText, optionsTextPos)
background.blit(storyText, storyTextPos)
background.blit(exitText, exitTextPos)
pointerL = PointerL(initialPositions[0]) # left pointer with start position at "START GAME"
pointerR = PointerR(initialPositions[1]) # right pointer with start position at "START GAME"
screen.blit(background, (22, 0))
screen.blit(pointerL.image, pointerL.rect)
screen.blit(pointerR.image, pointerR.rect)
pygame.display.flip()
pointerList = [pointerL, pointerR]
while selection != "EXIT GAME":
event = pygame.event.poll()
if event.type != KEYDOWN:
rollMenuAnimation(pointerList)
else:
handle(event, pointerList)
# music change test (WORKS!)
if slct_changed == True:
if selection == "OPTIONS":
if pygame.mixer:
music.stop()
music = pygame.mixer.Sound('data/level_one.ogg')
music.play(-1)
slct_changed = False
return("EXIT GAME")
def handle(event, pointerList): # event handler
global initialPositions, selection, slct, slct_changed
print initialPositions
print event
if event.dict['key'] == 273:
print 'The pointer should move up now.'
if (slct-1 < 0): # set pointers downmost
slct = 3
initialPositions = [[initialPositions[0][0], initialPositions[0][1]+(3*26)],
[initialPositions[1][0], initialPositions[1][1]+(3*26)]]
screen.blit(background, (22, 0))
rollMenuAnimation(pointerList)
else:
slct -= 1
initialPositions = [[initialPositions[0][0], initialPositions[0][1]-26],
[initialPositions[1][0], initialPositions[1][1]-26]]
screen.blit(background, (22, 0))
rollMenuAnimation(pointerList)
elif event.dict['key'] == 274:
print 'The pointer should move down now'
if (slct+1 >= len(selections)): # return pointers upmost
slct = 0
initialPositions = [[initialPositions[0][0], initialPositions[0][1]-(3*26)],
[initialPositions[1][0], initialPositions[1][1]-(3*26)]]
screen.blit(background, (22, 0))
rollMenuAnimation(pointerList)
else:
slct += 1
initialPositions = [[initialPositions[0][0], initialPositions[0][1]+26],
[initialPositions[1][0], initialPositions[1][1]+26]]
screen.blit(background, (22, 0))
rollMenuAnimation(pointerList)
elif event.dict['key'] == 13: # return key pressed
selection = selections[slct]
slct_changed = True
else:
print 'The key was irrelevant.'
def rollMenuAnimation(pointerList):
global initialPositions
time = pygame.time.get_ticks()
for i, pointer in enumerate(pointerList):
pointer.update(time, initialPositions[i])
screen.blit(pointer.image, pointer.rect)
pygame.display.flip()
return True
pygame.init() # initialize the pygame module
size = width, height = 600, 600
screen = pygame.display.set_mode(size)
pygame.display.set_caption('MitoBlaster v0.1')
background = pygame.image.load('data/main_screen.png')
background = background.convert()
if pygame.font:
font = pygame.font.Font('data/font/DOWN.TTF', 24)
text = font.render("MitoBlaster", 1, (152, 251, 152))
textpos = text.get_rect(centerx=background.get_width()/2, centery=background.get_width()/3)
background.blit(text, textpos)
screen.blit(background, (22, 0))
pygame.display.flip()
initialPositions = [[background.get_width()/2 - 75, background.get_width()/2 - 19],
[background.get_width()/2 + 120, background.get_width()/2 - 19]]
while selection != "EXIT GAME":
selection = gimmeMain()
sys.exit()