Added lasers

This commit is contained in:
2024-05-08 20:40:55 +01:00
parent bff1c6864b
commit 93f6236c71
8 changed files with 157 additions and 17 deletions

20
Bullet.gd Normal file
View File

@@ -0,0 +1,20 @@
extends RigidBody2D
signal hit_brick(brick : Node2D)
signal hit_alien(alien : Node2D)
signal hit_wall(wall : Node2D)
func _on_body_entered(body: Node) -> void:
if body is Brick:
if body.visible:
hit_brick.emit(body)
get_parent().call_deferred("remove_child", self)
call_deferred("queue_free")
if body is Alien:
hit_alien.emit(body)
get_parent().call_deferred("remove_child", self)
call_deferred("queue_free")
if body is Wall:
hit_wall.emit(body)
get_parent().call_deferred("remove_child", self)
call_deferred("queue_free")

39
Bullet.tscn Normal file
View File

@@ -0,0 +1,39 @@
[gd_scene load_steps=4 format=3 uid="uid://dh1lp7tib4d78"]
[ext_resource type="PhysicsMaterial" uid="uid://cql6t5hd40fgn" path="res://CorePhysics.tres" id="1_nbsxj"]
[ext_resource type="Script" path="res://Bullet.gd" id="2_ym7mu"]
[sub_resource type="Gradient" id="Gradient_gcqhp"]
colors = PackedColorArray(1, 1, 0, 1, 1, 1, 0, 0)
[node name="Bullet" type="RigidBody2D"]
collision_layer = 16
collision_mask = 0
physics_material_override = ExtResource("1_nbsxj")
continuous_cd = 1
max_contacts_reported = 5
contact_monitor = true
script = ExtResource("2_ym7mu")
[node name="Polygon2D" type="Polygon2D" parent="."]
color = Color(0.572549, 0.976471, 0.945098, 1)
polygon = PackedVector2Array(0, 0, 1, 1, 1, 4, 0, 3, -1, 4, -1, 1)
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PackedVector2Array(0, 0, 1, 1, 1, 4, 0, 3, -1, 4, -1, 1)
[node name="CPUParticles2D2" type="CPUParticles2D" parent="."]
position = Vector2(0, 3)
amount = 10
lifetime = 0.3
direction = Vector2(0, 0)
spread = 180.0
gravity = Vector2(0, 0)
initial_velocity_min = 1.0
initial_velocity_max = 1.0
color = Color(1, 1, 0, 1)
color_ramp = SubResource("Gradient_gcqhp")
hue_variation_min = 1.0
hue_variation_max = 1.0
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@@ -4,6 +4,7 @@ var _Brick = preload("res://Brick/Brick.tscn")
var _Ball = preload("res://Ball/Ball.tscn")
var _Upgrade = preload("res://Upgrade/Upgrade.tscn")
var _Alien = preload("res://Alien.tscn")
var _Bullet = preload("res://Bullet.tscn")
@onready var ScoreNode = $ScoreCard/Score/ScoreBox
@onready var LivesNode = $ScoreCard/Lives/LivesBox
@@ -69,9 +70,11 @@ func _process(delta : float) -> void:
if OS.has_feature("editor"):
if Input.is_action_just_pressed("cheat"):
spawn_alien()
for i in 50:
add_ball()
fire_bullet()
if PaddleNode.is_laser():
if Input.is_action_just_pressed("fire"):
fire_bullet()
if mode == MODE_EXIT:
if PaddleNode.global_position.x - (PaddleNode.width / 2) <= 20:
@@ -164,7 +167,7 @@ func _brick_destroyed(brick) -> void:
var upgrade = _Upgrade.instantiate()
upgrade.position = brick.position
upgrade.upgrade_collected.connect(_on_upgrade_collected)
match randi() % 6:
match randi() % 7:
0:
upgrade.set_upgrade("C", Color.BLUE)
1:
@@ -177,6 +180,8 @@ func _brick_destroyed(brick) -> void:
upgrade.set_upgrade("R", Color.LIGHT_CORAL)
5:
upgrade.set_upgrade("P", Color.AQUAMARINE)
6:
upgrade.set_upgrade("L", Color.GOLD)
call_deferred("add_child", upgrade)
bricks.erase(brick)
var brick_count = 0
@@ -234,7 +239,10 @@ func _input(event: InputEvent) -> void:
else:
PaddleNode.position = Vector2(min(max(16 + PaddleNode.width/2, event.position.x), 432-PaddleNode.width/2), 340)
if event is InputEventMouseButton:
if event.pressed:
if mode == MODE_PLAY:
if PaddleNode.is_laser():
fire_bullet()
if level_starting:
RunTimerNode.start()
level_starting = false
@@ -300,6 +308,8 @@ func _on_upgrade_collected(code : String) -> void:
PaddleNode.small()
"P":
start_powerball()
"L":
PaddleNode.laser()
func add_ball() -> void:
if balls.size() == 0:
@@ -432,3 +442,17 @@ func _on_alien_timer_timeout() -> void:
func _alien_died(points : int) -> void:
Global.score += points
AlienDieSoundNode.play()
func fire_bullet() -> void:
var bullet = _Bullet.instantiate()
bullet.global_position = PaddleNode.global_position - Vector2(0, 8)
bullet.hit_brick.connect(_on_bullet_hit_brick)
bullet.hit_alien.connect(_on_bullet_hit_alien)
add_child(bullet)
bullet.linear_velocity = Vector2(0, -500)
func _on_bullet_hit_brick(node) -> void:
node.hit()
func _on_bullet_hit_alien(node) -> void:
node.hit()

View File

@@ -9,7 +9,7 @@ enum {
PADDLE_CAPTURE,
PADDLE_SMALL,
PADDLE_LARGE,
PADDLE_LAZER
PADDLE_LASER
}
var mode : int = PADDLE_NORMAL
@@ -40,6 +40,7 @@ func show_paddle(paddle : Node2D) -> void:
$Small.visible = true if paddle == $Small else false
$Big.visible = true if paddle == $Big else false
$Magnet.visible = true if paddle == $Magnet else false
$Laser.visible = true if paddle == $Laser else false
$CollisionShape2D.shape.height = 32
if paddle == $Big: $CollisionShape2D.shape.height = 40
@@ -63,6 +64,11 @@ func normal() -> void:
$CollisionShape2D.shape.height = 32
_switch_effect(PADDLE_NORMAL)
func laser() -> void:
show_paddle($Laser)
$CollisionShape2D.shape.height = 32
_switch_effect(PADDLE_LASER, 15)
func capture() -> void:
show_paddle($Magnet)
$CollisionShape2D.shape.height = 32
@@ -83,5 +89,5 @@ func is_normal() -> bool:
func is_capture() -> bool:
return mode == PADDLE_CAPTURE
func is_lazer() -> bool:
return mode == PADDLE_LAZER
func is_laser() -> bool:
return mode == PADDLE_LASER

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://dndemjw7up2r6"]
[gd_scene load_steps=11 format=3 uid="uid://dndemjw7up2r6"]
[ext_resource type="PhysicsMaterial" uid="uid://cql6t5hd40fgn" path="res://CorePhysics.tres" id="1_oa72h"]
[ext_resource type="Script" path="res://Paddle/Paddle.gd" id="1_swo0j"]
@@ -8,6 +8,7 @@
[ext_resource type="Texture2D" uid="uid://bmwoidu5wsvu6" path="res://Paddle/PaddleMagnet.png" id="6_8ubfk"]
[ext_resource type="AudioStream" uid="uid://ds7om6qbk3p6l" path="res://Sounds/Grow.wav" id="6_hpb6a"]
[ext_resource type="AudioStream" uid="uid://bd2o8lynhy3wn" path="res://Sounds/Shrink.wav" id="7_3krfd"]
[ext_resource type="Texture2D" uid="uid://byb16ek3xcdn1" path="res://Paddle/PaddleLaser.png" id="7_3m0i8"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_tamfm"]
radius = 4.0
@@ -86,6 +87,22 @@ offset_right = 16.0
offset_bottom = 4.0
texture = ExtResource("6_8ubfk")
[node name="Laser" type="Node2D" parent="."]
visible = false
[node name="Polygon2D" type="Polygon2D" parent="Laser"]
z_index = -1
position = Vector2(2, 4)
color = Color(0, 0, 0, 0.247059)
polygon = PackedVector2Array(-14, -4, 14, -4, 16, -2, 16, 2, 14, 4, -14, 4, -16, 2, -16, -2)
[node name="TextureRect" type="TextureRect" parent="Laser"]
offset_left = -16.0
offset_top = -4.0
offset_right = 16.0
offset_bottom = 4.0
texture = ExtResource("7_3m0i8")
[node name="EffectTimer" type="Timer" parent="."]
[node name="GrowSound" type="AudioStreamPlayer" parent="."]

BIN
Paddle/PaddleLaser.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://byb16ek3xcdn1"
path="res://.godot/imported/PaddleLaser.png-8c27c343baed70e8b1b741a3e807b263.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Paddle/PaddleLaser.png"
dest_files=["res://.godot/imported/PaddleLaser.png-8c27c343baed70e8b1b741a3e807b263.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@@ -11,7 +11,7 @@ config_version=5
[application]
config/name="Dunkanoid"
config/version="0.6.1"
config/version="0.7.0"
run/main_scene="res://Intro.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
run/max_fps=30