Initial Commit
This commit is contained in:
20
scripts/control_box.gd
Normal file
20
scripts/control_box.gd
Normal file
@ -0,0 +1,20 @@
|
||||
extends MeshInstance3D
|
||||
|
||||
var movingTowards: Vector3
|
||||
var currentLocation: Vector3
|
||||
|
||||
func _ready() -> void:
|
||||
GameEngine.getGE().controlBox = self
|
||||
currentLocation = self.position
|
||||
movingTowards = currentLocation
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var currentMousePos = GameEngine.getGE().mainCamera.getMouseRayCast();
|
||||
|
||||
if currentMousePos != Vector3.INF && currentMousePos != movingTowards:
|
||||
movingTowards.x = currentMousePos.x
|
||||
|
||||
self.position = self.position.move_toward(movingTowards, GameEngine.getGE().getGameSpeed(delta))
|
||||
|
||||
func getMoveToLocation() -> Vector3:
|
||||
return self.position
|
1
scripts/control_box.gd.uid
Normal file
1
scripts/control_box.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dm3rne2akywg7
|
80
scripts/game_engine.gd
Normal file
80
scripts/game_engine.gd
Normal file
@ -0,0 +1,80 @@
|
||||
extends Node
|
||||
class_name GameEngine
|
||||
|
||||
enum OPS {ADD,SUB,MUL,DIV}
|
||||
|
||||
static var gameEngineInstance: GameEngine = null
|
||||
static var idaArray: Array
|
||||
var idaCount: int
|
||||
var gameSpeed: float = 3.0
|
||||
var mainCamera: Camera3D = null
|
||||
static var idaPack: Node3D = null
|
||||
var idaBase: PackedScene = (load("res://Objects/playerClone.tscn") as PackedScene)
|
||||
static var idaPrime: Node3D = null
|
||||
var controlBox: Node3D = null
|
||||
var gateSpawner: Node3D = null
|
||||
var gateMovementSpeed: float = 10.0
|
||||
var gateSpawnTime: float = 2.0
|
||||
var gateSpawnChance: int = 3
|
||||
|
||||
func setupEngine() -> void:
|
||||
idaArray.clear()
|
||||
idaCount = 0
|
||||
|
||||
static func getGE() -> GameEngine:
|
||||
if gameEngineInstance == null:
|
||||
gameEngineInstance = GameEngine.new()
|
||||
gameEngineInstance.setupEngine()
|
||||
return gameEngineInstance
|
||||
|
||||
func moveIda(ida: Node3D, delta: float, prime: bool) -> void:
|
||||
if prime:
|
||||
idaPack.position.x = idaPack.position.move_toward(getGE().controlBox.getMoveToLocation(), getGE().getGameSpeed(delta)).x
|
||||
|
||||
ida.look_at(getGE().controlBox.getMoveToLocation(), Vector3(0,1,0), true)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
moveIda(idaPrime, delta, true)
|
||||
for ida in idaArray:
|
||||
moveIda(ida, delta, false)
|
||||
|
||||
func getGameSpeed(delta: float) -> float:
|
||||
return gameSpeed * delta
|
||||
|
||||
func calculateIdas(value: int) -> void:
|
||||
var newValue: int = idaCount + value
|
||||
if newValue < 0:
|
||||
newValue = 0
|
||||
|
||||
idaCount = clampi(idaCount + value, 0, 2000)
|
||||
var idaOffset: int = idaArray.size() - idaCount
|
||||
print(str(idaCount) + " - " + str(idaOffset))
|
||||
|
||||
for i in range(abs(idaOffset)):
|
||||
if idaOffset < 0:
|
||||
var newIda = idaBase.instantiate()
|
||||
newIda.position = (idaPrime.position + (Vector3(-1.5 + randf() * 3, 0, -1.5 + randf() * 1.5)))
|
||||
idaPack.add_child(newIda)
|
||||
idaArray.push_back(newIda)
|
||||
elif idaOffset > 0:
|
||||
var currentIda = idaArray.pop_at(randi() % idaArray.size())
|
||||
currentIda.queue_free()
|
||||
|
||||
func modifyIdas(value: int, operation: OPS) -> void:
|
||||
var baseVal: int = 0
|
||||
match operation:
|
||||
OPS.ADD:
|
||||
baseVal += value
|
||||
OPS.SUB:
|
||||
baseVal -= value
|
||||
OPS.MUL:
|
||||
var newVal = ceil((1 + idaCount) * value) - idaCount
|
||||
baseVal += newVal - 1
|
||||
OPS.DIV:
|
||||
if idaCount != 0:
|
||||
var newVal = floor(float(1 + idaCount) / value)
|
||||
baseVal -= idaCount - (newVal - 1)
|
||||
else:
|
||||
baseVal = 0
|
||||
|
||||
calculateIdas(baseVal)
|
1
scripts/game_engine.gd.uid
Normal file
1
scripts/game_engine.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://b2tpu7b87ak68
|
50
scripts/gate_base.gd
Normal file
50
scripts/gate_base.gd
Normal file
@ -0,0 +1,50 @@
|
||||
extends "res://scripts/obsticle_base.gd"
|
||||
|
||||
var operation: GameEngine.OPS
|
||||
var value: int
|
||||
@onready var screenObject: MeshInstance3D = $Screen
|
||||
@onready var signObject: MeshInstance3D = $Screen/Sign
|
||||
var screenGreenMat: StandardMaterial3D = preload("res://materials/sign_green.material")
|
||||
var screenRedMat: StandardMaterial3D = preload("res://materials/sign_red.material")
|
||||
|
||||
func playerHit() -> void:
|
||||
GameEngine.getGE().modifyIdas(value, operation)
|
||||
physicsBody.queue_free()
|
||||
|
||||
func updateSignText(valueIn: int, opSign: String, negative: bool) -> void:
|
||||
signObject.mesh.text = opSign + " " + str(valueIn)
|
||||
|
||||
if negative:
|
||||
screenObject.mesh.material = screenRedMat
|
||||
else:
|
||||
screenObject.mesh.material = screenGreenMat
|
||||
|
||||
func _ready() -> void:
|
||||
var opPreSelected: int = randi() % 100
|
||||
var minValue: int = 2
|
||||
var maxValue: int = 10
|
||||
var opSign: String = ""
|
||||
var negative: bool = false
|
||||
|
||||
if (opPreSelected < 35):
|
||||
operation = GameEngine.OPS.ADD
|
||||
opSign = "+"
|
||||
elif (opPreSelected < 70):
|
||||
operation = GameEngine.OPS.SUB
|
||||
opSign = "-"
|
||||
negative = true
|
||||
elif (opPreSelected < 85):
|
||||
operation = GameEngine.OPS.MUL
|
||||
opSign = "x"
|
||||
maxValue = 5
|
||||
elif (opPreSelected < 100):
|
||||
operation = GameEngine.OPS.DIV
|
||||
opSign = "÷"
|
||||
maxValue = 5
|
||||
negative = true
|
||||
|
||||
value = randi() % maxValue
|
||||
if value < minValue:
|
||||
value = minValue
|
||||
|
||||
updateSignText(value, opSign, negative)
|
1
scripts/gate_base.gd.uid
Normal file
1
scripts/gate_base.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://rx1tvuhjo78w
|
4
scripts/ida_pack.gd
Normal file
4
scripts/ida_pack.gd
Normal file
@ -0,0 +1,4 @@
|
||||
extends Node3D
|
||||
|
||||
func _ready() -> void:
|
||||
GameEngine.getGE().idaPack = self
|
1
scripts/ida_pack.gd.uid
Normal file
1
scripts/ida_pack.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dvhpy5a48w6nl
|
22
scripts/main_view.gd
Normal file
22
scripts/main_view.gd
Normal file
@ -0,0 +1,22 @@
|
||||
extends Camera3D
|
||||
|
||||
func _ready() -> void:
|
||||
GameEngine.getGE().mainCamera = self
|
||||
|
||||
func getMouseRayCast() -> Vector3:
|
||||
var mousePos: Vector2 = get_viewport().get_mouse_position()
|
||||
var originPoint: Vector3 = self.project_ray_origin(mousePos)
|
||||
var directionVec: Vector3 = self.project_ray_normal(mousePos)
|
||||
|
||||
var rayLen: float = self.far
|
||||
var endPoint: Vector3 = originPoint + directionVec * rayLen
|
||||
|
||||
var spaceState = get_world_3d().direct_space_state
|
||||
var query = PhysicsRayQueryParameters3D.create(originPoint, endPoint)
|
||||
var result = spaceState.intersect_ray(query)
|
||||
|
||||
if not result.is_empty():
|
||||
return result["position"]
|
||||
else:
|
||||
return Vector3.INF
|
||||
|
1
scripts/main_view.gd.uid
Normal file
1
scripts/main_view.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bgh5muwu1ysof
|
15
scripts/obsticle_base.gd
Normal file
15
scripts/obsticle_base.gd
Normal file
@ -0,0 +1,15 @@
|
||||
extends Node3D
|
||||
|
||||
@export var physicsBody: PhysicsBody3D
|
||||
func playerHit() -> void:
|
||||
pass
|
||||
|
||||
func moveObsticle(moveDistance: float) -> void:
|
||||
position.z -= moveDistance
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if is_instance_valid(physicsBody):
|
||||
var hasCollision = physicsBody.move_and_collide(Vector3(0,0,-1), true)
|
||||
if hasCollision:
|
||||
if hasCollision.get_collider().has_meta("isPlayer"):
|
||||
playerHit()
|
1
scripts/obsticle_base.gd.uid
Normal file
1
scripts/obsticle_base.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://dt5ru6m5tecwk
|
36
scripts/spawned_gates.gd
Normal file
36
scripts/spawned_gates.gd
Normal file
@ -0,0 +1,36 @@
|
||||
extends Node3D
|
||||
|
||||
var gateArray: Array = []
|
||||
var spawnTimer: float = 0.0
|
||||
@export var leftSpawnPoint: Node3D = null
|
||||
@export var rightSpawnPoint: Node3D = null
|
||||
@export var ground: MeshInstance3D = null
|
||||
|
||||
func _ready() -> void:
|
||||
GameEngine.getGE().gateSpawner = self
|
||||
|
||||
func generateGateStats(spawnFrom: Node3D) -> void:
|
||||
var newGate: Node3D = (load("res://Objects/gate_base.tscn") as PackedScene).instantiate()
|
||||
newGate.position = spawnFrom.position
|
||||
self.add_child(newGate)
|
||||
gateArray.push_back(newGate)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
for gate in gateArray:
|
||||
if gate.position.z <= -300:
|
||||
gateArray.erase(gate)
|
||||
gate.queue_free()
|
||||
else:
|
||||
gate.moveObsticle(GameEngine.getGE().gateMovementSpeed * GameEngine.getGE().getGameSpeed(delta))
|
||||
|
||||
if spawnTimer >= GameEngine.getGE().gateSpawnTime:
|
||||
var spawnLeft: bool = ((randi() % GameEngine.getGE().gateSpawnChance) == 0)
|
||||
var spawnRight: bool = ((randi() % GameEngine.getGE().gateSpawnChance) == 0)
|
||||
spawnTimer = 0.0
|
||||
|
||||
if spawnLeft:
|
||||
generateGateStats(leftSpawnPoint)
|
||||
if spawnRight:
|
||||
generateGateStats(rightSpawnPoint)
|
||||
else:
|
||||
spawnTimer += delta
|
1
scripts/spawned_gates.gd.uid
Normal file
1
scripts/spawned_gates.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://cdm3pkabmplbr
|
Reference in New Issue
Block a user