start MapNodes

This commit is contained in:
2022-12-10 07:15:02 +01:00
parent 0d3aaf42d8
commit e4d130f581
8 changed files with 126 additions and 105 deletions

View File

@@ -1,78 +1,32 @@
[gd_scene load_steps=5 format=3 uid="uid://bl1yrgr7g06db"] [gd_scene load_steps=5 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://byo1m0n20yl45" path="res://Nodes/cannon.tscn" id="2_vrf6k"]
[ext_resource type="Script" path="res://scripts/Train.gd" id="2_xl0he"]
[sub_resource type="Curve3D" id="Curve3D_42kdk"] [sub_resource type="BoxMesh" id="BoxMesh_ognqx"]
_data = { size = Vector3(13, 1, 25)
"points": PackedVector3Array(-8, 0, 0, 8, 0, 0, 0, 0, -8, -16, 0, 0, 16, 0, 0, 72, 0, -16, 0, 0, -16, 0, 0, 16, 88, 0, 0, 16, 0, 0, -16, 0, 0, 72, 0, 16, 0, 0, 16, 0, 0, -16, 56, 0, 0, -16, 0, 0, 16, 0, 0, 72, 0, -16, 0, 0, -16, 0, 0, 16, 88, 0, 0, 16, 0, 0, -16, 0, 0, 72, 0, 16, 8, 0, 0, -8, 0, 0, 0, 0, 8, 0, 0, 8, 0, 0, -8, -8, 0, 0, -8, 0, 0, 8, 0, 0, 0, 0, -8, 0, 0, -8, 0, 0, 8, 8, 0, 0, 8, 0, 0, -8, 0, 0, 0, 0, 8, 0, 0, 8, 0, 0, -8, -8, 0, 0, -8, 0, 0, 8, 0, 0, 0, 0, -8),
"tilts": PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
}
point_count = 15
[sub_resource type="BoxMesh" id="BoxMesh_3vwcb"] [node name="Game" type="Node"]
size = Vector3(1, 1, 2)
[sub_resource type="Curve3D" id="Curve3D_ycdkn"]
_data = {
"points": PackedVector3Array(-16, 0, 0, 16, 0, 0, 0, 0, -16, 0, 0, -16, 0, 0, 16, 16, 0, 0, 16, 0, 0, -16, 0, 0, 0, 0, 16, 0, 0, 16, 0, 0, -16, -15.9109, 0.0032196, 0.0159729, -16, 0, 0, 16, 0, 0, 0, 0, -16, -8, 0, 0, 8, 0, 0, 72, 0, -8, 0, 0, -8, 0, 0, 8, 80, 0, 0, 8, 0, 0, -8, 0, 0, 72, 0, 8, 0, 0, 8, 0, 0, -8, 64, 0, 0, -8, 0, 0, 8, 0, 0, 72, 0, -8, 0, 0, -8, 0, 0, 8, 80, 0, 0, 8, 0, 0, -8, 0, 0, 72, 0, 8, 16, 0, 0, -16, 0, 0, 0, 0, 16, 0, 0, 16, 0, 0, -16, -16, 0, 0, -16, 0, 0, 16, 0, 0, 0, 0, -16),
"tilts": PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
}
point_count = 15
[node name="Game" type="Node" node_paths=PackedStringArray("p1", "p2")]
script = ExtResource("1_iox18") script = ExtResource("1_iox18")
p1 = NodePath("HBoxContainer/SubViewportContainer/SubViewport/Player1Path/PathFollow3D")
p2 = NodePath("HBoxContainer/SubViewportContainer2/SubViewport/Player2Path/PathFollow3D")
[node name="HBoxContainer" type="HBoxContainer" parent="."] [node name="Camera3D" type="Camera3D" parent="."]
offset_right = 40.0 transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 20, 0)
offset_bottom = 40.0
[node name="SubViewportContainer" type="SubViewportContainer" parent="HBoxContainer"] [node name="Player1" type="Node3D" parent="."]
layout_mode = 2 transform = Transform3D(1, 0, 3.55271e-15, 0, 1, 0, -3.55271e-15, 0, 1, -8, 0, 8)
script = ExtResource("2_xl0he")
[node name="SubViewport" type="SubViewport" parent="HBoxContainer/SubViewportContainer"] [node name="Cannon" parent="Player1" instance=ExtResource("2_vrf6k")]
handle_input_locally = false
size = Vector2i(960, 1080)
render_target_update_mode = 4
[node name="Player1Path" type="Path3D" parent="HBoxContainer/SubViewportContainer/SubViewport"] [node name="MeshInstance3D2" type="MeshInstance3D" parent="Player1"]
curve = SubResource("Curve3D_42kdk") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2, 0, -8)
mesh = SubResource("BoxMesh_ognqx")
[node name="PathFollow3D" type="PathFollow3D" parent="HBoxContainer/SubViewportContainer/SubViewport/Player1Path"] [node name="Player2" type="Node3D" parent="."]
transform = Transform3D(-4.37107e-08, 0, 0.999984, 0, 1, 0, -0.999984, 0, -4.37107e-08, 0, 0, -8) 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")
[node name="root" type="Node3D" parent="HBoxContainer/SubViewportContainer/SubViewport/Player1Path/PathFollow3D"] [node name="MeshInstance3D" type="MeshInstance3D" parent="Player2"]
transform = Transform3D(-0.0154456, -5.21524e-12, 0.999881, -6.75146e-10, 1, -5.21521e-12, -0.999881, -6.75146e-10, -0.0154456, 31.7182, -1.23195e-08, -18.4921)
[node name="Zug1" type="MeshInstance3D" parent="HBoxContainer/SubViewportContainer/SubViewport/Player1Path/PathFollow3D/root"] mesh = SubResource("BoxMesh_ognqx")
transform = Transform3D(1, 0, -7.10543e-15, 0, 1, 0, 7.10543e-15, 0, 1, 0, 0, 0)
mesh = SubResource("BoxMesh_3vwcb")
skeleton = NodePath("../..")
[node name="Camera3D" type="Camera3D" parent="HBoxContainer/SubViewportContainer/SubViewport/Player1Path/PathFollow3D/root"]
transform = Transform3D(1.00002, 4.37121e-08, 4.37128e-08, -4.37121e-08, -4.37121e-08, 1, 4.37121e-08, -1.00002, -4.37128e-08, 0, 20, 0)
[node name="SubViewportContainer2" type="SubViewportContainer" parent="HBoxContainer"]
layout_mode = 2
[node name="SubViewport" type="SubViewport" parent="HBoxContainer/SubViewportContainer2"]
handle_input_locally = false
size = Vector2i(960, 1080)
render_target_update_mode = 4
[node name="Player2Path" type="Path3D" parent="HBoxContainer/SubViewportContainer2/SubViewport"]
curve = SubResource("Curve3D_ycdkn")
[node name="PathFollow3D" type="PathFollow3D" parent="HBoxContainer/SubViewportContainer2/SubViewport/Player2Path"]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, -16)
[node name="root" type="Node3D" parent="HBoxContainer/SubViewportContainer2/SubViewport/Player2Path/PathFollow3D"]
transform = Transform3D(-0.0154456, -6.75146e-10, -0.999881, -5.21344e-12, 1, -6.75146e-10, 0.999881, -5.21341e-12, -0.0154456, 0, 0, 0)
[node name="Zug1" type="MeshInstance3D" parent="HBoxContainer/SubViewportContainer2/SubViewport/Player2Path/PathFollow3D/root"]
transform = Transform3D(1, 0, -7.10543e-15, 0, 1, 0, 7.10543e-15, 0, 1, 0, 0, 0)
mesh = SubResource("BoxMesh_3vwcb")
skeleton = NodePath("../..")
[node name="Camera3D2" type="Camera3D" parent="HBoxContainer/SubViewportContainer2/SubViewport/Player2Path/PathFollow3D/root"]
transform = Transform3D(-0.0154455, -0.99988, -4.43872e-08, -4.43872e-08, -4.37069e-08, 1, -0.99988, 0.0154455, -4.37069e-08, 0, 20, 0)

View File

@@ -15,6 +15,16 @@ _global_script_classes=[{
"path": "res://scripts/Modules/Cannon.gd" "path": "res://scripts/Modules/Cannon.gd"
}, { }, {
"base": "Node", "base": "Node",
"class": &"Game",
"language": &"GDScript",
"path": "res://scripts/Logic/Game.gd"
}, {
"base": "Node",
"class": &"MapNode",
"language": &"GDScript",
"path": "res://scripts/Logic/MapNode.gd"
}, {
"base": "Node",
"class": &"Module", "class": &"Module",
"language": &"GDScript", "language": &"GDScript",
"path": "res://scripts/Modules/Module.gd" "path": "res://scripts/Modules/Module.gd"
@@ -24,6 +34,16 @@ _global_script_classes=[{
"language": &"GDScript", "language": &"GDScript",
"path": "res://scripts/Modules/Storage.gd" "path": "res://scripts/Modules/Storage.gd"
}, { }, {
"base": "MapNode",
"class": &"StraightMapNode",
"language": &"GDScript",
"path": "res://scripts/Logic/StraightMapNode.gd"
}, {
"base": "Node",
"class": &"Train",
"language": &"GDScript",
"path": "res://scripts/Train.gd"
}, {
"base": "Module", "base": "Module",
"class": &"TrainEngine", "class": &"TrainEngine",
"language": &"GDScript", "language": &"GDScript",
@@ -31,8 +51,12 @@ _global_script_classes=[{
}] }]
_global_script_class_icons={ _global_script_class_icons={
"Cannon": "", "Cannon": "",
"Game": "",
"MapNode": "",
"Module": "", "Module": "",
"Storage": "", "Storage": "",
"StraightMapNode": "",
"Train": "",
"TrainEngine": "" "TrainEngine": ""
} }

View File

@@ -1,4 +1,5 @@
extends Node extends Node
class_name Game
#Signals #Signals
signal ammo_pickup signal ammo_pickup
@@ -6,36 +7,22 @@ signal shoot
var t = 0.0 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(): func _ready():
p1.get_node("root").test.connect(func(): print("player1")) p2_train.is_P1 = false
p2.get_node("root").test.connect(func(): print("player2")) p1_train.hit.connect(_on_hit_player)
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)
func _on_hit_player(player1,dmg):
if not player1:
p2_train.current_speed -= dmg
else:
p1_train.current_speed -= dmg
func _process(delta): func _process(delta):
if Input.is_action_pressed("test"): if Input.is_action_pressed("test"):
speed_p1 = 5
start_tween()
if round(p1.position.distance_to(p2.position)) == 9:
emit_signal("shoot") 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,8 @@
extends MapNode
class_name StraightMapNode
var next : MapNode
func _on_train_exit(train):
next._on_train_entered(train)
super._on_train_exit(train)

View 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)

View File

@@ -5,13 +5,13 @@ class_name Cannon
enum STATE {INACTIVE, RELOADING, SHOOTING} enum STATE {INACTIVE, RELOADING, SHOOTING}
var CAN_ENGAGE = true var CAN_ENGAGE = true
var DAMAGE = 5
@onready var train = get_parent() as Train
#------------Methods-------------# #------------Methods-------------#
func _ready(): func _ready():
var root = get_tree().root.get_child(0)
root.shoot.connect(_on_signal_shooting)
maxStashValue = 1 maxStashValue = 1
currentStashValue = 0 currentStashValue = 1
currentState = STATE.INACTIVE currentState = STATE.INACTIVE
#TODO: FINISH #TODO: FINISH
func interact(): func interact():
@@ -24,15 +24,15 @@ func interact():
return return
func _on_signal_shooting(): func shoot():
if not CAN_ENGAGE: if not CAN_ENGAGE:
return return false
CAN_ENGAGE = false CAN_ENGAGE = false
create_tween().tween_callback(func(): CAN_ENGAGE = true).set_delay(2) create_tween().tween_callback(func(): CAN_ENGAGE = true).set_delay(2)
if currentStashValue >= 1 and currentState == STATE.INACTIVE: if currentStashValue >= 1 and currentState == STATE.INACTIVE:
currentState = STATE.SHOOTING currentState = STATE.SHOOTING
currentStashValue -= 1 currentStashValue -= 1
print("hit")
currentState = STATE.INACTIVE currentState = STATE.INACTIVE
return return true
return false

View File

@@ -1,17 +1,33 @@
extends Node 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 CANNONS = []
var STORAGES = [] var STORAGES = []
#@onready var ENGINE = $Module/Engine #@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(): 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 _on_signal_shooting():
func _process(delta): for cannon in CANNONS:
test.emit() # Replace with function body. if cannon.shoot():
hit.emit(is_P1,cannon.DAMAGE)
print("Shot P2")
func is_dead():
if current_speed <= 0:
game_over.emit()