Initial project created

Added a simple basic template with a player control script and basic collision detection. Ideal coding style guidelines enforced.
This commit is contained in:
Paul Norberger
2020-04-17 19:25:34 +02:00
parent 9df79d57d3
commit f20abb41ef
7 changed files with 202 additions and 0 deletions

36
src/Player/Player.gd Normal file
View File

@@ -0,0 +1,36 @@
extends KinematicBody2D
class_name Player
"""
This is an example player controller script created by Paul
"""
var velocity := Vector2.ZERO
# This is how you export variables with ranges to the editor window
export(int, 0, 500) var MAX_SPEED = 125
export(int, 0, 500) var FRICTION = 200 # Speed at which the player deaccelarates
export(int, 0, 500) var ACCELERATION = 450
func _physics_process(delta):
"""
Run approximately every 1/60th of a second by default.
@param delta, so the time since lastt frame, should be pretty constant at 1/60 by default.
"""
# If a constant is applicable, use it instead of creating the object yourself
var input_vector := Vector2.ZERO
# This is a clever way to handle directional input
# Input.get_action_strength(...) returns a value between 0 and 1 depending
# on how strong the controller direction is pressed
# For keyboards it always returns 1 if pressed and 0 if not
# The actions are custom and defined in the project settings
input_vector.x = Input.get_action_strength("right") - Input.get_action_strength("left")
input_vector.y = Input.get_action_strength("down") - Input.get_action_strength("up")
input_vector = input_vector.normalized()
if input_vector == Vector2.ZERO:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
else:
velocity = velocity.move_toward(MAX_SPEED * input_vector, ACCELERATION * delta)
# IMPORTANT: If you are using move_and_slide don't multiply by delta
# Godots physics system does that internally
# In move_and_collide(...) you have to multiply by delta.
move_and_slide(velocity)

24
src/Player/Player.tscn Normal file
View File

@@ -0,0 +1,24 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Player/Player.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[sub_resource type="CapsuleShape2D" id=1]
radius = 6.0
height = 5.0
[node name="Player" type="KinematicBody2D"]
script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
FRICTION = 270
[node name="Sprite" type="Sprite" parent="."]
scale = Vector2( 0.5, 0.5 )
texture = ExtResource( 2 )
offset = Vector2( 0, -18 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = 1.5708
shape = SubResource( 1 )