Added basic enemy logic

This commit is contained in:
ObeseTermite 2025-04-26 14:32:12 -07:00
parent 05ef797e06
commit 2b0f292f8b
12 changed files with 179 additions and 6 deletions

View file

@ -4,5 +4,11 @@ var speed = 100
var base_speed = 10
var direction = 0
var damage
var hostile = false
func _physics_process(delta: float) -> void:
position += speed*delta*base_speed*direction
if position.x < 0 or position.x > 256 or position.y < 0 or position.y > 256:
queue_free()

11
scenes/enemies/enemy.gd Normal file
View file

@ -0,0 +1,11 @@
extends Node2D
var speed = 10
@export var player : CharacterBody2D
@onready var navigation : NavigationAgent2D = $NavigationAgent2D
func _physics_process(delta: float) -> void:
navigation.target_position = player.positiond
position = position.move_toward(navigation.get_next_path_position(), delta*speed)

View file

@ -0,0 +1 @@
uid://do2o6v238umse

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://nj5tjjv0a6v8"
path="res://.godot/imported/grunt.png-dd52cfd366c89106c2822cb066859c32.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://scenes/enemies/grunt/grunt.png"
dest_files=["res://.godot/imported/grunt.png-dd52cfd366c89106c2822cb066859c32.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

@ -0,0 +1,23 @@
[gd_scene load_steps=4 format=3 uid="uid://bnufqnypubedj"]
[ext_resource type="Script" uid="uid://do2o6v238umse" path="res://scenes/enemies/enemy.gd" id="1_y73h6"]
[ext_resource type="Texture2D" uid="uid://nj5tjjv0a6v8" path="res://scenes/enemies/grunt/grunt.png" id="2_668pk"]
[sub_resource type="CircleShape2D" id="CircleShape2D_cahuy"]
[node name="Grunt" type="Area2D"]
script = ExtResource("1_y73h6")
[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."]
avoidance_enabled = true
max_speed = 50.0
[node name="Grunt" type="Sprite2D" parent="."]
texture = ExtResource("2_668pk")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_cahuy")
[node name="NavigationObstacle2D" type="NavigationObstacle2D" parent="."]
radius = 10.0
avoidance_enabled = false

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

View file

@ -5,6 +5,11 @@ var items : Array[Array]
@onready var positive_modifiers = [$Speed,$BulletSpeed,$Ammunition,$Damage]
@onready var negative_modifiers = [$IncomingDamage,$FiringDelay,$Size,$TaxRate]
@onready var remaining_ammunition = $RemainingAmmunition
@onready var health = $Health
@onready var money = $Money
@onready var score = $Score
var item_offset : int = 26
@export var bonus_scene : PackedScene
@ -85,6 +90,11 @@ func update_calculations():
3:
player.tax = total
negative_modifiers[x].text = '=' + str(total)
func update_stats():
remaining_ammunition.text = '- ' + str(player.remaining_bullets)
health.text = '- ' + str(player.health)
money.text = '- ' + str(player.money)
score.text = 'SCORE - ' + str(player.score)
func inventory_to_global_coords(position : Vector2i) -> Vector2:
return items_start.global_position + Vector2(position.x*item_offset,position.y*item_offset)

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://o6e5ybx262ig"]
[gd_scene load_steps=12 format=3 uid="uid://o6e5ybx262ig"]
[ext_resource type="Script" uid="uid://466pugqribug" path="res://scenes/inventory/inventory.gd" id="1_el5y6"]
[ext_resource type="PackedScene" uid="uid://csdmile32lfyy" path="res://scenes/inventory/number/number.tscn" id="2_4axmw"]
@ -16,6 +16,21 @@ font = ExtResource("4_tvok8")
font_size = 8
font_color = Color(0.156863, 0.137255, 0.156863, 1)
[sub_resource type="LabelSettings" id="LabelSettings_x4j3l"]
font = ExtResource("4_tvok8")
font_size = 8
font_color = Color(0.772549, 0.411765, 0.505882, 1)
[sub_resource type="LabelSettings" id="LabelSettings_l6cit"]
font = ExtResource("4_tvok8")
font_size = 8
font_color = Color(0.329412, 0.360784, 0.494118, 1)
[sub_resource type="LabelSettings" id="LabelSettings_efxst"]
font = ExtResource("4_tvok8")
font_size = 8
font_color = Color(0.156863, 0.137255, 0.156863, 1)
[sub_resource type="LabelSettings" id="LabelSettings_v8e04"]
font = ExtResource("4_tvok8")
font_size = 8
@ -59,9 +74,36 @@ offset_left = -105.0
offset_top = 26.0
offset_right = -85.0
offset_bottom = 49.0
text = "- 100"
text = "- 7"
label_settings = SubResource("LabelSettings_kl7fi")
[node name="Health" type="Label" parent="."]
layout_mode = 0
offset_left = -105.0
offset_top = 36.0
offset_right = -85.0
offset_bottom = 59.0
text = "- 100"
label_settings = SubResource("LabelSettings_x4j3l")
[node name="Money" type="Label" parent="."]
layout_mode = 0
offset_left = -105.0
offset_top = 48.0
offset_right = -85.0
offset_bottom = 71.0
text = "- 0"
label_settings = SubResource("LabelSettings_l6cit")
[node name="Score" type="Label" parent="."]
layout_mode = 0
offset_left = -118.0
offset_top = 115.0
offset_right = 4.0
offset_bottom = 140.0
text = "SCORE - 0"
label_settings = SubResource("LabelSettings_efxst")
[node name="BulletSpeed" type="Label" parent="."]
layout_mode = 0
offset_left = -20.0
@ -88,6 +130,7 @@ text = "=10"
label_settings = SubResource("LabelSettings_bxceu")
[node name="Size" type="Label" parent="."]
layout_mode = 0
offset_left = -71.0
offset_top = -17.0
offset_right = -46.0
@ -97,6 +140,7 @@ label_settings = SubResource("LabelSettings_v8e04")
horizontal_alignment = 1
[node name="TaxRate" type="Label" parent="."]
layout_mode = 0
offset_left = -46.0
offset_top = -17.0
offset_right = -21.0
@ -106,6 +150,7 @@ label_settings = SubResource("LabelSettings_v8e04")
horizontal_alignment = 1
[node name="FiringDelay" type="Label" parent="."]
layout_mode = 0
offset_left = -98.0
offset_top = -17.0
offset_right = -73.0
@ -115,6 +160,7 @@ label_settings = SubResource("LabelSettings_v8e04")
horizontal_alignment = 1
[node name="IncomingDamage" type="Label" parent="."]
layout_mode = 0
offset_left = -124.0
offset_top = -17.0
offset_right = -99.0

View file

@ -12,7 +12,17 @@ var bullet_delay
var size = 100
var tax
var remaining_bullets = 100
var reloading = false
var remaining_bullets = 7
var health = 100
var money = 0
var score = 0
var reload_speed = 0.1
var bullet_timer = 0
@ -44,17 +54,36 @@ func _physics_process(delta):
sprite.global_position = Vector2i(global_position)
collision.scale = Vector2(0.3,0.3)*(pow(size,0.2))
if bullet_timer < 0 and reloading:
remaining_bullets += 1
bullet_timer = reload_speed
if remaining_bullets >= ammunition:
reloading = false
bullet_timer = 0.1*pow(bullet_delay,0.4)
inventory.update_stats()
func reload():
pass
reloading = true
func spawn_bullet():
if bullet_timer > 0: return
if bullet_timer > 0 or reloading: return
var new_bullet = bullet_scene.instantiate()
new_bullet.direction = global_position.direction_to(get_global_mouse_position())
new_bullet.position = position
new_bullet.damage = damage
new_bullet.speed = sqrt(bullet_speed)
get_tree().root.add_child(new_bullet)
bullet_timer = 0.1*pow(bullet_delay,0.4)
remaining_bullets -= 1
inventory.update_stats()
if remaining_bullets <= 0:
reload()
return

View file

@ -1,7 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://dinanmpmnja1"]
[gd_scene load_steps=5 format=3 uid="uid://dinanmpmnja1"]
[ext_resource type="PackedScene" uid="uid://o6e5ybx262ig" path="res://scenes/inventory/inventory.tscn" id="1_dphjl"]
[ext_resource type="PackedScene" uid="uid://citwevx7xvypn" path="res://scenes/player/player.tscn" id="2_sl2e5"]
[ext_resource type="PackedScene" uid="uid://bnufqnypubedj" path="res://scenes/enemies/grunt/grunt.tscn" id="3_1fp7r"]
[sub_resource type="NavigationPolygon" id="NavigationPolygon_6m72w"]
vertices = PackedVector2Array(230, 25.5312, 230, 244.82, 19.25, 241.148, 1.75781, 20.2891, 50.1172, 17.0078)
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3, 4)])
outlines = Array[PackedVector2Array]([PackedVector2Array(50, 7, 240, 16, 240, 255, 10, 251, -9, 11)])
[node name="World" type="Node2D"]
@ -13,3 +19,10 @@ player = NodePath("../../Player")
[node name="Player" parent="." node_paths=PackedStringArray("inventory") instance=ExtResource("2_sl2e5")]
position = Vector2(131, 131)
inventory = NodePath("../UI/Inventory")
[node name="Grunt" parent="." node_paths=PackedStringArray("player") instance=ExtResource("3_1fp7r")]
position = Vector2(42, 47)
player = NodePath("../Player")
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."]
navigation_polygon = SubResource("NavigationPolygon_6m72w")