Skip to content

Commit 42ad352

Browse files
committed
Fixed "More blocks" issue
Fixed "More blocks" issue (Number #2 ) Version: 1.1
1 parent e6f1f00 commit 42ad352

7 files changed

Lines changed: 53 additions & 15 deletions

File tree

code/SRunner.py

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@ def setup(self):
8080
### ~ Block generation ~ ###
8181

8282
BLOCKS = [1, 1]
83+
potentialValues = [1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]
8384

8485
while len(BLOCKS) < 998:
85-
x = random.randint(1,4)
86+
x = potentialValues[random.randint(0, len(potentialValues)-1)]
8687
if x != BLOCKS[-1]:
87-
BLOCKS.append(random.randint(1,4))
88+
BLOCKS.append(x)
8889

8990
### ~ Sprite Loading And Lists ~ ###
9091

@@ -123,21 +124,49 @@ def setup(self):
123124
self.jumper_sprite.center_y = 40
124125
self.jumper_list.append(self.jumper_sprite)
125126

126-
## Create the pool list and add the sprites to it
127+
## Create the hill list and add the sprites to it
127128

128-
self.pool_list = arcade.SpriteList()
129-
image_source4 ="resources/pool.png" ## Block type 3
129+
self.hill_list = arcade.SpriteList()
130+
image_source4 ="resources/hill.png" ## Block type 3
130131

131132
indexList = [i for i in range(len(BLOCKS)) if BLOCKS[i] == 3]
132133
valuesList = [i*240-120 for i in indexList]
133134

134135
for x in valuesList:
135-
self.pool_sprite = arcade.Sprite(image_source4, 1)
136-
self.pool_sprite.center_x = x
137-
self.pool_sprite.center_y = 2
138-
self.pool_list.append(self.pool_sprite)
136+
self.hill_sprite = arcade.Sprite(image_source4, 1)
137+
self.hill_sprite.center_x = x
138+
self.hill_sprite.center_y = 2
139+
self.hill_list.append(self.hill_sprite)
139140

140-
## Block type 4 is the gap
141+
## Create the bridge list and add the sprites to it
142+
143+
self.bridge_list = arcade.SpriteList()
144+
image_source4 ="resources/bridge.png" ## Block type 4
145+
146+
indexList = [i for i in range(len(BLOCKS)) if BLOCKS[i] == 4]
147+
valuesList = [i*240-120 for i in indexList]
148+
149+
for x in valuesList:
150+
self.bridge_sprite = arcade.Sprite(image_source4, 1)
151+
self.bridge_sprite.center_x = x
152+
self.bridge_sprite.center_y = 2
153+
self.bridge_list.append(self.bridge_sprite)
154+
155+
## Create the pool list and add the sprites to it
156+
157+
self.zapper_list = arcade.SpriteList()
158+
image_source4 ="resources/zapper.png" ## Block type 5
159+
160+
indexList = [i for i in range(len(BLOCKS)) if BLOCKS[i] == 5]
161+
valuesList = [i*240-120 for i in indexList]
162+
163+
for x in valuesList:
164+
self.zapper_sprite = arcade.Sprite(image_source4, 1)
165+
self.zapper_sprite.center_x = x
166+
self.zapper_sprite.center_y = 2
167+
self.zapper_list.append(self.zapper_sprite)
168+
169+
## Block type 6 is the gap
141170

142171

143172
### ~ Physics Engine Setup ~ ###
@@ -151,9 +180,11 @@ def setup(self):
151180

152181
self.physics_engine = arcade.PymunkPhysicsEngine(damping=damping, gravity=gravity)
153182
self.physics_engine.add_sprite(self.player_sprite, friction=PLAYER_FRICTION, mass=PLAYER_MASS, moment=arcade.PymunkPhysicsEngine.MOMENT_INF, collision_type="player", max_horizontal_velocity=PLAYER_MAX_HORIZONTAL_SPEED, max_vertical_velocity=PLAYER_MAX_VERTICAL_SPEED)
154-
self.physics_engine.add_sprite_list(self.floor_list, friction=0.4, collision_type="item", body_type=arcade.PymunkPhysicsEngine.STATIC)
155-
self.physics_engine.add_sprite_list(self.pool_list, friction=0.4, collision_type="item", body_type=arcade.PymunkPhysicsEngine.STATIC)
156-
self.physics_engine.add_sprite_list(self.jumper_list, friction=0.1, collision_type="item", body_type=arcade.PymunkPhysicsEngine.STATIC)
183+
self.physics_engine.add_sprite_list(self.floor_list, friction=0.6, collision_type="item", body_type=arcade.PymunkPhysicsEngine.STATIC)
184+
self.physics_engine.add_sprite_list(self.bridge_list, friction=0.1, collision_type="item", body_type=arcade.PymunkPhysicsEngine.STATIC)
185+
self.physics_engine.add_sprite_list(self.jumper_list, friction=0.6, collision_type="item", body_type=arcade.PymunkPhysicsEngine.STATIC)
186+
self.physics_engine.add_sprite_list(self.hill_list, friction=0.4, collision_type="item", body_type=arcade.PymunkPhysicsEngine.STATIC)
187+
self.physics_engine.add_sprite_list(self.zapper_list, friction=0.9, collision_type="item", body_type=arcade.PymunkPhysicsEngine.STATIC)
157188

158189
self.view_left = 0 ## Scrolling Setup
159190

@@ -170,7 +201,9 @@ def on_draw(self):
170201
self.floor_list.draw()
171202
self.player_list.draw()
172203
self.jumper_list.draw()
173-
self.pool_list.draw()
204+
self.hill_list.draw()
205+
self.zapper_list.draw()
206+
self.bridge_list.draw()
174207

175208
if GAME_STATUS == 2:
176209
arcade.draw_text("Game over, you score was " + str(SCORE), 20, 20, arcade.color.BLACK, 30)
@@ -210,7 +243,7 @@ def on_update(self, delta_time):
210243
-50,
211244
SCREEN_HEIGHT-50)
212245

213-
### ~ Super Jump block ~ ###
246+
### ~ Super Jump and Zapper block ~ ###
214247

215248
SCORE = round(self.player_sprite.center_x / 240)
216249
CURRENT_BLOCK_NUMBER = SCORE
@@ -220,6 +253,11 @@ def on_update(self, delta_time):
220253
if self.physics_engine.is_on_ground(self.player_sprite): ## Check if the player is on the ground
221254
impulse = (0, PLAYER_JUMP_IMPULSE*2) ## Make it jump twice the normal height
222255
self.physics_engine.apply_impulse(self.player_sprite, impulse) ## Apply the jump impulse
256+
257+
if CURRENT_BLOCK_TYPE == 5: ## Check for zapper block
258+
if self.physics_engine.is_on_ground(self.player_sprite): ## Check if the player is on the ground
259+
impulse = (PLAYER_JUMP_IMPULSE*5, PLAYER_JUMP_IMPULSE) ## Make it jump twice the normal height
260+
self.physics_engine.apply_impulse(self.player_sprite, impulse) ## Apply the jump impulse
223261

224262

225263
### ~ Preparing the game status ~ ###

code/resources/bridge.png

134 Bytes
Loading

code/resources/floor.png

-129 Bytes
Loading

code/resources/hill.png

416 Bytes
Loading

code/resources/jumper.png

-87 Bytes
Loading

code/resources/pool.png

-267 Bytes
Binary file not shown.

code/resources/zapper.png

171 Bytes
Loading

0 commit comments

Comments
 (0)