diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2015-12-09 08:38:23 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2015-12-09 08:38:23 +0100 |
commit | 8639cecf4cedd56452b47503be19c44b304cd02f (patch) | |
tree | e2a795da15e40c7d9d5b82e33378f8dbf0eaf67a /demos/viewport/2d_in_3d/pong.gd | |
parent | efbb834936fdc9da9789ad37c9cc61e0b90cda95 (diff) | |
download | redot-engine-8639cecf4cedd56452b47503be19c44b304cd02f.tar.gz |
Improve code formatting and update to 2.0
The scripts were streamlined using more or less the following conventions:
- space after a comma in lists of arguments
- space around weak operators (+, -), no space around strong operators (*, /)
- space after a comment start (#)
- removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now)
- function blocks separate by two newlines
The scene files were resaved with the (current) 2.0 format, and some scenes that were in XML format were converted to SCN, to be consistent across all demos.
Diffstat (limited to 'demos/viewport/2d_in_3d/pong.gd')
-rw-r--r-- | demos/viewport/2d_in_3d/pong.gd | 74 |
1 files changed, 34 insertions, 40 deletions
diff --git a/demos/viewport/2d_in_3d/pong.gd b/demos/viewport/2d_in_3d/pong.gd index bfffdcf0d8..113c1cd44e 100644 --- a/demos/viewport/2d_in_3d/pong.gd +++ b/demos/viewport/2d_in_3d/pong.gd @@ -1,73 +1,67 @@ extends Node2D -# member variables here, example: -# var a=2 -# var b="textvar" +# member variables const INITIAL_BALL_SPEED = 80 var ball_speed = INITIAL_BALL_SPEED var screen_size = Vector2(640,400) -#default ball direction +# default ball direction var direction = Vector2(-1,0) var pad_size = Vector2(8,32) const PAD_SPEED = 150 func _process(delta): - - - # get ball positio and pad rectangles + # get ball position and pad rectangles 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) - #integrate new ball postion - ball_pos+=direction*ball_speed*delta + # integrate new ball postion + ball_pos += direction*ball_speed*delta - #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)): + # 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)): direction.y = -direction.y - - #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)): - direction.x=-direction.x - ball_speed*=1.1 - direction.y=randf()*2.0-1 + + # 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)): + direction.x = -direction.x + ball_speed *= 1.1 + direction.y = randf()*2.0 - 1 direction = direction.normalized() - - #check gameover - if (ball_pos.x<0 or ball_pos.x>screen_size.x): - ball_pos=screen_size*0.5 - ball_speed=INITIAL_BALL_SPEED - direction=Vector2(-1,0) - - + + # check gameover + if (ball_pos.x < 0 or ball_pos.x > screen_size.x): + ball_pos = screen_size*0.5 + ball_speed = INITIAL_BALL_SPEED + direction = Vector2(-1,0) + get_node("ball").set_pos(ball_pos) - - #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 + left_pos.y += -PAD_SPEED*delta 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) - - #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 + right_pos.y += -PAD_SPEED*delta 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) + right_pos.y += PAD_SPEED*delta - + get_node("right").set_pos(right_pos) + func _ready(): + # Initalization here screen_size = get_viewport_rect().size # get actual size pad_size = get_node("left").get_texture().get_size() set_process(true) - |