-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathshelves.py
More file actions
executable file
·141 lines (118 loc) · 6.25 KB
/
shelves.py
File metadata and controls
executable file
·141 lines (118 loc) · 6.25 KB
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
import pygame
import config
from enums.cart_state import CartState
from enums.direction import Direction
from helper import obj_collision, can_interact_default, overlap
from render_game import render_text
from objects import InteractiveObject
class Shelf(InteractiveObject):
def __init__(self, x_position, y_position, shelf_image, food_image, string_type, price, capacity, quantity, load_images):
super().__init__(num_stages=1)
self.position = [x_position, y_position]
self.image = shelf_image
self.food_image = food_image
self.image_filenames = [shelf_image, food_image]
self.string_type = string_type
self.width = 2
self.height = 1
self.price = price
self.capacity = capacity
self.item_quantity = quantity
self.render_offset_y = -1
self.render_offset_x = 0
self.loaded = False
# self.player_inventory_limit = 12
if shelf_image == "images/Shelves/fridge.png":
self.is_fridge = True
else:
self.is_fridge = False
def __str__(self):
return "the {food} shelf".format(food=self.string_type)
def load_images(self, food_image, shelf_image):
self.image = pygame.transform.scale(pygame.image.load(shelf_image),
(int(2 * config.SCALE), int(2 * config.SCALE)))
self.food_image = pygame.transform.scale(pygame.image.load(food_image),
(int(.30 * config.SCALE), int(.30 * config.SCALE)))
def collision(self, obj, x_position, y_position):
return overlap(self.position[0], self.position[1], self.width, self.height,
x_position, y_position, obj.width, obj.height)
# return obj_collision(self, x_position, y_position, x_margin=0, y_margin=0)
def can_interact(self, player):
if player.direction == Direction.EAST or player.direction == Direction.WEST:
return False
return can_interact_default(self, player)
def render(self, screen, camera):
if not self.loaded:
self.load_images(self.food_image, self.image)
self.loaded = True
x_position = (self.position[0] + self.render_offset_x - camera.position[0]) * config.SCALE
y_position = (self.position[1] + self.render_offset_y - camera.position[1]) * config.SCALE
rect = pygame.Rect(x_position, y_position, config.SCALE, config.SCALE)
screen.blit(self.image, rect)
if self.item_quantity > 0:
# add blit for type of food-- FIX: DOESN'T ADJUST FOR CONFIG SCALE
if self.is_fridge:
for i in [0.9]:
for j in [0.2, 0.5]:
rect = pygame.Rect(x_position + j * config.SCALE, y_position + i * config.SCALE, config.SCALE,
config.SCALE)
screen.blit(self.food_image, rect)
for i in [0.9]:
for j in [1.2, 1.5]:
rect = pygame.Rect(x_position + j * config.SCALE, y_position + i * config.SCALE, config.SCALE,
config.SCALE)
screen.blit(self.food_image, rect)
if self.item_quantity > self.capacity / 2:
for i in [1.4]:
for j in [0.2, 0.5]:
rect = pygame.Rect(x_position + j * config.SCALE, y_position + i * config.SCALE,
config.SCALE, config.SCALE)
screen.blit(self.food_image, rect)
for i in [1.4]:
for j in [1.2, 1.5]:
rect = pygame.Rect(x_position + j * config.SCALE, y_position + i * config.SCALE,
config.SCALE, config.SCALE)
screen.blit(self.food_image, rect)
else:
for i in [0.9]:
for j in [0.3, 0.6, 0.9, 1.2, 1.5]:
rect = pygame.Rect(x_position + j * config.SCALE, y_position + i * config.SCALE, config.SCALE,
config.SCALE)
screen.blit(self.food_image, rect)
if self.item_quantity > self.capacity / 2:
for i in [1.4]:
for j in [0.3, 0.6, 0.9, 1.2, 1.5]:
rect = pygame.Rect(x_position + j * config.SCALE, y_position + i * config.SCALE,
config.SCALE, config.SCALE)
screen.blit(self.food_image, rect)
def interact(self, game, player):
empty = False
if self.item_quantity == 0:
empty = True
if player.curr_cart is None and player.curr_basket is None:
if player.holding_food is not None:
# check what kind of food...
self.set_interaction_message(player, "You put " + player.holding_food + " back on the shelf.")
empty = False
if player.holding_food == self.string_type:
self.item_quantity += 1
player.holding_food = None
# If you put the food back in the wrong place, that violates a norm
else:
if not empty:
player.holding_food = self.string_type
player.holding_food_image = self.food_image
self.set_interaction_message(player, "You picked up " + self.string_type + ".")
self.item_quantity -= 1
elif player.curr_basket is None:
self.set_interaction_message(player, "Let go of your cart to pick up food!")
else:
if not empty:
if not player.curr_basket.hit_limit():
self.set_interaction_message(player, "You put " + self.string_type + " in your basket.")
player.curr_basket.add_food(self.string_type, False)
self.item_quantity -= 1
else:
self.set_interaction_message(player, "The basket is full! The food won't fit.")
if empty:
self.set_interaction_message(player, "The shelf is empty.")