Skip to content

Commit

Permalink
Add tracking gamemode
Browse files Browse the repository at this point in the history
  • Loading branch information
antimundo committed Mar 2, 2024
1 parent 78231d7 commit 2a0d368
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 29 deletions.
1 change: 1 addition & 0 deletions assets/gamemodes/horizontal.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ movement={
"y": 0
}
size=1
health=0
initial_targets=1
1 change: 1 addition & 0 deletions assets/gamemodes/moving.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ movement={
"y": 5
}
size=2
health=0
initial_targets=6
1 change: 1 addition & 0 deletions assets/gamemodes/random.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ movement={
"y": 0
}
size=2
health=0
initial_targets=3
15 changes: 15 additions & 0 deletions assets/gamemodes/tracking.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id="tracking"
title="Tracking"
description="Keep your aim tracking a target."
spawn_location={
"x": [-15, 15],
"y": [2, 7]
}
time=30
movement={
"x": 15,
"y": 0
}
size=2
health=3
initial_targets=1
49 changes: 49 additions & 0 deletions assets/images/gamemodes/tracking.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions assets/images/gamemodes/tracking.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://r1y7o5b1hdud"
path="res://.godot/imported/tracking.svg-29df28c108fd2ebe1b543d8d3dae07d2.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/images/gamemodes/tracking.svg"
dest_files=["res://.godot/imported/tracking.svg-29df28c108fd2ebe1b543d8d3dae07d2.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
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
3 changes: 2 additions & 1 deletion scenes/autoload/global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ func load_gamemodes():
var config = ConfigFile.new()
config.load(PATH + file_name)
var id = config.get_value("", "id")
var this_gamemode : Dictionary
var this_gamemode : Dictionary = { }
this_gamemode.id = config.get_value("", "id")
this_gamemode.title = config.get_value("", "title")
this_gamemode.description = config.get_value("", "description")
this_gamemode.time = config.get_value("", "time")
this_gamemode.movement = config.get_value("", "movement")
this_gamemode.health = config.get_value("", "health")
this_gamemode.size = config.get_value("", "size")
this_gamemode.initial_targets = config.get_value("", "initial_targets")
this_gamemode.spawn_location = config.get_value("", "spawn_location")
Expand Down
37 changes: 24 additions & 13 deletions scenes/game_world/game_world.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,26 @@ grow_vertical = 2
theme = SubResource("Theme_agxdx")
script = ExtResource("5_of43n")

[node name="Panel" type="Panel" parent="CanvasLayer/GameplayUI"]
[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/GameplayUI"]
layout_mode = 1
offset_left = 76.0
offset_top = 66.0
offset_right = 302.0
offset_bottom = 214.0
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 50.0
offset_top = 50.0
offset_right = -50.0
offset_bottom = -50.0
grow_horizontal = 2
grow_vertical = 2

[node name="Panel" type="Panel" parent="CanvasLayer/GameplayUI/MarginContainer"]
custom_minimum_size = Vector2(220, 150)
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 0
theme_override_styles/panel = SubResource("StyleBoxFlat_fembj")

[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/GameplayUI/Panel"]
[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/GameplayUI/MarginContainer/Panel"]
layout_mode = 1
anchors_preset = 9
anchor_bottom = 1.0
Expand All @@ -302,34 +313,34 @@ theme_override_constants/margin_top = 25
theme_override_constants/margin_right = 25
theme_override_constants/margin_bottom = 25

[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/GameplayUI/Panel/MarginContainer"]
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/GameplayUI/MarginContainer/Panel/MarginContainer"]
layout_mode = 2

[node name="time" type="HBoxContainer" parent="CanvasLayer/GameplayUI/Panel/MarginContainer/VBoxContainer"]
[node name="time" type="HBoxContainer" parent="CanvasLayer/GameplayUI/MarginContainer/Panel/MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="label" type="Label" parent="CanvasLayer/GameplayUI/Panel/MarginContainer/VBoxContainer/time"]
[node name="label" type="Label" parent="CanvasLayer/GameplayUI/MarginContainer/Panel/MarginContainer/VBoxContainer/time"]
layout_mode = 2
theme = SubResource("Theme_p6jab")
text = "Time "
vertical_alignment = 1
uppercase = true

[node name="label2" type="Label" parent="CanvasLayer/GameplayUI/Panel/MarginContainer/VBoxContainer/time"]
[node name="label2" type="Label" parent="CanvasLayer/GameplayUI/MarginContainer/Panel/MarginContainer/VBoxContainer/time"]
layout_mode = 2
text = "60 s"

[node name="targets" type="HBoxContainer" parent="CanvasLayer/GameplayUI/Panel/MarginContainer/VBoxContainer"]
[node name="targets" type="HBoxContainer" parent="CanvasLayer/GameplayUI/MarginContainer/Panel/MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="label" type="Label" parent="CanvasLayer/GameplayUI/Panel/MarginContainer/VBoxContainer/targets"]
[node name="label" type="Label" parent="CanvasLayer/GameplayUI/MarginContainer/Panel/MarginContainer/VBoxContainer/targets"]
layout_mode = 2
theme = SubResource("Theme_p6jab")
text = "Targets "
vertical_alignment = 1
uppercase = true

[node name="label2" type="Label" parent="CanvasLayer/GameplayUI/Panel/MarginContainer/VBoxContainer/targets"]
[node name="label2" type="Label" parent="CanvasLayer/GameplayUI/MarginContainer/Panel/MarginContainer/VBoxContainer/targets"]
layout_mode = 2
text = "0"

Expand Down
4 changes: 2 additions & 2 deletions scenes/game_world/gameplay_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ extends Control
## Gameplay UI with game stats

@onready var animation_kill = $AnimationKill
@onready var kills = $Panel/MarginContainer/VBoxContainer/targets/label2
@onready var kills = $MarginContainer/Panel/MarginContainer/VBoxContainer/targets/label2
@onready var timer = $"../../Timer"
@onready var timer_label = $Panel/MarginContainer/VBoxContainer/time/label2
@onready var timer_label = $MarginContainer/Panel/MarginContainer/VBoxContainer/time/label2

func update_kills(value: int):
kills.set_text((str(value)))
Expand Down
34 changes: 23 additions & 11 deletions scenes/game_world/player_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ func _input(event) -> void:
rotate_y(deg_to_rad(-event.relative.x * mouse_sensitivity))
camera.rotate_x(deg_to_rad(-event.relative.y * mouse_sensitivity))
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-89), deg_to_rad(89))
if event.is_action_pressed("shoot"):
shoot()
if Global.current_gamemode.health == 0:
if event.is_action_pressed("shoot"):
shoot(1)
if event.is_action_pressed("jump"):
jump()

var elapsed: float
func _process(delta):
const COOLDOWN = .2
if Global.current_gamemode.health > 0:
elapsed += delta
if elapsed > COOLDOWN:
if Input.is_action_pressed("shoot"):
shoot(COOLDOWN)
elapsed = 0

func _physics_process(delta) -> void:
handle_gravity(delta)
var input := Input.get_vector("move_left", "move_right", "move_forward", "move_back")
Expand All @@ -60,15 +71,16 @@ func jump():
gravity = -JUMP_STRENGTH
return

func shoot():
func shoot(damage: float):
shooted.emit()
if raycast.is_colliding():
var target = raycast.get_collider()
var bullet_hole_instance = bullet_hole.instantiate()

target.add_child(bullet_hole_instance)
bullet_hole_instance.global_transform.origin = raycast.get_collision_point()
bullet_hole_instance.look_at(position + Vector3.FORWARD, raycast.get_collision_normal())

if target.is_in_group("Enemy"):
target.health -= 1
if target != null:
var bullet_hole_instance = bullet_hole.instantiate()

target.add_child(bullet_hole_instance)
bullet_hole_instance.global_transform.origin = raycast.get_collision_point()
bullet_hole_instance.look_at(position + Vector3.FORWARD, raycast.get_collision_normal())

if target.is_in_group("Enemy"):
target.health -= damage
5 changes: 3 additions & 2 deletions scenes/game_world/target.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ signal destroyed
@onready var mesh := $CollisionShape3D/MeshInstance3D

var current_velocity = null
var health = 1:
var health = 0.0:
set(value):
health = value
if health <= 0:
if health < 0.0:
emit_signal("destroyed")
queue_free()

func _ready():
health = Global.current_gamemode.health
var category = DataManager.categories.SETTINGS
if DataManager.get_data(category, "TargetColor") != null:
var material_override = mesh.get_mesh().get_material()
Expand Down
2 changes: 2 additions & 0 deletions scenes/main_menu/select_level.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ func add_gamemodes():
for gamemode in Global.gamemodes:
var button := Button.new()
button.text = Global.gamemodes[gamemode].title
button.icon = get_gamemode_texture(gamemode)
button.set_expand_icon(true)
button.name = gamemode
button.set_text_alignment(HORIZONTAL_ALIGNMENT_LEFT)
button.pressed.connect(select_gamemode.bind(button.name))
Expand Down

0 comments on commit 2a0d368

Please sign in to comment.