Beispiel #1
0
	def update(self, delta):
		self.time += delta
		self.delta = delta
		self.current_squares = self.getsquares(self.camera.rect)

		for obj in self.objects:
			obj.update(delta)

		self.player.update(delta)

		self.camera.update(delta)
		self.space.step(delta)

		if len(self.destroyed) > 0:
			for obj in self.destroyed:
				obj.destroy()
			self.destroyed = []

		if game.get_key_pressed(pygame.K_ESCAPE):
			game.set_state(MenuState())

		for message in self.messages:
			message[1] -= delta
			if message[1] < 0:
				self.messages.remove(message)
Beispiel #2
0
 def handle_event(self, event):
     from game import Overworld
     State.handle_event(self, event)
     if event.type == pygame.KEYDOWN:
         old_cur_x_index, old_cur_y_index = Overworld.cur_x_index, Overworld.cur_y_index
         if event.key == pygame.K_UP:
             Overworld.cur_y_index -= 1
             self.refresh_screen = True
         elif event.key == pygame.K_DOWN:
             Overworld.cur_y_index += 1
             self.refresh_screen = True
         elif event.key == pygame.K_LEFT:
             Overworld.cur_x_index -= 1
             self.refresh_screen = True
         elif event.key == pygame.K_RIGHT:
             Overworld.cur_x_index += 1
             self.refresh_screen = True
         if self._level.isWall(Overworld.center_x_index(), Overworld.center_y_index()):
             Overworld.cur_x_index = old_cur_x_index
             Overworld.cur_y_index = old_cur_y_index
         elif self._level.isLadder(Overworld.center_x_index(), Overworld.center_y_index()):
             self._level = self._level.load_level(Overworld.center_x_index(), Overworld.center_y_index())
             self.refresh_screen = True
         elif self._level.isMonster(Overworld.center_x_index(), Overworld.center_y_index()):
             from game import set_state
             from battle_state import BattleState
             from battle import Skeleton
             new_state = BattleState(Skeleton())
             set_state(new_state)
             new_state.play_music()
     return
Beispiel #3
0
	def draw(self, screen):
		gui.draw_image(screen, resources.splash)
		with gui.Box(screen, "Main Menu", (450, 300, 220, 240)):
			if gui.Button(screen, "play", "play", (10, 10, 200, 50)):
				game.set_state(GameState())
			if gui.Button(screen, "help", "help", (10, 70, 200, 50)):
				game.set_state(HelpState())
			if gui.Button(screen, "quit", "quit", (10, 130, 200, 50)):
				game.quit()
Beispiel #4
0
def main(initial_state = None):
    game.initialize()
    if initial_state:
        game.set_state(initial_state)
    state = game.state()
    state.play_music()
    while True:
        for event in pygame.event.get():
            state.handle_event(event)
        state.update()
        if state.refresh_screen:
            state.draw_to_screen()
            game.refresh_screen()
            state.refresh_screen = False
        state = game.state()
        game.tick()
    return
Beispiel #5
0
def main_loop(initial_state):
    game.set_state(initial_state)
    state = game.state()
    while True:
        for event in pygame.event.get():
            state.handle_event(event)
        state.update()
        if state.refresh_screen:
            state.draw(game.screen())
            game.refresh_screen()
            state.refresh_screen = False
        elif state.dirty_list:
            state.draw(game.screen())
            game.refresh_subscreen(state.dirty_list)
        state.dirty_list = []
        state = game.state()
        game.tick()
    return
Beispiel #6
0
 def handle_event(self, event):
     State.handle_event(self, event)
     if event.type == pygame.KEYDOWN:
         if event.key == pygame.K_DOWN:
             if self._current_choice < self._number_of_choices - 1:
                 self._current_choice += 1
                 self.refresh_screen = True
         elif event.key == pygame.K_UP:
             if self._current_choice > 0:
                 self._current_choice -= 1
                 self.refresh_screen = True
         elif event.key == pygame.K_RETURN:
             if self._current_choice == 0:
                 from level_state import LevelState
                 from game import set_state
                 state = LevelState("tower_entrance.txt")
                 set_state(state)
                 state.play_music()
     return
Beispiel #7
0
	def update(self, delta):
		self.leafy = pygame.image.load("data\\Environment\\Sky.png")
		self.flower = pygame.image.load("data\\Environment\\flower.png")
		self.wasp_body = pygame.image.load("data\\Characters\\Enemies\\Jalapeno\\Body.png")
		self.wasp_wing = pygame.image.load("data\\Characters\\Enemies\\Jalapeno\\Wing Front.png")
		self.broccoli_body = pygame.image.load("data\\Characters\\Enemies\\Onion\\Onion.png")
		self.player_body = pygame.image.load("data\\Characters\\Main Character\\Body.png")
		self.player_leg = pygame.image.load("data\\Characters\\Main Character\\Leg Front.png")
		self.player_wing = pygame.image.load("data\\Characters\\Main Character\\Wing Front.png")
		self.player_jaw_upper = pygame.image.load("data\\Characters\\Main Character\\Jaw Upper.png")
		self.player_jaw_lower = pygame.image.load("data\\Characters\\Main Character\\Jaw Lower.png")
		self.player_dead = pygame.image.load("data\\Characters\\Main Character\\Dead.png")
		self.bullet = pygame.image.load("data\\Characters\\Main Character\\Bullet.png")
		self.splash = pygame.image.load("data\\Menu\\SplashScreen.png")
		self.help = pygame.image.load("data\\Menu\\help.png")
		self.attack_icon = pygame.image.load("data\\Menu\\Attack.png")
		self.utility_icon = pygame.image.load("data\\Menu\\Utility.png")
		self.movement_icon = pygame.image.load("data\\Menu\\Movement.png")
		for i in range(len(GroundShapes)):
			GroundShapes[i] = (pygame.image.load(GroundShapes[i][0]), GroundShapes[i][1])
		game.set_state(MenuState())
Beispiel #8
0
 def cancelClicked(self, element, event):
     game.set_state(SelectCharacterState())
Beispiel #9
0
 def createClicked(self, element, event):
     name = self.gui.find('name')[0].text
     game.connection.send(message.make_create(name))
     game.set_state(SelectCharacterState())
Beispiel #10
0
 def characterNameClicked(self, element, event):
     print('Selected', element.text)
     game.connection.send(message.make_select(element.text))
     game.set_state(InGameState())
Beispiel #11
0
 def createClicked(self, element, event):
     game.set_state(CreateCharacterState())
Beispiel #12
0
 def handleLoginResponseMessage(self, successful):
     if successful:
         print("Login OK")
         game.set_state(SelectCharacterState())
     else:
         print("Login refused")
Beispiel #13
0
	def draw(self, screen):
		gui.draw_image(screen, resources.help)
		if gui.Button(screen, "back", "back", (300, 540, 200, 50)):
			game.set_state(MenuState())

# Initializations
num_of_iters = 3000000
batch_size = 100
game = game.GAME()
tabular_learning = tabular_learning(game, alpha=100 / num_of_iters)
deepQ = Deep_Q_learning(game)
policy = policies(eps_decay=2 / num_of_iters)

initial_state = {
    'Ball': [0, 0],
    'Agent': [1, 1, 0],
    'Ball_on_Agent': False
}  #None
game.set_state(initial_state)
game.start_recording()

# Restore checkpoint
# deepQ.saver.restore(deepQ.sess, "algo")

# Main Loop of Training
start_time = time.time()
loss_graph = []
batch_ind = 0
states = np.zeros((batch_size, game.width, game.height, 2))
predictions = np.zeros((batch_size, game.number_of_actions, 1))
loss = -1
for iter in range(0, num_of_iters):
    reward, finish = tabular_learning.tabular_play_iter(policy)
    '''s0 = np.expand_dims(game.state_as_tensor(), axis=0)