This commit is contained in:
2022-12-10 08:53:58 +01:00
parent c278c93c52
commit f3d3048291
7 changed files with 44 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
[gd_scene load_steps=8 format=3 uid="uid://n7w0ff7u25yc"] [gd_scene load_steps=9 format=3 uid="uid://n7w0ff7u25yc"]
[ext_resource type="Script" path="res://scripts/Logic/Game.gd" id="1_iox18"] [ext_resource type="Script" path="res://scripts/Logic/Game.gd" id="1_iox18"]
[ext_resource type="PackedScene" uid="uid://bqe8ucbruto1j" path="res://Nodes/StartNode.tscn" id="2_61aog"]
[ext_resource type="PackedScene" uid="uid://byo1m0n20yl45" path="res://Nodes/cannon.tscn" id="2_vrf6k"] [ext_resource type="PackedScene" uid="uid://byo1m0n20yl45" path="res://Nodes/cannon.tscn" id="2_vrf6k"]
[ext_resource type="Script" path="res://scripts/Train.gd" id="2_xl0he"] [ext_resource type="Script" path="res://scripts/Train.gd" id="2_xl0he"]
[ext_resource type="PackedScene" uid="uid://vwjd5od63jgh" path="res://Nodes/Player.tscn" id="4_1ipcp"] [ext_resource type="PackedScene" uid="uid://vwjd5od63jgh" path="res://Nodes/Player.tscn" id="4_1ipcp"]
@@ -17,6 +18,8 @@ data = PackedVector3Array(-6.5, 0.5, 12.5, 6.5, 0.5, 12.5, -6.5, -0.5, 12.5, 6.5
[node name="Game" type="Node"] [node name="Game" type="Node"]
script = ExtResource("1_iox18") script = ExtResource("1_iox18")
[node name="StartNode" parent="." instance=ExtResource("2_61aog")]
[node name="Camera3D" type="Camera3D" parent="."] [node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 20, 0) transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 20, 0)
@@ -38,6 +41,8 @@ shape = SubResource("ConcavePolygonShape3D_p3d4e")
[node name="CharacterBody3D" parent="Player1" instance=ExtResource("4_1ipcp")] [node name="CharacterBody3D" parent="Player1" instance=ExtResource("4_1ipcp")]
transform = Transform3D(1, 0, -3.55271e-15, 0, 1, 0, 3.55271e-15, 0, 1, -1.18815, 1, -11.064) transform = Transform3D(1, 0, -3.55271e-15, 0, 1, 0, 3.55271e-15, 0, 1, -1.18815, 1, -11.064)
[node name="Cannon2" parent="Player1" instance=ExtResource("2_vrf6k")]
[node name="Player2" type="Node3D" parent="."] [node name="Player2" type="Node3D" parent="."]
transform = Transform3D(-0.0154456, -6.75145e-10, -0.999879, -5.21344e-12, 1, -6.75146e-10, 0.999879, -5.2134e-12, -0.0154456, -8, 0, -32) transform = Transform3D(-0.0154456, -6.75145e-10, -0.999879, -5.21344e-12, 1, -6.75146e-10, 0.999879, -5.2134e-12, -0.0154456, -8, 0, -32)
script = ExtResource("2_xl0he") script = ExtResource("2_xl0he")

View File

@@ -48,6 +48,11 @@ _global_script_classes=[{
"class": &"TrainEngine", "class": &"TrainEngine",
"language": &"GDScript", "language": &"GDScript",
"path": "res://scripts/Modules/Engine.gd" "path": "res://scripts/Modules/Engine.gd"
}, {
"base": "StraightMapNode",
"class": &"TurnMapNode",
"language": &"GDScript",
"path": "res://scripts/Logic/TurnMapNode.gd"
}] }]
_global_script_class_icons={ _global_script_class_icons={
"Cannon": "", "Cannon": "",
@@ -57,7 +62,8 @@ _global_script_class_icons={
"Storage": "", "Storage": "",
"StraightMapNode": "", "StraightMapNode": "",
"Train": "", "Train": "",
"TrainEngine": "" "TrainEngine": "",
"TurnMapNode": ""
} }
[application] [application]

View File

@@ -10,12 +10,17 @@ var t = 0.0
@onready var p1_train = $Player1 as Train @onready var p1_train = $Player1 as Train
@onready var p2_train = $Player2 as Train @onready var p2_train = $Player2 as Train
@onready var StartNode = $StartNode
var p1_node : MapNode
var p2_node : MapNode
func _ready(): func _ready():
p1_node = StartNode
p2_node = StartNode
p2_train.get_node("CharacterBody3D").is_player1 = false p2_train.get_node("CharacterBody3D").is_player1 = false
p2_train.is_P1 = false p2_train.is_P1 = false
p1_train.hit.connect(_on_hit_player) p1_train.hit.connect(_on_hit_player)
p2_train.hit.connect(_on_hit_player)
func _on_hit_player(player1,dmg): func _on_hit_player(player1,dmg):
@@ -25,5 +30,19 @@ func _on_hit_player(player1,dmg):
p1_train.current_speed -= dmg p1_train.current_speed -= dmg
func _process(delta): 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 Input.is_action_pressed("test"): if Input.is_action_pressed("test"):
emit_signal("shoot") emit_signal("shoot")

View File

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

View File

@@ -1,10 +1,11 @@
extends StraightMapNode extends StraightMapNode
class_name TurnMapNode
signal turnEvent signal turnEvent
var is_left_turn = false
var turn = false var turn = false
var turn_node : MapNode @export var is_left_turn = false
@export var turn_node : MapNode
func _on_train_entered(train): func _on_train_entered(train):
super._on_train_entered(train) super._on_train_entered(train)
@@ -14,5 +15,7 @@ func _on_train_exit(train):
if(turn): if(turn):
turn_node._on_train_entered(train) turn_node._on_train_entered(train)
current_trains.erase(train) current_trains.erase(train)
return turn_node
else: else:
super._on_train_exit(train) super._on_train_exit(train)
return next

View File

@@ -15,7 +15,9 @@ func _ready():
func interact(): func interact():
if currentStashValue >= 1: if currentStashValue >= 1:
currentStashValue -= 1 currentStashValue -= 1
return return
func _on_signal_storing(): func _on_signal_storing():
if currentStashValue < maxStashValue: if currentStashValue < maxStashValue:
currentStashValue += 1 currentStashValue += 1

View File

@@ -5,7 +5,8 @@ signal hit(player, dmg)
signal game_over signal game_over
var is_P1 = true var is_P1 = true
var current_speed = 10 var current_distance = 0
var current_speed = 5
var CANNONS = [] var CANNONS = []
var STORAGES = [] var STORAGES = []
#@onready var ENGINE = $Module/Engine #@onready var ENGINE = $Module/Engine
@@ -25,7 +26,6 @@ func _on_signal_shooting():
for cannon in CANNONS: for cannon in CANNONS:
if cannon.shoot(): if cannon.shoot():
hit.emit(is_P1,cannon.DAMAGE) hit.emit(is_P1,cannon.DAMAGE)
print("Shot P2")
func is_dead(): func is_dead():
if current_speed <= 0: if current_speed <= 0: