Switch to 2 spaces
This commit is contained in:
parent
3d047f3a8b
commit
9cd7629023
2 changed files with 19 additions and 19 deletions
16
Paddle.gd
16
Paddle.gd
|
|
@ -5,13 +5,13 @@ const SPEED: float = 350.0
|
|||
@export var player_id: int
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed('up-%d' % player_id):
|
||||
velocity = Vector2(0, -SPEED)
|
||||
if event.is_action_pressed( 'down-%d' % player_id):
|
||||
velocity = Vector2(0, SPEED)
|
||||
if event.is_action_released('up-%d' % player_id) or \
|
||||
event.is_action_released('down-%d' % player_id):
|
||||
velocity = Vector2.ZERO
|
||||
if event.is_action_pressed('up-%d' % player_id):
|
||||
velocity = Vector2(0, -SPEED)
|
||||
if event.is_action_pressed( 'down-%d' % player_id):
|
||||
velocity = Vector2(0, SPEED)
|
||||
if event.is_action_released('up-%d' % player_id) or \
|
||||
event.is_action_released('down-%d' % player_id):
|
||||
velocity = Vector2.ZERO
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
move_and_slide()
|
||||
move_and_slide()
|
||||
|
|
|
|||
22
ball.gd
22
ball.gd
|
|
@ -3,19 +3,19 @@ extends CharacterBody2D
|
|||
const SPEED : float = 300.0
|
||||
|
||||
func _ready() -> void:
|
||||
initialize()
|
||||
initialize()
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var collision = move_and_collide(velocity * _delta)
|
||||
if collision:
|
||||
velocity = velocity.bounce(collision.get_normal())
|
||||
func _physics_process(delta: float) -> void:
|
||||
var collision = move_and_collide(velocity * _delta)
|
||||
if collision:
|
||||
velocity = velocity.bounce(collision.get_normal())
|
||||
|
||||
func initialize():
|
||||
var extra_offset = 0.0 if randf() < 0.5 else PI
|
||||
var angle = extra_offset + randf_range(-PI/3.0, PI/3.0)
|
||||
velocity = Vector2(cos(angle), sin(angle)).normalized() * SPEED
|
||||
position = get_viewport_rect().size / 2.0
|
||||
var extra_offset = 0.0 if randf() < 0.5 else PI
|
||||
var angle = extra_offset + randf_range(-PI/3.0, PI/3.0)
|
||||
velocity = Vector2(cos(angle), sin(angle)).normalized() * SPEED
|
||||
position = get_viewport_rect().size / 2.0
|
||||
|
||||
func _on_screen_exited() -> void:
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
initialize()
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
initialize()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue