-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfase5.py
134 lines (124 loc) · 6.21 KB
/
fase5.py
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import pygame
import random
import math
from fase1 import dist, target_reached, out_of_bounds
import numpy as np
G_CONST = -10
def collision_planeta(state): # Função que verifica se o personagem colidiu com o planeta
planeta_rect = pygame.Rect(state['buraco_branco_pos'][0], state['buraco_branco_pos'][1], 120, 120)
char_rect = pygame.Rect(state['char_pos'][0], state['char_pos'][1], 75, 75)
return char_rect.colliderect(planeta_rect)
def update_state(state, assets):
char_mass = state['char_mass']
Buraco_branco = state['buraco_negro_mass']/6
char_pos = np.array(state['char_pos'])
buraco_branco_pos = np.array(state['buraco_branco_pos'])
char_vel = np.array(state['char_vel'])
# calculate the distance and direction vector between the character and the planet
r = buraco_branco_pos - char_pos
r_norm = np.linalg.norm(r)
r_hat = r / r_norm
# calculate the gravitational force
f_grav = (G_CONST * char_mass * Buraco_branco) / (r_norm ** 2)
# calculate the acceleration vector
acc = f_grav * r_hat
# update the character acceleration
state['char_acc'] = acc
# update the character position and velocity
dt = 1 # time step
state['char_pos'] = tuple(char_pos + char_vel * dt)
state['char_vel'] = char_vel + acc * dt
if collision_planeta(state): # Se o personagem colidir com o planeta, ele volta para a posição inicial e perde uma vida
state['is_moving'] = False
state['tela_atual'] = 'fase5'
state['vidas'] -= 1
state['char_pos'] = (int(75/2), int(assets['height']/2))
if state['vidas'] == 0: # Se o personagem perder todas as vidas, ele vai para a tela de game over
pygame.mixer.music.stop()
pygame.mixer.music.load(assets['gameover_song'])
pygame.mixer.music.set_volume(0.5)
pygame.mixer.music.play()
state['tela_atual'] = 'game_over'
elif out_of_bounds(state): # Se o personagem sair da tela, ele volta para a posição inicial e perde uma vida
state['is_moving'] = False
state['tela_atual'] = 'fase5'
state['vidas'] -= 1
state['char_pos'] = (int(75/2), int(assets['height']/2))
if state['vidas'] == 0: # Se o personagem perder todas as vidas, ele vai para a tela de game over
pygame.mixer.music.stop()
pygame.mixer.music.load(assets['gameover_song'])
pygame.mixer.music.set_volume(0.5)
pygame.mixer.music.play()
state['tela_atual'] = 'game_over'
elif target_reached(state): # Se a coxinha for atingida, o jogo vai pro desafio
sound_effect = pygame.mixer.Sound("wavs/RUSH-E-_vocals_-_mp3cut.net_.wav")
sound_effect.play()
state['char_pos'] = (int(75/2), int(assets['height']/2))
state['is_moving'] = False
state['tela_atual'] = 'desafio_instrucoes'
state['vidas'] = 1
def fase5_instructions(window, assets, state): # Tela de instruções da fase 5
img = pygame.image.load(assets['fase5_instrucoes']).convert()
img = pygame.transform.scale(img, (1280, 720))
window.blit(img, (0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE: # Se o jogador apertar espaço, o jogo vai pra fase 5
state['tela_atual'] = 'fase5'
def fase5_game(window, assets, state): # Tela da fase 5
# esse tem mais vidas q o normal mas a ideia eh a mesma
if state['vidas'] == 5:
fase = pygame.image.load(assets['fases_5vidas']).convert()
fase = pygame.transform.scale(fase, (1280, 720))
window.blit(fase, (0, 0))
elif state['vidas'] == 4:
fase = pygame.image.load(assets['fases_4vidas']).convert()
fase = pygame.transform.scale(fase, (1280, 720))
window.blit(fase, (0, 0))
elif state['vidas'] == 3:
fase = pygame.image.load(assets['fases_3vidas']).convert()
fase = pygame.transform.scale(fase, (1280, 720))
window.blit(fase, (0, 0))
elif state['vidas'] == 2:
fase = pygame.image.load(assets['fases_2vidas']).convert()
fase = pygame.transform.scale(fase, (1280, 720))
window.blit(fase, (0, 0))
elif state['vidas'] == 1:
fase = pygame.image.load(assets['fases_1vidas']).convert()
fase = pygame.transform.scale(fase, (1280, 720))
window.blit(fase, (0, 0))
character = pygame.image.load(assets['character']).convert_alpha()
character = pygame.transform.scale(character, (75, 75))
window.blit(character, (state['char_pos'][0], state['char_pos'][1]))
planeta = pygame.image.load(assets['buraco_branco']).convert_alpha()
planeta = pygame.transform.scale(planeta, (150, 150))
window.blit(planeta, (state['buraco_branco_pos'][0], state['buraco_branco_pos'][1]))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN: # Se o jogador apertar enter, o jogo vai pro menu
state['tela_atual'] = 'menu'
state['vidas'] = 3
state['char_pos'] = (int(75/2), int(assets['height']/2))
state['is_moving'] = False
elif event.type == pygame.MOUSEBUTTONDOWN: # Se o jogador clicar com o mouse, o personagem vai pra direção do mouse
if event.button == 1 and not state['is_moving']: # Verifica se o personagem já está se movendo
# get mouse position
mouse_pos = event.pos
# launch the character in the direction of the mouse
# calculate the angle between the character and the mouse
angle = math.atan2(mouse_pos[1] - state['char_pos'][1], mouse_pos[0] - state['char_pos'][0])
state['is_moving'] = True
# calculate the velocity vector
vel_x = 20 * math.cos(angle)
vel_y = 20 * math.sin(angle)
# launch the character with uniform velocity
state['char_vel'] = (vel_x, vel_y)
state['char_acc'] = (0, 0)
if state['is_moving']:
update_state(state, assets)