diff --git a/godot/scenes/Boundary.gd b/godot/scenes/Boundary.gd new file mode 100644 index 0000000..4fe97d8 --- /dev/null +++ b/godot/scenes/Boundary.gd @@ -0,0 +1,18 @@ +class_name Boundary +extends Node2D + +@export var width = 200 + +# 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 + +func get_most_left_position(): + return global_position.x - width / 2 + +func get_most_right_position(): + return global_position.x + width / 2 diff --git a/godot/scenes/Tim.gd b/godot/scenes/Tim.gd new file mode 100644 index 0000000..1850e91 --- /dev/null +++ b/godot/scenes/Tim.gd @@ -0,0 +1,20 @@ +extends Node2D + +@export var move_speed = 100 +@export var boundary: Boundary + +# 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): + if Input.is_action_pressed("move_right"): + position += Vector2.RIGHT * delta * move_speed + if position.x > boundary.get_most_right_position(): + position = Vector2(boundary.get_most_right_position(), position.y) + + if Input.is_action_pressed("move_left"): + position += Vector2.LEFT * delta * move_speed + if position.x < boundary.get_most_left_position(): + position = Vector2(boundary.get_most_left_position(), position.y) diff --git a/godot/scenes/stage.tscn b/godot/scenes/stage.tscn new file mode 100644 index 0000000..6fedda2 --- /dev/null +++ b/godot/scenes/stage.tscn @@ -0,0 +1,25 @@ +[gd_scene load_steps=5 format=3 uid="uid://dw8tbafwj1rgo"] + +[ext_resource type="Script" path="res://scenes/Tim.gd" id="1_g3k2b"] +[ext_resource type="Texture2D" uid="uid://kq63ictuirhc" path="res://sprites/tim_side.png" id="1_saxit"] +[ext_resource type="Script" path="res://scenes/Boundary.gd" id="2_8p6ir"] + +[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_3hx6l"] +size = Vector2(600, 200) + +[node name="Stage" type="Node2D"] + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = SubResource("PlaceholderTexture2D_3hx6l") +offset = Vector2(0, -100) + +[node name="Tim" type="Node2D" parent="." node_paths=PackedStringArray("boundary")] +script = ExtResource("1_g3k2b") +boundary = NodePath("../Boundary") + +[node name="Sprite2D" type="Sprite2D" parent="Tim"] +texture = ExtResource("1_saxit") +offset = Vector2(0, -200) + +[node name="Boundary" type="Node2D" parent="."] +script = ExtResource("2_8p6ir") diff --git a/godot/sprites/tim_side.png b/godot/sprites/tim_side.png new file mode 100644 index 0000000..f669703 Binary files /dev/null and b/godot/sprites/tim_side.png differ diff --git a/godot/sprites/tim_side.png.import b/godot/sprites/tim_side.png.import new file mode 100644 index 0000000..59aa558 --- /dev/null +++ b/godot/sprites/tim_side.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://kq63ictuirhc" +path="res://.godot/imported/tim_side.png-2080c0b8b2d695e4d35042c1d2710b4f.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://sprites/tim_side.png" +dest_files=["res://.godot/imported/tim_side.png-2080c0b8b2d695e4d35042c1d2710b4f.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1