From 8aed0fe77fe2dfc763298251b8289e8ad59505a7 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 4 Sep 2021 13:39:10 -0600 Subject: [PATCH] godot squash the creeps player movement --- projects/godot-squash-the-creeps-3d/Main.tscn | 12 ++++++++- .../godot-squash-the-creeps-3d/Player.tscn | 7 ++++- .../art/mob.glb.import | 1 + .../art/player.glb.import | 1 + .../godot-squash-the-creeps-3d/build.hxml | 1 + .../godot-squash-the-creeps-3d/project.godot | 3 ++- .../scripts/Player.hx | 14 ++++++++++ .../scripts/Player.kiss | 27 +++++++++++++++++++ .../scripts/import.hx | 2 +- 9 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 projects/godot-squash-the-creeps-3d/scripts/Player.hx create mode 100644 projects/godot-squash-the-creeps-3d/scripts/Player.kiss diff --git a/projects/godot-squash-the-creeps-3d/Main.tscn b/projects/godot-squash-the-creeps-3d/Main.tscn index 3a84706d..44f06cb3 100644 --- a/projects/godot-squash-the-creeps-3d/Main.tscn +++ b/projects/godot-squash-the-creeps-3d/Main.tscn @@ -1,4 +1,6 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://Player.tscn" type="PackedScene" id=1] [sub_resource type="BoxShape" id=1] extents = Vector3( 30, 1, 30 ) @@ -21,3 +23,11 @@ material/0 = null [node name="DirectionalLight" type="DirectionalLight" parent="."] transform = Transform( 1, 0, 0, 0, -0.163205, 0.986592, 0, -0.986592, -0.163205, 0, 22.3151, 0 ) shadow_enabled = true + +[node name="Player" parent="." instance=ExtResource( 1 )] + +[node name="CameraPivot" type="Position3D" parent="."] +transform = Transform( 1, 0, 0, 0, 0.704176, 0.710026, 0, -0.710026, 0.704176, 0, 0, 0 ) + +[node name="Camera" type="Camera" parent="CameraPivot"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 19.0482 ) diff --git a/projects/godot-squash-the-creeps-3d/Player.tscn b/projects/godot-squash-the-creeps-3d/Player.tscn index ecfeb9f7..73ca7b52 100644 --- a/projects/godot-squash-the-creeps-3d/Player.tscn +++ b/projects/godot-squash-the-creeps-3d/Player.tscn @@ -1,11 +1,16 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://art/player.glb" type="PackedScene" id=1] +[ext_resource path="res://build/src/Player.cs" type="Script" id=2] [sub_resource type="SphereShape" id=1] radius = 0.79911 [node name="Player" type="KinematicBody"] +script = ExtResource( 2 ) +__meta__ = { +"haxe_script": "res://scripts/Player.hx" +} [node name="Pivot" type="Spatial" parent="."] diff --git a/projects/godot-squash-the-creeps-3d/art/mob.glb.import b/projects/godot-squash-the-creeps-3d/art/mob.glb.import index 8700e4eb..fac2d0dd 100644 --- a/projects/godot-squash-the-creeps-3d/art/mob.glb.import +++ b/projects/godot-squash-the-creeps-3d/art/mob.glb.import @@ -16,6 +16,7 @@ nodes/root_name="Scene Root" nodes/root_scale=1.0 nodes/custom_script="" nodes/storage=0 +nodes/use_legacy_names=true materials/location=1 materials/storage=1 materials/keep_on_reimport=true diff --git a/projects/godot-squash-the-creeps-3d/art/player.glb.import b/projects/godot-squash-the-creeps-3d/art/player.glb.import index 47c74d7e..18a951c6 100644 --- a/projects/godot-squash-the-creeps-3d/art/player.glb.import +++ b/projects/godot-squash-the-creeps-3d/art/player.glb.import @@ -16,6 +16,7 @@ nodes/root_name="Scene Root" nodes/root_scale=1.0 nodes/custom_script="" nodes/storage=0 +nodes/use_legacy_names=true materials/location=1 materials/storage=1 materials/keep_on_reimport=true diff --git a/projects/godot-squash-the-creeps-3d/build.hxml b/projects/godot-squash-the-creeps-3d/build.hxml index 31bcbe59..24ddbfde 100644 --- a/projects/godot-squash-the-creeps-3d/build.hxml +++ b/projects/godot-squash-the-creeps-3d/build.hxml @@ -4,5 +4,6 @@ --define analyzer-optimize --class-path scripts --library godot +--library kiss --macro godot.Godot.buildProject() --dce full diff --git a/projects/godot-squash-the-creeps-3d/project.godot b/projects/godot-squash-the-creeps-3d/project.godot index b544e259..6cb88f87 100644 --- a/projects/godot-squash-the-creeps-3d/project.godot +++ b/projects/godot-squash-the-creeps-3d/project.godot @@ -39,6 +39,7 @@ _global_script_class_icons={ [application] config/name="Squash the Creeps (3D)" +run/main_scene="res://Main.tscn" config/icon="res://icon.png" [editor_plugins] @@ -73,7 +74,7 @@ move_forward={ , Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) ] } -move_back={ +move_backward={ "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":16777234,"unicode":0,"echo":false,"script":null) , 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) diff --git a/projects/godot-squash-the-creeps-3d/scripts/Player.hx b/projects/godot-squash-the-creeps-3d/scripts/Player.hx new file mode 100644 index 00000000..ecb99c07 --- /dev/null +++ b/projects/godot-squash-the-creeps-3d/scripts/Player.hx @@ -0,0 +1,14 @@ +package; + +import kiss.Prelude; + +@:build(kiss.Kiss.build()) +class Player extends KinematicBody { + // Don't forget to rebuild the project so the editor knows about the new export variable. + // TODO is it possible to provide the export annotation from .kiss? + // How fast the player moves in meters per second. + @:export public var speed = 14; + + // The downward acceleration when in the air, in meters per second squared. + @:export public var fallAcceleration = 75; +} diff --git a/projects/godot-squash-the-creeps-3d/scripts/Player.kiss b/projects/godot-squash-the-creeps-3d/scripts/Player.kiss new file mode 100644 index 00000000..111ce41c --- /dev/null +++ b/projects/godot-squash-the-creeps-3d/scripts/Player.kiss @@ -0,0 +1,27 @@ +(var &mut :Spatial pivot null) +(var &mut :Vector3 _velocity Vector3.ZERO) + +(method &public &override :Void _Ready [] + (set pivot (cast (getNode "Pivot") Spatial))) + +(method &public &override :Void _PhysicsProcess [:Single delta] + (let [&mut direction Vector3.ZERO] + (when (Input.isActionPressed "move_right") + (+= direction.x 1)) + (when (Input.isActionPressed "move_left") + (-= direction.x 1)) + (when (Input.isActionPressed "move_backward") + (+= direction.z 1)) + (when (Input.isActionPressed "move_forward") + (-= direction.z 1)) + + (when !(= direction Vector3.ZERO) + (set direction (direction.normalized)) + // TODO for some reason, the Vector3 addition operator is only found when used in a raw haxe expr: + (pivot.lookAt #|translation + direction|# Vector3.UP)) + + (set _velocity.x (* direction.x speed)) + (set _velocity.z (* direction.z speed)) + (-= _velocity.y (* fallAcceleration delta)) + (set _velocity (moveAndSlide _velocity Vector3.UP)) + )) \ No newline at end of file diff --git a/projects/godot-squash-the-creeps-3d/scripts/import.hx b/projects/godot-squash-the-creeps-3d/scripts/import.hx index 90f4873d..33941d95 100644 --- a/projects/godot-squash-the-creeps-3d/scripts/import.hx +++ b/projects/godot-squash-the-creeps-3d/scripts/import.hx @@ -1,4 +1,4 @@ import godot.*; import godot.GD.*; -using godot.Utils; +// using godot.Utils;