Exemple #1
0
    def _start_main_menu(self):
        """Add everything to the main menu. Called after the title drops.

        The main menu animation and proper main menu could be two seperate scenes.
        """
        audio.play_music(constants.MUSIC_DUNGEON)
        options = ["New game", "Settings", "Exit"]
        if self.game.has_save():
            options.insert(0, "Continue game")
        pos = (self.game.width // 2, self.game.height // 2)
        option_select = self.add_child_scene(OptionSelect, options, pos)
        self.game.set_focus(option_select)
        option_select.connect_signal("selected", self.selected_option)

        # Help text
        self.widgets = (wgt.Text(renderer=self.game.renderer,
                                 offset=(5 * constants.MENU_SCALE,
                                         5 * constants.MENU_SCALE),
                                 size=5 * constants.MENU_SCALE,
                                 color=constants.LIGHT_GRAY,
                                 text="CONTROLS"),
                        wgt.TextLines(
                            renderer=self.game.renderer,
                            offset=(5 * constants.MENU_SCALE,
                                    16 * constants.MENU_SCALE),
                            size=5 * constants.MENU_SCALE,
                            color=constants.GRAY,
                            text=[
                                "WASD, ARROWS       MOVE",
                                "Z, SPACE, ENTER    SELECT/OPEN INVENTORY",
                                "X, ESCAPE          BACK/EXIT",
                                "TAB                OPEN/CLOSE INVENTORY"
                            ]))
Exemple #2
0
def start():
    global game
    global layer

    #Setup the game
    layer = cocos.layer.Layer()
    game = Game()
    lvl = level.BasicLevel()
    game.set_level(lvl)
    audio.play_music()

    #load game data
    entity.load_data()

    batch = cocos.batch.BatchNode()
    game.sprite_batch = batch
    layer.add(batch)

    #Setup controls
    import interface.controls  # TODO: Add init functions for modules so late import isnt needed
    c = interface.controls.init()
    layer.add(c)

    layer.schedule(game.update)
    layer.schedule(game.update_render)

    return layer
Exemple #3
0
 def player_death_anim_done(self):
     if globals.g_lives >= 1:
         globals.g_lives -= 1
         self.game.add_fade(palette.FADE_STEP_TICKS_DEFAULT, 
             palette.FADE_LEVEL_6, self.game.restart_stage)
     else:
         self.state = STATE_GAME_OVER
         audio.play_music(audio.MUS_GAME_OVER, False)
	def titlescreen_clicked(self, *args):
		self.bac_canvas.delete('bac')
		self.bac_canvas.create_image(0, 0, image = self.new_bac, anchor = NW, tag = 'bac')
		self.bac_canvas.unbind('<1>')
		self.bac_canvas.bind('<1>', self.new_game_clicked) # so we can do that fancy click to start
		
		if sound.get() == 1:
			audio.play_music('start.wav')
Exemple #5
0
 def handle_input(self, keypress):
     if keypress.has_action(key_input.Action.ACCEPT):
         audio.play_music(constants.MUSIC_DUNGEON)
         self.game.change_base_scene(character_select.CharacterSelect)
         return True
     if keypress.has_action(key_input.Action.BACK):
         self.game.change_base_scene(main_menu.MainMenu)
         return True
Exemple #6
0
    def __init__(self, mode=None, replay=None):

        # Initialise basic parts
        self.event_queue = event.DynamicQueue()
        self.random_generator = random.Random(data.config.wave_seed
                                              if hasattr(data.config,
                                                         "wave_seed")
                                              else WAVE_SEED)
        self.particles = particle.ParticleSystem()
        self.hud = GameHUD(self)
        self.controller = control.Controller()
        self.controller.acquire()
        self.controller.add_press(INPUT_PAUSE, self.pause)
        control.set_exit_callback(self.pause)
        audio.play_music(["m030", "m031"], 1)
        fader = video.AlphaRect((0, 0), SCREEN_SIZE)
        fader.a = video.Lerp(255, 0, 30)
        self.event_queue.add_event(30,
                                   lambda: video.remove_renderer(fader.render))

        # Initialise enemy systems
        self.enemies = set()
        self.enemy_bullets = set()
        self.available_enemies = START_ENEMIES
        self.wave_number = 0
        self.next_wave = START_WAVE
        self.rank = 0
        self.min_rank = 0
        self.score = 0
        self.kills = 0
        self.combo_count = 0
        self.combo_time = 0
        self.extends = 0
        self.extend_point = 1000000
        self.aborting = False
        self.pause_screen = None

        # Initialise player
        self.items = set()
        self.player_bullets = set()
        self.player = player.PlayerShip(self)
        self.player_coordinates = PLAYER_START
        self.lives = data.config.starting_lives

        # Initialise renderers
        video.add_renderer(video.draw_clouds, LAYER_BACKGROUND_1)
        self.lower_particle_renderer = lambda x: self.particles.render(x, 0)
        video.add_renderer(self.lower_particle_renderer, LAYER_PARTICLE_LOWER)
        video.add_renderer(self.render_items, LAYER_ITEMS)
        video.add_renderer(self.player.render, LAYER_PLAYER)
        video.add_renderer(self.render_enemies, LAYER_ENEMY)
        video.add_renderer(self.particles.render, LAYER_PARTICLE_UPPER)
        #video.add_renderer(self.player.render_aura, LAYER_PLAYER_AURA)
        video.add_renderer(self.render_bullets, LAYER_ENEMY_BULLETS)
        video.add_renderer(self.hud.render, LAYER_UI)
        video.add_renderer(fader.render, LAYER_OVERLAY_1)
        video.set_parallax(lambda: self.player_coordinates[0])
Exemple #7
0
 def is_complete(self):
     for i in self.lights:
         if i.is_hit == False:
             return False
             
     audio.play_music(audio.MUS_STAGE_COMPLETE, False)
     self._check_next_stage()
     
     return True
Exemple #8
0
 def __init__(self):
     self.pal_control = palette.PaletteControl()
     
     self.screen_shake = screenshake.ScreenShake(self)
     
     self.main_menu = mainmenu.MainMenu(self)
     self.stage = stage.Stage(self, 0)
     self.hud = hud.Hud(self)
     
     self.pal_index = 0
     
     audio.play_music(audio.MUS_TITLE, True)
Exemple #9
0
    def titlescreen_clicked(self, *args):
        self.bac_canvas.delete('bac')
        self.bac_canvas.create_image(0,
                                     0,
                                     image=self.new_bac,
                                     anchor=NW,
                                     tag='bac')
        self.bac_canvas.unbind('<1>')
        self.bac_canvas.bind(
            '<1>',
            self.new_game_clicked)  # so we can do that fancy click to start

        if sound.get() == 1:
            audio.play_music('start.wav')
    def on_update(self, dt):
        self.camera.update(dt)
        self.attaboy.update(dt)

        if self.running_text:
            if self.running_text.finished:
                self.running_text = None
                return pyglet.event.EVENT_HANDLED
            else:
                return pyglet.event.EVENT_HANDLED
        elif self.band_pic:
            if self.band_pic.finished:
                self.band_pic.delete()
                self.band_pic = None
                return pyglet.event.EVENT_HANDLED
            else:
                self.band_pic.update(dt)
                return pyglet.event.EVENT_HANDLED
        if self.script:
            s = self.script.pop(0)
            if s[0] == "fade":
                self.running_text = self.attaboy.add_centered_fade(*s[1])
            elif s[0] == "game":
                self.window.push_state(gamestate.GameState, s[1], s[2], s[3], s[4])
            elif s[0] == "music":
                if audio.playing():
                    audio.play_music_fade(s[1])
                else:
                    audio.play_music(s[1])
            elif s[0] == "main_menu":
                self.window.replace_state(menustate.MainMenuState)
            elif s[0] == "band_pic":
                self.band_pic = AboutPic("./data/rsjf.png")
            elif s[0] == "cc_pic":
                self.band_pic = AboutPic("./data/ccsa.png")
            else:
                pass
        #            self.window.replace_state(self.next_state)
        else:
            # self.window.replace_state(self.next_state, **self.next_state_args)
            self.window.pop_state()
        return pyglet.event.EVENT_HANDLED
Exemple #11
0
 def reset(self):
     self.is_visible = True
     self.show_press_start = True
     self.press_start_flash_ticks = 0
     self.sel_index = 0
     audio.play_music(audio.MUS_TITLE, True)
Exemple #12
0
    def grid_button_clicked(self, event):

        x = (int((event.y - 2) / 64))
        y = (int((event.x - 2) / 64))

        if x > 4:
            x = 4

        if y > 4:
            y = 4

        if x < 0:
            x = 0

        if y < 0:
            y = 0

        if self.cur_piece == '':  # if you haven't picked a piece yet

            for e in self.human_state.dic:  # loop thru human dict

                if self.human_state.board[x][
                        y] == e:  # if this clicked piece is one of yours!!!!

                    self.output_text(ai.speak.get_speech(1))

                    if sound.get() == 1:
                        audio.play_music("pickup.wav")

                    self.cur_piece = self.human_state.board[x][
                        y]  # set it current piece (so we can go to phase 2)
                    self.last_x = x  # save our position
                    self.last_y = y  # ^ ye

                    #self.output_text('You selected ' + self.cur_piece + ' at (' + str(x) +  ',' +str(y) + ')') # wut dis do? lol output

        elif self.cur_piece == self.human_state.board[x][
                y]:  # if you click on the piece you already selected, deselect it!

            if sound.get() == 1:
                audio.play_music("putdown.wav")

            #self.output_text('You deselected ' + self.cur_piece)

            self.cur_piece = ''  # i aint select no darn piece

        else:  # else

            if self.human_state.validate_location(
                    self.last_x, self.last_y, x, y, self.cur_piece,
                    ai.state.board):  # if valid move

                # get the ai move first (so it doesn't cheat ;) )
                dic_ai, piece_ai = ai.get_move(self.human_state.dic)

                # if ai cant find any moves, it must be stalemate (I trust my ai)
                if dic_ai == False:

                    if messagebox.askyesno(
                            'Play again?',
                            ai.speak.get_speech(7) +
                            '\n\nStalemate! \n Would you like to play again?'):
                        self.new_game()
                    else:  # you lose
                        sys.exit()

                # jus sum outbuts
                #self.output_text('You moved ' + self.cur_piece + ' to (' + str(x) +  ',' +str(y) + ')')

                # move human piece
                self.human_state.dic = self.human_state.move_piece(
                    x, y, self.cur_piece, self.human_state.dic)

                # now actually make the moves (let the carnage begin \(>-<)/ )
                self.human_state.dic, dic_ai, msg = grid.finalize_move(
                    self.human_state.dic, dic_ai, self.cur_piece, piece_ai)
                #print(self.human_state.dic, dic_ai)

                if msg != '':
                    self.output_text(msg)

                if sound.get() == 1:
                    audio.play_music("alert.wav")

                # check if the peasants are worthy of knighthood
                dic_ai, mb = grid.check_knight(dic_ai)

                # make the boards used for display from dicts
                self.human_state.board = grid.recreate_grid(
                    self.human_state.dic)
                ai.state.board = grid.recreate_grid(ai.state.dic)

                # if you have 2 knights, put random
                if mb != 'none':

                    x = random.randint(0, grid.GRID_HEIGHT - 1)
                    y = random.randint(0, grid.GRID_WIDTH - 1)

                    while self.human_state.board[x][
                            y] != grid.b and ai.state.board[x][y] != grid.b:
                        x = random.randint(0, grid.GRID_HEIGHT - 1)
                        y = random.randint(0, grid.GRID_WIDTH - 1)

                    dic_ai[mb] = [x, y]
                    self.output_text('AI relocated ' + mb + ' to (' + str(x) +
                                     ',' + str(y) + ')')

                # k
                self.human_state.dic, mb = grid.check_knight(
                    self.human_state.dic)

                # if you have 2 knights, ask to relocate
                if mb != 'none':
                    a = Popup_Knight(self.root, mb, self.human_state.dic, self)

                # send the ai dictionary back (it got updated)
                ai.dic_ai = dic_ai

                # make the boards used for display from dicts
                self.human_state.board = grid.recreate_grid(
                    self.human_state.dic)
                ai.state.board = grid.recreate_grid(ai.dic_ai)

                #self.update_grid()

                # if WE HAVE A WINNER!
                won = grid.get_winner(self.human_state.dic, ai.dic_ai)

                if won == 'ai':  # if my great ai won (and it will ;) )

                    if messagebox.askyesno(
                            'Play again?',
                            ai.speak.get_speech(5) +
                            '\n\nYou Lose! :( \n Would you like to play again?'
                    ):
                        self.new_game()
                    else:  # you lose
                        sys.exit()

                elif won == 'human':  # if you fluked out somehow :p

                    if messagebox.askyesno(
                            'Play again?',
                            ai.speak.get_speech(6) +
                            '\n\nYou win! :) \n Would you like to play again?'
                    ):
                        self.new_game()
                    else:  # you lose
                        sys.exit()

                elif won == 'draw':  # if it is stalemate, Nova!

                    if messagebox.askyesno(
                            'Play again?',
                            ai.speak.get_speech(7) +
                            '\n\nStalemate!!! \n Would you like to play again?'
                    ):
                        self.new_game()
                    else:  # you lose
                        sys.exit()

                #print(grid.recreate_grid(self.human_state.dic))
                #print(grid.recreate_grid(ai.dic_ai))

                self.cur_piece = ''  # you already moved so why u need dat piece homie?

            else:

                self.output_text('You earned a penalty point')  # oh no!!!
                self.output_text(ai.speak.get_speech(1))
                self.human_state.penalty += 1  # stacks on stacks
                self.bac_canvas.itemconfig('penalty', image=self.spr_penalty)
                #audio.play_beep("SystemHand") #replace

                if self.human_state.penalty == 2:  # red card + 6 fouls :/

                    if messagebox.askyesno(
                            'Play again?',
                            ai.speak.get_speech(5) +
                            '\n\nYou Lose! :( \n Would you like to play again?'
                    ):
                        self.new_game()
                    else:  # you lose
                        sys.exit()  # and your kicked out! <(;-;)>
Exemple #13
0
    def __init__(self, game, num):
        self.game = game
        self.num = num
        self.tm = 0
        self.tmu = 0
        self.tmv = num * 16
        
        self.state = STATE_INTRO
        if self.num <= 0:
            self.state = STATE_DEMO
        elif self.num == MAX_STAGE_NUM + 1:
            self.tm = 1
            self.tmu = 0
            self.tmv = 0
            self.state = STATE_GAME_COMPLETE
        
        self.solid_rects = [
            [0, 0, 160, 16], # [x, y, w, h]
            [0, 16, 8, 128],
            [152, 16, 8, 128],
            [0, 136, 160, 8]
        ]
        
        self.slopes = [] # [x, y]
        self.pockets = [] # [x, y, w, h]
        self.lights = [] # Light objects
        self.spinners = [] # Spinner objects
        
        self.en_spawn_locs_topleft = [] # [[x,y],[x,y],[x,y]...]
        self.en_spawn_locs_topright = [] # [[x,y],[x,y],[x,y]...]
        self.en_spawn_locs_bottomleft = [] # [[x,y],[x,y],[x,y]...]
        self.en_spawn_locs_bottomright = [] # [[x,y],[x,y],[x,y]...]
        
        if self.state != STATE_GAME_COMPLETE:
            for yc in range(HEIGHT_TILES):
                y = self.tmv + yc
                for xc in range(WIDTH_TILES):
                    x = self.tmu + xc
                    tile = pyxel.tilemap(self.tm).get(x, y)
                    if tile == POST_TILE:
                        self.solid_rects.append([xc*8 + 8, yc*8 + 16, 8, 8])
                    elif tile in SLOPE_TILES:
                        self.slopes.append([xc*8 + 8, yc*8 + 16])
                    elif tile == LIGHT_TILE:
                        self.lights.append(light.Light(xc*8 + 8, yc*8 + 16))
                        
                    if tile == POCKET_TILE_NW:
                        if x < self.tmu + WIDTH_TILES-1 and y < self.tmv + HEIGHT_TILES-1:
                            if pyxel.tilemap(self.tm).get(x+1, y) == POCKET_TILE_NE and\
                                pyxel.tilemap(self.tm).get(x+1, y+1) == POCKET_TILE_SE and\
                                pyxel.tilemap(self.tm).get(x, y+1) == POCKET_TILE_SW:
                                    self.pockets.append([xc*8 + 8, yc*8 + 16, 16, 16])
                                    
                    if tile != POST_TILE and \
                        xc > 0 and \
                        xc < WIDTH_TILES-1 and \
                        yc > 0 and \
                        yc < HEIGHT_TILES-1 and \
                        (xc < 5 or xc > WIDTH_TILES-6) and \
                        (yc < 5 or yc > HEIGHT_TILES-6):
                        
                        loc = [xc*8 + 8 + 4, yc*8 + 16 + 4]
                        
                        if xc < 9:
                            if yc < 7:
                                self.en_spawn_locs_topleft.append(loc)
                            else:
                                self.en_spawn_locs_bottomleft.append(loc)
                        else:
                            if yc < 7:
                                self.en_spawn_locs_topright.append(loc)
                            else:
                                self.en_spawn_locs_bottomright.append(loc)

            #print(self.pockets)
            num_spinners = 0
            stage_diff_name = stagedata.STAGE_DIFFICULTY[self.num]
            for i in range(len(spinner.TYPES)):
                en_qty = stagedata.ENEMIES[stage_diff_name][stagedata.SPINNER_KEY][i]
                for sq in range(en_qty):
                    loc = self.get_random_spawn_loc(-1)
                    self.spinners.append(spinner.Spinner(loc[0], loc[1], i))
        
        self.player = player.Player(75,75)#(12, 20)
        if self.state == STATE_GAME_COMPLETE:
            self.player.state = player.STATE_GAME_COMPLETE
            audio.play_music(audio.MUS_IN_GAME, True)
        else:
            if self.state != STATE_DEMO:
                audio.play_music(audio.MUS_START, False)
        
        self.pause_menu = PauseMenu(self)
        
        self.stage_over_ticks = 0
        
        self.next_stage_flash_num = 0
	def grid_button_clicked(self, event):
		
		x = ( int( (event.y - 2) / 64) )
		y = ( int( (event.x - 2) / 64) )
		
		if x > 4:
			x = 4
			
		if y > 4:
			y = 4
		
		if x < 0:
			x = 0
			
		if y < 0:
			y = 0		
		
		
		if self.cur_piece == '': # if you haven't picked a piece yet
				
			for e in self.human_state.dic: # loop thru human dict
				
				if self.human_state.board[x][y] == e: # if this clicked piece is one of yours!!!!
				
					self.output_text(ai.speak.get_speech(1))
					
					if sound.get() == 1:
						audio.play_music("pickup.wav")
					
					self.cur_piece = self.human_state.board[x][y] # set it current piece (so we can go to phase 2)
					self.last_x = x # save our position
					self.last_y = y # ^ ye
					
					#self.output_text('You selected ' + self.cur_piece + ' at (' + str(x) +  ',' +str(y) + ')') # wut dis do? lol output
					
					
		elif self.cur_piece == self.human_state.board[x][y]: # if you click on the piece you already selected, deselect it!
		
			if sound.get() == 1:
				audio.play_music("putdown.wav")	
				
			#self.output_text('You deselected ' + self.cur_piece) 		
			
			self.cur_piece = '' # i aint select no darn piece
			
			
		else: # else
			
			
				
			if self.human_state.validate_location(self.last_x, self.last_y, x, y, self.cur_piece, ai.state.board): # if valid move
			
				# get the ai move first (so it doesn't cheat ;) )
				dic_ai, piece_ai = ai.get_move(self.human_state.dic)

				# if ai cant find any moves, it must be stalemate (I trust my ai)
				if dic_ai == False:
				
					if messagebox.askyesno('Play again?', ai.speak.get_speech(7) + '\n\nStalemate! \n Would you like to play again?'):
						self.new_game()
					else:# you lose
						sys.exit()
					
				# jus sum outbuts
				#self.output_text('You moved ' + self.cur_piece + ' to (' + str(x) +  ',' +str(y) + ')')

				# move human piece
				self.human_state.dic = self.human_state.move_piece(x,y,self.cur_piece, self.human_state.dic)
				
				# now actually make the moves (let the carnage begin \(>-<)/ )
				self.human_state.dic, dic_ai, msg = grid.finalize_move( self.human_state.dic, dic_ai, self.cur_piece, piece_ai)
				#print(self.human_state.dic, dic_ai)
				
				if msg != '':
					self.output_text(msg)
				
				if sound.get() == 1:
					audio.play_music("alert.wav")
					
				# check if the peasants are worthy of knighthood
				dic_ai, mb = grid.check_knight(dic_ai)
				
				# make the boards used for display from dicts
				self.human_state.board = grid.recreate_grid(self.human_state.dic)
				ai.state.board = grid.recreate_grid(ai.state.dic)
				
				# if you have 2 knights, put random
				if mb != 'none':
					
					x = random.randint(0, grid.GRID_HEIGHT - 1)
					y = random.randint(0, grid.GRID_WIDTH - 1)

					while self.human_state.board[x][y] != grid.b and ai.state.board[x][y] != grid.b:
						x = random.randint(0, grid.GRID_HEIGHT - 1)
						y = random.randint(0, grid.GRID_WIDTH - 1)
						
					dic_ai[mb] = [x,y]
					self.output_text('AI relocated ' + mb + ' to (' + str(x) +  ',' +str(y) + ')')
					
				# k
				self.human_state.dic, mb = grid.check_knight(self.human_state.dic)
				
				# if you have 2 knights, ask to relocate
				if mb != 'none':
					a = Popup_Knight(self.root, mb, self.human_state.dic, self)
					
				# send the ai dictionary back (it got updated)
				ai.dic_ai = dic_ai
				
				# make the boards used for display from dicts
				self.human_state.board = grid.recreate_grid(self.human_state.dic)
				ai.state.board = grid.recreate_grid(ai.dic_ai)
				
				#self.update_grid()
					
				# if WE HAVE A WINNER!
				won = grid.get_winner(self.human_state.dic, ai.dic_ai)
				
				if won == 'ai': # if my great ai won (and it will ;) )
				
					if messagebox.askyesno('Play again?', ai.speak.get_speech(5) + '\n\nYou Lose! :( \n Would you like to play again?'):
						self.new_game()
					else:# you lose
						sys.exit()
					
				elif won == 'human': # if you fluked out somehow :p
				
					if messagebox.askyesno('Play again?', ai.speak.get_speech(6) + '\n\nYou win! :) \n Would you like to play again?'):
						self.new_game()
					else:# you lose
						sys.exit()
						
				elif won == 'draw': # if it is stalemate, Nova!
				
					if messagebox.askyesno('Play again?', ai.speak.get_speech(7) + '\n\nStalemate!!! \n Would you like to play again?'):
						self.new_game()
					else:# you lose
						sys.exit()
				
				#print(grid.recreate_grid(self.human_state.dic))
				#print(grid.recreate_grid(ai.dic_ai))
				
				self.cur_piece = '' # you already moved so why u need dat piece homie?
				
			else:
				
				self.output_text('You earned a penalty point') # oh no!!!	
				self.output_text(ai.speak.get_speech(1))
				self.human_state.penalty += 1 # stacks on stacks
				self.bac_canvas.itemconfig('penalty', image = self.spr_penalty)
				#audio.play_beep("SystemHand") #replace
				
				if self.human_state.penalty == 2: # red card + 6 fouls :/
				
					if messagebox.askyesno('Play again?', ai.speak.get_speech(5) + '\n\nYou Lose! :( \n Would you like to play again?'):
						self.new_game()
					else:# you lose
						sys.exit() # and your kicked out! <(;-;)>
Exemple #15
0
 def restart_music(self):
     if self.state == STATE_PLAY:
         audio.play_music(audio.MUS_IN_GAME)
Exemple #16
0
	def grid_button_clicked(self, event):
		
		x = ( int( (event.y - 2) / 64) )
		y = ( int( (event.x - 2) / 64) )
		
		#print('hey',self.cur_piece)
		if self.cur_piece == '': # if you haven't picked a piece yet
			audio.play_music("pickup.wav")
			for e in self.dic_human: # loop thru human dict
				
				if self.human_board.board[x][y] == e: # if this clicked piece is one of yours!!!!
					
					self.cur_piece = self.human_board.board[x][y] # set it current piece (so we can go to phase 2)
					self.last_x = x # save our position
					self.last_y = y # ^ ye
					
					self.output_text('You selected ' + self.cur_piece + ' at (' + str(x) +  ',' +str(y) + ')') # wut dis do? lol output
					
					
		elif self.cur_piece == self.human_board.board[x][y]: # if you click on the piece you already selected, deselect it!
			audio.play_music("putdown.wav")	
			self.output_text('You deselected ' + self.cur_piece) 		
			
			self.cur_piece = '' # i aint select no darn piece
			
			
		else: # else
			audio.play_music("alert.wav")
			if self.human_board.validate_location(self.last_x, self.last_y, x, y, self.cur_piece, ai.board.board): # if valid move
			
				# get the ai move first (so it doesn't cheat ;) )
				dic_ai, piece_ai = ai.get_move(self.dic_human)

				# if ai cant find any moves, it must be stalemate (I trust my ai)
				if dic_ai == False:
					messagebox.showinfo('', 'Stalemate!')
					sys.exit() # will be replaced by restart
					
				# jus sum outbuts
				self.output_text('You moved ' + self.cur_piece + ' to (' + str(x) +  ',' +str(y) + ')')

				# move human piece
				self.dic_human = self.human_board.move_piece(x,y,self.cur_piece, self.dic_human)
				
				# now actually make the moves (let the carnage begin \(>-<)/ )
				self.dic_human, dic_ai = grid.finalize_move( self.dic_human, dic_ai, self.cur_piece, piece_ai)
				#print(self.dic_human, dic_ai)
				
				# check if the peasants are worthy of knighthood
				dic_ai, mb = grid.check_knight(dic_ai)
				
				# make the boards used for display from dicts
				self.human_board.board = grid.recreate_grid(self.dic_human)
				ai.board.board = grid.recreate_grid(ai.dic_ai)
				
				# if you have 2 knights, put random
				if mb != 'none':
					
					x = random.randint(0, grid.GRID_HEIGHT)
					y = random.randint(0, grid.GRID_WIDTH)
					#if the new picked locations are not valid, repick
					while self.human_board.board[x][y] != grid.b and ai.board.board[x][y] != grid.b:
						x = random.randint(0, grid.GRID_HEIGHT)
						y = random.randint(0, grid.GRID_WIDTH)
					
					#change the location of the pawn in the ai dictionary		
					dic_ai[mb] = [x,y]
					self.output_text('AI relocated ' + mb + ' to (' + str(x) +  ',' +str(y) + ')')
					
				# k
				self.dic_human, mb = grid.check_knight(self.dic_human)
				
				# if you have 2 knights, ask to relocate
				if mb != 'none':
					a = Popup_Knight(self.root, mb, self.dic_human, self)
					
				# send the ai dictionary back (it got updated)
				ai.dic_ai = dic_ai
				
				# make the boards used for display from dicts
				self.human_board.board = grid.recreate_grid(self.dic_human)
				ai.board.board = grid.recreate_grid(ai.dic_ai)
				
				#self.update_grid()
					
				# if WE HAVE A WINNER!
				won = grid.get_winner(self.dic_human, ai.dic_ai)
				
				if won == 'ai': # if my great ai won (and it will ;) )
				
					messagebox.showinfo('', 'You lose! :(')
					sys.exit()
					
				elif won == 'human': # if you fluked out somehow :p
				
					messagebox.showinfo(' ', 'You Win! :)')
					sys.exit()

					

					self.root.destroy()

				elif won == 'draw': # if it is stalemate, Nova!
				
					messagebox.showinfo('', 'Stalemate!')
					sys.exit()
				
				#print(grid.recreate_grid(self.dic_human))
				#print(grid.recreate_grid(ai.dic_ai))
				
				self.cur_piece = '' # you already moved so why u need dat piece homie?
			
			#if the location picked is invalid.	
			else:
			
				global penalty # you goin to penalty!!!!!!!!
				
				self.output_text('You earned a penalty point') # oh no!!!	
				
				penalty += 1 # stacks on stacks
				
				if penalty == 2: # with 2 invalid moves you lose
				
					messagebox.showinfo(' ', 'You Lose! :(') # you lose
					sys.exit() # and your kicked out! <(;-;)>
Exemple #17
0
	def setup_game(self, *args):
		#self.choose_player()
		audio.play_music("indusalarm.wav")
		self.bac_canvas.delete('bac')

		self.bac_canvas.create_image(0, 0, image = self.main_bac, anchor = NW, tag = 'bac') # add spiffy background
		
		#Empty grid for buttons 
		self.grid = []
		
		## Sets up the game board ##
		
		#Container for the board 
		#self.board_frame = ttk.Frame(self.root)
		#self.board_frame.place(x = self.w/2 - 6*self.BASIC_UNIT, y = self.h/2 - 2*self.BASIC_UNIT, width = 5*self.BASIC_UNIT, height = 5*self.BASIC_UNIT)
		self.board_canvas = Canvas(self.root, bd = 0)
		self.board_canvas.place(x = self.w/2 - 6*self.BASIC_UNIT - 2, y = self.h/2 - 2*self.BASIC_UNIT - 2, width = 5*self.BASIC_UNIT + 4, height = 5*self.BASIC_UNIT + 4 )
		
		self.board_canvas.bind('<Button-1>', self.grid_button_clicked)
				
		
		#Places buttons onto the empty grid
		for i in range(grid.GRID_HEIGHT):
		
			row = [] # row so we can append to 2D grid
			
			for j in range(grid.GRID_WIDTH):
			
				block_color = 1
				
				# this allows us to draw a checkerboard pattern
				if (i%2)==(j%2):
					block_color = 0
					
				self.board_canvas.create_image(2 + j * 64, 2 + i *  64, image = self.spr_board[block_color], anchor = NW, tag = 'board'+str(i)+str(j))

				self.board_canvas.create_image(2 + j * 64, 2 + i *  64, image = '', anchor = NW, tag = 'piece'+str(i)+str(j))
				
				self.board_canvas.create_image(2 + j * 64, 2 + i *  64, image = '', anchor = NW, tag = 'overlay'+str(i)+str(j))
				
		
		# update dat griiid
		#self.update_grid()
		
		## Sets up the console (will be used for trash talking computer)##
		
		self.console_text = ['' for i in range(self.CON_LINES)] # the text in the console
		self.console_lines = [] # the line objects
		self.console_icons = [] # emoticons. coming soon!

		#Create canvas for the console
		self.console_canvas = Canvas(self.root, bg = 'white')
		self.console_canvas.place(x = self.w/2 + self.BASIC_UNIT, y = self.h/2 - self.BASIC_UNIT*2, width = self.BASIC_UNIT*6, height = self.CON_SIZE)
		
		#Putting the text lines onto the consoles
		for i in range(self.CON_LINES):
			self.console_lines.append(self.console_canvas.create_text(4, i*(self.CON_SIZE/self.CON_LINES) + 4, anchor = NW))
			self.console_canvas.itemconfig(self.console_lines[i], text = self.console_text[i])
			
		#Input text 
		self.entry_var = StringVar()
		self.console_entry = ttk.Entry(self.root, textvariable = self.entry_var)
		self.console_entry.place(x = self.w/2 + self.BASIC_UNIT, y = self.h/2 - self.BASIC_UNIT*2 + self.CON_SIZE + 16, width = self.BASIC_UNIT*4, height = 24)

		
		# button to reply to that rude bot (bot not implemented.... yet!)
		self.entry_button = ttk.Button(text = 'Send', command = self.send_button_clicked)
		self.entry_button.place(x = self.w/2 + self.BASIC_UNIT*5.5, y = self.h/2 - self.BASIC_UNIT*2 + self.CON_SIZE + 16, width = self.BASIC_UNIT, height = 24)
		self.root.bind('<Return>', self.send_button_clicked)
		
		self.update_grid(0)
Exemple #18
0
def start():
    global scroller
    global game
    global collision_map

    resources.init()

    #Setup the game
    #The scene structure is like this:
    #Scene
    #  ScrollingManager
    #    ScrollingLayer
    #      Batch
    #    TileMap
    #  Layer
    #    Controls
    #    Gui

    scroller = cocos.layer.ScrollingManager()
    scrolling_layer = cocos.layer.ScrollableLayer()
    scroller.s_layer = scrolling_layer  # TODO: Ugh it reeks of nastiness
    layer = cocos.layer.Layer()
    game = Game()

    lvl = level.BasicLevel()
    game.set_level(lvl)
    audio.play_music()

    #load game data
    entity.load_data()

    batch = cocos.batch.BatchNode()
    game.sprite_batch = batch
    scrolling_layer.add(batch)

    #load the map
    background, collision_map = tilemap.init()
    scroller.add(background, z=-2)
    scroller.add(collision_map, z=-1)
    scroller.add(scrolling_layer)

    #initalize the pathfinding map
    collision.init_collision(collision_map)

    #initalize the general collision system
    grid = collision.get_map_grid()
    for x, i in enumerate(grid):
        for y, tile in enumerate(i):
            if tile:
                # TODO: non-static tile width/height
                scale = 64.0 / constants.PIXEL_TO_METER
                body = game.collision_world.CreateStaticBody(
                    position=(x * scale, y * scale),
                    userData = {"type": "wall",
                                "friendly": False,
                                "mask_collision": 0b110,
                                "mask_event": 0b000}
                )
                body.CreatePolygonFixture(box=(scale/2.0, scale/2.0))

    #add an enemy for testing purposes
    #enemy = entity.get_entity_type("basicenemy")()
    #enemy.position = Vector2(100, 100)
    #enemy.movement_speed = 0.35
    #game.spawn(enemy)

    #Setup controls
    import interface.controls  # TODO: Add init functions for modules so late import isnt needed

    interface.gui.init()  # TODO: Figure out why it has to go here instead of earlier

    c = interface.controls.init()
    layer.add(c)

    scrolling_layer.schedule(game.update)
    #scrolling_layer.schedule(game.update_render)

    #Load the gui
    game.gui = interface.gui.Gui()  # TODO: would be better to have this is instance in the interface package
    layer.add(game.gui)
    game.gui.log.add_message("Welcome to RPGame.")
    return game, layer, scroller
Exemple #19
0
 def restart_music(self):
     if self.main_menu.is_visible:
         audio.play_music(audio.MUS_TITLE)
     else:
         self.stage.restart_music()
Exemple #20
0
 def player_intro_done(self):
     if self.state != STATE_PLAYER_WEAPON:
         audio.play_music(audio.MUS_IN_GAME, True)
         
     self.state = STATE_PLAY
Exemple #21
0
 def player_hit(self):
     self.state = STATE_DIED
     audio.play_music(audio.MUS_DEATH, False)