From e7a3167e600bac3e831d75281d1ad69ae032f203 Mon Sep 17 00:00:00 2001 From: fram3d Date: Sun, 9 Jun 2024 17:51:43 +0200 Subject: [PATCH] add ooze movement --- src/NPCs/Ooze.tscn | 12 ---------- src/NPCs/{Goblin.tscn => goblin.tscn} | 2 +- src/NPCs/moss.gd | 17 ++++++++++++++ src/NPCs/moss.tscn | 16 ++++++++++++-- src/NPCs/ooze.gd | 24 ++++++++++++++++++++ src/NPCs/ooze.tscn | 24 ++++++++++++++++++++ src/World.tscn | 32 ++++++++++++++------------- src/global.gd | 16 ++++++++++++++ src/project.godot | 8 +++++++ 9 files changed, 121 insertions(+), 30 deletions(-) delete mode 100644 src/NPCs/Ooze.tscn rename src/NPCs/{Goblin.tscn => goblin.tscn} (89%) create mode 100644 src/NPCs/moss.gd create mode 100644 src/NPCs/ooze.gd create mode 100644 src/NPCs/ooze.tscn create mode 100644 src/global.gd diff --git a/src/NPCs/Ooze.tscn b/src/NPCs/Ooze.tscn deleted file mode 100644 index 8c016a2..0000000 --- a/src/NPCs/Ooze.tscn +++ /dev/null @@ -1,12 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[ext_resource path="res://NPCs/ooze.png" type="Texture" id=1] - -[node name="Ooze" type="KinematicBody2D"] - -[node name="ooze" type="Sprite" parent="."] -position = Vector2( -0.061738, 0.18198 ) -texture = ExtResource( 1 ) - -[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] -polygon = PoolVector2Array( 4.09251, -4.06066, 4.04832, 4.15946, -4.1276, 4.02687, -4.1718, -4.06066 ) diff --git a/src/NPCs/Goblin.tscn b/src/NPCs/goblin.tscn similarity index 89% rename from src/NPCs/Goblin.tscn rename to src/NPCs/goblin.tscn index aec0ac6..222b772 100644 --- a/src/NPCs/Goblin.tscn +++ b/src/NPCs/goblin.tscn @@ -2,7 +2,7 @@ [ext_resource path="res://NPCs/goblin.png" type="Texture" id=1] -[node name="Goblin" type="KinematicBody2D"] +[node name="goblin" type="KinematicBody2D"] [node name="goblin" type="Sprite" parent="."] position = Vector2( 0.380203, -0.127379 ) diff --git a/src/NPCs/moss.gd b/src/NPCs/moss.gd new file mode 100644 index 0000000..b3fe967 --- /dev/null +++ b/src/NPCs/moss.gd @@ -0,0 +1,17 @@ +extends Area2D + + +# 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 diff --git a/src/NPCs/moss.tscn b/src/NPCs/moss.tscn index 952d4ae..60e89a5 100644 --- a/src/NPCs/moss.tscn +++ b/src/NPCs/moss.tscn @@ -1,8 +1,13 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://NPCs/moss.png" type="Texture" id=1] +[ext_resource path="res://NPCs/moss.gd" type="Script" id=2] -[node name="Moss" type="StaticBody2D"] +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 5.3049, 5.46393 ) + +[node name="moss" type="Area2D"] +script = ExtResource( 2 ) [node name="moss" type="Sprite" parent="."] position = Vector2( 0.110608, -0.127491 ) @@ -10,3 +15,10 @@ texture = ExtResource( 1 ) [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] polygon = PoolVector2Array( -3.90663, -4.01647, -3.77405, 3.8501, 4.04832, 3.8059, 4.09251, -4.01647 ) + +[node name="Hitbox" type="Area2D" parent="."] +collision_layer = 2 +collision_mask = 4 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"] +shape = SubResource( 1 ) diff --git a/src/NPCs/ooze.gd b/src/NPCs/ooze.gd new file mode 100644 index 0000000..bcdbe26 --- /dev/null +++ b/src/NPCs/ooze.gd @@ -0,0 +1,24 @@ +extends KinematicBody2D + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + +const MOVEMENT_VECTORS = [ + Vector2.UP, + Vector2.RIGHT, + Vector2.DOWN, + Vector2.LEFT +] + +# 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 _physics_process(delta): + var movement = MOVEMENT_VECTORS[randi() % 4] + move_and_collide(movement * 2) + pass diff --git a/src/NPCs/ooze.tscn b/src/NPCs/ooze.tscn new file mode 100644 index 0000000..fa72ac2 --- /dev/null +++ b/src/NPCs/ooze.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://NPCs/ooze.png" type="Texture" id=1] +[ext_resource path="res://NPCs/ooze.gd" type="Script" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 4.91306, 4.99174 ) + +[node name="ooze" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="ooze" type="Sprite" parent="."] +position = Vector2( -0.061738, 0.18198 ) +texture = ExtResource( 1 ) + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."] +polygon = PoolVector2Array( 4.09251, -4.06066, 4.04832, 4.15946, -4.1276, 4.02687, -4.1718, -4.06066 ) + +[node name="Hitbox" type="Area2D" parent="."] +collision_layer = 4 +collision_mask = 2 + +[node name="CollisionPolygon2D" type="CollisionShape2D" parent="Hitbox"] +shape = SubResource( 1 ) diff --git a/src/World.tscn b/src/World.tscn index 99ddd29..9d9f136 100644 --- a/src/World.tscn +++ b/src/World.tscn @@ -3,8 +3,8 @@ [ext_resource path="res://Tilesets/stone.png" type="Texture" id=1] [ext_resource path="res://Tilesets/dirt.png" type="Texture" id=2] [ext_resource path="res://Tilesets/water.png" type="Texture" id=3] -[ext_resource path="res://NPCs/Goblin.tscn" type="PackedScene" id=4] -[ext_resource path="res://NPCs/Ooze.tscn" type="PackedScene" id=5] +[ext_resource path="res://NPCs/goblin.tscn" type="PackedScene" id=4] +[ext_resource path="res://NPCs/ooze.tscn" type="PackedScene" id=5] [ext_resource path="res://NPCs/moss.tscn" type="PackedScene" id=6] [sub_resource type="ConvexPolygonShape2D" id=1] @@ -136,7 +136,6 @@ points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 ) [node name="World" type="Node2D"] [node name="TileMap" type="TileMap" parent="."] -position = Vector2( 2, 0 ) tile_set = SubResource( 7 ) cell_size = Vector2( 8, 8 ) cell_quadrant_size = 8 @@ -144,20 +143,23 @@ cell_custom_transform = Transform2D( 8, 0, 0, 8, 0, 0 ) format = 1 tile_data = PoolIntArray( 0, 1, 0, 1, 1, 0, 2, 1, 0, 3, 1, 0, 4, 1, 0, 5, 1, 0, 6, 1, 0, 7, 1, 0, 8, 1, 0, 9, 1, 0, 65536, 1, 0, 65537, 0, 0, 65538, 0, 0, 65539, 0, 0, 65540, 2, 65537, 65541, 2, 65537, 65542, 2, 65537, 65543, 1, 0, 65544, 1, 0, 65545, 1, 0, 131072, 1, 0, 131073, 0, 0, 131074, 1, 0, 131075, 0, 0, 131076, 0, 0, 131077, 1, 0, 131078, 2, 65537, 131079, 1, 0, 131080, 1, 0, 131081, 1, 0, 196608, 1, 0, 196609, 0, 0, 196610, 1, 0, 196611, 0, 0, 196612, 0, 0, 196613, 0, 0, 196614, 2, 65537, 196615, 2, 65537, 196616, 2, 2, 196617, 1, 0, 262144, 1, 0, 262145, 0, 0, 262146, 1, 0, 262147, 0, 0, 262148, 0, 0, 262149, 1, 0, 262150, 2, 65536, 262151, 2, 65537, 262152, 2, 65538, 262153, 1, 0, 327680, 1, 0, 327681, 0, 0, 327682, 1, 0, 327683, 0, 0, 327684, 0, 0, 327685, 0, 0, 327686, 2, 65536, 327687, 2, 65537, 327688, 2, 65538, 327689, 1, 0, 393216, 1, 0, 393217, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 2, 131072, 393223, 2, 131073, 393224, 2, 131074, 393225, 1, 0, 458752, 1, 0, 458753, 1, 0, 458754, 1, 0, 458755, 1, 0, 458756, 1, 0, 458757, 1, 0, 458758, 1, 0, 458759, 1, 0, 458760, 1, 0, 458761, 1, 0 ) -[node name="Moss" parent="TileMap" instance=ExtResource( 6 )] -position = Vector2( 35.5938, 20.699 ) +[node name="Moss2" parent="." instance=ExtResource( 6 )] +position = Vector2( 44, 44 ) -[node name="Moss2" parent="TileMap" instance=ExtResource( 6 )] -position = Vector2( 44.5283, 44.7697 ) +[node name="Moss" parent="." instance=ExtResource( 6 )] +position = Vector2( 37.5938, 20.699 ) -[node name="Ooze" parent="TileMap" instance=ExtResource( 5 )] -position = Vector2( 27.8155, 44.3492 ) +[node name="Moss3" parent="." instance=ExtResource( 6 )] +position = Vector2( 44, 52 ) -[node name="Goblin" parent="TileMap" instance=ExtResource( 4 )] -position = Vector2( 13.9407, 21.5399 ) +[node name="Ooze" parent="." instance=ExtResource( 5 )] +position = Vector2( 28, 44 ) -[node name="Goblin2" parent="TileMap" instance=ExtResource( 4 )] -position = Vector2( 35.4887, 33.6278 ) +[node name="Goblin" parent="." instance=ExtResource( 4 )] +position = Vector2( 12, 20 ) -[node name="Ooze2" parent="TileMap" instance=ExtResource( 5 )] -position = Vector2( 35.3835, 52.6531 ) +[node name="Goblin2" parent="." instance=ExtResource( 4 )] +position = Vector2( 28, 36 ) + +[node name="Ooze2" parent="." instance=ExtResource( 5 )] +position = Vector2( 36, 52 ) diff --git a/src/global.gd b/src/global.gd new file mode 100644 index 0000000..1eccaec --- /dev/null +++ b/src/global.gd @@ -0,0 +1,16 @@ +extends Node + + +# 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 diff --git a/src/project.godot b/src/project.godot index bc4b592..24dcfc1 100644 --- a/src/project.godot +++ b/src/project.godot @@ -19,6 +19,10 @@ config/name="Fishtank" run/main_scene="res://World.tscn" config/icon="res://icon.png" +[autoload] + +Global="*res://global.gd" + [display] window/size/width=80 @@ -29,6 +33,10 @@ window/size/test_width=1280 window/size/test_height=720 window/stretch/mode="2d" +[physics] + +common/physics_fps=2 + [rendering] quality/driver/driver_name="GLES2"