Skip to content

Commit abc62f1

Browse files
committed
Refactor code and add a lot of new features
1. Amazing UI to show how many bullets you have! 2. A lot of bug fixes 3. ATTENTION TO DETAIL??!!! OMG, this is so cool, download OpenFPS NOW!
1 parent d710c99 commit abc62f1

12 files changed

+999
-139
lines changed

UI.gd

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
extends Control
2+
3+
@onready var bullets = [$Background/Bullet, $Background/Bullet2, $Background/Bullet3, $Background/Bullet4, $Background/Bullet5, $Background/Bullet6, $Background/Bullet7]
4+
@onready var player = $"../CharacterBody3D"
5+
6+
# Called every frame. 'delta' is the elapsed time since the previous frame.
7+
func _process(delta):
8+
if player.ammo == 6:
9+
bullets[0].visible = false
10+
elif player.ammo == 5:
11+
bullets[1].visible = false
12+
elif player.ammo == 4:
13+
bullets[2].visible = false
14+
elif player.ammo == 3:
15+
bullets[3].visible = false
16+
elif player.ammo == 2:
17+
bullets[4].visible = false
18+
elif player.ammo == 1:
19+
bullets[5].visible = false
20+
elif player.ammo == 0:
21+
bullets[6].visible = false
22+
else:
23+
for bullet in bullets:
24+
bullet.visible = true

UI.tscn

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[gd_scene load_steps=4 format=3 uid="uid://i1xsfxvo8ctf"]
2+
3+
[ext_resource type="Script" path="res://UI.gd" id="1_sxsfn"]
4+
[ext_resource type="Texture2D" uid="uid://crc6twp0rgprx" path="res://assets/ammo.png" id="1_to6pr"]
5+
[ext_resource type="Texture2D" uid="uid://6i2c06kqgnao" path="res://assets/bullet.png" id="2_0rfxh"]
6+
7+
[node name="Control" type="Control"]
8+
layout_mode = 3
9+
anchors_preset = 15
10+
anchor_right = 1.0
11+
anchor_bottom = 1.0
12+
grow_horizontal = 2
13+
grow_vertical = 2
14+
script = ExtResource("1_sxsfn")
15+
16+
[node name="Background" type="Sprite2D" parent="."]
17+
position = Vector2(60, 612)
18+
scale = Vector2(0.1875, 0.2)
19+
texture = ExtResource("1_to6pr")
20+
21+
[node name="Bullet" type="Sprite2D" parent="Background"]
22+
position = Vector2(-254, -5.05566)
23+
scale = Vector2(3.33333, 2.38889)
24+
texture = ExtResource("2_0rfxh")
25+
26+
[node name="Bullet2" type="Sprite2D" parent="Background"]
27+
position = Vector2(-167.805, -5.05566)
28+
scale = Vector2(3.33333, 2.38889)
29+
texture = ExtResource("2_0rfxh")
30+
31+
[node name="Bullet3" type="Sprite2D" parent="Background"]
32+
position = Vector2(-81.6094, -5.05566)
33+
scale = Vector2(3.33333, 2.38889)
34+
texture = ExtResource("2_0rfxh")
35+
36+
[node name="Bullet4" type="Sprite2D" parent="Background"]
37+
position = Vector2(4.58588, -5.05566)
38+
scale = Vector2(3.33333, 2.38889)
39+
texture = ExtResource("2_0rfxh")
40+
41+
[node name="Bullet5" type="Sprite2D" parent="Background"]
42+
position = Vector2(90.7811, -5.05566)
43+
scale = Vector2(3.33333, 2.38889)
44+
texture = ExtResource("2_0rfxh")
45+
46+
[node name="Bullet6" type="Sprite2D" parent="Background"]
47+
position = Vector2(176.976, -5.05566)
48+
scale = Vector2(3.33333, 2.38889)
49+
texture = ExtResource("2_0rfxh")
50+
51+
[node name="Bullet7" type="Sprite2D" parent="Background"]
52+
position = Vector2(263.172, -5.05566)
53+
scale = Vector2(3.33333, 2.38889)
54+
texture = ExtResource("2_0rfxh")

animations.gd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
3+

assets/ammo.png

1.92 KB
Loading

assets/ammo.png.import

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://crc6twp0rgprx"
6+
path="res://.godot/imported/ammo.png-8e32d4eb9fd99120a8d85ead8ec3046c.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://assets/ammo.png"
14+
dest_files=["res://.godot/imported/ammo.png-8e32d4eb9fd99120a8d85ead8ec3046c.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1

assets/bullet.png

605 Bytes
Loading

assets/bullet.png.import

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://6i2c06kqgnao"
6+
path="res://.godot/imported/bullet.png-c68d06721d4ad8b0013707b0a51654af.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://assets/bullet.png"
14+
dest_files=["res://.godot/imported/bullet.png-c68d06721d4ad8b0013707b0a51654af.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1

node_3d.gd

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ func _input(event):
88
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
99
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
1010
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
11+
12+
13+
14+

node_3d.tscn

+752-85
Large diffs are not rendered by default.

pistol.gd

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extends Node3D
2+
3+
@onready var camera = $"../Camera3D"
4+
5+
func _physics_process(delta):
6+
transform = camera.transform

player.gd

+83-54
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
extends CharacterBody3D
22

3-
const SPEED = 5.0
4-
const JUMP_VELOCITY = 4.5
3+
4+
const SPEED = 10.0
5+
const JUMP_VELOCITY = 5
56
const mouse_sensitivity = 0.002
67

8+
@onready var firesound = $firesound
9+
@onready var dryFireSound = $dryFireSound
10+
@onready var animplayer = $Camera3D/pistol/AnimationPlayer
711

12+
# Animation names
13+
var fire_animation:String = "attachment_vm_pi_papa320_mag_skeleton|fire1"
14+
var reload_animation:String = "attachment_vm_pi_papa320_mag_skeleton|reload_empty"
15+
var draw_animation:String = "attachment_vm_pi_papa320_mag_skeleton|draw_first"
16+
var draw_empty_animation:String = "attachment_vm_pi_papa320_mag_skeleton|draw_empty"
17+
var idle_animation:String = "attachment_vm_pi_papa320_mag_skeleton|idle"
18+
var ads_animation:String = "ads"
819

9-
# Get the gravity from the project settings to be synced with RigidBody nodes.
10-
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
11-
var ammo = 5
20+
var ammo = 7
1221
var shots = 0
13-
var is_moving = false
14-
var stop_walking = true
15-
var reload_finished = true
1622
var ads = false
23+
var reload_finished = true
24+
var inspecting = false
25+
26+
# Get the gravity from the project settings to be synced with RigidBody nodes.
27+
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
28+
1729
# Initialize the animation player and the audio stream players
18-
@onready var animplayer = $Camera3D/pistol/AnimationPlayer
19-
@onready var firesound = $firesound
20-
@onready var dryFireSound = $dryFireSound
2130
@onready var camera = $Camera3D
2231

2332

@@ -27,8 +36,6 @@ func _input(event):
2736
camera.rotate_x(-event.relative.y * mouse_sensitivity)
2837
camera.rotation.x = clampf(camera.rotation.x, -deg_to_rad(70), deg_to_rad(70))
2938

30-
31-
3239
func _physics_process(delta):
3340
# Add the gravity.
3441
if not is_on_floor():
@@ -37,28 +44,15 @@ func _physics_process(delta):
3744
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
3845
velocity.y = JUMP_VELOCITY
3946
# Handle the left mouse button (fire) event
40-
if Input.is_action_just_pressed("fire") and reload_finished:
41-
if ammo != 0:
42-
animplayer.stop()
43-
animplayer.play("attachment_vm_pi_papa320_mag_skeleton|fire1")
44-
firesound.playing = true
45-
shots += 1
46-
ammo -= 1
47-
if ammo == 0:
48-
dryFireSound.playing = true
49-
if Input.is_action_just_pressed("reload"):
47+
if Input.is_action_just_pressed("fire"):
48+
shoot()
49+
if Input.is_action_just_pressed("reload") and not inspecting:
5050
reload()
5151
if Input.is_action_just_pressed("ads"):
52-
if ads and reload_finished:
53-
ads = false
54-
animplayer.play_backwards("ads")
55-
elif ads and not reload_finished:
56-
pass
57-
elif not ads and not reload_finished:
58-
pass
59-
else:
60-
ads = true
61-
animplayer.play("ads")
52+
ads_func()
53+
if Input.is_action_just_pressed("inspect"):
54+
draw()
55+
6256
# Get the input direction and handle the movement/deceleration.
6357
# As good practice, you should replace UI actions with custom gameplay actions.
6458
var input_dir = Input.get_vector("left", "right", "forward", "backward")
@@ -72,37 +66,72 @@ func _physics_process(delta):
7266

7367
move_and_slide()
7468
idle()
75-
76-
77-
func _on_animation_player_animation_started(anim_name):
78-
if anim_name == "" and not is_moving:
79-
stop_walking = true
80-
elif anim_name == "attachment_vm_pi_papa320_mag_skeleton|reload_empty":
81-
reload_finished = false
82-
stop_walking = true
83-
else:
84-
stop_walking = false
8569

8670

87-
88-
89-
func _on_animation_player_animation_finished(anim_name):
90-
if anim_name == "attachment_vm_pi_papa320_mag_skeleton|reload_empty":
91-
reload_finished = true
92-
9371
func reload():
9472
if ammo == 0:
95-
animplayer.play("attachment_vm_pi_papa320_mag_skeleton|reload_empty")
96-
ammo += 5
73+
animplayer.play(reload_animation)
74+
ammo += 7
9775
shots = 0
98-
elif ammo == 5:
76+
elif ammo == 7:
9977
pass
10078
else:
101-
animplayer.play("attachment_vm_pi_papa320_mag_skeleton|reload_empty")
79+
animplayer.play(reload_animation)
10280
ammo += shots
10381
shots = 0
10482

83+
84+
func draw():
85+
if ads:
86+
pass
87+
elif !reload_finished:
88+
pass
89+
elif ammo == 0:
90+
animplayer.stop()
91+
animplayer.play(draw_empty_animation)
92+
else:
93+
animplayer.stop()
94+
animplayer.play(draw_animation)
95+
96+
func shoot():
97+
if reload_finished and not inspecting:
98+
if ammo != 0:
99+
animplayer.stop()
100+
animplayer.play(fire_animation)
101+
firesound.playing = true
102+
shots += 1
103+
ammo -= 1
104+
if ammo == 0:
105+
dryFireSound.playing = true
106+
else:
107+
pass
108+
func ads_func():
109+
if ads and reload_finished:
110+
ads = false
111+
animplayer.play_backwards(ads_animation)
112+
elif ads and not reload_finished or inspecting:
113+
pass
114+
elif not ads and not reload_finished or inspecting:
115+
pass
116+
else:
117+
ads = true
118+
animplayer.play(ads_animation)
119+
105120
func idle():
106121
if animplayer.is_playing() == false:
107-
animplayer.play("attachment_vm_pi_papa320_mag_skeleton|idle")
122+
animplayer.play(idle_animation)
123+
124+
125+
126+
func _on_animation_player_animation_started(anim_name):
127+
if anim_name == reload_animation:
128+
reload_finished = false
129+
elif anim_name == draw_animation or anim_name == draw_empty_animation:
130+
inspecting = true
131+
132+
func _on_animation_player_animation_finished(anim_name):
133+
if anim_name == reload_animation:
134+
reload_finished = true
135+
elif anim_name == draw_animation or anim_name == draw_empty_animation:
136+
inspecting = false
108137

project.godot

+5
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@ ads={
5858
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(223, 4),"global_position":Vector2(226, 36),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
5959
]
6060
}
61+
inspect={
62+
"deadzone": 0.5,
63+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"echo":false,"script":null)
64+
]
65+
}

0 commit comments

Comments
 (0)