delete gitignore files

This commit is contained in:
2022-12-10 09:38:18 +01:00
parent 7c076dbebb
commit 2fb20600e2
32 changed files with 974 additions and 0 deletions

69
scripts/Logic/Game.gd Normal file
View File

@@ -0,0 +1,69 @@
extends Node
class_name Game
const CHILL = 0
const FIGHTING = 1
#Signals
signal ammo_pickup
signal shoot
var fight_state = CHILL
var t = 0.0
@onready var p1_train = $Player1 as Train
@onready var p2_train = $Player2 as Train
@onready var StartNode = $StartNode
var p1_node : MapNode
var p2_node : MapNode
func _ready():
p1_node = StartNode
p2_node = StartNode
p2_train.get_node("CharacterBody3D").is_player1 = false
p2_train.is_P1 = false
p1_train.current_speed = 10
p1_train.hit.connect(_on_hit_player)
p2_train.hit.connect(_on_hit_player)
func _on_hit_player(player1,dmg):
if not player1:
p2_train.current_speed -= dmg
else:
p1_train.current_speed -= dmg
func _process(delta):
p1_train.current_distance += p1_train.current_speed * delta
p2_train.current_distance += p2_train.current_speed * delta
if(p1_train.current_distance >= p1_node.LENGTH):
var distance_delta = p1_train.current_distance - p1_node.LENGTH
p1_node = p1_node._on_train_exit(p1_train)
p1_train.current_distance = distance_delta
if(p2_train.current_distance >= p2_node.LENGTH):
var distance_delta = p2_train.current_distance - p2_node.LENGTH
p2_node = p2_node._on_train_exit(p2_train)
p2_train.current_distance = distance_delta
if(p1_node == p2_node && p1_train.current_distance - p2_train.current_distance < 2):
if(fight_state == CHILL):
var tween = create_tween()
tween.tween_property($Camera3D, "position", Vector3(0,10,0), 1)
fight_state = FIGHTING
else:
fight_state = CHILL
var tween = create_tween()
tween.tween_property($Camera3D, "position", Vector3(0,20,0), 1)
if Input.is_action_pressed("test"):
emit_signal("shoot")

14
scripts/Logic/MapNode.gd Normal file
View File

@@ -0,0 +1,14 @@
extends Node
class_name MapNode
const LENGTH = 10
const PICKUP = 0
var previous : MapNode
var current_trains = []
func _on_train_entered(train):
current_trains.append(train)
func _on_train_exit(train):
current_trains.erase(train)

View File

@@ -0,0 +1,9 @@
extends MapNode
class_name StraightMapNode
@export var next : MapNode
func _on_train_exit(train):
next._on_train_entered(train)
super._on_train_exit(train)
return next

View File

@@ -0,0 +1,21 @@
extends StraightMapNode
class_name TurnMapNode
signal turnEvent
var turn = false
@export var is_left_turn = false
@export var turn_node : MapNode
func _on_train_entered(train):
super._on_train_entered(train)
turnEvent.emit()
func _on_train_exit(train):
if(turn):
turn_node._on_train_entered(train)
current_trains.erase(train)
return turn_node
else:
super._on_train_exit(train)
return next

38
scripts/Modules/Cannon.gd Normal file
View File

@@ -0,0 +1,38 @@
extends Module
class_name Cannon
enum STATE {INACTIVE, RELOADING, SHOOTING}
var CAN_ENGAGE = true
var DAMAGE = 5
@onready var train = get_parent() as Train
#------------Methods-------------#
func _ready():
maxStashValue = 1
currentStashValue = 1
currentState = STATE.INACTIVE
#TODO: FINISH
func interact():
if currentState == STATE.INACTIVE:
#TODO: RELOADING
if currentStashValue < maxStashValue:
currentState = STATE.RELOADING
currentStashValue += 1
return
return
func shoot():
if not CAN_ENGAGE:
return false
CAN_ENGAGE = false
create_tween().tween_callback(func(): CAN_ENGAGE = true).set_delay(2)
if currentStashValue >= 1 and currentState == STATE.INACTIVE:
currentState = STATE.SHOOTING
currentStashValue -= 1
currentState = STATE.INACTIVE
return true
return false

25
scripts/Modules/Engine.gd Normal file
View File

@@ -0,0 +1,25 @@
extends Module
class_name TrainEngine
enum STATE {RUNNING, DEAD}
#------------Methods-------------#
func _ready():
var root = get_tree().root.get_child(0)
maxStashValue = 100
currentStashValue = 100
currentState = STATE.RUNNING
#TODO: FINISH
func interact():
if currentState == STATE.RUNNING:
if currentStashValue < maxStashValue:
currentStashValue += 10
if currentStashValue > maxStashValue:
currentStashValue = maxStashValue
return
#TODO: Repair Train
currentState = STATE.RUNNING

47
scripts/Modules/Module.gd Normal file
View File

@@ -0,0 +1,47 @@
extends Node
class_name Module
#-----------Parameters----------------'
var currentStashValue = 0 : set = _set_currentStashValue, get = _get_currentStashValue
var maxStashValue = 0 : set = _set_maxStashValue, get = _get_maxStashValue
var currentState = null : set = _set_state, get = _get_state
var level = 0 : set = _set_level, get = _get_level
enum MODULE_TYPE {CANNON, STEERING, ENGINE, STORAGE}
#------------Methods-------------#
func interact():
pass
func _ready():
var root = get_tree().root.get_child(0)
#-----------Setter and Getter---------------#
func _set_currentStashValue(newValue):
currentStashValue = newValue
func _get_currentStashValue():
return currentStashValue
func _set_maxStashValue(newValue):
currentStashValue = newValue
func _get_maxStashValue():
return currentStashValue
func _set_level(newValue):
level = newValue
func _get_level():
return level
func _set_state(newValue):
currentState = newValue
func _get_state():
return currentState

View File

@@ -0,0 +1,25 @@
extends Module
class_name Storage
enum TYPE {AMMO, GUNPOWDER, FUEL}
@export var currentType: TYPE
#------------Methods-------------#
func _ready():
var root = get_tree().root.get_child(0)
root.ammo_pickup.connect(_on_signal_storing)
maxStashValue = 5
currentStashValue = 0
func interact():
if currentStashValue >= 1:
currentStashValue -= 1
return
func _on_signal_storing():
if currentStashValue < maxStashValue:
currentStashValue += 1
return

59
scripts/Player.gd Normal file
View File

@@ -0,0 +1,59 @@
extends CharacterBody3D
#-----------Parameters--------------#
var SPEED = 10
var movement = Vector3(0,0,0)
var collisionLayer = 3
var inventory = 0 #1 - full, 0 - empty inventory
var resource = 0
var is_alive = true
@onready var is_player1 = true
#---------------Methods--------------#
func _physics_process(delta):
movement = Vector3(0,0,0)
check_interaction()
check_input()
velocity = movement * SPEED
move_and_slide()
func check_input():
if is_player1:
if Input.is_action_pressed("p1_left"):
movement.x -= 1
if Input.is_action_pressed("p1_right"):
movement.x += 1
if Input.is_action_pressed("p1_up"):
movement.z -= 1
if Input.is_action_pressed("p1_down"):
movement.z += 1
else:
if Input.is_action_pressed("p2_left"):
movement.x -= 1
if Input.is_action_pressed("p2_right"):
movement.x += 1
if Input.is_action_pressed("p2_up"):
movement.z -= 1
if Input.is_action_pressed("p2_down"):
movement.z += 1
func check_interaction():
var action
if is_player1:
action = "p1_interact"
else:
action = "p2_interact"
if Input.is_action_just_pressed(action):
for body in $HitBox.get_overlapping_bodies():
if body is Module:
#Storage interaction
if not inventory && body is Storage:
body.interact()
elif inventory && not body is Storage:
body.interact()

33
scripts/Train.gd Normal file
View File

@@ -0,0 +1,33 @@
extends Node
class_name Train
signal hit(player, dmg)
signal game_over
var is_P1 = true
var current_distance = 0
var current_speed = 5
var CANNONS = []
var STORAGES = []
#@onready var ENGINE = $Module/Engine
@onready var root = get_tree().root.get_child(0) as Game
func _ready():
for child in get_children():
if(child is Cannon):
CANNONS.append(child)
if(child is Storage):
STORAGES.append(child)
root.shoot.connect(_on_signal_shooting)
func _on_signal_shooting():
for cannon in CANNONS:
if cannon.shoot():
hit.emit(is_P1,cannon.DAMAGE)
func is_dead():
if current_speed <= 0:
game_over.emit()