From a8745f4b7772ff683361d3611e084b38be4da450 Mon Sep 17 00:00:00 2001 From: Lucas Popenke Date: Sat, 19 Nov 2016 22:46:28 -0200 Subject: [PATCH] Fixed some parts where code was rendered as normal text Fixed some code parts that where rendered as normal text. There is also one variable - 'direction' - that is not anywhere in code examples and I don't know how fix it. --- tutorials/step_by_step/simple_2d_game.rst | 28 +++++++++-------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/tutorials/step_by_step/simple_2d_game.rst b/tutorials/step_by_step/simple_2d_game.rst index 978fb3e65..7eeed09f2 100644 --- a/tutorials/step_by_step/simple_2d_game.rst +++ b/tutorials/step_by_step/simple_2d_game.rst @@ -148,11 +148,11 @@ our ball move. var screen_size var pad_size - # constant for pad speed (in pixels/second) + # Constant for pad speed (in pixels/second) const INITIAL_BALL_SPEED = 80 - # speed of the ball (also in pixels/second) + # Speed of the ball (also in pixels/second) var ball_speed = INITIAL_BALL_SPEED - # constant for pads speed + # Constant for pads speed const PAD_SPEED = 150 func _ready(): @@ -175,10 +175,8 @@ default, so a small adjustment of ``pad_size / 2`` must be added. func _process(delta): var ball_pos = get_node("ball").get_pos() - var left_rect = Rect2( get_node("left").get_pos() - pad_size*0.5, -pad_size ) - var right_rect = Rect2( get_node("right").get_pos() - pad_size*0.5, -pad_size ) + var left_rect = Rect2( get_node("left").get_pos() - pad_size*0.5, pad_size ) + var right_rect = Rect2( get_node("right").get_pos() - pad_size*0.5, pad_size ) Now, let's add some movement to the ball in the ``_process()`` function. Since the ball position is stored in the ``ball_pos`` variable, @@ -200,8 +198,7 @@ the floor and the roof: :: # Flip when touching roof or floor - if ((ball_pos.y < 0 and direction.y < 0) or (ball_pos.y > -screen_size.y and direction.y > 0)): + if ((ball_pos.y < 0 and direction.y < 0) or (ball_pos.y > screen_size.y and direction.y > 0)): direction.y = -direction.y Second, the pads: if one of the pads was touched, we need to invert the @@ -212,8 +209,7 @@ speed a little. :: # Flip, change direction and increase speed when touching pads - if ((left_rect.has_point(ball_pos) and direction.x < 0) or -(right_rect.has_point(ball_pos) and direction.x > 0)): + if ((left_rect.has_point(ball_pos) and direction.x < 0) or (right_rect.has_point(ball_pos) and direction.x > 0)): direction.x = -direction.x direction.y = randf()*2.0 - 1 direction = direction.normalized() @@ -243,24 +239,22 @@ is done using the Input class: :: - #move left pad + # Move left pad var left_pos = get_node("left").get_pos() if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")): left_pos.y += -PAD_SPEED * delta - if (left_pos.y < screen_size.y and -Input.is_action_pressed("left_move_down")): + if (left_pos.y < screen_size.y and Input.is_action_pressed("left_move_down")): left_pos.y += PAD_SPEED * delta get_node("left").set_pos(left_pos) - #move right pad + # Move right pad var right_pos = get_node("right").get_pos() if (right_pos.y > 0 and Input.is_action_pressed("right_move_up")): right_pos.y += -PAD_SPEED * delta - if (right_pos.y < screen_size.y and -Input.is_action_pressed("right_move_down")): + if (right_pos.y < screen_size.y and Input.is_action_pressed("right_move_down")): right_pos.y += PAD_SPEED * delta get_node("right").set_pos(right_pos)