godot squash the creeps player movement

This commit is contained in:
2021-09-04 13:39:10 -06:00
parent 217ea99717
commit 8aed0fe77f
9 changed files with 64 additions and 4 deletions

View File

@@ -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] [sub_resource type="BoxShape" id=1]
extents = Vector3( 30, 1, 30 ) extents = Vector3( 30, 1, 30 )
@@ -21,3 +23,11 @@ material/0 = null
[node name="DirectionalLight" type="DirectionalLight" parent="."] [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 ) transform = Transform( 1, 0, 0, 0, -0.163205, 0.986592, 0, -0.986592, -0.163205, 0, 22.3151, 0 )
shadow_enabled = true 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 )

View File

@@ -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://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] [sub_resource type="SphereShape" id=1]
radius = 0.79911 radius = 0.79911
[node name="Player" type="KinematicBody"] [node name="Player" type="KinematicBody"]
script = ExtResource( 2 )
__meta__ = {
"haxe_script": "res://scripts/Player.hx"
}
[node name="Pivot" type="Spatial" parent="."] [node name="Pivot" type="Spatial" parent="."]

View File

@@ -16,6 +16,7 @@ nodes/root_name="Scene Root"
nodes/root_scale=1.0 nodes/root_scale=1.0
nodes/custom_script="" nodes/custom_script=""
nodes/storage=0 nodes/storage=0
nodes/use_legacy_names=true
materials/location=1 materials/location=1
materials/storage=1 materials/storage=1
materials/keep_on_reimport=true materials/keep_on_reimport=true

View File

@@ -16,6 +16,7 @@ nodes/root_name="Scene Root"
nodes/root_scale=1.0 nodes/root_scale=1.0
nodes/custom_script="" nodes/custom_script=""
nodes/storage=0 nodes/storage=0
nodes/use_legacy_names=true
materials/location=1 materials/location=1
materials/storage=1 materials/storage=1
materials/keep_on_reimport=true materials/keep_on_reimport=true

View File

@@ -4,5 +4,6 @@
--define analyzer-optimize --define analyzer-optimize
--class-path scripts --class-path scripts
--library godot --library godot
--library kiss
--macro godot.Godot.buildProject() --macro godot.Godot.buildProject()
--dce full --dce full

View File

@@ -39,6 +39,7 @@ _global_script_class_icons={
[application] [application]
config/name="Squash the Creeps (3D)" config/name="Squash the Creeps (3D)"
run/main_scene="res://Main.tscn"
config/icon="res://icon.png" config/icon="res://icon.png"
[editor_plugins] [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) , 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, "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) "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) , 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)

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
import godot.*; import godot.*;
import godot.GD.*; import godot.GD.*;
using godot.Utils; // using godot.Utils;