Guns, ground enemy AI beginnings

This commit is contained in:
ToasterPanic 2025-12-06 19:33:42 -05:00
parent 750606b11d
commit be879a03a4
20 changed files with 468 additions and 49 deletions

View file

@ -205,6 +205,26 @@ ui_back={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
]
}
aim_left={
"deadzone": 0.2,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null)
]
}
aim_right={
"deadzone": 0.2,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null)
]
}
aim_up={
"deadzone": 0.2,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)
]
}
aim_down={
"deadzone": 0.2,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
]
}
[physics]

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=3 uid="uid://dy6dv2tio433m"]
[gd_scene load_steps=10 format=3 uid="uid://dy6dv2tio433m"]
[ext_resource type="Script" uid="uid://8d4jhy3fo32b" path="res://scripts/enemy.gd" id="1_xwavj"]
[ext_resource type="AudioStream" uid="uid://brqjxveo53kco" path="res://sounds/boost.mp3" id="2_nenq2"]
@ -6,35 +6,11 @@
[ext_resource type="AudioStream" uid="uid://5tr30e1tmdp6" path="res://sounds/collision.mp3" id="4_ipns3"]
[ext_resource type="AudioStream" uid="uid://bney1c4julhfk" path="res://sounds/explode.mp3" id="5_ipns3"]
[ext_resource type="Texture2D" uid="uid://dtwo7g0ipc4k" path="res://textures/ship_1.png" id="6_w8i8w"]
[ext_resource type="Script" uid="uid://ck38qwl4qytnt" path="res://scripts/particle_group.gd" id="7_md484"]
[ext_resource type="Texture2D" uid="uid://5iimabvyld40" path="res://textures/particles/basic.png" id="7_nenq2"]
[ext_resource type="Texture2D" uid="uid://bpe67g6185n5v" path="res://textures/particles/fire.png" id="9_ipns3"]
[ext_resource type="PackedScene" path="res://scenes/particles/explosion.tscn" id="7_nenq2"]
[sub_resource type="CircleShape2D" id="CircleShape2D_lnu2h"]
radius = 20.0
[sub_resource type="Curve" id="Curve_ipns3"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.7512195, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 3
[sub_resource type="CurveTexture" id="CurveTexture_8qclf"]
curve = SubResource("Curve_ipns3")
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_w8i8w"]
particle_flag_disable_z = true
angle_min = -720.0
angle_max = 720.0
spread = 180.0
initial_velocity_min = 30.3
initial_velocity_max = 260.81
gravity = Vector3(0, 0, 0)
damping_min = 2.0
damping_max = 14.000001
scale_min = 0.099999994
scale_max = 0.25
alpha_curve = SubResource("CurveTexture_8qclf")
collision_use_scale = true
[sub_resource type="ConvexPolygonShape2D" id="ConvexPolygonShape2D_ipns3"]
points = PackedVector2Array(-16, 16, 16, 16, 0, -16)
@ -79,26 +55,7 @@ target_position = Vector2(0, -256)
[node name="FireCast" type="RayCast2D" parent="."]
target_position = Vector2(0, -1024)
[node name="Explosion" type="Node2D" parent="."]
script = ExtResource("7_md484")
[node name="GPUParticles2D" type="GPUParticles2D" parent="Explosion"]
emitting = false
amount = 24
texture = ExtResource("7_nenq2")
lifetime = 10.0
one_shot = true
explosiveness = 1.0
process_material = SubResource("ParticleProcessMaterial_w8i8w")
[node name="GPUParticles2D2" type="GPUParticles2D" parent="Explosion"]
emitting = false
amount = 24
texture = ExtResource("9_ipns3")
lifetime = 10.0
one_shot = true
explosiveness = 1.0
process_material = SubResource("ParticleProcessMaterial_w8i8w")
[node name="Explosion" parent="." instance=ExtResource("7_nenq2")]
[node name="CollisionShape" type="CollisionShape2D" parent="."]
shape = SubResource("ConvexPolygonShape2D_ipns3")

View file

@ -694,7 +694,7 @@ layout_mode = 2
[node name="Label" type="Label" parent="UI/Control/ControlsBox/Flow5"]
layout_mode = 2
size_flags_horizontal = 3
text = "NAVPANEL"
text = "NAVPANEL "
[node name="InputIconTextureRect" type="TextureRect" parent="UI/Control/ControlsBox/Flow5"]
custom_minimum_size = Vector2(32, 32)

View file

@ -1,9 +1,12 @@
[gd_scene load_steps=23 format=3 uid="uid://by43ihcec8e8q"]
[gd_scene load_steps=27 format=3 uid="uid://by43ihcec8e8q"]
[ext_resource type="Script" uid="uid://b2sw6ymaf4t0s" path="res://scripts/game_ground.gd" id="1_6ra5r"]
[ext_resource type="Script" uid="uid://dowu512otgyyf" path="res://scripts/player_ground.gd" id="3_8gbjj"]
[ext_resource type="AudioStream" uid="uid://cdl70q0x28717" path="res://sounds/dialogue.mp3" id="3_rncil"]
[ext_resource type="Texture2D" uid="uid://c0cyhybh30ogt" path="res://textures/player-ground-sheet.png" id="4_2c1ag"]
[ext_resource type="Texture2D" uid="uid://csrlh1sbdroud" path="res://textures/pistol.png" id="5_8gbjj"]
[ext_resource type="AudioStream" uid="uid://5x8fl2mk082h" path="res://sounds/gunshot_1.mp3" id="6_2c1ag"]
[ext_resource type="Script" uid="uid://bv7ymrwe6ciax" path="res://scripts/enemy_ground.gd" id="7_modao"]
[ext_resource type="Shader" uid="uid://d3hoh7ec2w8q7" path="res://scripts/outline.gdshader" id="7_vuhkc"]
[ext_resource type="Shader" uid="uid://d2e0541hawkml" path="res://scripts/vignette.gdshader" id="9_5vwr8"]
[ext_resource type="Shader" uid="uid://bk7q00br1ms30" path="res://scripts/retro.gdshader" id="9_257nh"]
@ -76,6 +79,9 @@ animations = [{
radius = 21.0
height = 48.0
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_8gbjj"]
height = 94.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_8gbjj"]
shader = ExtResource("9_5vwr8")
shader_parameter/radius = 1.0
@ -140,6 +146,65 @@ position_smoothing_enabled = true
position = Vector2(0, 40)
shape = SubResource("CapsuleShape2D_176r3")
[node name="HeldItem" type="Node2D" parent="PlayerGround"]
[node name="Cast" type="RayCast2D" parent="PlayerGround/HeldItem"]
target_position = Vector2(2048, 0)
collision_mask = 2
collide_with_areas = true
[node name="Sprite" type="Sprite2D" parent="PlayerGround/HeldItem"]
position = Vector2(56, 0)
texture = ExtResource("5_8gbjj")
[node name="Gunshot" type="AudioStreamPlayer2D" parent="PlayerGround/HeldItem"]
stream = ExtResource("6_2c1ag")
[node name="Hitbox" type="Area2D" parent="PlayerGround"]
collision_layer = 2
collision_mask = 2
[node name="CollisionShape" type="CollisionShape2D" parent="PlayerGround/Hitbox"]
shape = SubResource("CapsuleShape2D_8gbjj")
debug_color = Color(1, 0, 0, 0.41960785)
[node name="EnemyTest" type="CharacterBody2D" parent="."]
position = Vector2(349, -58)
script = ExtResource("7_modao")
[node name="Sprite" type="AnimatedSprite2D" parent="EnemyTest"]
scale = Vector2(2, 2)
sprite_frames = SubResource("SpriteFrames_aergo")
[node name="Camera" type="Camera2D" parent="EnemyTest"]
position_smoothing_enabled = true
[node name="CollisionShape" type="CollisionShape2D" parent="EnemyTest"]
position = Vector2(0, 40)
shape = SubResource("CapsuleShape2D_176r3")
[node name="HeldItem" type="Node2D" parent="EnemyTest"]
[node name="Cast" type="RayCast2D" parent="EnemyTest/HeldItem"]
target_position = Vector2(2048, 0)
collision_mask = 2
collide_with_areas = true
[node name="Sprite" type="Sprite2D" parent="EnemyTest/HeldItem"]
position = Vector2(56, 0)
texture = ExtResource("5_8gbjj")
[node name="Gunshot" type="AudioStreamPlayer2D" parent="EnemyTest/HeldItem"]
stream = ExtResource("6_2c1ag")
[node name="Hitbox" type="Area2D" parent="EnemyTest"]
collision_layer = 2
collision_mask = 2
[node name="CollisionShape" type="CollisionShape2D" parent="EnemyTest/Hitbox"]
shape = SubResource("CapsuleShape2D_8gbjj")
debug_color = Color(1, 0, 0, 0.41960785)
[node name="UI" type="CanvasLayer" parent="."]
[node name="Vignette" type="ColorRect" parent="UI"]

View file

@ -67,7 +67,8 @@ texture_region_size = Vector2i(32, 32)
[sub_resource type="TileSet" id="TileSet_uxsmb"]
tile_size = Vector2i(32, 32)
occlusion_layer_0/light_mask = 1
physics_layer_0/collision_layer = 1
physics_layer_0/collision_layer = 3
physics_layer_0/collision_mask = 3
sources/0 = SubResource("TileSetAtlasSource_k741b")
sources/1 = SubResource("TileSetAtlasSource_mdep3")
sources/2 = SubResource("TileSetAtlasSource_bhfm6")

View file

@ -0,0 +1,38 @@
[gd_scene load_steps=6 format=3 uid="uid://ckbjyhwv6su8y"]
[ext_resource type="Script" uid="uid://ck38qwl4qytnt" path="res://scripts/particle_group.gd" id="1_416m4"]
[ext_resource type="Texture2D" uid="uid://cduq2cbhvwqj4" path="res://textures/particles/bullet.png" id="2_c1ocy"]
[sub_resource type="Curve" id="Curve_ipns3"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.49242425, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 3
[sub_resource type="CurveTexture" id="CurveTexture_416m4"]
curve = SubResource("Curve_ipns3")
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_ty3mr"]
particle_flag_disable_z = true
angle_min = -720.0
angle_max = 720.0
spread = 180.0
initial_velocity_min = 30.3
initial_velocity_max = 260.81
gravity = Vector3(0, 0, 0)
damping_min = 2.0
damping_max = 14.000001
scale_min = 0.29999998
scale_max = 0.5
alpha_curve = SubResource("CurveTexture_416m4")
collision_use_scale = true
[node name="BulletImpact" type="Node2D"]
script = ExtResource("1_416m4")
[node name="GPUParticles2D" type="GPUParticles2D" parent="."]
emitting = false
amount = 24
texture = ExtResource("2_c1ocy")
lifetime = 0.2
one_shot = true
explosiveness = 1.0
process_material = SubResource("ParticleProcessMaterial_ty3mr")

View file

@ -0,0 +1,100 @@
[gd_scene load_steps=5 format=3 uid="uid://d8llv1fieoga"]
[ext_resource type="Script" uid="uid://i21n4rlirxln" path="res://scripts/bullet_trail.gd" id="1_086qf"]
[sub_resource type="Animation" id="Animation_rlhfg"]
resource_name = "default"
length = 0.4
step = 0.0167
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:width")
tracks/0/interp = 1
tracks/0/loop_wrap = false
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.4),
"transitions": PackedFloat32Array(1, 3.3635848),
"update": 0,
"values": [6.0, 0.0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:default_color:b")
tracks/1/interp = 1
tracks/1/loop_wrap = false
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [0.0, 1.0]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath(".:default_color:a")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0, 0.4),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [1.0, 0.0]
}
[sub_resource type="Animation" id="Animation_gt5uw"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:width")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [6.0]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:default_color:b")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0.0]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath(".:default_color:a")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [1.0]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_p1in0"]
_data = {
&"RESET": SubResource("Animation_gt5uw"),
&"default": SubResource("Animation_rlhfg")
}
[node name="BulletTrail" type="Line2D"]
points = PackedVector2Array(0, 0, 128, 0)
width = 6.0
default_color = Color(1, 1, 0, 1)
script = ExtResource("1_086qf")
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_p1in0")
}

View file

@ -0,0 +1,48 @@
[gd_scene load_steps=7 format=3 uid="uid://bsvwpuwvh3hga"]
[ext_resource type="Script" uid="uid://ck38qwl4qytnt" path="res://scripts/particle_group.gd" id="1_uommb"]
[ext_resource type="Texture2D" uid="uid://5iimabvyld40" path="res://textures/particles/basic.png" id="2_02mh3"]
[ext_resource type="Texture2D" uid="uid://bpe67g6185n5v" path="res://textures/particles/fire.png" id="3_nnsi5"]
[sub_resource type="Curve" id="Curve_ipns3"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.7512195, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 3
[sub_resource type="CurveTexture" id="CurveTexture_8qclf"]
curve = SubResource("Curve_ipns3")
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_w8i8w"]
particle_flag_disable_z = true
angle_min = -720.0
angle_max = 720.0
spread = 180.0
initial_velocity_min = 30.3
initial_velocity_max = 260.81
gravity = Vector3(0, 0, 0)
damping_min = 2.0
damping_max = 14.000001
scale_min = 0.099999994
scale_max = 0.25
alpha_curve = SubResource("CurveTexture_8qclf")
collision_use_scale = true
[node name="Explosion" type="Node2D"]
script = ExtResource("1_uommb")
[node name="GPUParticles2D" type="GPUParticles2D" parent="."]
emitting = false
amount = 24
texture = ExtResource("2_02mh3")
lifetime = 10.0
one_shot = true
explosiveness = 1.0
process_material = SubResource("ParticleProcessMaterial_w8i8w")
[node name="GPUParticles2D2" type="GPUParticles2D" parent="."]
emitting = false
amount = 24
texture = ExtResource("3_nnsi5")
lifetime = 10.0
one_shot = true
explosiveness = 1.0
process_material = SubResource("ParticleProcessMaterial_w8i8w")

8
scripts/bullet_trail.gd Normal file
View file

@ -0,0 +1,8 @@
extends Line2D
func play() -> void:
$AnimationPlayer.play("default")
await $AnimationPlayer.animation_finished
queue_free()

View file

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

View file

@ -3,14 +3,34 @@ extends CharacterBody2D
var horizontial_movement = 0
var vertical_movement = 0
var speed = 256
var health = 100
var fire_delay = 0
## Is the player busy in an interaction?
var busy = false
var firing = false
var equipped_ground_gun = "pistol"
var ammo_in_mag = 12
func set_ground_gun(value: String):
equipped_ground_gun = value
$HeldItem/Sprite.texture = load("res://textures/" + equipped_ground_gun + ".png")
ammo_in_mag = global.ground_guns
func _ready() -> void:
$Sprite.play()
if has_node("HeldItem") and (equipped_ground_gun != null):
set_ground_gun(equipped_ground_gun)
$HeldItem/Cast.add_exception(self)
func _process(delta: float) -> void:
if !$Sprite.is_playing():
$Sprite.play()
if busy:
velocity = Vector2()
else:
@ -27,5 +47,34 @@ func _process(delta: float) -> void:
else:
$Sprite.animation = "idle"
fire_delay -= delta
if firing and (fire_delay < 0):
if has_node("HeldItem") and (equipped_ground_gun != null):
$HeldItem/Cast.force_raycast_update()
var hit_target = $HeldItem/Cast.get_collider()
if "health" in hit_target:
hit_target.health -= 10
var bullet_impact = preload("res://scenes/particles/bullet_impact.tscn").instantiate()
bullet_impact.global_position = $HeldItem/Cast.get_collision_point()
get_parent().add_child(bullet_impact)
bullet_impact.play()
var bullet_trail = preload("res://scenes/particles/bullet_trail.tscn").instantiate()
bullet_trail.global_position = $HeldItem/Sprite.global_position
bullet_trail.points[1] = ($HeldItem/Cast.get_collision_point() - bullet_trail.global_position)
get_parent().add_child(bullet_trail)
bullet_trail.play()
$HeldItem/Gunshot.play()
fire_delay = 0.5
move_and_slide()

32
scripts/enemy_ground.gd Normal file
View file

@ -0,0 +1,32 @@
extends "res://scripts/character_ground.gd"
var last_aim_direction = Vector2(0, 0)
@export var starting_gun: String = &"pistol"
func _ready() -> void:
super()
set_ground_gun(starting_gun)
func _process(delta: float) -> void:
super(delta)
if input_icon.using_gamepad:
if !((Input.get_axis("aim_left", "aim_right") == 0) and (Input.get_axis("aim_up", "aim_down") == 0)):
$HeldItem.rotation = Vector2(
Input.get_axis("aim_left", "aim_right"),
Input.get_axis("aim_up", "aim_down")
).angle()
if ($HeldItem.rotation_degrees < -90) or ($HeldItem.rotation_degrees > 90):
$HeldItem/Sprite.scale.y = -1
else:
$HeldItem/Sprite.scale.y = 1
else:
$HeldItem.look_at(get_global_mouse_position())
horizontial_movement = Input.get_axis("ground_left", "ground_right")
vertical_movement = Input.get_axis("ground_up", "ground_down")
firing = Input.is_action_pressed("fire")

View file

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

View file

@ -28,6 +28,16 @@ var orbit_zones = [
]
var ground_guns = {
"pistol": {
"name": "Oni",
"type": "energy",
"damage": 10,
"magazine_size": 12,
"fire_rate": 0.3
}
}
func generate_save():
var save_dict = {
"stats": stats
@ -101,6 +111,7 @@ var default_stats = {
"ship_rotation": 0,
"story_progress": 1,
"navigation_goal": null,
"equipped_ground_gun": "pistol"
}
var stats = default_stats.duplicate_deep()

View file

@ -1,5 +1,11 @@
extends Node2D
func play():
var last = null
for n in get_children():
last = n
n.restart()
await last.finished
queue_free()

View file

@ -1,7 +1,30 @@
extends "res://scripts/character_ground.gd"
var last_aim_direction = Vector2(0, 0)
func _ready() -> void:
super()
set_ground_gun(global.stats.equipped_ground_gun)
func _process(delta: float) -> void:
super(delta)
if input_icon.using_gamepad:
if !((Input.get_axis("aim_left", "aim_right") == 0) and (Input.get_axis("aim_up", "aim_down") == 0)):
$HeldItem.rotation = Vector2(
Input.get_axis("aim_left", "aim_right"),
Input.get_axis("aim_up", "aim_down")
).angle()
if ($HeldItem.rotation_degrees < -90) or ($HeldItem.rotation_degrees > 90):
$HeldItem/Sprite.scale.y = -1
else:
$HeldItem/Sprite.scale.y = 1
else:
$HeldItem.look_at(get_global_mouse_position())
horizontial_movement = Input.get_axis("ground_left", "ground_right")
vertical_movement = Input.get_axis("ground_up", "ground_down")
firing = Input.is_action_pressed("fire")

BIN
sounds/gunshot_1.mp3 Normal file

Binary file not shown.

View file

@ -0,0 +1,19 @@
[remap]
importer="mp3"
type="AudioStreamMP3"
uid="uid://5x8fl2mk082h"
path="res://.godot/imported/gunshot_1.mp3-ef270f77ac19a4282389883c7fa7e203.mp3str"
[deps]
source_file="res://sounds/gunshot_1.mp3"
dest_files=["res://.godot/imported/gunshot_1.mp3-ef270f77ac19a4282389883c7fa7e203.mp3str"]
[params]
loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cduq2cbhvwqj4"
path="res://.godot/imported/bullet.png-c6ea14d6c2effaceac001d6322d192c4.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://textures/particles/bullet.png"
dest_files=["res://.godot/imported/bullet.png-c6ea14d6c2effaceac001d6322d192c4.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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