mirror of
https://github.com/PfandBoss/SemesterGameJam2022.git
synced 2025-11-12 12:16:14 +01:00
start MapNodes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
extends Node
|
||||
class_name Game
|
||||
|
||||
#Signals
|
||||
signal ammo_pickup
|
||||
@@ -6,36 +7,22 @@ signal shoot
|
||||
|
||||
var t = 0.0
|
||||
|
||||
@onready var tween = create_tween() as Tween
|
||||
@onready var p1_train = $Player1 as Train
|
||||
@onready var p2_train = $Player2 as Train
|
||||
|
||||
@export var p1 : PathFollow3D
|
||||
@export var p2 : PathFollow3D
|
||||
|
||||
var speed_p1 = 10
|
||||
var speed_p2 = 10
|
||||
|
||||
func _ready():
|
||||
p1.get_node("root").test.connect(func(): print("player1"))
|
||||
p2.get_node("root").test.connect(func(): print("player2"))
|
||||
start_tween()
|
||||
|
||||
func start_tween():
|
||||
tween.stop()
|
||||
tween = create_tween()
|
||||
tween.set_parallel()
|
||||
tween.set_trans(Tween.TRANS_LINEAR)
|
||||
tween.tween_property(p1, "progress_ratio", 1, speed_p1)
|
||||
tween.tween_property(p2, "progress_ratio", -1, speed_p2)
|
||||
|
||||
p2_train.is_P1 = false
|
||||
p1_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):
|
||||
if Input.is_action_pressed("test"):
|
||||
speed_p1 = 5
|
||||
start_tween()
|
||||
|
||||
if round(p1.position.distance_to(p2.position)) == 9:
|
||||
emit_signal("shoot")
|
||||
|
||||
|
||||
|
||||
|
||||
14
scripts/Logic/MapNode.gd
Normal file
14
scripts/Logic/MapNode.gd
Normal 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)
|
||||
8
scripts/Logic/StraightMapNode.gd
Normal file
8
scripts/Logic/StraightMapNode.gd
Normal file
@@ -0,0 +1,8 @@
|
||||
extends MapNode
|
||||
class_name StraightMapNode
|
||||
|
||||
var next : MapNode
|
||||
|
||||
func _on_train_exit(train):
|
||||
next._on_train_entered(train)
|
||||
super._on_train_exit(train)
|
||||
18
scripts/Logic/TurnMapNode.gd
Normal file
18
scripts/Logic/TurnMapNode.gd
Normal file
@@ -0,0 +1,18 @@
|
||||
extends StraightMapNode
|
||||
|
||||
signal turnEvent
|
||||
|
||||
var is_left_turn = false
|
||||
var turn = false
|
||||
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)
|
||||
else:
|
||||
super._on_train_exit(train)
|
||||
@@ -5,13 +5,13 @@ 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():
|
||||
var root = get_tree().root.get_child(0)
|
||||
root.shoot.connect(_on_signal_shooting)
|
||||
maxStashValue = 1
|
||||
currentStashValue = 0
|
||||
currentStashValue = 1
|
||||
currentState = STATE.INACTIVE
|
||||
#TODO: FINISH
|
||||
func interact():
|
||||
@@ -24,15 +24,15 @@ func interact():
|
||||
|
||||
return
|
||||
|
||||
func _on_signal_shooting():
|
||||
func shoot():
|
||||
if not CAN_ENGAGE:
|
||||
return
|
||||
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
|
||||
print("hit")
|
||||
currentState = STATE.INACTIVE
|
||||
return
|
||||
return true
|
||||
return false
|
||||
|
||||
@@ -1,17 +1,33 @@
|
||||
extends Node
|
||||
class_name Train
|
||||
|
||||
signal test
|
||||
signal hit(player, dmg)
|
||||
signal game_over
|
||||
|
||||
var speed = 10
|
||||
var is_P1 = true
|
||||
var current_speed = 10
|
||||
var CANNONS = []
|
||||
var STORAGES = []
|
||||
#@onready var ENGINE = $Module/Engine
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
@onready var root = get_tree().root.get_child(0) as Game
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
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)
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
test.emit() # Replace with function body.
|
||||
func _on_signal_shooting():
|
||||
for cannon in CANNONS:
|
||||
if cannon.shoot():
|
||||
hit.emit(is_P1,cannon.DAMAGE)
|
||||
print("Shot P2")
|
||||
|
||||
func is_dead():
|
||||
if current_speed <= 0:
|
||||
game_over.emit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user