forked from IgrPhillipe/go-go-vaccines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGamePlay.py
120 lines (101 loc) · 4.69 KB
/
GamePlay.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
from background.MovingBackground import MovingBackground
from background.VaccineBackground import VaccineBackground
from player.Player import Player
from manager.VirusManager import VirusManager
from collectables.IndependentHeart import IndependentHeart
from collectables.IndependentVaccine import IndependentVaccine
from collectables.Heart import Heart
from collectables.Vaccine import Vaccine
from humans.HandleCrocodileToHuman import HandleCrocodileToHuman
from collision.Collisions import Collisions
from sound.Sound import Sound
from pontuation.Pontuation import Pontuation
import pygame
import time
class GamePlay:
def __init__(self):
self.__screen = pygame.display.set_mode((1000, 700))
self.__vaccines_background = VaccineBackground()
self.__player = Player()
self.__heart = Heart()
self.__vaccine = Vaccine()
self.__handle_crocodile_human = HandleCrocodileToHuman()
self.__virus_manager = VirusManager()
self.__collision = Collisions()
self.__sound = Sound()
def playing(self, start):
gameover = start
self.__pontuation = Pontuation()
self.__independent_heart = IndependentHeart()
self.__independent_vaccine = IndependentVaccine()
while gameover:
current_time = time.time()
self.__draw_background()
hit_virus = self.__collision.with_virus.did_virus_collide_with_player(
self.__player, self.__virus_manager.virus)
hit_crocodile = self.__collision.with_crocodile.did_player_collide_with_crocodile(
self.__player, self.__handle_crocodile_human.crocodile)
player_is_invencible = self.__player.invencible
gameover = self.__action_after_hit_crocodile(
hit_crocodile, player_is_invencible)
gameover = gameover and self.__action_after_hit_virus_and_player_not_invencible(
hit_virus, player_is_invencible)
self.__draw_managers()
gameover = gameover and self.__player.move()
self.__player.draw(self.__screen)
self.__draw_collectables()
hit_heart = self.__collision.with_heart.did_heart_collide_with_player(
self.__player, self.__independent_heart)
self.__action_after_hit_heart(hit_heart)
hit_vaccine = self.__collision.with_vaccine.did_vaccine_collide_with_player(
self.__player, self.__independent_vaccine)
self.__action_after_hit_vacine(hit_vaccine)
self.__handle_crocodile_human.draw(self.__screen)
self.__pontuation.draw(self.__screen)
pygame.display.update()
if (gameover == False):
return self.__pontuation.get_pontuation(current_time)
def __action_after_hit_crocodile(self, hit_crocodile, player_is_invencible):
if not self.__handle_crocodile_human.is_human:
if hit_crocodile and self.__vaccine.zero_vaccine_left():
if not player_is_invencible:
self.__heart.lost_life()
if self.__heart.zero_lives_left():
return False
else:
self.__player.is_invencible()
self.__sound.lost_life_play()
elif hit_crocodile:
self.__handle_crocodile_human.hit_crocodile_with_vaccine()
self.__vaccine.spend_vaccine()
self.__pontuation.add_point()
return True
def __action_after_hit_virus_and_player_not_invencible(self, hit_virus, player_is_invencible):
current_time = time.time()
if hit_virus and not player_is_invencible:
self.__heart.lost_life()
if self.__heart.zero_lives_left():
return False
else:
self.__sound.lost_life_play()
self.__player.is_invencible()
return True
def __action_after_hit_vacine(self, hit_vaccine):
if hit_vaccine:
self.__independent_vaccine.colided()
self.__vaccine.got_vaccine()
self.__sound.vaccine_heart_play()
def __action_after_hit_heart(self, hit_heart):
if hit_heart:
self.__independent_heart.colided()
self.__heart.win_life()
self.__sound.vaccine_heart_play()
def __draw_collectables(self):
self.__heart.draw(self.__screen)
self.__vaccine.draw(self.__screen)
self.__independent_heart.draw(self.__screen)
self.__independent_vaccine.draw(self.__screen)
def __draw_managers(self):
self.__virus_manager.draw(self.__screen)
def __draw_background(self):
self.__vaccines_background.draw(self.__screen)