commit 987955704b8075d45d098b50e7bb1228c6f5daa4 Author: karl Date: Thu Mar 18 10:41:54 2021 +0100 First exercise done diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f48ad7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Godot-specific ignores +.import/ +export.cfg +export_presets.cfg + +# Imported translations (automatically generated from CSV files) +*.translation + +# Mono-specific ignores +.mono/ +data_*/ diff --git a/InputConverter.gd b/InputConverter.gd new file mode 100644 index 0000000..acf9045 --- /dev/null +++ b/InputConverter.gd @@ -0,0 +1,37 @@ +extends Node + + +export(float) var inner_deadzone = 0.2 +export(float) var outer_deadzone = 0.8 + + +func _process(delta): + var input = Vector2(Input.get_joy_axis(0, 0), Input.get_joy_axis(0, 1)) + + # Remove signs to reduce the number of cases + var signs = Vector2(sign(input.x), sign(input.y)) + input = Vector2(abs(input.x), abs(input.y)) + + # Deazones for each axis + if input.x > outer_deadzone: + input.x = 1.0 + elif input.x < inner_deadzone: + input.x = 0.0 + else: + input.x = inverse_lerp(inner_deadzone, outer_deadzone, input.x) + + if input.y > outer_deadzone: + input.y = 1.0 + elif input.y < inner_deadzone: + input.y = 0.0 + else: + input.y = inverse_lerp(inner_deadzone, outer_deadzone, input.y) + + # Re-apply signs + input *= signs + + # Limit at length 1 + if input.length() > 1.0: + input /= input.length() + + print(input) diff --git a/InputConverter.tscn b/InputConverter.tscn new file mode 100644 index 0000000..cbb45e3 --- /dev/null +++ b/InputConverter.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://InputConverter.gd" type="Script" id=1] + +[node name="InputConverter" type="Node"] +script = ExtResource( 1 ) diff --git a/default_env.tres b/default_env.tres new file mode 100644 index 0000000..20207a4 --- /dev/null +++ b/default_env.tres @@ -0,0 +1,7 @@ +[gd_resource type="Environment" load_steps=2 format=2] + +[sub_resource type="ProceduralSky" id=1] + +[resource] +background_mode = 2 +background_sky = SubResource( 1 ) diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..c98fbb6 Binary files /dev/null and b/icon.png differ diff --git a/icon.png.import b/icon.png.import new file mode 100644 index 0000000..96cbf46 --- /dev/null +++ b/icon.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.png" +dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..d34f240 --- /dev/null +++ b/project.godot @@ -0,0 +1,51 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=4 + +_global_script_classes=[ ] +_global_script_class_icons={ + +} + +[application] + +config/name="Physics Project" +run/main_scene="res://InputConverter.tscn" +config/icon="res://icon.png" + +[input] + +ui_left={ +"deadzone": 0.0, +"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":16777231,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null) + ] +} +ui_right={ +"deadzone": 0.0, +"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":16777233,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null) + ] +} +ui_up={ +"deadzone": 0.0, +"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":16777232,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null) + ] +} +ui_down={ +"deadzone": 0.0, +"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":16777234,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) + ] +} + +[rendering] + +environment/default_environment="res://default_env.tres"