obstacles = []
player = codesters.Sprite("person1")
player.set_size(.5)
stage.set_gravity(10)
gameOver = False
score = 0
score_text = codesters.Text("Score: 0", 0,150, "grey")
def initialize():
stage.set_background_color("lightblue")
stage.disable_all_walls()
ground = codesters.Rectangle(0,-200, 1000,50, "red")
ground.set_gravity_off()
def collision(player, hit_sprite):
global gameOver
player.set_y_speed(0)
player.set_gravity_off()
if hit_sprite.get_color() is "blue":
codesters.Text("You Lose!",0,0,"red")
gameOver = True
player.event_collision(collision)
def create_obstacles():
distance = 300
x = -100
y = -130
for i in range(5):
x = x + distance
new_obstacle = codesters.Rectangle(x,y, 50,100, "blue")
new_obstacle.set_gravity_off()
obstacles.append(new_obstacle)
def scroll_world(dx, dy):
for s in obstacles:
s.set_x(s.get_x()+dx)
s.set_y(s.get_y()+dy)
def jump():
global player
player.set_y_speed(10)
player.set_gravity_on()
def move():
global gameOver
while gameOver== False:
scroll_world(-5, 0)
stage.wait(0.1)
initialize()
create_obstacles()
score = 0
def get_score():
global score
for s in obstacles:
if s.get_x() < -250:
score = score + 1
obstacles.remove(s)
stage.remove_sprite(s)
while gameOver == False:
scroll_world(-5, 0)
stage.event_key("space",jump)
get_score()
score_text.set_text("Score: "+ str(score))
stage.wait(0.05)
-
Run Code
-
-
Stop Running Code
-
Show Chart
-
Show Console
-
Codesters How To (opens in a new tab)