Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Oreboat authored Dec 26, 2023
1 parent cd9502a commit 84b4e3b
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 0 deletions.
25 changes: 25 additions & 0 deletions UI/hud.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extends Control

var players = []
@export var defaultSeperation = 250
@export var playerStats : Resource
@onready var StatContainer = $StatContainer
# Called when the node enters the scene tree for the first time.
func _ready():
var stats = preload("res://src/UI/Scenes/player_stats.tscn")
StatContainer.add_theme_constant_override("separation", defaultSeperation)
NodeObject.findNodesOfType(get_parent(),"CharacterBody3D", players)
for player in players:
defaultSeperation -= 50
var pstats = stats.instantiate()
StatContainer.add_child(pstats)
pstats.get_node("Label").text = ("Player " + str(player.playerID + 1))
pstats.player = player
pass
StatContainer.add_theme_constant_override("separation", defaultSeperation)
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
23 changes: 23 additions & 0 deletions UI/player_stats.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extends Control

var player
@onready var healthBar = $ProgressBar
@onready var lives = $Label2
@onready var timer = $Timer
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
if player != null:
healthBar.value = player.currentHealth
healthBar.max_value = player.maxHealth
lives.text = "Lives: " + str(player.lives)
if player.get_node("Health Component").respawn:
timer.show()
timer.get_child(1).text = ("%2d" %player.get_node("Health Component").respawnTimer.time_left)
else:
timer.hide()
pass
12 changes: 12 additions & 0 deletions autoload/LevelData.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends Node

var players = []
# Called when the node enters the scene tree for the first time.
func _ready():
NodeObject.findNodesOfType(get_parent(), "CharacterBody3D", players)
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
22 changes: 22 additions & 0 deletions autoload/Object.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
extends Node


# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.


func findNodesOfType(node: Node, className: String, result: Array):
if node.is_class(className):
result.push_back(node)
print(node.name + " has " + className)
for child in node.get_children():
findNodesOfType(child, className, result)
func lerpPos(lerpPosition: Vector3, lerpSpeed: float, delta: float, lerpObject: Node3D):
lerp(lerpObject.global_position, lerpPosition, lerpSpeed * delta)
pass
func approxLerp():
pass
9 changes: 9 additions & 0 deletions data/fighter.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends Resource
class_name fighter

@export var characterName: String
@export var characterMesh : Resource
@export var topSpeed: float
@export var acceleration: float
@export var friction: float
@export var jumpHeight: float
65 changes: 65 additions & 0 deletions player/Camera Controller.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
extends Node3D

@export var springOffset = 5.0
@onready var springArm = $SpringArm3D
@onready var camera = $Camera3D
@export var CenterPoint = Node3D
@export var clampAngle = 15
@export var camDistance = 5
@export var camera_speed = 5

# Called when the node enters the scene tree for the first time.
func _ready():


camera.top_level = true
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if(Level.players.size() > 1):
global_position = calculateAveragePosition()
calculateCameraRotation(delta)
#if abs(position.x - CenterPoint.position.x) > camDistance:
#look_at(CenterPoint.position, transform.basis.y)
rotation = Vector3(0,clamp(-rotation.y,deg_to_rad(-clampAngle),deg_to_rad(clampAngle)),0)
#camera.position.x = lerp()
camera.position.z = position.z + 15
camera.position.x = lerp(camera.position.x, position.x, 10 * delta)
camera.position.x = clamp(camera.position.x, -camDistance, camDistance)
camera.size = calculatePlayerDistance() + springOffset
camera.look_at(global_position, transform.basis.y)
#calculateCameraLookAt(delta)
#camera.rotation.y = clamp(-rotation.y,deg_to_rad(-15),deg_to_rad(15))
springArm.spring_length = global_position.length() + springOffset
#springArm.get_child(0).look_at(position, Vector3.UP, false)
else:
global_position = Level.players[0].global_position
camera.look_at(global_position, transform.basis.y)
camera.position.z = position.z + 10
camera.position.x = lerp(camera.position.x, position.x, 10 * delta)
pass
func calculateAveragePosition():
var average = Vector3.ZERO
if Level.players.size() > 1:
for player in Level.players:
average += player.global_position
return average/Level.players.size()
else:
return Level.players[0].global_position

func calculatePlayerDistance():
var maxDistance = 0.0
for player in Level.players:
var distance = player.position.distance_to(position)
if distance > maxDistance:
maxDistance = distance
return maxDistance
func calculateCameraRotation(delta):
var T=global_transform.looking_at(CenterPoint.global_transform.origin, Vector3(0,1,0))
global_transform.basis.y=lerp(global_transform.basis.y, T.basis.y, delta*camera_speed)
func calculateCameraLookAt(delta):
var T=global_transform.looking_at(CenterPoint.global_transform.origin, Vector3(0,1,0))
global_transform.basis.x =lerp(global_transform.basis.x, T.basis.y, delta*camera_speed)
#global_rotation = lerp_angle(r, angle, 1)
59 changes: 59 additions & 0 deletions player/Health Component.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
extends Node3D

var player
@onready var respawnTimer = $Timer
@export var decal = Node
var respawn = false
var testDec = 15.0808123131321313
var delta
# Called when the node enters the scene tree for the first time.
func _ready():
player = get_parent()
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
delta = _delta
print("%2d" % respawnTimer.time_left)
if player != null:
if player.currentHealth == 0:
if respawn == false:
player.lives -= 1
#print(player.lives)
if player.lives > 0:
respawn = true
respawnTimer.start()
if player.lives > 0:
#player_respawn()
decal.rotation.y += deg_to_rad(2)
player.isDead = true
player.velocity.y = 0
player.pivot.hide()
decal.show()
player.pivot.position.y = 7.5
player.deathMarker.show()
player.CollisionShape.disabled = true
player.deathMarker.position.y = player.Raycast.get_collision_point().y + 1.5
else:
Level.players.erase(player)
player.queue_free()
pass


func respawn_player():
player.currentHealth = player.maxHealth
decal.hide()
player.pivot.show()
player.global_position = player.pivot.global_position
player.pivot.position = Vector3.ZERO
player.deathMarker.hide()
player.CollisionShape.disabled = false
player.isDead = false
respawn = false
pass # Replace with function body.
func _input(_event):
if Input.is_action_just_pressed("player_bottom_action_" + str(player.playerID)) and respawn:
respawnTimer.stop()
respawnTimer.emit_signal("timeout")

139 changes: 139 additions & 0 deletions player/player_controller.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
extends CharacterBody3D


@export var walk_speed = 5.0
var current_speed
@export var gravity = -9.8
@export var jump_impulse = 2.0
@export var acceleration = 0.0
@export var friction = 3.0
@export var playerID = 0
@export var coyoteTime = 0.2
@export var airFriction = 2
@export var dashSpeed = 15
@export var dashLength = .2

var coyoteTimer = 0
var currentHealth = 100
@export var maxHealth = 100
@export var lives = 3
@export var characterData: fighter
var pivot
var playerText
@onready var dashTimer = $Timer
@onready var deathMarker = $CSGBox3D
@onready var Raycast = $RayCast3D
@onready var CollisionShape = $CollisionShape3D
var doublejump = true
var maxShieldTimer = 1.5
var currentShieldTimer = 0
var isShielding = false
var isDashing = false
var isDead = false
var dashDirection = Vector3.ZERO
# Get the gravity from the project settings to be synced with RigidBody nodes.

func _ready():
currentHealth = maxHealth
loadPlayerData()
return
playerText = characterData.get_node("PlayerID")
playerText.text = "Player " + str(playerID + 1)
func loadPlayerData():
current_speed = characterData.topSpeed
acceleration = characterData.acceleration
friction = characterData.friction
jump_impulse = characterData.jumpHeight
print(characterData.characterMesh.get_path())
#var playerMesh = load(characterData.characterMesh.get_path())
func _process(delta):
return
Raycast.position = pivot.position
if is_on_floor():
coyoteTimer = coyoteTime
else:
coyoteTimer -= delta

func _physics_process(delta):
return
var input_vector = Vector3.ZERO
if isShielding == false:
input_vector = get_input_vector()
var direction = get_direction(input_vector)
if !isDead:
apply_gravity(delta)
apply_jump()
apply_movement(input_vector, direction, delta)
apply_friction(direction, delta)
dash(delta, input_vector)
move_and_slide()
if Input.is_action_pressed("debug_drain_" + str(playerID)) and currentHealth > 0:
currentHealth -= 1
parry(delta)
func apply_friction(direction, delta):
if direction == Vector3.ZERO and !isDashing:
if is_on_floor():
velocity = velocity.move_toward(Vector3.ZERO, friction * delta)
else:
velocity.x = velocity.move_toward(direction * current_speed,airFriction * delta).x
velocity.z = velocity.move_toward(direction * current_speed, airFriction * delta).z
func get_input_vector():
var input_vector = Vector3.ZERO
input_vector.x = Input.get_action_strength("player_right_%s" % [playerID] ) - Input.get_action_strength("player_left_%s" % [playerID])
input_vector.z = Input.get_action_strength("player_down_%s" % [playerID]) - Input.get_action_strength("player_up_%s" % [playerID])
return input_vector.normalized() if input_vector.length() > 1 else input_vector
func get_direction(input_vector):
var direction = (input_vector.x * transform.basis.x) + (input_vector.z * transform.basis.z)
return direction
func apply_movement(input_vector, direction, delta):
if input_vector != Vector3.ZERO and !isDashing:
velocity.x = velocity.move_toward(direction * current_speed, acceleration * delta).x
velocity.z = velocity.move_toward(direction * current_speed, acceleration * delta).z
pivot.rotation.y = lerp_angle(pivot.rotation.y,atan2(0,input_vector.x),25 * delta)
func apply_gravity(delta):
if !isDashing:
velocity.y += gravity * delta
velocity.y = clamp(velocity.y, gravity, jump_impulse)
func apply_jump():
if(Input.is_action_just_pressed("player_jump_%s" % [playerID])):
if coyoteTimer > 0:
velocity.y += jump_impulse
doublejump = true
elif coyoteTimer <= 0 and doublejump:
velocity.y += jump_impulse
doublejump = false
elif Input.is_action_just_released("player_jump_%s" % [playerID]):
velocity.y *= .5
func parry(delta):
if Input.is_action_pressed("player_shield_" + str(playerID)) and is_on_floor():
if currentShieldTimer > 0:
currentShieldTimer -= delta
isShielding = true
elif currentHealth < maxHealth:
currentHealth += (delta * 30)
else:
isShielding = false
else:
isShielding = false
currentShieldTimer = maxShieldTimer
func dash(delta, input_vector):
if Input.is_action_just_pressed("player_shield_" + str(playerID)) and !is_on_floor() and dashDirection == Vector3.ZERO:
isDashing = true
dashTimer.wait_time = dashLength
dashTimer.start()
dashDirection = get_direction(Vector3(dashInput(input_vector.x),0, dashInput(input_vector.z)))
velocity.y = 0
if isDashing:
velocity.x = velocity.move_toward(dashDirection * dashSpeed, 1).x
velocity.z = velocity.move_toward(dashDirection * dashSpeed, delta).z
if Input.is_action_just_released("player_shield_" + str(playerID)) and !is_on_floor() or dashTimer.is_stopped():
isDashing = false
dashTimer.stop()
dashDirection = Vector3.ZERO
func dashInput(InputFloat):
if InputFloat > 0:
return 1
elif InputFloat < 0:
return -1
elif InputFloat == 0:
return 0

0 comments on commit 84b4e3b

Please sign in to comment.