Browse Source

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.
Lucas Popenke 8 years ago
parent
commit
a8745f4b77
1 changed files with 11 additions and 17 deletions
  1. 11 17
      tutorials/step_by_step/simple_2d_game.rst

+ 11 - 17
tutorials/step_by_step/simple_2d_game.rst

@@ -148,11 +148,11 @@ our ball move.
     var screen_size
     var screen_size
     var pad_size
     var pad_size
     
     
-    # constant for pad speed (in pixels/second)
+    # Constant for pad speed (in pixels/second)
     const INITIAL_BALL_SPEED = 80
     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
     var ball_speed = INITIAL_BALL_SPEED
-    # constant for pads speed
+    # Constant for pads speed
     const PAD_SPEED = 150
     const PAD_SPEED = 150
 
 
     func _ready():
     func _ready():
@@ -175,10 +175,8 @@ default, so a small adjustment of ``pad_size / 2`` must be added.
 
 
     func _process(delta):
     func _process(delta):
         var ball_pos = get_node("ball").get_pos()
         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.
 Now, let's add some movement to the ball in the ``_process()`` function.
 Since the ball position is stored in the ``ball_pos`` variable,
 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
         # 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
             direction.y = -direction.y
 
 
 Second, the pads: if one of the pads was touched, we need to invert the
 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
         # 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.x = -direction.x
             direction.y = randf()*2.0 - 1
             direction.y = randf()*2.0 - 1
             direction = direction.normalized()
             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()
         var left_pos = get_node("left").get_pos()
 
 
         if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")):
         if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")):
             left_pos.y += -PAD_SPEED * delta
             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
             left_pos.y += PAD_SPEED * delta
 
 
         get_node("left").set_pos(left_pos)
         get_node("left").set_pos(left_pos)
 
 
-        #move right pad 
+        # Move right pad 
         var right_pos = get_node("right").get_pos()
         var right_pos = get_node("right").get_pos()
 
 
         if (right_pos.y > 0 and Input.is_action_pressed("right_move_up")):
         if (right_pos.y > 0 and Input.is_action_pressed("right_move_up")):
             right_pos.y += -PAD_SPEED * delta
             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
             right_pos.y += PAD_SPEED * delta
 
 
         get_node("right").set_pos(right_pos)
         get_node("right").set_pos(right_pos)