From 93f6236c718d5ee1150a1bb2a93994922bafb58d Mon Sep 17 00:00:00 2001 From: Matt Jenkins Date: Wed, 8 May 2024 20:40:55 +0100 Subject: [PATCH] Added lasers --- Bullet.gd | 20 ++++++++++++++ Bullet.tscn | 39 +++++++++++++++++++++++++++ Dunkanoid.gd | 48 +++++++++++++++++++++++++--------- Paddle/Paddle.gd | 12 ++++++--- Paddle/Paddle.tscn | 19 +++++++++++++- Paddle/PaddleLaser.png | Bin 0 -> 4605 bytes Paddle/PaddleLaser.png.import | 34 ++++++++++++++++++++++++ project.godot | 2 +- 8 files changed, 157 insertions(+), 17 deletions(-) create mode 100644 Bullet.gd create mode 100644 Bullet.tscn create mode 100644 Paddle/PaddleLaser.png create mode 100644 Paddle/PaddleLaser.png.import diff --git a/Bullet.gd b/Bullet.gd new file mode 100644 index 0000000..8a6358f --- /dev/null +++ b/Bullet.gd @@ -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") diff --git a/Bullet.tscn b/Bullet.tscn new file mode 100644 index 0000000..5a8fd2c --- /dev/null +++ b/Bullet.tscn @@ -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"] diff --git a/Dunkanoid.gd b/Dunkanoid.gd index 2083a35..81a348c 100644 --- a/Dunkanoid.gd +++ b/Dunkanoid.gd @@ -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,15 +239,18 @@ 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 mode == MODE_PLAY: - if level_starting: - RunTimerNode.start() - level_starting = false - time_run = true + if event.pressed: + if mode == MODE_PLAY: + if PaddleNode.is_laser(): + fire_bullet() + if level_starting: + RunTimerNode.start() + level_starting = false + time_run = true - for ball in balls: - if (ball.captured): - ball.release() + for ball in balls: + if (ball.captured): + ball.release() func _on_hit_paddle(ball) -> void: if PaddleNode.is_capture(): @@ -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() diff --git a/Paddle/Paddle.gd b/Paddle/Paddle.gd index 168f2fd..b1f90bb 100644 --- a/Paddle/Paddle.gd +++ b/Paddle/Paddle.gd @@ -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 @@ -62,6 +63,11 @@ func normal() -> void: show_paddle($Normal) $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) @@ -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 diff --git a/Paddle/Paddle.tscn b/Paddle/Paddle.tscn index 76a611e..65d0916 100644 --- a/Paddle/Paddle.tscn +++ b/Paddle/Paddle.tscn @@ -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="."] diff --git a/Paddle/PaddleLaser.png b/Paddle/PaddleLaser.png new file mode 100644 index 0000000000000000000000000000000000000000..16f12c993e1ba6a7a1a6342a8ca34e33f91a8009 GIT binary patch literal 4605 zcmeHKYj6|S6<*mjcFn^NOaRxUi%e=0y3+3Iwc1*KAjwF8i2MkCgw(8dSN4u2tt_o2 z*~C1I4FnTsaGKadOdthP8ka{1Nv0tLdoZOCQ)UuE+5z(@lcoeH1!e-phV<@Aehr!F zc&7R1)g0Zs=broBbH01-k?za(Ws9c9r^Z7NG}US`6@nH95*IfKe0MZIIsiek6t>jr zv|68q;(%^4Q2YdvfgTJ*7U_#4QL<<#8nkUdrpcn9WYBg1Nd|h+UX)Z>jMTmh`ag^G z4}pGW#73Ntfw@yb`!Nt4^ix3lXCU0h@VXa4Uwq=EkI~0c0?WWbPN;$xS#5S`a6SaR z0LF(}Q3>M;3{|KIfQaI164j6>0plo%Ye-B3ML`?dVxie!&O;!wog@B&*Wu^Mm6jh! z{VT9<;*3VS)o6shKHkZ>SO^MrHf%Lmj_0PGsCc2pykJ@&v1XHf`%Q;At$N00``mN! z`^b(J4`XbpZ7DMs^?Y#U%1OtUJtxXaVoUN82cepPw@}!c{C#^$d2h&j@zvn{r-Qel zHSeD;em_IDcN@zTTIaS`%&4zOGQ~aGL@#x`lbx}d3$-3t_25DM%xh(r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V?d00001 diff --git a/Paddle/PaddleLaser.png.import b/Paddle/PaddleLaser.png.import new file mode 100644 index 0000000..5d46de1 --- /dev/null +++ b/Paddle/PaddleLaser.png.import @@ -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 diff --git a/project.godot b/project.godot index ee97645..0ddd657 100644 --- a/project.godot +++ b/project.godot @@ -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