STEP 13: Before we make the top block, we need to make sure there's a gap between the top and bottom blocks.
Go to the LOGIC tab and the toolkit. Drag Addition onto the next line in make_blocks().
Change my_var to y2. Replace the 2 with y1 and replace 3 with 150. (150 is half the bottom block's height)
y1 plus 150 gets us to the top of the bottom block. Then, add+ block_gap + 150 to the equation.
By adding block_gap and half of the top block's height, we calculate y2 which is the y-position of the top block.
To navigate the page using the TAB key, first press ESC to exit the code editor.
# 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)
t = codesters.Teacher()
adds = t.find_text("+")
try:
tval1 = adds[3][1].lower().replace(' ','')
tval1_indent = t.get_indent_at_line(adds[3][0])
except:
tval1 = "DNE"
tval1_indent = "DNE"
t1 = TestObjective()
t1.add_success('y2=y1+150+block_gap+150' in tval1 and tval1_indent == 4, "Great Job!")
t1.add_failure(tval1 == "DNE", "Did you add the equation from the instructions inside the make_blocks() function?")
t1.add_failure(tval1 != "DNE" and 'y2=y1+150+block_gap+150' not in tval1, "Are you sure you got the equation correct?")
t1.add_failure(tval1 != "DNE" and tval1_indent != 4, "Make sure the equation is indented once inside make_blocks()!")
tester = TestManager()
tester.add_test_list([t1])
tester.run_tests()
tester.display_first_feedback()
Are you already running a Codesters project in another tab or window?
Micro:bit can only connect to one web page at a time.
Try stopping other Codesters projects or closing
other tabs or windows that may be using your Micro:bit.
If that doesn't fix the problem try disconnecting your Micro:bit,
reloading this page, and reconnecting your Micro:bit.