Skip to content

Commit 4bff1f9

Browse files
committed
first files
0 parents  commit 4bff1f9

11 files changed

+204
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source_md5="47313fa4c47a9963fddd764e1ec6e4a8"
2+
dest_md5="fd776f4da6b582f16154b0e1c0ad7524"
3+
Binary file not shown.

MovementStopper.gd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extends KinematicBody2D
2+
3+
4+
# Declare member variables here. Examples:
5+
# var a = 2
6+
# var b = "text"
7+
8+
9+
# Called when the node enters the scene tree for the first time.
10+
func _ready():
11+
pass # Replace with function body.
12+
13+
14+
# Called every frame. 'delta' is the elapsed time since the previous frame.
15+
#func _process(delta):
16+
# pass

MovementStopper.tscn

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[gd_scene load_steps=3 format=2]
2+
3+
[ext_resource path="res://icon.png" type="Texture" id=1]
4+
5+
[sub_resource type="RectangleShape2D" id=1]
6+
extents = Vector2( 8, 8 )
7+
8+
[node name="MovementStopper" type="KinematicBody2D"]
9+
10+
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
11+
position = Vector2( 8, 8 )
12+
shape = SubResource( 1 )
13+
14+
[node name="Sprite" type="Sprite" parent="."]
15+
position = Vector2( 8, 8 )
16+
scale = Vector2( 0.25, 0.25 )
17+
texture = ExtResource( 1 )

Player.gd

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
extends KinematicBody2D
2+
3+
4+
# Declare member variables here. Examples:
5+
# var a = 2
6+
# var b = "text"
7+
var input_direction = Vector2.ZERO
8+
var previous_input_direction = Vector2.ZERO
9+
10+
var walk_speed = 75
11+
enum PlayerStates {
12+
WALKING,
13+
STOPPING,
14+
IDLE
15+
}
16+
var player_state = PlayerStates.IDLE
17+
# Called when the node enters the scene tree for the first time.
18+
func _ready():
19+
pass # Replace with function body.
20+
21+
func _physics_process(delta):
22+
process_input()
23+
move_and_collide(input_direction * delta * walk_speed)
24+
if player_state == PlayerStates.WALKING:
25+
walk(delta)
26+
elif player_state == PlayerStates.STOPPING:
27+
stop(delta)
28+
elif player_state == PlayerStates.IDLE:
29+
idle()
30+
31+
func process_input():
32+
if input_direction != Vector2.ZERO:
33+
previous_input_direction = input_direction
34+
if input_direction.y == 0:
35+
input_direction.x = int(Input.get_action_strength("ui_right")) - int(Input.get_action_strength("ui_left"))
36+
if input_direction.x == 0:
37+
input_direction.y = int(Input.get_action_strength("ui_down")) - int(Input.get_action_strength("ui_up"))
38+
39+
if input_direction != Vector2.ZERO:
40+
player_state = PlayerStates.WALKING
41+
elif player_state == PlayerStates.WALKING:
42+
add_stopper()
43+
player_state = PlayerStates.STOPPING
44+
45+
func walk(delta):
46+
var result = move_and_collide(input_direction * walk_speed * delta)
47+
48+
func stop(delta):
49+
var result = move_and_collide(previous_input_direction * walk_speed * delta)
50+
if result:
51+
#result.collider.queue_free();
52+
player_state = PlayerStates.IDLE
53+
54+
func idle():
55+
pass
56+
57+
func add_stopper():
58+
var stopperClass = load("res://MovementStopper.tscn")
59+
var stopper = stopperClass.instance()
60+
var x_remainder = fmod(position.x, 16)
61+
var y_remainder = fmod(position.y, 16)
62+
if x_remainder != 0:
63+
stopper.position.x = position.x - x_remainder + 16
64+
if y_remainder != 0:
65+
stopper.position.y = position.y - y_remainder - 16
66+
get_parent().add_child(stopper)
67+
68+
# Called every frame. 'delta' is the elapsed time since the previous frame.
69+
#func _process(delta):
70+
# pass

Player.tscn

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[gd_scene load_steps=4 format=2]
2+
3+
[ext_resource path="res://icon.png" type="Texture" id=1]
4+
[ext_resource path="res://Player.gd" type="Script" id=2]
5+
6+
[sub_resource type="RectangleShape2D" id=1]
7+
extents = Vector2( 8, 8 )
8+
9+
[node name="KinematicBody2D" type="KinematicBody2D"]
10+
script = ExtResource( 2 )
11+
12+
[node name="Sprite" type="Sprite" parent="."]
13+
scale = Vector2( 0.25, 0.25 )
14+
texture = ExtResource( 1 )
15+
centered = false
16+
17+
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
18+
position = Vector2( 8, 8 )
19+
shape = SubResource( 1 )

World.tscn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[gd_scene load_steps=2 format=2]
2+
3+
[ext_resource path="res://Player.tscn" type="PackedScene" id=1]
4+
5+
[node name="Node2D" type="Node2D"]
6+
7+
[node name="Player" parent="." instance=ExtResource( 1 )]

default_env.tres

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[gd_resource type="Environment" load_steps=2 format=2]
2+
3+
[sub_resource type="ProceduralSky" id=1]
4+
5+
[resource]
6+
background_mode = 2
7+
background_sky = SubResource( 1 )

icon.png

3.23 KB
Loading

icon.png.import

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
9+
10+
[deps]
11+
12+
source_file="res://icon.png"
13+
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/bptc_ldr=0
21+
compress/normal_map=0
22+
flags/repeat=0
23+
flags/filter=false
24+
flags/mipmaps=false
25+
flags/anisotropic=false
26+
flags/srgb=2
27+
process/fix_alpha_border=true
28+
process/premult_alpha=false
29+
process/HDR_as_SRGB=false
30+
process/invert_color=false
31+
stream=false
32+
size_limit=0
33+
detect_3d=false
34+
svg/scale=1.0

0 commit comments

Comments
 (0)