Mostly health
This commit is contained in:
27
scenes/bullet.tscn
Normal file
27
scenes/bullet.tscn
Normal file
@ -0,0 +1,27 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://4uk2iyn5fef2"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/bullet.gd" id="1_5kpin"]
|
||||
[ext_resource type="Texture2D" uid="uid://ds114lnkh1ydj" path="res://sprites/objects/projectile.png" id="2_ugbet"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_m137n"]
|
||||
radius = 5.09902
|
||||
|
||||
[node name="bullet" type="Area2D"]
|
||||
top_level = true
|
||||
rotation = 0.815342
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_5kpin")
|
||||
|
||||
[node name="Projectile" type="Sprite2D" parent="."]
|
||||
position = Vector2(-4.28308, -1.28656)
|
||||
rotation = 0.00146517
|
||||
scale = Vector2(0.296997, 0.352615)
|
||||
texture = ExtResource("2_ugbet")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(-2.18388, -2.05686)
|
||||
rotation = -2.34336
|
||||
scale = Vector2(1, 1)
|
||||
shape = SubResource("CircleShape2D_m137n")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
@ -3,7 +3,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://c3i6a6ji8i1q8" path="res://scenes/player.tscn" id="1_fwjx1"]
|
||||
[ext_resource type="Script" path="res://scripts/game_manager.gd" id="1_gd2n3"]
|
||||
[ext_resource type="PackedScene" uid="uid://d65w0p8s6dv4" path="res://scenes/chest.tscn" id="2_u0oqr"]
|
||||
[ext_resource type="PackedScene" uid="uid://cw2jmrfd0fivj" path="res://scenes/enemy.tscn" id="4_7i7ld"]
|
||||
[ext_resource type="PackedScene" uid="uid://cw2jmrfd0fivj" path="res://sprites/characters/enemy.tscn" id="4_7i7ld"]
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
|
||||
@ -22,9 +22,68 @@ offset_right = 1124.0
|
||||
offset_bottom = 637.0
|
||||
color = Color(0.726739, 0.942318, 0.74966, 1)
|
||||
|
||||
[node name="Enemy" parent="." instance=ExtResource("4_7i7ld")]
|
||||
[node name="Enemies" type="Node" parent="."]
|
||||
|
||||
[node name="Enemy" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(29, 37)
|
||||
|
||||
[node name="Enemy2" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-183, 47)
|
||||
|
||||
[node name="Enemy4" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-246, -63)
|
||||
|
||||
[node name="Enemy5" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-73, 63)
|
||||
|
||||
[node name="Enemy6" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-106, -135)
|
||||
|
||||
[node name="Enemy7" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(106, 154)
|
||||
|
||||
[node name="Enemy8" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(307, 50)
|
||||
|
||||
[node name="Enemy9" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(276, 177)
|
||||
|
||||
[node name="Enemy10" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-1, 269)
|
||||
|
||||
[node name="Enemy11" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-176, 259)
|
||||
|
||||
[node name="Enemy12" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-374, 203)
|
||||
|
||||
[node name="Enemy13" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-391, 54)
|
||||
|
||||
[node name="Enemy14" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-561, 22)
|
||||
|
||||
[node name="Enemy15" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-496, -164)
|
||||
|
||||
[node name="Enemy16" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-361, -299)
|
||||
|
||||
[node name="Enemy17" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(-187, -364)
|
||||
|
||||
[node name="Enemy18" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(107, -366)
|
||||
|
||||
[node name="Enemy19" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(245, -234)
|
||||
|
||||
[node name="Enemy20" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(314, -53)
|
||||
|
||||
[node name="Enemy3" parent="Enemies" instance=ExtResource("4_7i7ld")]
|
||||
position = Vector2(65, -107)
|
||||
|
||||
[node name="player" parent="." instance=ExtResource("1_fwjx1")]
|
||||
position = Vector2(-86, -60)
|
||||
|
||||
|
20
scenes/gun.gd
Normal file
20
scenes/gun.gd
Normal file
@ -0,0 +1,20 @@
|
||||
extends Area2D
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var enemies_in_range = get_overlapping_bodies()
|
||||
if enemies_in_range.size() > 0:
|
||||
var closest_target = enemies_in_range.front()
|
||||
look_at(closest_target.global_position)
|
||||
|
||||
func shoot():
|
||||
const BULLET = preload("res://scenes/bullet.tscn")
|
||||
var new_bullet = BULLET.instantiate()
|
||||
new_bullet.global_position = %shootingPoint.global_position
|
||||
new_bullet.global_rotation = %weponPivot.global_rotation
|
||||
%shootingPoint.add_child(new_bullet)
|
||||
|
||||
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
shoot()
|
34
scenes/gun.tscn
Normal file
34
scenes/gun.tscn
Normal file
@ -0,0 +1,34 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://woincqnmbsax"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://d0heqigxyqlxk" path="res://sprites/objects/pistol.png" id="1_s3jta"]
|
||||
[ext_resource type="Script" path="res://scenes/gun.gd" id="1_tnui5"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_bfjrk"]
|
||||
radius = 251.149
|
||||
|
||||
[node name="gun" type="Area2D"]
|
||||
collision_layer = 0
|
||||
collision_mask = 2
|
||||
script = ExtResource("1_tnui5")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(-7, 2)
|
||||
shape = SubResource("CircleShape2D_bfjrk")
|
||||
|
||||
[node name="weponPivot" type="Marker2D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="Pistol" type="Sprite2D" parent="weponPivot"]
|
||||
position = Vector2(15, -2.5)
|
||||
scale = Vector2(0.207111, 0.291078)
|
||||
texture = ExtResource("1_s3jta")
|
||||
|
||||
[node name="shootingPoint" type="Marker2D" parent="weponPivot/Pistol"]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2(30.3333, -10.1852)
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
wait_time = 0.3
|
||||
autostart = true
|
||||
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=11 format=3 uid="uid://c3i6a6ji8i1q8"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://c3i6a6ji8i1q8"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dl1pu82xwqw3m" path="res://sprites/characters/player.png" id="1_6xeiv"]
|
||||
[ext_resource type="Script" path="res://scripts/playerscript.gd" id="1_sty7f"]
|
||||
[ext_resource type="PackedScene" uid="uid://woincqnmbsax" path="res://scenes/gun.tscn" id="3_2dsng"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_0xuex"]
|
||||
atlas = ExtResource("1_6xeiv")
|
||||
@ -57,6 +58,24 @@ animations = [{
|
||||
radius = 5.0
|
||||
height = 18.0
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_vrmo8"]
|
||||
radius = 7.0
|
||||
height = 22.0
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ax0mg"]
|
||||
bg_color = Color(0.664164, 0, 0.0638879, 1)
|
||||
corner_radius_top_left = 1
|
||||
corner_radius_top_right = 1
|
||||
corner_radius_bottom_right = 1
|
||||
corner_radius_bottom_left = 1
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_vh4rv"]
|
||||
bg_color = Color(0, 0.724967, 0.216409, 1)
|
||||
corner_radius_top_left = 1
|
||||
corner_radius_top_right = 1
|
||||
corner_radius_bottom_right = 1
|
||||
corner_radius_bottom_left = 1
|
||||
|
||||
[node name="player" type="CharacterBody2D"]
|
||||
script = ExtResource("1_sty7f")
|
||||
|
||||
@ -65,8 +84,31 @@ position = Vector2(0, -8)
|
||||
sprite_frames = SubResource("SpriteFrames_gatfb")
|
||||
animation = &"idle"
|
||||
autoplay = "idle"
|
||||
frame_progress = 0.0176069
|
||||
frame_progress = 0.491158
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, -9)
|
||||
shape = SubResource("CapsuleShape2D_4lp1q")
|
||||
|
||||
[node name="Gun" parent="." instance=ExtResource("3_2dsng")]
|
||||
position = Vector2(0, -7)
|
||||
|
||||
[node name="Hurtbox" type="Area2D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hurtbox"]
|
||||
position = Vector2(0, -9)
|
||||
shape = SubResource("CapsuleShape2D_vrmo8")
|
||||
debug_color = Color(0.821755, 0.152326, 0.89675, 0.42)
|
||||
|
||||
[node name="ProgressBar" type="ProgressBar" parent="."]
|
||||
unique_name_in_owner = true
|
||||
offset_left = -13.0
|
||||
offset_top = -25.0
|
||||
offset_right = 14.0
|
||||
offset_bottom = -20.0
|
||||
theme_override_styles/background = SubResource("StyleBoxFlat_ax0mg")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_vh4rv")
|
||||
value = 100.0
|
||||
show_percentage = false
|
||||
|
21
scripts/bullet.gd
Normal file
21
scripts/bullet.gd
Normal file
@ -0,0 +1,21 @@
|
||||
extends Area2D
|
||||
|
||||
const SPEED = 500
|
||||
const RANGE = 500
|
||||
|
||||
var travelled_distance = 0
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var direction = Vector2.RIGHT.rotated(rotation)
|
||||
position += direction * SPEED * delta
|
||||
|
||||
travelled_distance += SPEED * delta
|
||||
|
||||
if travelled_distance > RANGE:
|
||||
queue_free()
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
queue_free()
|
||||
if body.has_method("take_damage"):
|
||||
body.take_damage()
|
@ -1,8 +1,14 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
var health = 5
|
||||
@onready var player = get_node("/root/Game/player")
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
var direction = global_position.direction_to(player.global_position)
|
||||
velocity = direction * 50
|
||||
move_and_slide()
|
||||
|
||||
func take_damage():
|
||||
health -= 1
|
||||
if health == 0:
|
||||
queue_free()
|
||||
|
@ -1,7 +1,20 @@
|
||||
extends CharacterBody2D
|
||||
signal health_depleted
|
||||
|
||||
var health = 100.0
|
||||
const DAMAGE_RATE = 5.0
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
velocity = direction * 200
|
||||
move_and_slide()
|
||||
pass
|
||||
|
||||
|
||||
var overlappong_mobs = %Hurtbox.get_overlapping_bodies()
|
||||
|
||||
if overlappong_mobs.size() > 0 :
|
||||
health -= DAMAGE_RATE * overlappong_mobs.size() * delta
|
||||
%ProgressBar.value = health
|
||||
if health <= 0.0:
|
||||
health_depleted.emit()
|
||||
|
BIN
sprites/objects/pistol.png
Normal file
BIN
sprites/objects/pistol.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
34
sprites/objects/pistol.png.import
Normal file
34
sprites/objects/pistol.png.import
Normal file
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://d0heqigxyqlxk"
|
||||
path="res://.godot/imported/pistol.png-4d0d56869593790c972adddea09fe2c1.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/objects/pistol.png"
|
||||
dest_files=["res://.godot/imported/pistol.png-4d0d56869593790c972adddea09fe2c1.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
|
BIN
sprites/objects/projectile.png
Normal file
BIN
sprites/objects/projectile.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 799 B |
34
sprites/objects/projectile.png.import
Normal file
34
sprites/objects/projectile.png.import
Normal file
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://ds114lnkh1ydj"
|
||||
path="res://.godot/imported/projectile.png-b90d942ccb51346df1ff1fdf7ba87dd1.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/objects/projectile.png"
|
||||
dest_files=["res://.godot/imported/projectile.png-b90d942ccb51346df1ff1fdf7ba87dd1.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
|
Reference in New Issue
Block a user