示例#1
0
	def event(self,e):
		if base.SOUND:
			if base.PLAYING_MENU_MUSIC == False:
				for item in music.Music:
					music.Stop(item)
				music.Play("MenuMusic")
				base.PLAYING_MENU_MUSIC = True
##		gameVariables = self.main.gameVariables
		
		if e.type is KEYDOWN and e.key == K_UP:
			self.cur = (self.cur-1+len(self.menu))%len(self.menu)
			self.repaint()
		if e.type is KEYDOWN and e.key == K_DOWN:
			self.cur = (self.cur+1+len(self.menu))%len(self.menu)
			self.repaint()
			
		if e.type is MOUSEMOTION:
			for n,rect in self.zones:
				if rect.collidepoint(e.pos):
					if self.cur != n:
						self.cur = n
						self.repaint()
						
##		ToDo: Finish Joystick movement settings
##		if e.type is JOYAXISMOTION: and e.key == K_UP:
##			self.cur = (self.cur-1+len(self.menu))%len(self.menu)
##			self.repaint()
##		if e.type is JOYAXISMOTION: and e.key == K_DOWN:
##			self.cur = (self.cur+1+len(self.menu))%len(self.menu)
##			self.repaint()
			
		if (e.type is KEYDOWN and e.key in (K_RETURN,K_ESCAPE)) or (e.type is MOUSEBUTTONDOWN) or (e.type is  JOYBUTTONDOWN):
			val = self.menu[self.cur]
			if e.type is KEYDOWN and e.key == K_ESCAPE:
				return engine.Quit(self.main)
				
			if val == "continue game":
				base.PLAYING_MENU_MUSIC = False
##				return Loading(self.main)
				import game
				return game.Game(self.main)
			
			if val == "credits":
				return Credits(self.main)

			if val == "start a new game":
				base.PLAYING_MENU_MUSIC = False
				return SetDifficulty(self.main)
			if val == "quit":
				return engine.Quit(self.main)

			if val == "about":
				return About(self.main)
			
			if val == "help":
				return Help(self.main)
			
			if val == "options":
				return Options(self.main)
示例#2
0
 def event(self, e):
     if (len(self.displaybuffer) > 1):
         if e.type is KEYDOWN:
             if e.key == K_ESCAPE:
                 return engine.Quit(self.game)
             if e.key == K_SPACE or e.key == K_RETURN:
                 return playscreen(self.game, self.sounds, self.mixer, 1, 0)
示例#3
0
	def __init__(self,game,value):
		self.game = game
		
		self.cur = 0
		self.options = [
			("Play < $l >",level.Level(self.game,None)),
			("High Scores",HighScores(self.game,None)),
			("Help",Help(self.game,None)),
			("Quit",engine.Quit(self.game,None)),
			]
示例#4
0
文件: main.py 项目: illume/zanthor
    def event(self, e):
        # Android-specific:
        if android:
            if android.check_pause():
                android.wait_for_resume()

        #capture special events on a top level,
        #should only be used for screen shots, forced quits,
        #magic cheat buttons, etc... debug keys and the like ...
        if e.type is QUIT:
            self.state = engine.Quit(self)
            return 1
 def event(self, e):
     if e.type is USEREVENT and e.action == 'down':
         self.cur = (self.cur + 1) % len(self.items)
         self.repaint()
     elif e.type is USEREVENT and e.action == 'up':
         self.cur = (self.cur - 1 + len(self.items)) % len(self.items)
         self.repaint()
     elif e.type is USEREVENT and e.action == 'left':
         self.game.lcur = (self.game.lcur - 1 + len(self.levels)) % len(
             self.levels)
         self.cur = 1
         self.repaint()
     elif e.type is USEREVENT and e.action == 'right':
         self.game.lcur = (self.game.lcur + 1) % len(self.levels)
         self.cur = 1
         self.repaint()
     elif e.type is USEREVENT and e.action == 'exit':
         return engine.Quit(self.game)
     elif e.type is USEREVENT and (e.action == 'menu'
                                   or e.action == 'jump'):
         text, value = self.items[self.cur]
         if value == 'start':
             self.game.init_play()
             self.game.lcur = 0
             import level
             l = level.Level(self.game, None, self)
             return Transition(self.game, l)
         elif value == 'play':
             self.game.init_play()
             import level
             l = level.Level(self.game, None, self)
             return Transition(self.game, l)
         elif value == 'quit':
             return engine.Quit(self.game)
         elif value == 'credits':
             return Transition(self.game, Credits(self.game, self))
         elif value == 'help':
             return Transition(self.game, Help(self.game, self))
     elif e.type is KEYDOWN and e.key == K_d:
         self.debug_mode()
示例#6
0
    def event(self, e):
        if e.type is QUIT:
            self.state = engine.Quit(self)
            return 1

        if e.type is KEYDOWN:
            if e.key == K_F2:
                if base.SOUND:
                    pygame.mixer.quit()
                    base.SOUND = False
                else:
                    pygame.mixer.init()
                    base.SOUND = True
                return 1
示例#7
0
 def event(self, e):
     if e.type is QUIT:
         self.state = engine.Quit(self)
         return 1
     if e.type is KEYDOWN and e.key == K_F10:
         pygame.display.toggle_fullscreen()
         return 1
     if e.type is KEYDOWN and e.key == K_F12:  #screen shots
         self.state = states.Pause(self, ("", self.state))
         return 1
     if e.type is KEYDOWN and e.key == K_F2:
         if self.audio:
             self.music ^= 1
             pygame.mixer.music.set_volume(self.music)
示例#8
0
def main():
    # print "Hello from your game's main()"
    # print data.load('sample.txt').read()

    fname = None  # data.filepath(os.path.join('levels','test.tga'))
    for v in sys.argv:
        if '.tga' in v:
            fname = v

    g = Game()
    import menu
    l = l2 = menu.Menu(g)
    # l = menu.Intro(g,l2)
    if fname is not None:
        import level
        l = level.Level(g, fname, engine.Quit(g))

    g.run(l)
    pygame.quit()
示例#9
0
    def event(self, e):
        # The keys, buttons and axis for the input can be changed in cnst.py

        self.random += 1 + self.random % 100  # this will generate pseudo random numbers

        event = None
        action = None
        if (e.type == KEYDOWN and e.key in JUMP_KEYS) or \
           (e.type == JOYBUTTONDOWN and e.button in JUMP_BUTTONS):
            action = 'jump'
        elif (e.type == KEYUP and e.key in JUMP_KEYS) or \
             (e.type == JOYBUTTONUP and e.button in JUMP_BUTTONS):
            action = 'stop-jump'
        elif e.type == KEYDOWN and e.key in BUBBLE_KEYS or \
                (e.type == JOYBUTTONDOWN and e.button in BUBBLE_BUTTONS):
            action = 'bubble'
        elif e.type == KEYDOWN or e.type == KEYUP:
            if e.type == KEYDOWN:
                value = True
            else:
                value = False
            if e.key in LEFT_KEYS:
                self.input.left = value
                if value:
                    self.input.right = False
                action = 'left'
            if e.key in RIGHT_KEYS:
                self.input.right = value
                if value:
                    self.input.left = False
                action = 'right'
            if e.key in UP_KEYS:
                self.input.up = value
                if value:
                    self.input.down = False
                action = 'up'
            if e.key in DOWN_KEYS:
                self.input.down = value
                if value:
                    self.input.up = False
                action = 'down'
            if e.type == KEYUP:
                action = None
        elif e.type == JOYAXISMOTION:
            if e.axis in HORIZONTAL_AXIS:
                if e.value < -0.6:
                    action = 'left'
                    self.input.left = True
                if e.value > -0.4:
                    self.input.left = False
                if e.value > 0.6:
                    action = 'right'
                    self.input.right = True
                if e.value < 0.4:
                    self.input.right = False
            if e.axis in VERTICAL_AXIS:
                if e.value < -0.6:
                    action = 'up'
                    self.input.up = True
                if e.value > -0.4:
                    self.input.up = False
                if e.value > 0.6:
                    action = 'down'
                    self.input.down = True
                if e.value < 0.4:
                    self.input.down = False
        if e.type is KEYDOWN and e.key in EXIT_KEYS:
            action = 'exit'
        elif e.type is JOYBUTTONDOWN and e.button in EXIT_BUTTONS:
            action = 'exit'
        elif e.type is KEYDOWN and e.key in MENU_KEYS:
            action = 'menu'
        elif e.type is JOYBUTTONDOWN and e.button in MENU_BUTTONS:
            action = 'menu'

        if action is not None:
            event = pygame.event.Event(USEREVENT, action=action)

            self.fnc('event', event)
            return True

        if e.type is QUIT:
            self.state = engine.Quit(self)
            return 1

        # if e.type is KEYDOWN and e.key == K_ESCAPE:
        # self.state = engine.Quit(self)
        # return 1

        if e.type is KEYDOWN and e.key == K_F4:  # K_F12:

            try:
                dname = '.'
                if not os.path.exists(dname):
                    return
            except:
                return
            try:
                n = 1
                while n < 1000:
                    fname = os.path.join(dname, 'shot%03d.bmp' % n)
                    if not os.path.exists(fname):
                        break
                    n += 1
                self.flip()
                pygame.image.save(self._screen, fname)
                return 1
            except:
                pass
 def _init_state_machine(self):
     self.menu_state = Menu(self)
     self.playervsCPU_state = play_vsCPU.PlayerVSCPU(self)
     self.playervsplayer_state = play_pvp.PlayerVSPlayer(self)
     self.result_state = Result(self)
     self.quit_state = engine.Quit(self)
示例#11
0
 def event(self, e):
     if e.type is KEYDOWN and not self.regiondrawing:
         if (self.tagedit):
             if e.key == K_RETURN:
                 self.tagedit = False
             elif (e.key == K_BACKSPACE):
                 self.tagname = self.tagname[:len(self.tagname) - 1]
             elif (e.key >= 32 and e.key <= 125):
                 self.tagname = self.tagname + chr(e.key)
         elif (self.paletteedit):
             if e.key == K_RETURN:
                 self.paletteedit = False
         elif (self.attributeeditkey):
             if e.key == K_RETURN:
                 self.attributeeditkey = False
                 self.attributeeditvalue = True
             elif (e.key == K_DELETE):
                 self.attributeeditkey = False
                 self.attributeeditvalue = False
                 del self.attributetag.attributes[self.attributekey]
             elif (e.key == K_BACKSPACE):
                 self.attributekey = self.attributekey[:len(self.
                                                            attributekey) -
                                                       1]
             elif (e.key >= 32 and e.key <= 125):
                 self.attributekey = self.attributekey + chr(e.key)
         elif (self.attributeeditvalue):
             if e.key == K_RETURN:
                 self.attributeeditvalue = False
                 self.attributetag.attributes[
                     self.attributekey] = self.attributevalue
             elif (e.key == K_BACKSPACE):
                 self.attributevalue = self.attributevalue[:len(
                     self.attributevalue) - 1]
             elif (e.key == K_SLASH):
                 self.attributevalue = self.attributevalue + "?"
             elif (e.key >= 32 and e.key <= 125):
                 if (pygame.key.get_mods() & pygame.KMOD_SHIFT):
                     self.attributevalue = self.attributevalue + upper(
                         chr(e.key))
                 else:
                     self.attributevalue = self.attributevalue + chr(e.key)
         elif (self.attributeedit):
             if (e.key == K_RETURN):
                 self.attributeedit = False
                 self.attributetag = None
         else:
             if e.key == K_t:
                 self.tagedit = True
                 self.tagname = ""
             elif e.key == K_l:
                 for i in self.regiontags:
                     i.togglefont()
                 for i in self.pointtags:
                     i.togglefont()
                 self.fontshown = not (self.fontshown)
             elif e.key == K_F2:
                 self.hidepointlayer = not (self.hidepointlayer)
             elif e.key == K_TAB:
                 self.paletteedit = True
             elif e.key == K_m:
                 self.editmode += 1
                 if (self.editmode > MODE_ATTRIBUTES):
                     self.editmode = MODE_REGION
             elif e.key == K_s:
                 self.savelevel(self.filename)
             elif e.key == K_UP:
                 self.movingup = True
                 self.movingdown = False
             elif e.key == K_DOWN:
                 self.movingdown = True
                 self.movingup = False
             elif e.key == K_LEFT:
                 self.movingleft = True
                 self.movingright = False
             elif e.key == K_RIGHT:
                 self.movingright = True
                 self.movingleft = False
             elif e.key == K_ESCAPE:
                 self.savelevel(self.filename)
                 return engine.Quit(self.game)
     elif e.type is KEYUP:
         if e.key == K_UP:
             self.movingup = False
         elif e.key == K_DOWN:
             self.movingdown = False
         elif e.key == K_LEFT:
             self.movingleft = False
         elif e.key == K_RIGHT:
             self.movingright = False
     elif e.type == MOUSEBUTTONDOWN:
         button1, button2, button3 = pygame.mouse.get_pressed()
         if button1:
             if (self.regiondrawing):
                 self.regiondrawing = False
                 (rectleft, recttop) = self.regionstart
                 (rectright, rectbottom) = pygame.mouse.get_pos()
                 rectright = int(rectright / 16) * 16
                 rectbottom = int(rectbottom / 16) * 16
                 regionrect = pygame.Rect(
                     (rectleft, recttop, -rectleft + rectright,
                      -recttop + rectbottom))
                 if (-recttop + rectbottom != 0
                         and -rectleft + rectright != 0):
                     self.regiontags.append(
                         regiontag(regionrect, self.tagname,
                                   IMAGE_FILES[self.tagname], self.font, {},
                                   self.fontshown))
                     self.regiontaggroup.add(self.regiontags[-1])
             elif (self.paletteedit):
                 self.paletteedit = False
                 x, y = pygame.mouse.get_pos()
                 index = int(x / 32) + 16 * int(y / 16)
                 i = 0
                 for key, value in IMAGE_FILES.items():
                     if (REGION_NODES.count(key)):
                         if (i == index):
                             self.tagname = key
                         i += 1
             elif (self.editmode == MODE_REGION):
                 self.regiondrawing = True
                 x, y = pygame.mouse.get_pos()
                 self.regionstart = (int(x / 16) * 16, int(y / 16) * 16)
             elif (self.editmode == MODE_POINT):
                 x, y = pygame.mouse.get_pos()
                 self.pointtags.append(
                     pointtag(
                         int(x / 16) * 16,
                         int(y / 16) * 16, self.tagname,
                         IMAGE_FILES[self.tagname], self.font, {},
                         self.fontshown))
                 self.pointtaggroup.add(self.pointtags[-1])
             elif (self.editmode == MODE_DELETE):
                 self.delete()
             elif (self.attributeedit):
                 (x, y) = pygame.mouse.get_pos()
                 self.attributenumber = int(y / 16)
                 self.attributeeditkey = True
                 self.attributeeditvalue = False
                 i = 0
                 foundkey = False
                 for key in self.attributetag.attributes.keys():
                     if (i == self.attributenumber):
                         self.attributekey = key
                         self.attributevalue = self.attributetag.attributes[
                             key]
                         foundkey = True
                     i += 1
                 if (not (foundkey)):
                     self.attributekey = ""
                     self.attributevalue = ""
             elif (self.editmode == MODE_ATTRIBUTES):
                 self.showattributes()