forked from campavao/brick-break-brunner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball.gd
More file actions
25 lines (17 loc) · 663 Bytes
/
ball.gd
File metadata and controls
25 lines (17 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
extends CharacterBody2D
@export var speed = 200
var direction = Vector2(-1, -1)
func _ready():
randomize()
velocity = Vector2(randf_range(-1, 1), randf_range(-1, 1)).normalized()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
var collision = move_and_collide(velocity * speed * delta)
if !collision:
return
velocity = velocity.bounce(collision.get_normal())
var tilemap = collision.get_collider()
if tilemap is TileMap:
var hit = collision.get_position() - collision.get_normal() * safe_margin
var tile_position = tilemap.local_to_map(hit)
tilemap.erase_cell(0, tile_position)