From d8830f09816fe37780ca521fd01cb76328d365c1 Mon Sep 17 00:00:00 2001 From: SyntaX Date: Sun, 24 Nov 2019 13:17:53 +0100 Subject: [PATCH 1/4] temp for controller mouse move --- WikiJam/Player/Player.gd | 9 +++++++ WikiJam/Player/UI/HUD.gd | 52 ++++++++++++++++++++++++++++++-------- WikiJam/Player/UI/HUD.tscn | 14 +++++----- WikiJam/project.godot | 10 ++++++++ 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/WikiJam/Player/Player.gd b/WikiJam/Player/Player.gd index 4876c7e..e43cbe9 100644 --- a/WikiJam/Player/Player.gd +++ b/WikiJam/Player/Player.gd @@ -15,6 +15,7 @@ const SPRINT_SPEED = 12 const ACCEL = 15.0 const MAX_SLOPE_ANGLE = 40 const MOUSE_SENSITIVITY = 0.05 +const MAX_MOUSE_SPEED = 25 const INTERACT_DISTANCE = 4 const SPRINT_DEC = 0.01; const SPRINT_ACC = 0.005; @@ -94,6 +95,14 @@ func _process_input(): _dir += -camera_transform.basis.z * input_movement_vector.y _dir += camera_transform.basis.x * input_movement_vector.x + # look around with controller + #var look = Vector2() + #look.x = -Input.get_action_strength("cam_move_left") + Input.get_action_strength("cam_move_right") + #look.y = +Input.get_action_strength("cam_move_down") - Input.get_action_strength("cam_move_up") + ##Logger.info("look at: " + String(look)) + ##Input.warp_mouse_position(look) + #look_at(Vector3(look.x, look.y, 1), Vector3.UP) + # jumping if Input.is_action_just_pressed("move_jump") and is_on_floor(): _vel.y = JUMP_SPEED diff --git a/WikiJam/Player/UI/HUD.gd b/WikiJam/Player/UI/HUD.gd index c0ecb4f..924cd40 100644 --- a/WikiJam/Player/UI/HUD.gd +++ b/WikiJam/Player/UI/HUD.gd @@ -1,43 +1,73 @@ extends Control -export(NodePath) var label_nodepath export(NodePath) var popup_nodepath export(NodePath) var gameover_sound_path +export(NodePath) var container_path -const SCORE = 100 - -var _labelScore: Label var _popup: Popup var _gameover_sound: AudioStreamPlayer +var _collectibles: GridContainer var _score: int = 0 +var _init: bool = false +var _texCrystal = preload("res://Images/crystal-unlit.png") +var _texCrystalLit = preload("res://Images/crystal.png") func _ready(): - _labelScore = get_node(label_nodepath) as Label - assert(null != _labelScore) _popup = get_node(popup_nodepath) as Popup assert(null != _popup) _gameover_sound = get_node(gameover_sound_path) as AudioStreamPlayer assert(null != _gameover_sound) + + _collectibles = get_node(container_path) as GridContainer + assert(null != _collectibles) + + +func _process(_delta): + if _init == false: + _init = true + + # TODO: handle with signals + var count = Collector.getCount() + for i in count: + var rect = _createTexture(_texCrystal) + _collectibles.add_child(rect) + + +func _createTexture(texture): + var rect = TextureRect.new() + rect.texture = texture + rect.expand = true + rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT + rect.rect_min_size = Vector2(50, 50) + rect.rect_size = Vector2(50, 50) + + return rect func increaseScore(): - _score += SCORE - _labelScore.text = "Score: " + String(_score) - Logger.info(String(_score) + " of " + String(Collector.getCount() * SCORE) + " possible points") - if (_score >= (Collector.getCount() * SCORE)): - Logger.info("YOU WON!") + _score += 1 + Logger.info(String(_score) + " of " + String(Collector.getCount()) + " possible points") + + var rect = _createTexture(_texCrystalLit) + #_collectibles.add_child(rect) + _collectibles.add_child_below_node(self, rect) + _collectibles.remove_child(_collectibles.get_child(0)) + + if (_score >= (Collector.getCount())): success() func gameOver(): + Logger.info("YOU FAILED!") _gameover_sound.play() _endGame(false) func success(): + Logger.info("YOU WON!") _endGame(true) diff --git a/WikiJam/Player/UI/HUD.tscn b/WikiJam/Player/UI/HUD.tscn index d69ac8b..3ca4cfe 100644 --- a/WikiJam/Player/UI/HUD.tscn +++ b/WikiJam/Player/UI/HUD.tscn @@ -6,16 +6,9 @@ margin_right = 40.0 margin_bottom = 40.0 script = ExtResource( 1 ) -label_nodepath = NodePath("../HUD/LabelScore") popup_nodepath = NodePath("../HUD/Popup") gameover_sound_path = NodePath("../GameOverSound") - -[node name="LabelScore" type="Label" parent="."] -margin_left = 15.0 -margin_top = 15.0 -margin_right = 115.0 -margin_bottom = 30.0 -text = "Score: 0" +container_path = NodePath("GridContainer") [node name="Popup" type="Popup" parent="."] editor/display_folded = true @@ -71,4 +64,9 @@ margin_right = 614.651 margin_bottom = 582.551 step = 1.0 value = 100.0 + +[node name="GridContainer" type="GridContainer" parent="."] +margin_right = 250.0 +margin_bottom = 150.0 +columns = 15 [connection signal="pressed" from="Popup/Button" to="." method="_on_Button_pressed"] diff --git a/WikiJam/project.godot b/WikiJam/project.godot index 74e392f..57f4df2 100644 --- a/WikiJam/project.godot +++ b/WikiJam/project.godot @@ -118,6 +118,16 @@ cam_move_right={ "events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null) ] } +cam_move_up={ +"deadzone": 0.5, +"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null) + ] +} +cam_move_down={ +"deadzone": 0.5, +"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null) + ] +} [rendering] From 03637820cd806abf71cb9706731dbd50ca9aff01 Mon Sep 17 00:00:00 2001 From: SyntaX Date: Sun, 24 Nov 2019 13:45:09 +0100 Subject: [PATCH 2/4] sound and display for collecting crystals --- WikiJam/Player/Player.tscn | 7 ++++++- WikiJam/Player/UI/HUD.gd | 22 +++++++++++++++------- WikiJam/Player/UI/HUD.tscn | 1 - WikiJam/Sounds/ding.wav.import | 21 +++++++++++++++++++++ WikiJam/project.godot | 26 ++++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 WikiJam/Sounds/ding.wav.import diff --git a/WikiJam/Player/Player.tscn b/WikiJam/Player/Player.tscn index 356ef40..292a645 100644 --- a/WikiJam/Player/Player.tscn +++ b/WikiJam/Player/Player.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://Player/Player.gd" type="Script" id=1] [ext_resource path="res://Player/Footsteps.gd" type="Script" id=2] [ext_resource path="res://Resources/Audio/Step.wav" type="AudioStream" id=3] [ext_resource path="res://Player/UI/HUD.tscn" type="PackedScene" id=4] [ext_resource path="res://Sounds/dino-eat.wav" type="AudioStream" id=5] +[ext_resource path="res://Sounds/ding.wav" type="AudioStream" id=6] [sub_resource type="CylinderShape" id=1] height = 2.5 @@ -79,10 +80,14 @@ unit_db = -10.0 pitch_scale = 1.5 [node name="HUD" parent="." instance=ExtResource( 4 )] +collect_sound_path = NodePath("../CollectSound") [node name="GameOverSound" type="AudioStreamPlayer" parent="."] stream = ExtResource( 5 ) +[node name="CollectSound" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 6 ) + [node name="InteractArea" type="Area" parent="."] gravity = 0.0 diff --git a/WikiJam/Player/UI/HUD.gd b/WikiJam/Player/UI/HUD.gd index 924cd40..2a089ca 100644 --- a/WikiJam/Player/UI/HUD.gd +++ b/WikiJam/Player/UI/HUD.gd @@ -2,11 +2,15 @@ extends Control export(NodePath) var popup_nodepath export(NodePath) var gameover_sound_path +export(NodePath) var collect_sound_path export(NodePath) var container_path var _popup: Popup var _gameover_sound: AudioStreamPlayer +var _collect_sound: AudioStreamPlayer var _collectibles: GridContainer + +var _itemWidth = 50; var _score: int = 0 var _init: bool = false var _texCrystal = preload("res://Images/crystal-unlit.png") @@ -14,13 +18,15 @@ var _texCrystalLit = preload("res://Images/crystal.png") func _ready(): - _popup = get_node(popup_nodepath) as Popup assert(null != _popup) _gameover_sound = get_node(gameover_sound_path) as AudioStreamPlayer assert(null != _gameover_sound) + _collect_sound = get_node(collect_sound_path) as AudioStreamPlayer + assert(null != _collect_sound) + _collectibles = get_node(container_path) as GridContainer assert(null != _collectibles) @@ -31,6 +37,9 @@ func _process(_delta): # TODO: handle with signals var count = Collector.getCount() + _itemWidth = int(get_viewport_rect().size.x / (count + 1)) + _collectibles.columns = count + for i in count: var rect = _createTexture(_texCrystal) _collectibles.add_child(rect) @@ -41,9 +50,7 @@ func _createTexture(texture): rect.texture = texture rect.expand = true rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT - rect.rect_min_size = Vector2(50, 50) - rect.rect_size = Vector2(50, 50) - + rect.rect_min_size = Vector2(_itemWidth, _itemWidth) return rect @@ -51,10 +58,11 @@ func increaseScore(): _score += 1 Logger.info(String(_score) + " of " + String(Collector.getCount()) + " possible points") + _collect_sound.play() + var rect = _createTexture(_texCrystalLit) - #_collectibles.add_child(rect) - _collectibles.add_child_below_node(self, rect) - _collectibles.remove_child(_collectibles.get_child(0)) + _collectibles.add_child_below_node(_collectibles.get_child(0), rect) + _collectibles.remove_child(_collectibles.get_child(0 if _score == 1 else _score)) if (_score >= (Collector.getCount())): success() diff --git a/WikiJam/Player/UI/HUD.tscn b/WikiJam/Player/UI/HUD.tscn index 3ca4cfe..a7b2f6e 100644 --- a/WikiJam/Player/UI/HUD.tscn +++ b/WikiJam/Player/UI/HUD.tscn @@ -68,5 +68,4 @@ value = 100.0 [node name="GridContainer" type="GridContainer" parent="."] margin_right = 250.0 margin_bottom = 150.0 -columns = 15 [connection signal="pressed" from="Popup/Button" to="." method="_on_Button_pressed"] diff --git a/WikiJam/Sounds/ding.wav.import b/WikiJam/Sounds/ding.wav.import new file mode 100644 index 0000000..4aed317 --- /dev/null +++ b/WikiJam/Sounds/ding.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/ding.wav-88e1747ad335c067902263abe685dc63.sample" + +[deps] + +source_file="res://Sounds/ding.wav" +dest_files=[ "res://.import/ding.wav-88e1747ad335c067902263abe685dc63.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=true +edit/normalize=true +edit/loop=false +compress/mode=0 diff --git a/WikiJam/project.godot b/WikiJam/project.godot index 16e5707..396cd50 100644 --- a/WikiJam/project.godot +++ b/WikiJam/project.godot @@ -65,36 +65,62 @@ config/icon="res://icon.png" Logger="*res://Util/gs_logger/logger.gd" Collector="*res://Util/Collector.gd" +[display] + +window/size/width=1080 +window/size/height=720 + [input] move_fwrd={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null) ] } move_back={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":13,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null) ] } move_left={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null) ] } move_right={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":15,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) ] } move_jump={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null) ] } move_sprint={ "deadzone": 0.5, "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":7,"pressure":0.0,"pressed":false,"script":null) + ] +} +cam_move_left={ +"deadzone": 0.5, +"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null) + ] +} +cam_move_right={ +"deadzone": 0.5, +"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null) ] } cam_move_up={ From f5e7305d0167f8549906215d6541bc5ec69faffe Mon Sep 17 00:00:00 2001 From: SyntaX Date: Sun, 24 Nov 2019 14:42:37 +0100 Subject: [PATCH 3/4] resolution dependent changes --- WikiJam/Player/Player.tscn | 1 + WikiJam/Player/UI/HUD.gd | 4 +- WikiJam/Player/UI/HUD.tscn | 88 ++++++++++++++++++++------------------ 3 files changed, 50 insertions(+), 43 deletions(-) diff --git a/WikiJam/Player/Player.tscn b/WikiJam/Player/Player.tscn index 292a645..183ba58 100644 --- a/WikiJam/Player/Player.tscn +++ b/WikiJam/Player/Player.tscn @@ -80,6 +80,7 @@ unit_db = -10.0 pitch_scale = 1.5 [node name="HUD" parent="." instance=ExtResource( 4 )] +gameover_sound_path = NodePath("../GameOverSound") collect_sound_path = NodePath("../CollectSound") [node name="GameOverSound" type="AudioStreamPlayer" parent="."] diff --git a/WikiJam/Player/UI/HUD.gd b/WikiJam/Player/UI/HUD.gd index 2a089ca..3656070 100644 --- a/WikiJam/Player/UI/HUD.gd +++ b/WikiJam/Player/UI/HUD.gd @@ -84,8 +84,8 @@ func _endGame (value): Collector.Clear() - _popup.get_node("LabelWon").visible = value - _popup.get_node("LabelFail").visible = !value + _popup.get_node("CenterContainer/Container/LabelWon").visible = value + _popup.get_node("CenterContainer/Container/LabelFail").visible = !value _popup.get_node("PanelWon").visible = value _popup.get_node("PanelFail").visible = !value diff --git a/WikiJam/Player/UI/HUD.tscn b/WikiJam/Player/UI/HUD.tscn index a7b2f6e..6eb0fba 100644 --- a/WikiJam/Player/UI/HUD.tscn +++ b/WikiJam/Player/UI/HUD.tscn @@ -6,66 +6,72 @@ margin_right = 40.0 margin_bottom = 40.0 script = ExtResource( 1 ) -popup_nodepath = NodePath("../HUD/Popup") -gameover_sound_path = NodePath("../GameOverSound") +popup_nodepath = NodePath("Popup") container_path = NodePath("GridContainer") [node name="Popup" type="Popup" parent="."] -editor/display_folded = true visible = true -margin_left = 383.0 -margin_top = 187.0 -margin_right = 530.0 -margin_bottom = 289.0 +anchor_right = 1.0 +anchor_bottom = 1.0 [node name="PanelFail" type="Panel" parent="Popup"] modulate = Color( 0.996078, 0, 0, 1 ) -margin_left = -383.0 -margin_top = -187.36 -margin_right = 641.0 -margin_bottom = 412.64 +anchor_right = 1.0 +anchor_bottom = 1.0 [node name="PanelWon" type="Panel" parent="Popup"] modulate = Color( 0.0313726, 0, 0.996078, 1 ) -margin_left = -383.0 -margin_top = -187.36 -margin_right = 641.0 -margin_bottom = 412.64 +anchor_right = 1.0 +anchor_bottom = 1.0 -[node name="LabelWon" type="Label" parent="Popup"] -margin_left = 87.064 -margin_top = 24.4867 -margin_right = 169.064 -margin_bottom = 72.4867 -text = "Gratulations! +[node name="CenterContainer" type="CenterContainer" parent="Popup"] +anchor_right = 1.0 +anchor_bottom = 1.0 - You Won!" +[node name="Container" type="Control" parent="Popup/CenterContainer"] +margin_left = 20.0 +margin_top = 20.0 +margin_right = 20.0 +margin_bottom = 20.0 -[node name="LabelFail" type="Label" parent="Popup"] -margin_left = 88.9828 -margin_top = 28.0094 -margin_right = 168.983 -margin_bottom = 76.0094 +[node name="LabelFail" type="Label" parent="Popup/CenterContainer/Container"] +margin_left = 10.0 +margin_top = -24.0 +margin_right = 80.0 +margin_bottom = 24.0 text = " You died! Game over" -[node name="Button" type="Button" parent="Popup"] -margin_left = 86.5054 -margin_top = 144.902 -margin_right = 179.505 -margin_bottom = 181.902 -text = "play again" +[node name="LabelWon" type="Label" parent="Popup/CenterContainer/Container"] +margin_left = 10.0 +margin_top = -24.0 +margin_right = 92.0 +margin_bottom = 24.0 +text = "Gratulations! -[node name="ProgressBar" type="ProgressBar" parent="."] -margin_left = 410.651 -margin_top = 560.551 -margin_right = 614.651 -margin_bottom = 582.551 -step = 1.0 -value = 100.0 + You Won!" + +[node name="Button" type="Button" parent="Popup/CenterContainer/Container"] +margin_left = -33.0 +margin_top = 49.0 +margin_right = 120.0 +margin_bottom = 126.0 +text = "play again" [node name="GridContainer" type="GridContainer" parent="."] margin_right = 250.0 margin_bottom = 150.0 -[connection signal="pressed" from="Popup/Button" to="." method="_on_Button_pressed"] + +[node name="ProgressBar" type="ProgressBar" parent="."] +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +margin_left = 405.248 +margin_top = 613.044 +margin_right = 615.248 +margin_bottom = 658.044 +rect_min_size = Vector2( 250, 45 ) +step = 1.0 +value = 100.0 +[connection signal="pressed" from="Popup/CenterContainer/Container/Button" to="." method="_on_Button_pressed"] From 07583cd522491ebee42e6c7839ccc9b99a47d0f1 Mon Sep 17 00:00:00 2001 From: SyntaX Date: Sun, 24 Nov 2019 15:28:52 +0100 Subject: [PATCH 4/4] look around with controller --- WikiJam/Player/Player.gd | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/WikiJam/Player/Player.gd b/WikiJam/Player/Player.gd index e43cbe9..6fc2bf2 100644 --- a/WikiJam/Player/Player.gd +++ b/WikiJam/Player/Player.gd @@ -89,20 +89,23 @@ func _process_input(): if Input.is_action_pressed("move_right"): input_movement_vector.x += 1 + # look around with controller + var look = Vector2() + look.x = -Input.get_action_strength("cam_move_left") + Input.get_action_strength("cam_move_right") + look.y = +Input.get_action_strength("cam_move_down") - Input.get_action_strength("cam_move_up") + #Logger.info("look at: " + String(look)) + _camera.rotate_x(deg2rad(look.y * -1)) + self.rotate_y(deg2rad(look.x * -1)) + + # Prevent player from doing a purzelbaum + _camera.rotation_degrees.x = clamp(_camera.rotation_degrees.x, -70, 70) + # look around with mouse _dir = Vector3() var camera_transform = _camera.get_global_transform() _dir += -camera_transform.basis.z * input_movement_vector.y _dir += camera_transform.basis.x * input_movement_vector.x - # look around with controller - #var look = Vector2() - #look.x = -Input.get_action_strength("cam_move_left") + Input.get_action_strength("cam_move_right") - #look.y = +Input.get_action_strength("cam_move_down") - Input.get_action_strength("cam_move_up") - ##Logger.info("look at: " + String(look)) - ##Input.warp_mouse_position(look) - #look_at(Vector3(look.x, look.y, 1), Vector3.UP) - # jumping if Input.is_action_just_pressed("move_jump") and is_on_floor(): _vel.y = JUMP_SPEED