This commit is contained in:
Merlar 2019-11-24 14:39:10 +00:00
commit 07df071317
6 changed files with 176 additions and 60 deletions

View File

@ -15,6 +15,7 @@ const SPRINT_SPEED = 12
const ACCEL = 15.0 const ACCEL = 15.0
const MAX_SLOPE_ANGLE = 40 const MAX_SLOPE_ANGLE = 40
const MOUSE_SENSITIVITY = 0.05 const MOUSE_SENSITIVITY = 0.05
const MAX_MOUSE_SPEED = 25
const INTERACT_DISTANCE = 4 const INTERACT_DISTANCE = 4
const SPRINT_DEC = 0.01; const SPRINT_DEC = 0.01;
const SPRINT_ACC = 0.005; const SPRINT_ACC = 0.005;
@ -88,6 +89,17 @@ func _process_input():
if Input.is_action_pressed("move_right"): if Input.is_action_pressed("move_right"):
input_movement_vector.x += 1 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 # look around with mouse
_dir = Vector3() _dir = Vector3()
var camera_transform = _camera.get_global_transform() var camera_transform = _camera.get_global_transform()

View File

@ -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/Player.gd" type="Script" id=1]
[ext_resource path="res://Player/Footsteps.gd" type="Script" id=2] [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://Resources/Audio/Step.wav" type="AudioStream" id=3]
[ext_resource path="res://Player/UI/HUD.tscn" type="PackedScene" id=4] [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/dino-eat.wav" type="AudioStream" id=5]
[ext_resource path="res://Sounds/ding.wav" type="AudioStream" id=6]
[sub_resource type="CylinderShape" id=1] [sub_resource type="CylinderShape" id=1]
height = 2.5 height = 2.5
@ -79,10 +80,15 @@ unit_db = -10.0
pitch_scale = 1.5 pitch_scale = 1.5
[node name="HUD" parent="." instance=ExtResource( 4 )] [node name="HUD" parent="." instance=ExtResource( 4 )]
gameover_sound_path = NodePath("../GameOverSound")
collect_sound_path = NodePath("../CollectSound")
[node name="GameOverSound" type="AudioStreamPlayer" parent="."] [node name="GameOverSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 5 ) stream = ExtResource( 5 )
[node name="CollectSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 6 )
[node name="InteractArea" type="Area" parent="."] [node name="InteractArea" type="Area" parent="."]
gravity = 0.0 gravity = 0.0

View File

@ -1,43 +1,81 @@
extends Control extends Control
export(NodePath) var label_nodepath
export(NodePath) var popup_nodepath export(NodePath) var popup_nodepath
export(NodePath) var gameover_sound_path export(NodePath) var gameover_sound_path
export(NodePath) var collect_sound_path
export(NodePath) var container_path
const SCORE = 100
var _labelScore: Label
var _popup: Popup var _popup: Popup
var _gameover_sound: AudioStreamPlayer var _gameover_sound: AudioStreamPlayer
var _collect_sound: AudioStreamPlayer
var _collectibles: GridContainer
var _itemWidth = 50;
var _score: int = 0 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(): func _ready():
_labelScore = get_node(label_nodepath) as Label
assert(null != _labelScore)
_popup = get_node(popup_nodepath) as Popup _popup = get_node(popup_nodepath) as Popup
assert(null != _popup) assert(null != _popup)
_gameover_sound = get_node(gameover_sound_path) as AudioStreamPlayer _gameover_sound = get_node(gameover_sound_path) as AudioStreamPlayer
assert(null != _gameover_sound) 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)
func _process(_delta):
if _init == false:
_init = true
# 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)
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(_itemWidth, _itemWidth)
return rect
func increaseScore(): func increaseScore():
_score += SCORE _score += 1
_labelScore.text = "Score: " + String(_score) Logger.info(String(_score) + " of " + String(Collector.getCount()) + " possible points")
Logger.info(String(_score) + " of " + String(Collector.getCount() * SCORE) + " possible points")
if (_score >= (Collector.getCount() * SCORE)): _collect_sound.play()
Logger.info("YOU WON!")
var rect = _createTexture(_texCrystalLit)
_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() success()
func gameOver(): func gameOver():
Logger.info("YOU FAILED!")
_gameover_sound.play() _gameover_sound.play()
_endGame(false) _endGame(false)
func success(): func success():
Logger.info("YOU WON!")
_endGame(true) _endGame(true)
@ -46,8 +84,8 @@ func _endGame (value):
Collector.Clear() Collector.Clear()
_popup.get_node("LabelWon").visible = value _popup.get_node("CenterContainer/Container/LabelWon").visible = value
_popup.get_node("LabelFail").visible = !value _popup.get_node("CenterContainer/Container/LabelFail").visible = !value
_popup.get_node("PanelWon").visible = value _popup.get_node("PanelWon").visible = value
_popup.get_node("PanelFail").visible = !value _popup.get_node("PanelFail").visible = !value

View File

@ -6,69 +6,72 @@
margin_right = 40.0 margin_right = 40.0
margin_bottom = 40.0 margin_bottom = 40.0
script = ExtResource( 1 ) script = ExtResource( 1 )
label_nodepath = NodePath("../HUD/LabelScore") popup_nodepath = NodePath("Popup")
popup_nodepath = NodePath("../HUD/Popup") container_path = NodePath("GridContainer")
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"
[node name="Popup" type="Popup" parent="."] [node name="Popup" type="Popup" parent="."]
editor/display_folded = true
visible = true visible = true
margin_left = 383.0 anchor_right = 1.0
margin_top = 187.0 anchor_bottom = 1.0
margin_right = 530.0
margin_bottom = 289.0
[node name="PanelFail" type="Panel" parent="Popup"] [node name="PanelFail" type="Panel" parent="Popup"]
modulate = Color( 0.996078, 0, 0, 1 ) modulate = Color( 0.996078, 0, 0, 1 )
margin_left = -383.0 anchor_right = 1.0
margin_top = -187.36 anchor_bottom = 1.0
margin_right = 641.0
margin_bottom = 412.64
[node name="PanelWon" type="Panel" parent="Popup"] [node name="PanelWon" type="Panel" parent="Popup"]
modulate = Color( 0.0313726, 0, 0.996078, 1 ) modulate = Color( 0.0313726, 0, 0.996078, 1 )
margin_left = -383.0 anchor_right = 1.0
margin_top = -187.36 anchor_bottom = 1.0
margin_right = 641.0
margin_bottom = 412.64
[node name="LabelWon" type="Label" parent="Popup"] [node name="CenterContainer" type="CenterContainer" parent="Popup"]
margin_left = 87.064 anchor_right = 1.0
margin_top = 24.4867 anchor_bottom = 1.0
margin_right = 169.064
margin_bottom = 72.4867
text = "Gratulations!
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"] [node name="LabelFail" type="Label" parent="Popup/CenterContainer/Container"]
margin_left = 88.9828 margin_left = 10.0
margin_top = 28.0094 margin_top = -24.0
margin_right = 168.983 margin_right = 80.0
margin_bottom = 76.0094 margin_bottom = 24.0
text = " You died! text = " You died!
Game over" Game over"
[node name="Button" type="Button" parent="Popup"] [node name="LabelWon" type="Label" parent="Popup/CenterContainer/Container"]
margin_left = 86.5054 margin_left = 10.0
margin_top = 144.902 margin_top = -24.0
margin_right = 179.505 margin_right = 92.0
margin_bottom = 181.902 margin_bottom = 24.0
text = "Gratulations!
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" text = "play again"
[node name="GridContainer" type="GridContainer" parent="."]
margin_right = 250.0
margin_bottom = 150.0
[node name="ProgressBar" type="ProgressBar" parent="."] [node name="ProgressBar" type="ProgressBar" parent="."]
margin_left = 410.651 anchor_top = 0.5
margin_top = 560.551 anchor_right = 1.0
margin_right = 614.651 anchor_bottom = 0.5
margin_bottom = 582.551 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 step = 1.0
value = 100.0 value = 100.0
[connection signal="pressed" from="Popup/Button" to="." method="_on_Button_pressed"] [connection signal="pressed" from="Popup/CenterContainer/Container/Button" to="." method="_on_Button_pressed"]

View File

@ -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

View File

@ -65,36 +65,72 @@ config/icon="res://icon.png"
Logger="*res://Util/gs_logger/logger.gd" Logger="*res://Util/gs_logger/logger.gd"
Collector="*res://Util/Collector.gd" Collector="*res://Util/Collector.gd"
[display]
window/size/width=1080
window/size/height=720
[input] [input]
move_fwrd={ move_fwrd={
"deadzone": 0.5, "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) "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={ move_back={
"deadzone": 0.5, "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) "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={ move_left={
"deadzone": 0.5, "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) "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={ move_right={
"deadzone": 0.5, "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) "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={ move_jump={
"deadzone": 0.5, "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) "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={ move_sprint={
"deadzone": 0.5, "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) "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={
"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)
] ]
} }