# Program variables (DON'T DELETE!!!)
block_speed = -6 # controls how fast the pipes move across the stage
block_gap = 200 # controls the space between the top and bottom of each pipe
block_interval = 1 # controls how often a new pipe appears
gravity = 8 # controls how fast the sprite falls
flappiness = 5 # controls how much the sprite moves up
# Store and display score
score = 0
score_text = codesters.Text("Score: " + str(score), 100, 200, "yellow")
########################################################################
# ADD CODE BELOW THIS LINE #
########################################################################
stage.set_background("space")
stage.disable_all_walls()
sprite = codesters.Sprite("dinosaur")
sprite.set_size(0.4)
sprite.set_say_color("yellow")
sprite.say("TAP THE SPACE BAR TO GUIDE ME THROUGH THE BLOCKS!", 3)
sprite.go_to(-200, 0)
stage.set_gravity(gravity)
def space_bar():
sprite.jump(flappiness)
stage.event_key("space", space_bar)
def interval():
global score
score += 1
score_text.set_text("Score: " + str(score))
make_blocks()
stage.event_interval(interval, block_interval)
def make_blocks():
pass # delete after adding indented code
y1 = random.randint(-250, -100)
# sprite = codesters.Rectangle(x, y, width, height, "color")
sprite = codesters.Rectangle(250, y1, 100, 300, "red")
sprite.set_gravity_off()
sprite.set_x_speed(block_speed)
y2 = y1 + 150 + block_gap + 150
# sprite = codesters.Rectangle(x, y, width, height, "color")
sprite = codesters.Rectangle(250, y2, 100, 300, "red")
sprite.set_gravity_off()
sprite.set_x_speed(block_speed)
def collision(sprite, hit_sprite):
sprite.set_physics_off()
stage.event_interval(None)
message = "GAME OVER. YOU COLLECTED " + str(score) + " POINTS!"
# sprite = codesters.Text("text", x, y, "color")
sprite = codesters.Text(message, 0, 0, "yellow")
# add any other actions...
sprite.event_collision(collision)
t = codesters.Teacher()
sprites = t.find_function("Sprite")
try:
tval1 = block_interval
except:
tval1 = "DNE"
try:
tval2 = block_speed
except:
tval2 = "DNE"
try:
tval3 = sprites[0][1].lower().replace(' ','')
except:
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 != 1, "Great Job!")
t1.add_failure(tval1 == "DNE", "Oops, did you delete block_interval?")
t1.add_failure(tval1 == 1, "Did you try changing block_interval? Maybe to 0.75?")
t2 = TestObjective()
t2.add_success(tval2 != -6, "Great Job!")
t2.add_failure(tval2 == "DNE", "Oops, did you delete block_speed?")
t2.add_failure(tval2 == -6, "Did you try changing block_speed? Maybe to -3?")
t3 = TestObjective()
t3.add_success(tval3 == "DNE" or (tval3 != "DNE" and '"dinosaur"' not in tval3), "Great job!")
t3.add_failure(tval3 != "DNE" and '"dinosaur"' in tval3, "Did you try changing the sprite? A circle will make the game easier.")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()