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
|
@export var player_id: int
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed('up-%d' % player_id):
|
if event.is_action_pressed('up-%d' % player_id):
|
||||||
velocity = Vector2(0, -SPEED)
|
velocity = Vector2(0, -SPEED)
|
||||||
if event.is_action_pressed( 'down-%d' % player_id):
|
if event.is_action_pressed( 'down-%d' % player_id):
|
||||||
velocity = Vector2(0, SPEED)
|
velocity = Vector2(0, SPEED)
|
||||||
if event.is_action_released('up-%d' % player_id) or \
|
if event.is_action_released('up-%d' % player_id) or \
|
||||||
event.is_action_released('down-%d' % player_id):
|
event.is_action_released('down-%d' % player_id):
|
||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
|
|
||||||
func _physics_process(_delta: float) -> void:
|
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
|
const SPEED : float = 300.0
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
initialize()
|
initialize()
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
var collision = move_and_collide(velocity * _delta)
|
var collision = move_and_collide(velocity * _delta)
|
||||||
if collision:
|
if collision:
|
||||||
velocity = velocity.bounce(collision.get_normal())
|
velocity = velocity.bounce(collision.get_normal())
|
||||||
|
|
||||||
func initialize():
|
func initialize():
|
||||||
var extra_offset = 0.0 if randf() < 0.5 else PI
|
var extra_offset = 0.0 if randf() < 0.5 else PI
|
||||||
var angle = extra_offset + randf_range(-PI/3.0, PI/3.0)
|
var angle = extra_offset + randf_range(-PI/3.0, PI/3.0)
|
||||||
velocity = Vector2(cos(angle), sin(angle)).normalized() * SPEED
|
velocity = Vector2(cos(angle), sin(angle)).normalized() * SPEED
|
||||||
position = get_viewport_rect().size / 2.0
|
position = get_viewport_rect().size / 2.0
|
||||||
|
|
||||||
func _on_screen_exited() -> void:
|
func _on_screen_exited() -> void:
|
||||||
await get_tree().create_timer(1.0).timeout
|
await get_tree().create_timer(1.0).timeout
|
||||||
initialize()
|
initialize()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue