Skip to content

Commit 4d6b38b

Browse files
committed
Added new start screen
Added new start screen Version: 1.1.8
1 parent 751e303 commit 4d6b38b

File tree

1 file changed

+76
-35
lines changed

1 file changed

+76
-35
lines changed

code/SRunner.py

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
Program Name: SRunner.py
33
Creator: James Ashwood
4-
Date last modified: 8 Aug 2021
5-
Github Link: https://github.com/James-Ashwood/SRunner
4+
Date last modified: 9 Aug 2021
5+
Github Link: https://github.com/The-Intil-Coding-Group/SRunner/
66
"""
77

88
### ~ Imports and variable definiitions ~ ###
@@ -13,6 +13,8 @@
1313
from typing import Optional
1414
import random
1515

16+
from arcade.window_commands import start_render
17+
1618
## Constants
1719

1820
SCREEN_WIDTH = 800
@@ -42,21 +44,24 @@
4244

4345
## Game specific data
4446

45-
global GAME_STATUS, CURRENT_BLOCK_NUMBER, CURRENT_BLOCK_TYPE, SCORE, BLOCKS
47+
global GAME_STATUS, CURRENT_BLOCK_NUMBER, CURRENT_BLOCK_TYPE, SCORE, BLOCKS, SELECTED, START_X
4648

47-
GAME_STATUS = 1
49+
GAME_STATUS = 0
4850

4951
CURRENT_BLOCK_NUMBER = 1
5052
CURRENT_BLOCK_TYPE = 0
5153
SCORE = 1
5254

5355
BLOCKS = []
5456

57+
SELECTED = 2
58+
START_X = 400
59+
5560
class MyGame(arcade.Window):
5661
def __init__(self, width, height, title):
5762
super().__init__(width, height, title)
5863

59-
arcade.set_background_color((101,124,133))
64+
arcade.set_background_color((89, 89, 89))
6065

6166
### ~ Variable Definitions ~ ###
6267

@@ -92,6 +97,22 @@ def setup(self):
9297
BLOCKS.append(x)
9398

9499
### ~ Sprite Loading And Lists ~ ###
100+
101+
## Load up charecter
102+
103+
self.start_list = arcade.SpriteList()
104+
image_sourceA ="code/resources/main.png" ## Main player
105+
self.start_sprite = arcade.Sprite(image_sourceA, 2)
106+
self.start_sprite.center_x = 400
107+
self.start_sprite.center_y = 150
108+
self.start_list.append(self.start_sprite)
109+
image_sourceB ="code/resources/floor.png" ## Floor
110+
self.start_sprite = arcade.Sprite(image_sourceB, 2)
111+
self.start_sprite.center_x = 500
112+
self.start_sprite.center_y = 60
113+
self.start_list.append(self.start_sprite)
114+
115+
## Player
95116

96117
self.player_list = arcade.SpriteList()
97118
image_source ="code/resources/main.png" ## Main player
@@ -183,16 +204,6 @@ def setup(self):
183204
self.bg_sprite.center_y = 250
184205
self.bg.append(self.bg_sprite)
185206

186-
## Start button
187-
188-
self.start_list = arcade.SpriteList()
189-
image_source7 ="code/resources/startbutton.png" ## Block type 5
190-
191-
self.start_sprite = arcade.Sprite(image_source7, 1)
192-
self.start_sprite.center_x = 120
193-
self.start_sprite.center_y = 130
194-
self.start_list.append(self.start_sprite)
195-
196207
### ~ Physics Engine Setup ~ ###
197208

198209
## Set variables
@@ -216,10 +227,18 @@ def on_draw(self):
216227

217228
### ~ Displaying The Game ~ ###
218229

219-
global GAME_STATUS, SCORE
230+
global GAME_STATUS, SCORE, SELECTED
220231
arcade.start_render()
221232

222233
## Display the data based on the game status
234+
235+
if GAME_STATUS == 0:
236+
arcade.draw_text("SRunner - Run for victory", 20, 525, arcade.color.BLACK, 50, font_name="code/resources/font.ttf")
237+
arcade.draw_text("Play", 20, 485, arcade.color.BLACK, 35, font_name="code/resources/font.ttf")
238+
arcade.draw_text("Help", 20, 445, arcade.color.BLACK, 35, font_name="code/resources/font.ttf")
239+
arcade.draw_text("Info", 20, 405, arcade.color.BLACK, 35, font_name="code/resources/font.ttf")
240+
arcade.draw_text("|", 5, ((40 * SELECTED) + 405), arcade.color.GREEN, 35, font_name="code/resources/font.ttf")
241+
self.start_list.draw()
223242

224243
if GAME_STATUS == 1:
225244
self.bg.draw()
@@ -236,7 +255,14 @@ def on_draw(self):
236255
def on_update(self, delta_time):
237256

238257
## Check for the right game status
239-
global GAME_STATUS, CURRENT_BLOCK_NUMBER, CURRENT_BLOCK_TYPE, SCORE, BLOCKS
258+
global GAME_STATUS, CURRENT_BLOCK_NUMBER, CURRENT_BLOCK_TYPE, SCORE, BLOCKS, START_X
259+
260+
if GAME_STATUS == 0:
261+
for sprite in self.start_list:
262+
sprite.center_x = sprite.center_x + 1
263+
if sprite.center_x > 1000:
264+
for sprite in self.start_list:
265+
sprite.center_x = sprite.center_x - 1200
240266

241267
if GAME_STATUS == 1:
242268

@@ -307,26 +333,41 @@ def on_mouse_press(self, _x, _y, _button, _modifiers):
307333

308334
def on_key_press(self, key, modifiers):
309335

310-
global CURRENT_BLOCK_TYPE
336+
global CURRENT_BLOCK_TYPE, GAME_STATUS, SELECTED
311337

312-
## Player jumps if the UP or W key is pressed
313-
314-
if key == arcade.key.UP or key == arcade.key.W:
315-
if self.physics_engine.is_on_ground(self.player_sprite): ## Check if the player is on the ground
316-
impulse = (0, PLAYER_JUMP_IMPULSE)
317-
self.physics_engine.apply_impulse(self.player_sprite, impulse) ## Apply the jump impulse
318-
319-
## If the player moves left or right, apply a force in that direction and turn off friction for the time being
320-
321-
elif key == arcade.key.LEFT or key == arcade.key.A:
322-
force = (-PLAYER_MOVE_FORCE_ON_GROUND, 0)
323-
self.physics_engine.apply_force(self.player_sprite, force)
324-
self.physics_engine.set_friction(self.player_sprite, 0)
338+
if GAME_STATUS == 1:
339+
340+
## Player jumps if the UP or W key is pressed
325341

326-
elif key == arcade.key.RIGHT or key == arcade.key.D:
327-
force = (PLAYER_MOVE_FORCE_ON_GROUND, 0)
328-
self.physics_engine.apply_force(self.player_sprite, force)
329-
self.physics_engine.set_friction(self.player_sprite, 0)
342+
if key == arcade.key.UP or key == arcade.key.W:
343+
if self.physics_engine.is_on_ground(self.player_sprite): ## Check if the player is on the ground
344+
impulse = (0, PLAYER_JUMP_IMPULSE)
345+
self.physics_engine.apply_impulse(self.player_sprite, impulse) ## Apply the jump impulse
346+
347+
## If the player moves left or right, apply a force in that direction and turn off friction for the time being
348+
349+
elif key == arcade.key.LEFT or key == arcade.key.A:
350+
force = (-PLAYER_MOVE_FORCE_ON_GROUND, 0)
351+
self.physics_engine.apply_force(self.player_sprite, force)
352+
self.physics_engine.set_friction(self.player_sprite, 0)
353+
354+
elif key == arcade.key.RIGHT or key == arcade.key.D:
355+
force = (PLAYER_MOVE_FORCE_ON_GROUND, 0)
356+
self.physics_engine.apply_force(self.player_sprite, force)
357+
self.physics_engine.set_friction(self.player_sprite, 0)
358+
359+
if GAME_STATUS == 0:
360+
if key == arcade.key.UP or key == arcade.key.W:
361+
SELECTED += 1
362+
if SELECTED > 2:
363+
SELECTED = 0
364+
if key == arcade.key.DOWN or key == arcade.key.S:
365+
SELECTED -= 1
366+
if SELECTED < 0:
367+
SELECTED = 2
368+
if (key == arcade.key.SPACE or key == arcade.key.ENTER) and (SELECTED == 2):
369+
GAME_STATUS = 1
370+
self.setup()
330371

331372
def on_key_release(self, key, key_modifiers):
332373

0 commit comments

Comments
 (0)