Menu

[r16]: / main.py  Maximize  Restore  History

Download this file

120 lines (88 with data), 4.4 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
#!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
selection = "START GAME"
global event
def gimmeMain():
global initialPositions
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, 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]
#debug counter:
events = 0
while events < 5:
event = pygame.event.poll()
if event.type != KEYDOWN:
rollMenuAnimation(pointerList)
else:
handle(event, pointerList)
events += 1
return("EXIT GAME")
def handle(event, pointerList): # Java-like event handler
global initialPositions
print initialPositions
print event
if event.dict['key'] == 273:
print 'The pointer should move up now.'
elif event.dict['key'] == 274:
print 'The pointer should move down now'
initialPositions = [[initialPositions[0][0], initialPositions[0][1]+23],
[initialPositions[1][0], initialPositions[1][1]+23]]
screen.blit(background, (22, 0))
rollMenuAnimation(pointerList)
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()