-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathriver.py
More file actions
150 lines (114 loc) · 5.01 KB
/
river.py
File metadata and controls
150 lines (114 loc) · 5.01 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
148
149
150
import pygame
import os
from pygame.locals import *
from bin import Bins
from item import Item
import random
from status import Status
class RiverScene:
# takes width and height of window as params
def __init__(self, width, height, screen):
self.count = 0
self.start = True
self.finished = False # True if level is over
self.itempicked = False # True if item has been picked up
self.draw_item = False # True if item needs to be drawn
self.width, self.height = width, height
self.bins = Bins()
self.item = Item(0, (0,0))
self.status = Status(width, height)
self.items = []
self.item = None
self.endpopout_rect = pygame.Rect((self.width / 2) - 300, (self.height / 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.width / 2) - 300, (self.height / 2) - 230, 500, 500)
self.startsurface = pygame.image.load(os.path.join("images/start_end", "riverInstructions.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", "riverBackground.png"))
self.bgrect = self.bg.get_rect()
self.bgrect.x = 0
self.bgrect.y = 0
self.bgrect.width = 1400
self.bgrect.height = 900
screen.blit(self.bg, self.bgrect)
self.speedcount = 1
self.speed = 3
# spawns a random item at given location
def spawnItem(self, location):
type = random.randint(0,14)
item = Item(type, location)
item.setSpeed(self.speed)
self.items.append(item)
# resets game score and images
def reset(self, gamelogic):
self.finished = False
self.items.clear()
gamelogic.setScore(0)
self.count = 0
self.start = True
self.status.colorScore((0,0,0), gamelogic)
self.status.moveScore(self.width - 100, 50)
gamelogic.health = 3
self.speed = 3
self.itempicked = False
self.item = None
# render items in river scene
def render(self, screen, gamelogic):
if self.start:
screen.blit(self.startsurface, self.startpopout_rect)
gamelogic.setState(2)
elif not self.finished:
self.bins.render(screen)
if self.draw_item:
self.item.draw(screen)
for item in self.items:
item.draw(screen)
item.moveWithSpeed()
elif self.finished:
# display correct endscreen
if gamelogic.getScore() > 300:
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)
# updates river scene
def update(self, gamelogic, event):
if gamelogic.health == 0:
self.finished = True
if event.type == MOUSEBUTTONDOWN and self.start and self.startbutton.collidepoint(event.pos):
self.start = False
self.itempicked = False
if event.type == MOUSEBUTTONDOWN and self.finished and self.endbutton.collidepoint(event.pos):
self.reset(gamelogic)
self.status.update(gamelogic, event, gamelogic.getScore(), self)
if self.speedcount%1000 == 0:
self.speed = self.speed+1
self.speedcount = 0
self.speedcount = self.speedcount + 1
if self.count%200 == 0 and not self.start:
# Spawn item at beginning of river
self.spawnItem((50, 280))
self.count = 0
self.count += 1
for item in self.items:
if item.rect.x+item.rect.width/2 >= self.width:
gamelogic.health = gamelogic.health-1
self.items.remove(item)
gamelogic.setScore(gamelogic.getScore()-5)
item.updateTouch(event)
if self.item == None and item.touched:
self.itempicked = True
self.item = item
if self.itempicked:
if self.item.update(event, self.bins, gamelogic):
self.draw_item = False
self.itempicked = False
self.items.remove(self.item)
self.item = None