-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.py
160 lines (140 loc) · 6.2 KB
/
objects.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import pygame
import random
from constantes import (
ETHER_IMAGE,
NEEDLE_IMAGE,
SYRINGE_IMAGE,
SPRITE_SIZE,
ONE_IMAGE,
TWO_IMAGE,
THREE_IMAGE,
WALL_IMAGE,
RESET_IMAGE,
)
class Objects:
"""
Objects items in the game
"""
def __init__(self, syringe_image, ether_image, needle_image, labyrinth, window):
self.ether = pygame.image.load(ETHER_IMAGE).convert_alpha()
self.needle = pygame.image.load(NEEDLE_IMAGE).convert_alpha()
self.syringe = pygame.image.load(SYRINGE_IMAGE).convert_alpha()
self.counter_ether = 0
self.counter_needle = 0
self.counter_syringe = 0
self.objects_collected = 0
self.labyrinth = labyrinth
self.window = window
def generate_random_position(self):
"""
Random position generator
"""
searching = True
self.x = 0
self.y = 0
while searching:
self.position = []
self.x = random.randrange(0, 14, 1)
self.y = random.randrange(0, 14, 1)
if self.labyrinth.structure[self.y][self.x] == "F":
self.position.extend([self.x, self.y])
searching = False
return self.position
def display_objects(self):
"""
Use the random position generator to assign objects positions to pictures
"""
self.ether_position = []
self.needle_position = []
self.syringe_position = []
while (
self.ether_position == self.syringe_position
or self.ether_position == self.needle_position
or self.syringe_position == self.needle_position
):
self.ether_position = self.generate_random_position()
self.syringe_position = self.generate_random_position()
self.needle_position = self.generate_random_position()
self.ether_position_pixel = [
i * SPRITE_SIZE for i in self.ether_position]
self.needle_position_pixel = [
i * SPRITE_SIZE for i in self.needle_position]
self.syringe_position_pixel = [
i * SPRITE_SIZE for i in self.syringe_position
]
self.window.blit(self.ether, self.ether_position_pixel)
self.window.blit(self.syringe, self.syringe_position_pixel)
self.window.blit(self.needle, self.needle_position_pixel)
def collect_objects(self, player):
"""
Count number of objects collected
"""
if player.position == self.ether_position:
self.counter_ether = 1
elif player.position == self.syringe_position:
self.counter_syringe = 1
elif player.position == self.needle_position:
self.counter_needle = 1
self.objects_collected = (
self.counter_ether + self.counter_syringe + self.counter_needle
)
self.display_object_collected(
self.objects_collected,
ONE_IMAGE,
TWO_IMAGE,
THREE_IMAGE,
WALL_IMAGE,
player,
)
return self.objects_collected
def display_object_collected(
self, objects_collected, one, two, three, reset_image, player
):
"""
Display counter of collected objects
"""
one = pygame.image.load(ONE_IMAGE).convert_alpha()
two = pygame.image.load(TWO_IMAGE).convert_alpha()
three = pygame.image.load(THREE_IMAGE).convert_alpha()
reset_image = pygame.image.load(RESET_IMAGE).convert_alpha()
ether_image = pygame.image.load(ETHER_IMAGE).convert_alpha()
needle_image = pygame.image.load(NEEDLE_IMAGE).convert_alpha()
syringe_image = pygame.image.load(SYRINGE_IMAGE).convert_alpha()
position_objects_display = [i * SPRITE_SIZE for i in [0, 15]]
position_objects_display_1 = [i * SPRITE_SIZE for i in [1, 15]]
position_objects_display_2 = [i * SPRITE_SIZE for i in [2, 15]]
position_objects_display_3 = [i * SPRITE_SIZE for i in [3, 15]]
window = self.window
if objects_collected == 1 and player.position == self.ether_position:
window.blit(one, position_objects_display)
window.blit(ether_image, position_objects_display_1)
elif objects_collected == 1 and player.position == self.needle_position:
window.blit(one, position_objects_display)
window.blit(needle_image, position_objects_display_1)
elif objects_collected == 1 and player.position == self.syringe_position:
window.blit(one, position_objects_display)
window.blit(syringe_image, position_objects_display_1)
elif objects_collected == 2 and player.position == self.ether_position:
window.blit(reset_image, position_objects_display)
window.blit(two, position_objects_display)
window.blit(ether_image, position_objects_display_2)
elif objects_collected == 2 and player.position == self.needle_position:
window.blit(reset_image, position_objects_display)
window.blit(two, position_objects_display)
window.blit(needle_image, position_objects_display_2)
elif objects_collected == 2 and player.position == self.syringe_position:
window.blit(reset_image, position_objects_display)
window.blit(two, position_objects_display)
window.blit(syringe_image, position_objects_display_2)
elif objects_collected == 3 and player.position == self.ether_position:
window.blit(reset_image, position_objects_display)
window.blit(three, position_objects_display)
window.blit(ether_image, position_objects_display_3)
elif objects_collected == 3 and player.position == self.needle_position:
window.blit(reset_image, position_objects_display)
window.blit(three, position_objects_display)
window.blit(needle_image, position_objects_display_3)
elif objects_collected == 3 and player.position == self.syringe_position:
window.blit(reset_image, position_objects_display)
window.blit(three, position_objects_display)
window.blit(syringe_image, position_objects_display_3)