-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4bff1f9
Showing
11 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source_md5="47313fa4c47a9963fddd764e1ec6e4a8" | ||
dest_md5="fd776f4da6b582f16154b0e1c0ad7524" | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extends KinematicBody2D | ||
|
||
|
||
# Declare member variables here. Examples: | ||
# var a = 2 | ||
# var b = "text" | ||
|
||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
pass # Replace with function body. | ||
|
||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
#func _process(delta): | ||
# pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[gd_scene load_steps=3 format=2] | ||
|
||
[ext_resource path="res://icon.png" type="Texture" id=1] | ||
|
||
[sub_resource type="RectangleShape2D" id=1] | ||
extents = Vector2( 8, 8 ) | ||
|
||
[node name="MovementStopper" type="KinematicBody2D"] | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
position = Vector2( 8, 8 ) | ||
shape = SubResource( 1 ) | ||
|
||
[node name="Sprite" type="Sprite" parent="."] | ||
position = Vector2( 8, 8 ) | ||
scale = Vector2( 0.25, 0.25 ) | ||
texture = ExtResource( 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
extends KinematicBody2D | ||
|
||
|
||
# Declare member variables here. Examples: | ||
# var a = 2 | ||
# var b = "text" | ||
var input_direction = Vector2.ZERO | ||
var previous_input_direction = Vector2.ZERO | ||
|
||
var walk_speed = 75 | ||
enum PlayerStates { | ||
WALKING, | ||
STOPPING, | ||
IDLE | ||
} | ||
var player_state = PlayerStates.IDLE | ||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
pass # Replace with function body. | ||
|
||
func _physics_process(delta): | ||
process_input() | ||
move_and_collide(input_direction * delta * walk_speed) | ||
if player_state == PlayerStates.WALKING: | ||
walk(delta) | ||
elif player_state == PlayerStates.STOPPING: | ||
stop(delta) | ||
elif player_state == PlayerStates.IDLE: | ||
idle() | ||
|
||
func process_input(): | ||
if input_direction != Vector2.ZERO: | ||
previous_input_direction = input_direction | ||
if input_direction.y == 0: | ||
input_direction.x = int(Input.get_action_strength("ui_right")) - int(Input.get_action_strength("ui_left")) | ||
if input_direction.x == 0: | ||
input_direction.y = int(Input.get_action_strength("ui_down")) - int(Input.get_action_strength("ui_up")) | ||
|
||
if input_direction != Vector2.ZERO: | ||
player_state = PlayerStates.WALKING | ||
elif player_state == PlayerStates.WALKING: | ||
add_stopper() | ||
player_state = PlayerStates.STOPPING | ||
|
||
func walk(delta): | ||
var result = move_and_collide(input_direction * walk_speed * delta) | ||
|
||
func stop(delta): | ||
var result = move_and_collide(previous_input_direction * walk_speed * delta) | ||
if result: | ||
#result.collider.queue_free(); | ||
player_state = PlayerStates.IDLE | ||
|
||
func idle(): | ||
pass | ||
|
||
func add_stopper(): | ||
var stopperClass = load("res://MovementStopper.tscn") | ||
var stopper = stopperClass.instance() | ||
var x_remainder = fmod(position.x, 16) | ||
var y_remainder = fmod(position.y, 16) | ||
if x_remainder != 0: | ||
stopper.position.x = position.x - x_remainder + 16 | ||
if y_remainder != 0: | ||
stopper.position.y = position.y - y_remainder - 16 | ||
get_parent().add_child(stopper) | ||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
#func _process(delta): | ||
# pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[gd_scene load_steps=4 format=2] | ||
|
||
[ext_resource path="res://icon.png" type="Texture" id=1] | ||
[ext_resource path="res://Player.gd" type="Script" id=2] | ||
|
||
[sub_resource type="RectangleShape2D" id=1] | ||
extents = Vector2( 8, 8 ) | ||
|
||
[node name="KinematicBody2D" type="KinematicBody2D"] | ||
script = ExtResource( 2 ) | ||
|
||
[node name="Sprite" type="Sprite" parent="."] | ||
scale = Vector2( 0.25, 0.25 ) | ||
texture = ExtResource( 1 ) | ||
centered = false | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
position = Vector2( 8, 8 ) | ||
shape = SubResource( 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://Player.tscn" type="PackedScene" id=1] | ||
|
||
[node name="Node2D" type="Node2D"] | ||
|
||
[node name="Player" parent="." instance=ExtResource( 1 )] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=false | ||
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=false | ||
svg/scale=1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
; 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 | ||
|
||
[application] | ||
|
||
config/name="grid-movement" | ||
run/main_scene="res://World.tscn" | ||
config/icon="res://icon.png" | ||
|
||
[display] | ||
|
||
window/size/width=320 | ||
window/size/height=180 | ||
window/size/test_width=1280 | ||
window/size/test_height=720 | ||
window/stretch/mode="2d" | ||
|
||
[physics] | ||
|
||
common/enable_pause_aware_picking=true | ||
|
||
[rendering] | ||
|
||
environment/default_environment="res://default_env.tres" |