-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpile.py
More file actions
147 lines (115 loc) · 5.56 KB
/
pile.py
File metadata and controls
147 lines (115 loc) · 5.56 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
142
143
144
145
146
147
import pygame
import os
from pygame.locals import *
from bin import Bins
from item import Item
import random
from status import Status
class Pile(pygame.sprite.Sprite):
# takes width and height of window as params
def __init__(self, width, height, screen):
super().__init__()
self.count = 0
self.finished = False
self.itempicked = False
self.draw_item = False
self.w, self.h = width, height
self.start = True
# finished pop out window
self.font = pygame.font.Font('freesansbold.ttf', 45)
self.text = self.font.render("Congratulations you finished!", True, (255,255,255))
self.text_rect = self.text.get_rect()
self.text_rect.center = (self.w / 2, self.h / 2)
self.endpopout_rect = pygame.Rect((self.w / 2) - 300, (self.h / 2) - 230, 500, 500)
self.endsurface1 = pygame.image.load(os.path.join("images/start_end", "greatFinish.png")).convert_alpha()
self.endsurface2 = pygame.image.load(os.path.join("images/start_end", "goodFinish.png")).convert_alpha()
self.endsurface3 = pygame.image.load(os.path.join("images/start_end", "badFinish.png")).convert_alpha()
self.startpopout_rect = pygame.Rect((self.w / 2) - 300, (self.h / 2) - 230, 500, 500)
self.startsurface = pygame.image.load(os.path.join("images/start_end", "pileInstructions.png")).convert_alpha()
self.startbutton = pygame.Rect(self.startpopout_rect.x + 80, self.startpopout_rect.y + 388, 440, 50)
self.endbutton = pygame.Rect(self.endpopout_rect.x + 80, self.endpopout_rect.y + 388, 440, 50)
self.bg = pygame.image.load(os.path.join("images", "pileBackground.png"))
self.bgrect = self.bg.get_rect()
self.bgrect.x = 0
self.bgrect.y = 0
self.bgrect.width = 1400
self.bgrect.height = 900
# initialize image and rect
self.image = pygame.image.load(os.path.join("images","pile.png")).convert_alpha()
self.rect = self.image.get_rect()
self.rect.center = self.w / 2, self.h / 2 - (self.h / 4)
self.bins = Bins()
self.item = None
self.status = Status(width, height)
# spawn random recycle/ trash item
def spawnItem(self):
type = random.randint(0, 14)
self.item = Item(type, pygame.mouse.get_pos())
self.item.moving = True
self.itempicked = True
self.draw_item = True
def reset(self, gamelogic):
self.finished = False
self.draw_item = False
self.itempicked = False
self.count = 0
self.start = True
self.status.colorScore((0,0,0), gamelogic)
self.status.moveScore(self.w - 100, 50)
self.item = None
def render(self, screen, gamelogic):
if self.start:
screen.blit(self.startsurface, self.startpopout_rect)
self.image = pygame.image.load(os.path.join("images","pile.png")).convert_alpha()
self.rect = self.image.get_rect()
self.rect.center = self.w / 2, self.h / 2 - (self.h / 4)
gamelogic.setScore(0)
gamelogic.setState(1)
else:
if not self.finished:
screen.blit(self.image, self.rect)
self.bins.render(screen)
if self.draw_item:
self.item.draw(screen)
if self.finished:
if gamelogic.getScore() > 250:
screen.blit(self.endsurface1, self.endpopout_rect)
elif gamelogic.getScore() > 50:
screen.blit(self.endsurface2, self.endpopout_rect)
else:
screen.blit(self.endsurface3, self.endpopout_rect)
self.status.moveScore(560, 322)
self.status.colorScore((65, 170, 47), gamelogic)
self.status.render(screen)
# decreases size of pile
def update(self, gamelogic, event):
if event.type == MOUSEBUTTONDOWN and self.start and self.startbutton.collidepoint(event.pos):
self.start = False
if event.type == MOUSEBUTTONDOWN and self.finished and self.endbutton.collidepoint(event.pos):
self.reset(gamelogic)
#self.item.update(event, self.bins, gamelogic)
self.status.update(gamelogic, event, gamelogic.getScore(), self)
if event.type == MOUSEBUTTONDOWN and not self.finished and not self.start:
# Check pile click
if self.rect.collidepoint(event.pos):
if not self.itempicked:
self.count += 1
if(self.count % 3 == 0):
# adjust size of image
size = self.image.get_width() * .9, self.image.get_height() * .9
self.image = pygame.transform.scale(self.image, size)
# adjust size and position of rect
self.rect.width, self.rect.height = self.image.get_width(), self.image.get_height()
self.rect.move_ip(15, 22)
# pick up item
self.spawnItem()
self.draw_item = True
else:
pygame.mixer.music.load("sounds/putInTrash.wav")
pygame.mixer.music.play()
if self.item != None and self.item.update(event, self.bins, gamelogic):
if self.count == 15:
self.finished = True
self.draw_item = False
self.itempicked = False
self.item = None