Added pause and mute.
Improved fonts and font scaling Added level editor
This commit is contained in:
78
Ball/Ball.gd
78
Ball/Ball.gd
@@ -1,6 +1,7 @@
|
||||
extends RigidBody2D
|
||||
|
||||
const MIN_SPEED = 100.0
|
||||
const MIN_SPEED = 50.0
|
||||
const MAX_SPEED = 500.0
|
||||
|
||||
signal hit_brick(ball : Node, brick : Node)
|
||||
signal hit_paddle(ball : Node)
|
||||
@@ -10,9 +11,11 @@ signal hit_wall(ball : Node)
|
||||
var captured : bool = false
|
||||
var capture_object : Node2D
|
||||
var capture_offset : Vector2 = Vector2.ZERO
|
||||
|
||||
var speed : float = 100
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
angular_velocity = 0
|
||||
# angular_velocity = 0
|
||||
rotation = 0
|
||||
if captured:
|
||||
PhysicsServer2D.body_set_state(
|
||||
@@ -23,39 +26,13 @@ func _physics_process(delta: float) -> void:
|
||||
linear_velocity = Vector2.ZERO
|
||||
angular_velocity = 0
|
||||
else:
|
||||
if linear_velocity.length() < MIN_SPEED:
|
||||
linear_damp = 0
|
||||
linear_velocity = linear_velocity.normalized() * MIN_SPEED
|
||||
if linear_velocity.length() != speed:
|
||||
linear_velocity = linear_velocity.normalized() * speed
|
||||
|
||||
|
||||
|
||||
func _on_body_entered(body: Node) -> void:
|
||||
if body is Brick:
|
||||
if not body.visible:
|
||||
return
|
||||
#linear_velocity = (linear_velocity.normalized() + (Vector2(randf() - 0.5, randf() - 0.5) / 2.0)).normalized() * linear_velocity.length()
|
||||
$BrickSound.play()
|
||||
body.hit()
|
||||
hit_brick.emit(self, body)
|
||||
return
|
||||
if body is Paddle:
|
||||
var diff = (position.x - body.position.x) / (body.width/2)
|
||||
linear_velocity = (Vector2(diff, -1).normalized()) * linear_velocity.length()
|
||||
$PaddleSound.play()
|
||||
body.hit()
|
||||
hit_paddle.emit(self)
|
||||
return
|
||||
if body is Wall:
|
||||
if abs(linear_velocity.y) < 0.01:
|
||||
linear_velocity.y = randf() * 10.0
|
||||
elif abs(linear_velocity.y) < 1:
|
||||
linear_velocity.y *= 10.0
|
||||
#linear_velocity = (linear_velocity.normalized() + (Vector2(randf() - 0.5, randf() - 0.5) / 5.0)).normalized() * linear_velocity.length()
|
||||
$WallSound.play()
|
||||
hit_wall.emit(self)
|
||||
return
|
||||
if body is Floor:
|
||||
#$FloorSound.play()
|
||||
hit_floor.emit(self)
|
||||
return
|
||||
pass
|
||||
|
||||
func capture(ob : Node2D, offset : Vector2 = Vector2.ZERO) -> void:
|
||||
captured = true
|
||||
@@ -65,7 +42,40 @@ func capture(ob : Node2D, offset : Vector2 = Vector2.ZERO) -> void:
|
||||
func release() -> void:
|
||||
global_position = capture_object.global_position - capture_offset
|
||||
var diff = (global_position.x - capture_object.global_position.x) / (capture_object.width/2)
|
||||
linear_velocity = Vector2(diff, -1).normalized() * 100
|
||||
# linear_velocity = Vector2(diff, -1).normalized() * 100
|
||||
apply_central_impulse(Vector2(diff, -1).normalized() * 1)
|
||||
captured = false
|
||||
capture_object = null
|
||||
|
||||
|
||||
|
||||
func _on_body_exited(body: Node) -> void:
|
||||
if body is Brick:
|
||||
if not body.visible:
|
||||
return
|
||||
$BrickSound.play()
|
||||
body.hit()
|
||||
hit_brick.emit(self, body)
|
||||
speed += 1
|
||||
return
|
||||
if body is Paddle:
|
||||
var diff = (position.x - body.position.x) / (body.width/2)
|
||||
linear_velocity = (Vector2(diff, -1).normalized()) * speed
|
||||
$PaddleSound.play()
|
||||
body.hit()
|
||||
hit_paddle.emit(self)
|
||||
return
|
||||
if body is Wall:
|
||||
if abs(linear_velocity.y) < 0.01:
|
||||
linear_velocity.y = randf() * 10.0
|
||||
elif abs(linear_velocity.y) < 1:
|
||||
linear_velocity.y *= 10.0
|
||||
$WallSound.play()
|
||||
hit_wall.emit(self)
|
||||
return
|
||||
if body is Floor:
|
||||
hit_floor.emit(self)
|
||||
return
|
||||
|
||||
func slowdown() -> void:
|
||||
speed = 100
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://clfo2nrropg8y"]
|
||||
|
||||
[ext_resource type="Script" path="res://Ball/Ball.gd" id="1_2xu4j"]
|
||||
[ext_resource type="PhysicsMaterial" uid="uid://cql6t5hd40fgn" path="res://CorePhysics.tres" id="1_vk3rj"]
|
||||
[ext_resource type="Texture2D" uid="uid://wye1kea3ts48" path="res://Ball/Ball.png" id="2_cpnep"]
|
||||
[ext_resource type="AudioStream" uid="uid://7kjt62y3t8lc" path="res://Sounds/WallHit.wav" id="3_bwkax"]
|
||||
[ext_resource type="AudioStream" uid="uid://b6vosap1la1ts" path="res://Sounds/BrickHit.wav" id="4_ly8mo"]
|
||||
[ext_resource type="AudioStream" uid="uid://d3g30x1n2ncjj" path="res://Sounds/PaddleHit.wav" id="5_f8nt3"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_tqihs"]
|
||||
rough = true
|
||||
bounce = 1.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_nwcsc"]
|
||||
radius = 3.0
|
||||
|
||||
[node name="Ball" type="RigidBody2D"]
|
||||
collision_layer = 0
|
||||
physics_material_override = SubResource("PhysicsMaterial_tqihs")
|
||||
mass = 0.01
|
||||
physics_material_override = ExtResource("1_vk3rj")
|
||||
gravity_scale = 0.0
|
||||
continuous_cd = 1
|
||||
continuous_cd = 2
|
||||
max_contacts_reported = 5
|
||||
contact_monitor = true
|
||||
script = ExtResource("1_2xu4j")
|
||||
@@ -49,3 +47,4 @@ max_polyphony = 5
|
||||
stream = ExtResource("5_f8nt3")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
|
||||
|
||||
Reference in New Issue
Block a user