From 711be6a85c8faabf2ce7f5fc4a7f3d88c6ecca2c Mon Sep 17 00:00:00 2001 From: Cookie-CHR Date: Sun, 3 Apr 2022 02:09:19 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9A=99=EF=B8=8F=20ability=20to=20shoot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.godot | 18 ++++++++++++++---- src/entities/Bullet.tscn | 19 +++++++++++++++++++ src/entities/behaviours/BulletMovement.gd | 19 +++++++++++++++++++ src/entities/behaviours/BulletSpawn.gd | 17 +++++++++++++++++ src/levels/Game.tscn | 12 +++++------- src/mechanics/Black.png.import | 1 - src/mechanics/GimpWood.png.import | 1 - src/mechanics/Light.png.import | 1 - src/mechanics/White.png.import | 1 - 9 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 src/entities/Bullet.tscn create mode 100644 src/entities/behaviours/BulletMovement.gd create mode 100644 src/entities/behaviours/BulletSpawn.gd diff --git a/project.godot b/project.godot index a7ad8fb..2de5219 100644 --- a/project.godot +++ b/project.godot @@ -8,6 +8,11 @@ config_version=4 +_global_script_classes=[ ] +_global_script_class_icons={ + +} + [application] config/name="LD50" @@ -27,32 +32,37 @@ window/size/resizable=false player_move_up={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) ] } player_move_down={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null) ] } player_move_left={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) ] } player_move_right={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null) ] } +shoot={ +"deadzone": 0.5, +"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null) + ] +} [layer_names] diff --git a/src/entities/Bullet.tscn b/src/entities/Bullet.tscn new file mode 100644 index 0000000..5505f0e --- /dev/null +++ b/src/entities/Bullet.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://src/mechanics/White.png" type="Texture" id=1] +[ext_resource path="res://src/entities/behaviours/BulletMovement.gd" type="Script" id=2] + +[sub_resource type="RectangleShape2D" id=1] + +[node name="Bullet" type="KinematicBody2D"] + +[node name="BulletMovement" type="Node" parent="."] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +scale = Vector2( 1, 0.5 ) +texture = ExtResource( 1 ) + +[node name="Shape" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) +disabled = true diff --git a/src/entities/behaviours/BulletMovement.gd b/src/entities/behaviours/BulletMovement.gd new file mode 100644 index 0000000..b6b0ba2 --- /dev/null +++ b/src/entities/behaviours/BulletMovement.gd @@ -0,0 +1,19 @@ +extends Node + +onready var target: KinematicBody2D = get_parent() +onready var angle: float = deg2rad(target.get_rotation_degrees()) +export var movement_per_second: float = 96.0 + +var direction : Vector2 = Vector2(0,0) + +func _ready(): + direction = Vector2.ZERO + + direction += sin(angle) * Vector2.DOWN + direction += cos(angle) * Vector2.RIGHT + + if direction.length() > 1: + direction.normalized() + +func _physics_process(delta): + var _motion: Vector2 = target.move_and_slide(direction * movement_per_second) diff --git a/src/entities/behaviours/BulletSpawn.gd b/src/entities/behaviours/BulletSpawn.gd new file mode 100644 index 0000000..69af19b --- /dev/null +++ b/src/entities/behaviours/BulletSpawn.gd @@ -0,0 +1,17 @@ +extends Position2D + +# Items +onready var bullet = preload("res://src/entities/Bullet.tscn") +onready var spawner = get_node("/root/Game/PhaseOne/PhaseOneContainer/Player") + +func _process(_delta): + if Input.is_action_just_pressed("shoot"): + _on_Click() + +func _on_Click(): + var newBullet = bullet.instance() + newBullet.set_position(spawner.position) + var bulletRotation = rad2deg(newBullet.get_angle_to(get_global_mouse_position())) + newBullet.set_rotation_degrees(bulletRotation) + add_child(newBullet) + diff --git a/src/levels/Game.tscn b/src/levels/Game.tscn index bc971ef..f585c60 100644 --- a/src/levels/Game.tscn +++ b/src/levels/Game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://src/mechanics/Background.tscn" type="PackedScene" id=1] [ext_resource path="res://src/mechanics/Darkness.tscn" type="PackedScene" id=2] @@ -7,9 +7,7 @@ [ext_resource path="res://src/entities/Enemy.tscn" type="PackedScene" id=5] [ext_resource path="res://src/levels/Game.gd" type="Script" id=6] [ext_resource path="res://src/ui/TimeSurvived.tscn" type="PackedScene" id=7] -[ext_resource path="res://src/music/BaseChoir.mp3" type="AudioStream" id=8] -[ext_resource path="res://src/music/BaseDrum.mp3" type="AudioStream" id=9] -[ext_resource path="res://src/music/BaseBell.mp3" type="AudioStream" id=10] +[ext_resource path="res://src/entities/behaviours/BulletSpawn.gd" type="Script" id=8] [ext_resource path="res://src/levels/PhaseOneMusic.gd" type="Script" id=11] [node name="Game" type="Node2D"] @@ -23,17 +21,14 @@ script = ExtResource( 11 ) fire_path = NodePath("../PhaseOneContainer/Fire") [node name="Bell" type="AudioStreamPlayer" parent="PhaseOne/PhaseOneMusic"] -stream = ExtResource( 10 ) volume_db = -80.0 autoplay = true [node name="Choir" type="AudioStreamPlayer" parent="PhaseOne/PhaseOneMusic"] -stream = ExtResource( 8 ) volume_db = -80.0 autoplay = true [node name="Drum" type="AudioStreamPlayer" parent="PhaseOne/PhaseOneMusic"] -stream = ExtResource( 9 ) volume_db = -80.0 autoplay = true @@ -55,6 +50,9 @@ position = Vector2( 755, 508 ) position = Vector2( 493, 305 ) intensity = 0.3 +[node name="Position2D" type="Position2D" parent="PhaseOne/PhaseOneContainer"] +script = ExtResource( 8 ) + [node name="UserInterface" type="CanvasLayer" parent="."] [node name="UserIntefaceContainer" type="Panel" parent="UserInterface"] diff --git a/src/mechanics/Black.png.import b/src/mechanics/Black.png.import index 85b0395..fb608a7 100644 --- a/src/mechanics/Black.png.import +++ b/src/mechanics/Black.png.import @@ -28,7 +28,6 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false -process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/src/mechanics/GimpWood.png.import b/src/mechanics/GimpWood.png.import index 3d2809b..7391d93 100644 --- a/src/mechanics/GimpWood.png.import +++ b/src/mechanics/GimpWood.png.import @@ -28,7 +28,6 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false -process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/src/mechanics/Light.png.import b/src/mechanics/Light.png.import index cf679d9..23e8036 100644 --- a/src/mechanics/Light.png.import +++ b/src/mechanics/Light.png.import @@ -28,7 +28,6 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false -process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true diff --git a/src/mechanics/White.png.import b/src/mechanics/White.png.import index dcf8377..480fcca 100644 --- a/src/mechanics/White.png.import +++ b/src/mechanics/White.png.import @@ -28,7 +28,6 @@ process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false process/invert_color=false -process/normal_map_invert_y=false stream=false size_limit=0 detect_3d=true