working on picking up arrows
This commit is contained in:
@@ -1,13 +1,45 @@
|
||||
extends Projectile
|
||||
class_name Arrow
|
||||
|
||||
@onready var hit_ray: RayCast3D = $HitRay
|
||||
@onready var land_depth: Marker3D = $LandDepth
|
||||
@onready var arrow: MeshInstance3D = $Arrow
|
||||
@onready var pickup_collision: Area3D = $PickupCollision
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
if hit_ray.is_colliding():
|
||||
var stick_point = hit_ray.get_collision_point()
|
||||
if land_depth.global_position.distance_to(stick_point) > .2:
|
||||
var follow_target
|
||||
var spawn_out = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
pickup_collision.monitorable = false
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if !despawn:
|
||||
if hit_ray.is_colliding():
|
||||
despawn = true
|
||||
var body_hit = hit_ray.get_collider()
|
||||
if body_hit is EnemyCharacter:
|
||||
body_hit.hit(damage)
|
||||
reparent(body_hit)
|
||||
var stick_point = hit_ray.get_collision_point()
|
||||
if land_depth.global_position.distance_to(stick_point) > .2:
|
||||
global_position += global_transform.basis * Vector3(0,0,-speed) * delta
|
||||
else:
|
||||
global_position += global_transform.basis * Vector3(0,0,-speed) * delta
|
||||
else:
|
||||
global_position += global_transform.basis * Vector3(0,0,-speed) * delta
|
||||
pickup_collision.monitorable = true
|
||||
|
||||
pickup_follow(delta)
|
||||
|
||||
func pickup_follow(delta):
|
||||
if follow_target != null:
|
||||
if spawn_out:
|
||||
follow_target.arrow += 1
|
||||
queue_free()
|
||||
else:
|
||||
if global_position.distance_to(follow_target.global_position) < .5:
|
||||
spawn_out = true
|
||||
else:
|
||||
var direction_to_player = global_position.direction_to(follow_target.global_position)
|
||||
var distance_to_player = global_position.distance_to(follow_target.global_position)
|
||||
global_position += global_transform.basis * direction_to_player * (5 + distance_to_player * 3) * delta
|
||||
|
||||
20
Scripts/cloudSpawner.gd
Normal file
20
Scripts/cloudSpawner.gd
Normal file
@@ -0,0 +1,20 @@
|
||||
extends CSGSpawner
|
||||
|
||||
@export var number_of_clouds : int = 50
|
||||
const CLOUD_1 = preload("res://cloud1.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
spawn_clouds()
|
||||
|
||||
func spawn_clouds():
|
||||
while number_of_clouds >= 0:
|
||||
number_of_clouds -= 1
|
||||
|
||||
var spawn_pos = random_box_pos()
|
||||
var set_pos = self.global_position + spawn_pos
|
||||
var cloud = CLOUD_1.instantiate()
|
||||
cloud.visible = false
|
||||
add_child(cloud)
|
||||
cloud.global_position = set_pos
|
||||
await cloud.global_position == set_pos
|
||||
cloud.visible = true
|
||||
1
Scripts/cloudSpawner.gd.uid
Normal file
1
Scripts/cloudSpawner.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bot4t8im34ldh
|
||||
11
Scripts/csg_spawner.gd
Normal file
11
Scripts/csg_spawner.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
extends CSGBox3D
|
||||
class_name CSGSpawner
|
||||
|
||||
func _ready() -> void:
|
||||
visible = false
|
||||
|
||||
func random_box_pos():
|
||||
var x : float = randf_range(size.x / 2, -size.x /2)
|
||||
var y : float = randf_range(size.y/ 2, -size.y /2)
|
||||
var z : float = randf_range(size.z / 2, -size.z /2)
|
||||
return Vector3(x,y,z)
|
||||
1
Scripts/csg_spawner.gd.uid
Normal file
1
Scripts/csg_spawner.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c28po5p783mb2
|
||||
41
Scripts/enemy.gd
Normal file
41
Scripts/enemy.gd
Normal file
@@ -0,0 +1,41 @@
|
||||
extends CharacterBody3D
|
||||
class_name EnemyCharacter
|
||||
|
||||
@export var start_health : int = 10
|
||||
@export var loot_dropped : int = 3
|
||||
|
||||
const GOLDCOIN = preload("res://Prefabs/goldcoin.tscn")
|
||||
const MAX_AV = 15
|
||||
const MAX_LV = 2
|
||||
|
||||
|
||||
var health
|
||||
|
||||
func _ready() -> void:
|
||||
health = start_health
|
||||
|
||||
func hit(damage):
|
||||
health -= damage
|
||||
print("HEALTH : ",health)
|
||||
print("HIT")
|
||||
if health <= 0:
|
||||
die()
|
||||
|
||||
func die():
|
||||
drop_loot()
|
||||
queue_free()
|
||||
|
||||
func drop_loot():
|
||||
while loot_dropped > 0:
|
||||
var instance_coin = GOLDCOIN.instantiate()
|
||||
var av_x = randf_range(-MAX_AV,MAX_AV)
|
||||
var av_y = randf_range(-MAX_AV,MAX_AV)
|
||||
var av_z = randf_range(-MAX_AV,MAX_AV)
|
||||
var lv_x = randf_range(-MAX_LV,MAX_LV)
|
||||
var lv_y = randf_range(0,MAX_LV)
|
||||
var lv_z = randf_range(-MAX_LV,MAX_LV)
|
||||
get_tree().current_scene.add_child(instance_coin)
|
||||
instance_coin.global_position = global_position
|
||||
instance_coin.angular_velocity = Vector3(av_x,av_y,av_z)
|
||||
instance_coin.linear_velocity = Vector3(lv_x,lv_y,lv_z)
|
||||
loot_dropped -= 1
|
||||
1
Scripts/enemy.gd.uid
Normal file
1
Scripts/enemy.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cf6bja6cahxl5
|
||||
@@ -10,9 +10,6 @@ const SPAWN_OUT_HEIGHT = 14.0
|
||||
func _process(delta: float) -> void:
|
||||
if follow_target != null:
|
||||
if spawn_out:
|
||||
#if global_position.y < SPAWN_OUT_HEIGHT: REMOVED BECAUSE I DIDN'T LIKE THE LOOK, LEAVING FOR NOW IN CASE I WANT TO MAKE A DIFFERENT EFFECT HAPPEN
|
||||
#linear_velocity = Vector3(0,10,0)
|
||||
#else:
|
||||
follow_target.gold += amount
|
||||
queue_free()
|
||||
else:
|
||||
|
||||
@@ -5,6 +5,7 @@ var dodge_direction
|
||||
|
||||
@onready var body: MeshInstance3D = $Body
|
||||
@onready var anim_player: AnimationPlayer = $AnimationPlayer
|
||||
@onready var sword_hit_area: Area3D = $SwordHit
|
||||
|
||||
var gold_to_vacuum = []
|
||||
var gold = 0
|
||||
@@ -12,6 +13,8 @@ var gold = 0
|
||||
const MAX_HEALTH : float = 100
|
||||
var health = MAX_HEALTH
|
||||
|
||||
var arrows = 10
|
||||
|
||||
const MAX_STAMINA : float = 100
|
||||
var stamina = MAX_STAMINA
|
||||
|
||||
@@ -34,3 +37,7 @@ func stamina_regen(delta):
|
||||
func _on_area_3d_body_entered(body: Node3D) -> void:
|
||||
if body is Gold:
|
||||
body.follow_target = self
|
||||
|
||||
func _on_area_3d_area_entered(area: Area3D) -> void:
|
||||
if area.get_parent() is Arrow:
|
||||
body.get_parent().follow_target = self
|
||||
|
||||
@@ -2,9 +2,10 @@ extends Node3D
|
||||
|
||||
@export var player : Player
|
||||
|
||||
@onready var gold_label: Label = $Camera3D/Control/BoxContainer/GOLD
|
||||
@onready var health_bar: ProgressBar = $Camera3D/Control/BoxContainer/VBoxContainer/HealthBar
|
||||
@onready var stamina_bar: ProgressBar = $Camera3D/Control/BoxContainer/VBoxContainer/StaminaBar
|
||||
@onready var gold_label: Label = $Camera3D/Control/VBoxContainer2/GOLD
|
||||
@onready var arrow_label: Label = $Camera3D/Control/VBoxContainer2/Arrows
|
||||
@onready var health_bar: ProgressBar = $Camera3D/Control/VBoxContainer/HealthBar
|
||||
@onready var stamina_bar: ProgressBar = $Camera3D/Control/VBoxContainer/StaminaBar
|
||||
|
||||
|
||||
const CAM_MOVE_SPEED = 5
|
||||
@@ -12,6 +13,7 @@ const CAM_MOVE_SPEED = 5
|
||||
func _physics_process(delta: float) -> void:
|
||||
follow_player(delta)
|
||||
gold_label.text = "Gold : " + str(player.gold)
|
||||
arrow_label.text = "Arrows : " + str(player.arrows)
|
||||
stamina_bar.value = player.stamina
|
||||
health_bar.value = player.health
|
||||
|
||||
|
||||
@@ -10,4 +10,5 @@ func Physics_Update(delta):
|
||||
attack()
|
||||
|
||||
if Input.is_action_just_pressed("ranged_attack"):
|
||||
Transitioned.emit(self,"ranged attack")
|
||||
if character.arrows > 0:
|
||||
Transitioned.emit(self,"ranged attack")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends Node3D
|
||||
class_name Projectile
|
||||
|
||||
var damage
|
||||
var damage = 1
|
||||
var speed
|
||||
var despawn = false
|
||||
|
||||
@@ -3,13 +3,14 @@ class_name PlayerRangedAttack
|
||||
|
||||
@export var fired_object : PackedScene
|
||||
@export var object_speed : float = 20.0
|
||||
@export var arrow_damage : float = 1
|
||||
|
||||
func Enter():
|
||||
character.velocity = Vector3.ZERO
|
||||
|
||||
func Physics_Update(delta):
|
||||
body_look_at_mouse()
|
||||
|
||||
apply_gravity(delta)
|
||||
if Input.is_action_just_released("ranged_attack"):
|
||||
fire_projectile()
|
||||
Transitioned.emit(self,"on floor")
|
||||
@@ -18,6 +19,7 @@ func Physics_Update(delta):
|
||||
func fire_projectile():
|
||||
var arrow_spawn = fired_object.instantiate()
|
||||
get_tree().current_scene.add_child(arrow_spawn)
|
||||
character.arrows -= 1
|
||||
arrow_spawn.speed = object_speed
|
||||
arrow_spawn.transform.basis = character.body.global_transform.basis
|
||||
arrow_spawn.global_position = character.body.global_position
|
||||
|
||||
1
Scripts/rat.gd
Normal file
1
Scripts/rat.gd
Normal file
@@ -0,0 +1 @@
|
||||
extends EnemyCharacter
|
||||
1
Scripts/rat.gd.uid
Normal file
1
Scripts/rat.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://blcfh1bg820w7
|
||||
Reference in New Issue
Block a user