Skip to content

Commit 5ba3199

Browse files
committed
content: add extra test to drawing squares practice in lesson 6
close #486
1 parent 5ca66eb commit 5ba3199

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

course/lesson-6-multiple-function-parameters/drawing_squares/TestsDrawingSquares.gd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ func _prepare():
1818

1919

2020
func test_turtle_ends_facing_towards_the_right() -> String:
21+
var turn_right_between_jumps := 0
22+
for command in turtle.get_command_stack():
23+
if command.command == "turn":
24+
turn_right_between_jumps += 1
25+
if not is_equal_approx(command.angle, 90.0):
26+
return tr("The turtle should always turn by 90 degrees. Instead, we found that it turned by %s degrees in one call to turn_right()." % command.angle)
27+
elif command.command == "jump":
28+
if turn_right_between_jumps != 4:
29+
return tr("The turtle should turn four times to draw a square so that it always starts drawing the squares in the same direction. Did you call turn_right() four times?")
30+
return ""
31+
32+
33+
func test_turtle_starts_each_square_facing_towards_the_right() -> String:
2134
if not is_equal_approx(wrapf(turtle.turn_degrees, 0.0, 360.0), 0.0):
2235
return tr(
2336
"The turtle should be facing towards the right to draw squares in the same direction every time. Did you call turn_right(90) four times in your function?"

course/lesson-6-multiple-function-parameters/lesson.tres

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ We could use these squares as outlines when selecting units in a tactical game,
338338
339339
Create a function named [code]draw_square()[/code] that takes one parameter: the [code]length[/code] of the square's sides.
340340
341-
The turtle should face towards the right when starting or completing a rectangle."
341+
[b]The turtle should face towards the right when starting or completing a square.[/b]
342+
343+
Be sure to call [b]turn_right(90)[/b] enough times in your function to do so."
342344
starting_code = ""
343345
cursor_line = 0
344346
cursor_column = 0
@@ -357,7 +359,7 @@ goal = "Let's make our square drawing function more flexible to include rectangl
357359
358360
Your job is to code a function named [code]draw_rectangle()[/code] that takes two parameters: the [code]length[/code] and the [code]height[/code] of the rectangle.
359361
360-
The turtle should face towards the right when starting or completing a rectangle.
362+
[b]The turtle should face towards the right when starting or completing a rectangle.[/b]
361363
362364
Note that we could still draw a square with [code]draw_rectangle()[/code] by having the [code]length[/code] and [code]height[/code] equal the same value."
363365
starting_code = "func draw_rectangle():

game_demos/DrawingTurtle.gd

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,6 @@ func play_draw_animation() -> void:
207207
line.start()
208208

209209

210-
# Animates the turtle's height and shadow scale when jumping. Tween the progress
211-
# value from 0 to 1.
212-
func _animate_jump(progress: float) -> void:
213-
var parabola := -pow(2.0 * progress - 1.0, 2.0) + 1.0
214-
_sprite.position.y = -parabola * 100.0
215-
var shadow_scale := (1.0 - parabola + 1.0) / 2.0
216-
_shadow.scale = shadow_scale * Vector2.ONE
217-
218-
219210
# Returns the total bounding rectangle enclosing all the turtle's drawn
220211
# polygons.
221212
func get_rect() -> Rect2:
@@ -227,6 +218,19 @@ func get_rect() -> Rect2:
227218
return bounds
228219

229220

221+
func get_command_stack() -> Array:
222+
return _command_stack.duplicate()
223+
224+
225+
# Animates the turtle's height and shadow scale when jumping. Tween the progress
226+
# value from 0 to 1.
227+
func _animate_jump(progress: float) -> void:
228+
var parabola := -pow(2.0 * progress - 1.0, 2.0) + 1.0
229+
_sprite.position.y = -parabola * 100.0
230+
var shadow_scale := (1.0 - parabola + 1.0) / 2.0
231+
_shadow.scale = shadow_scale * Vector2.ONE
232+
233+
230234
func _close_polygon() -> void:
231235
if _points.empty():
232236
return

0 commit comments

Comments
 (0)