pongodot

Tinkering with Godot, remaking pong
git clone git://git.hellocld.com/pongodot
Log | Files | Refs

Ball.gd (834B)


      1 extends KinematicBody2D
      2 
      3 export var _speed = 10
      4 var _dir = Vector2(1, 1)
      5 var _radius = 0
      6 var _hits = 0
      7 
      8 func _physics_process(delta):
      9 	var collision = move_and_collide(_dir * _speed * delta)
     10 	if collision:
     11 		$SFX.play()
     12 		_hits += 1
     13 		if _hits % 3 == 0:
     14 			_speed += 10
     15 		print(collision.collider.name)
     16 		$AnimationPlayer.play("Boop")
     17 		_dir = _dir.bounce(collision.normal)
     18 	if position.x >= get_viewport().size.x - _radius or position.x < _radius:
     19 		$SFX.play()
     20 		_dir.x *= -1
     21 	if position.y >= get_viewport().size.y - _radius or position.y < _radius:
     22 		$SFX.play()
     23 		_dir.y *= -1
     24 
     25 
     26 func _ready():
     27 	randomize()
     28 	if(randf() > 0.5):
     29 		_dir.x = 1
     30 	else:
     31 		_dir.x = -1
     32 	if(randf() > 0.5):
     33 		_dir.y = 1
     34 	else:
     35 		_dir.y = -1
     36 	_dir = _dir.normalized()
     37 	var shape = $CollisionShape2D.shape as CircleShape2D
     38 	_radius = shape.radius
     39 	_hits = 0