From 24cc1b8f04d6dcd21f974bc7c41521241d053ab4 Mon Sep 17 00:00:00 2001 From: CactiChameleon9 Date: Sat, 16 Jul 2022 08:15:35 +0100 Subject: [PATCH] Add Player and BattleScene --- Characters/Player.gd | 3 +++ Characters/Player.tscn | 10 ++++++++++ Scenes/BattleScene.gd | 29 +++++++++++++++++++++++++++++ Scenes/BattleScene.tscn | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 Characters/Player.gd create mode 100644 Characters/Player.tscn create mode 100644 Scenes/BattleScene.gd create mode 100644 Scenes/BattleScene.tscn diff --git a/Characters/Player.gd b/Characters/Player.gd new file mode 100644 index 0000000..ec026cc --- /dev/null +++ b/Characters/Player.gd @@ -0,0 +1,3 @@ +extends Node2D + +export var starting_pos : Vector2 = Vector2.ZERO diff --git a/Characters/Player.tscn b/Characters/Player.tscn new file mode 100644 index 0000000..5d7f4f3 --- /dev/null +++ b/Characters/Player.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://icon.png" type="Texture" id=1] +[ext_resource path="res://Characters/Player.gd" type="Script" id=2] + +[node name="Player" type="Node2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) diff --git a/Scenes/BattleScene.gd b/Scenes/BattleScene.gd new file mode 100644 index 0000000..ae3facf --- /dev/null +++ b/Scenes/BattleScene.gd @@ -0,0 +1,29 @@ +extends Node2D + +var movement_queue = [] + +func _physics_process(delta): + + if Input.is_action_just_pressed("ui_up"): + movement_queue.append(Vector2.UP) + if Input.is_action_just_pressed("ui_down"): + movement_queue.append(Vector2.DOWN) + if Input.is_action_just_pressed("ui_left"): + movement_queue.append(Vector2.LEFT) + if Input.is_action_just_pressed("ui_right"): + movement_queue.append(Vector2.RIGHT) + + #remove uneeded inputs from the queue + for i in len(movement_queue) - 1: + #remove if adjacent values are opposites + if (movement_queue[i].x * movement_queue[i+1].x == -1 or + movement_queue[i].y * movement_queue[i+1].y == -1): + movement_queue[i] = Vector2.ZERO + movement_queue[i+1] = Vector2.ZERO + #remove null values + for i in len(movement_queue): + if movement_queue.find(Vector2.ZERO) != -1: + movement_queue.remove(movement_queue.find(Vector2.ZERO)) + + + diff --git a/Scenes/BattleScene.tscn b/Scenes/BattleScene.tscn new file mode 100644 index 0000000..a4617ba --- /dev/null +++ b/Scenes/BattleScene.tscn @@ -0,0 +1,35 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://icon.png" type="Texture" id=1] +[ext_resource path="res://Characters/Player.tscn" type="PackedScene" id=2] +[ext_resource path="res://Scenes/BattleScene.gd" type="Script" id=3] + +[sub_resource type="TileSet" id=1] +0/name = "icon.png 0" +0/texture = ExtResource( 1 ) +0/tex_offset = Vector2( 0, 0 ) +0/modulate = Color( 1, 1, 1, 1 ) +0/region = Rect2( 8, 4, 51, 19 ) +0/tile_mode = 0 +0/occluder_offset = Vector2( 0, 0 ) +0/navigation_offset = Vector2( 0, 0 ) +0/shape_offset = Vector2( 0, 0 ) +0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +0/shape_one_way = false +0/shape_one_way_margin = 0.0 +0/shapes = [ ] +0/z_index = 0 + +[node name="BattleScene" type="Node2D"] +script = ExtResource( 3 ) + +[node name="TileMap" type="TileMap" parent="."] +mode = 2 +tile_set = SubResource( 1 ) +cell_size = Vector2( 128, 64 ) +cell_custom_transform = Transform2D( 128, 0, 32, 64, 0, 0 ) +centered_textures = true +format = 1 +tile_data = PoolIntArray( 65540, 0, 0, 131074, 0, 0, 131075, 0, 0, 131076, 0, 0, 131077, 0, 0, 131078, 0, 0, 196610, 0, 0, 196611, 0, 0, 196612, 0, 0, 196613, 0, 0, 196614, 0, 0, 262144, 0, 0, 262145, 0, 0, 262146, 0, 0, 262147, 0, 0, 262148, 0, 0, 262149, 0, 0, 262150, 0, 0, 327681, 0, 0, 327682, 0, 0, 327683, 0, 0, 327684, 0, 0, 327685, 0, 0, 327686, 0, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 524291, 0, 0, 524292, 0, 0 ) + +[node name="Player" parent="." instance=ExtResource( 2 )]