diff --git a/Nodes/P1MiniGame.gd b/Nodes/P1MiniGame.gd new file mode 100644 index 0000000..519e755 --- /dev/null +++ b/Nodes/P1MiniGame.gd @@ -0,0 +1,81 @@ +extends Node + +#-----------Parameters--------------# + +var P1inMiniGame = 0 +var MiniGame = [0, 0, 0] +var MiniGamePos = 0 +var rng = RandomNumberGenerator.new() +#---------------Methods--------------# +func _ready(): + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton0").hide() + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton1").hide() + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton2").hide() + +func miniGameColor(input: int, red: int): + if(input == 0): + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton0").modulate = Color(1,1,red) + if(input == 1): + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton1").modulate = Color(1,1,red) + if(input == 2): + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton2").modulate = Color(1,1,red) + +func miniGameReset(): + MiniGamePos = 0 + miniGameColor(0,1) + miniGameColor(1,1) + miniGameColor(2,1) + MiniGame[0] = rng.randi_range(0, 3) + miniGameSetArrow(0) + MiniGame[1] = rng.randi_range(0, 3) + miniGameSetArrow(1) + MiniGame[2] = rng.randi_range(0, 3) + miniGameSetArrow(2) + +func miniGameSetArrow(buttonNr: int): + if(buttonNr == 0): + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton0").frame = 26 + MiniGame[0] + #$MiniGameButton0.frame = 26 + MiniGame[0] + if(buttonNr == 1): + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton1").frame = 26 + MiniGame[1] + #$MiniGameButton1.frame = 26 + MiniGame[1] + if(buttonNr == 2): + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton2").frame = 26 + MiniGame[2] + #$MiniGameButton2.frame = 26 + MiniGame[2] + +func miniGameCheck(input : int): + if(input == MiniGame[MiniGamePos]): + miniGameColor(MiniGamePos, 0) + MiniGamePos = MiniGamePos +1 + else: + miniGameReset() + + if(MiniGamePos >= 3): + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton0").hide() + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton1").hide() + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton2").hide() + P1inMiniGame = 0 + get_parent().P1inMiniGame = 0 + miniGameReset() + +func _process(delta): + if Input.is_action_just_pressed("p1_extra"): + if(P1inMiniGame == 0): + P1inMiniGame = 1 + get_parent().P1inMiniGame = 1 + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton0").show() + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton1").show() + get_parent().get_parent().find_child("CharacterBody3D").find_child("MiniGameButton2").show() + +func check_input(): + if(P1inMiniGame): + if Input.is_action_just_pressed("p1_up"): + miniGameCheck(0) + if Input.is_action_just_pressed("p1_right"): + miniGameCheck(1) + if Input.is_action_just_pressed("p1_down"): + miniGameCheck(2) + if Input.is_action_just_pressed("p1_left"): + miniGameCheck(3) + + diff --git a/Nodes/Player.tscn b/Nodes/Player.tscn index 4927bd4..6a99028 100644 --- a/Nodes/Player.tscn +++ b/Nodes/Player.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=5 format=3 uid="uid://vwjd5od63jgh"] +[gd_scene load_steps=4 format=3 uid="uid://vwjd5od63jgh"] [ext_resource type="Script" path="res://scripts/Player.gd" id="1_dta8q"] -[ext_resource type="Texture2D" uid="uid://7qppu15lvd1j" path="res://Nodes/Keys.png" id="2_h1504"] [sub_resource type="CylinderShape3D" id="CylinderShape3D_h8ivv"] radius = 0.494048 @@ -22,24 +21,3 @@ shape = SubResource("CylinderShape3D_h8ivv") [node name="CollisionShape3D" type="CollisionShape3D" parent="HitBox"] transform = Transform3D(2.74062, 0, 0, 0, 2.24144, 0, 0, 0, 2.70992, 0, 0, 0) shape = SubResource("CylinderShape3D_8lrgm") - -[node name="MiniGameButton0" type="Sprite3D" parent="."] -transform = Transform3D(8, 0, 0, 0, -3.93403e-07, 1, 0, -9, -4.37114e-08, 0, 6, 0) -texture = ExtResource("2_h1504") -hframes = 5 -vframes = 8 -frame = 26 - -[node name="MiniGameButton1" type="Sprite3D" parent="."] -transform = Transform3D(8, 0, 0, 0, -3.93403e-07, 1, 0, -9, -4.37114e-08, 1.5, 6, 0) -texture = ExtResource("2_h1504") -hframes = 5 -vframes = 8 -frame = 26 - -[node name="MiniGameButton2" type="Sprite3D" parent="."] -transform = Transform3D(8, 0, 0, 0, -3.93403e-07, 1, 0, -9, -4.37114e-08, 3, 6, 0) -texture = ExtResource("2_h1504") -hframes = 5 -vframes = 8 -frame = 26 diff --git a/Nodes/Train_P1.tscn b/Nodes/Train_P1.tscn index f61decc..648ee5e 100644 --- a/Nodes/Train_P1.tscn +++ b/Nodes/Train_P1.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=23 format=3 uid="uid://md2ofbviios3"] [ext_resource type="Script" path="res://scripts/Train.gd" id="1_0x664"] -[ext_resource type="PackedScene" uid="uid://bhivunrkj87cy" path="res://Nodes/engine.tscn" id="3_1ix85"] +[ext_resource type="PackedScene" path="res://Nodes/engine.tscn" id="3_1ix85"] [ext_resource type="PackedScene" uid="uid://vwjd5od63jgh" path="res://Nodes/Player.tscn" id="3_in6up"] [ext_resource type="PackedScene" uid="uid://c1mymb38wqdg6" path="res://Nodes/train.tscn" id="3_jmv6b"] [ext_resource type="PackedScene" uid="uid://cet80w4yr8rse" path="res://Storage.tscn" id="4_5jw5g"] @@ -15,6 +15,7 @@ [ext_resource type="Texture2D" uid="uid://ctbxpx6p36bdi" path="res://walking_ball2.png" id="8_0u1e2"] [ext_resource type="Texture2D" uid="uid://ckdlv6b7okseq" path="res://walking_powder2.png" id="10_a137a"] [ext_resource type="Texture2D" uid="uid://b5ioch3ad8y6r" path="res://walking_coal2.png" id="11_1jgcf"] +[ext_resource type="Texture2D" uid="uid://7qppu15lvd1j" path="res://Nodes/Keys.png" id="13_d8wle"] [ext_resource type="PackedScene" uid="uid://bkpnrgcfr1jgl" path="res://Nodes/Bin.tscn" id="16_q3kvk"] [ext_resource type="AudioStream" uid="uid://b52sd64x20ulv" path="res://Assets/Sounds/_SOUNDFX_/Gunpowder.wav" id="17_ajifv"] @@ -117,6 +118,27 @@ animation = &"walking_coal" speed_scale = 2.0 playing = true +[node name="MiniGameButton0" type="Sprite3D" parent="CharacterBody3D"] +transform = Transform3D(8, 0, 0, 0, -3.93403e-07, 1, 0, -9, -4.37114e-08, 0, 6, 0) +texture = ExtResource("13_d8wle") +hframes = 5 +vframes = 8 +frame = 26 + +[node name="MiniGameButton1" type="Sprite3D" parent="CharacterBody3D"] +transform = Transform3D(8, 0, 0, 0, -3.93403e-07, 1, 0, -9, -4.37114e-08, 1.5, 6, 0) +texture = ExtResource("13_d8wle") +hframes = 5 +vframes = 8 +frame = 26 + +[node name="MiniGameButton2" type="Sprite3D" parent="CharacterBody3D"] +transform = Transform3D(8, 0, 0, 0, -3.93403e-07, 1, 0, -9, -4.37114e-08, 3, 6, 0) +texture = ExtResource("13_d8wle") +hframes = 5 +vframes = 8 +frame = 26 + [node name="Storage" parent="." instance=ExtResource("4_5jw5g")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.31598, 0.0193453, -5.2771) diff --git a/project.godot b/project.godot index e27040c..d79b725 100644 --- a/project.godot +++ b/project.godot @@ -142,3 +142,8 @@ p1_extra={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"unicode":0,"echo":false,"script":null) ] } +p2_extra={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":90,"unicode":0,"echo":false,"script":null) +] +} diff --git a/scripts/Player.gd b/scripts/Player.gd index 66ef5fa..d05b552 100644 --- a/scripts/Player.gd +++ b/scripts/Player.gd @@ -16,24 +16,24 @@ enum TYPE {AMMO, GUNPOWDER, FUEL} var P1inMiniGame = 0 var P2inMiniGame = 0 -var MiniGame = [-1, -1, -1] +var MiniGame = [0, 0, 0] var MiniGamePos = 0 var rng = RandomNumberGenerator.new() #---------------Methods--------------# func _ready(): walking = "walking" idle = "idle" - $MiniGameButton0.hide() - $MiniGameButton1.hide() - $MiniGameButton2.hide() + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton0").hide() + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton1").hide() + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton2").hide() func miniGameColor(input: int, red: int): if(input == 0): - $MiniGameButton0.modulate = Color(1,1,red) + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton0").modulate = Color(1,1,red) if(input == 1): - $MiniGameButton1.modulate = Color(1,1,red) + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton1").modulate = Color(1,1,red) if(input == 2): - $MiniGameButton2.modulate = Color(1,1,red) + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton2").modulate = Color(1,1,red) func miniGameReset(): MiniGamePos = 0 @@ -49,11 +49,14 @@ func miniGameReset(): func miniGameSetArrow(buttonNr: int): if(buttonNr == 0): - $MiniGameButton0.frame = 26 + MiniGame[0] + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton0").frame = 26 + MiniGame[0] + #$MiniGameButton0.frame = 26 + MiniGame[0] if(buttonNr == 1): - $MiniGameButton1.frame = 26 + MiniGame[1] + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton1").frame = 26 + MiniGame[1] + #$MiniGameButton1.frame = 26 + MiniGame[1] if(buttonNr == 2): - $MiniGameButton2.frame = 26 + MiniGame[2] + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton2").frame = 26 + MiniGame[2] + #$MiniGameButton2.frame = 26 + MiniGame[2] func miniGameCheck(input : int): if(input == MiniGame[MiniGamePos]): @@ -63,19 +66,22 @@ func miniGameCheck(input : int): miniGameReset() if(MiniGamePos >= 3): - $MiniGameButton0.hide() - $MiniGameButton1.hide() - $MiniGameButton2.hide() - P1inMiniGame = 0 + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton0").hide() + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton1").hide() + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton2").hide() + if(is_player1): + P1inMiniGame = 0 + else: + P2inMiniGame = 0 miniGameReset() func _process(delta): if Input.is_action_just_pressed("p1_extra"): if(P1inMiniGame == 0): P1inMiniGame = 1 - $MiniGameButton0.show() - $MiniGameButton1.show() - $MiniGameButton2.show() + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton0").show() + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton1").show() + get_parent().find_child("CharacterBody3D").find_child("MiniGameButton2").show() func _physics_process(delta): if(velocity.length() > 0):