Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, pos_x, pos_y, player_path, current_sprite, run_speed, state_s
self.target_update_freq = 100 # Update target network every 100 steps

#load train weights
#checkpoint = torch.load('runs/ml-model-test-118/model.pt')
#checkpoint = torch.load('runs/ml-model-test-109/model.pt')
#self.q_network.load_state_dict(checkpoint['model_state_dict'])
#self.target_q_network.load_state_dict(checkpoint['model_state_dict'])

Expand All @@ -58,10 +58,6 @@ def jump(self):
self.is_jumping = False
self.jump_vel = 8.5





def make_decision(self):
if self.rect.y < 400:
return 1 # Pular
Expand Down
20 changes: 13 additions & 7 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,7 @@ def step(self):
self.bomb.inc = 0.12
else:
self.bomb.current_sprite = 0.0

## Check if player collides with the bomb
if self.player.rect.colliderect(self.bomb):
self.bomb.rect.x = randint(3000, 4000)
self.bomb.inc = 0




# Check if the player collides with the coin
if self.two_players and self.agent is not None:
Expand All @@ -209,6 +203,13 @@ def step(self):
self.coin.rect.y = randint(350,500)


if self.two_players and self.agent is not None:
if self.agent.rect.colliderect(self.bomb):
self.two_players = False




# Check for collisions with the shark and update the score accordingly
if self.two_players and self.agent is not None:
if (
Expand All @@ -221,6 +222,11 @@ def step(self):
if self.shark.rect.x <= -150:
self.shark.rect.x = randint(1000, 1400) # Move the shark to a new position

if self.player.rect.colliderect(self.bomb):
if self.two_players == False:
print("FIM DE JOGO!")
return 0, self.score, self.hi_score


if (pygame.sprite.spritecollide(self.player, self.moving_shark, False, pygame.sprite.collide_mask)):
if self.two_players == False:
Expand Down