This commit is contained in:
Фёдор Веселов 2024-09-10 19:36:20 +05:00
commit 2eb65c3092
24 changed files with 566 additions and 49 deletions

View file

@ -7,12 +7,17 @@ public partial class Cursor : Node
public override void _Ready()
{
Instance = this;
SetDefaultCursorSet();
SetDefaultCursor();
}
public void SetDefaultCursorSet()
public void SetDefaultCursor()
{
Input.SetCustomMouseCursor(ResourceLoader.Load<Texture2D>("res://assets/sprites/atlases/cursor/default_arrow.png"));
Input.SetCustomMouseCursor(ResourceLoader.Load<Texture2D>("res://assets/sprites/atlases/cursor/default_point.png"),shape:Input.CursorShape.PointingHand);
}
public void SetPlantCursor()
{
Input.SetCustomMouseCursor(ResourceLoader.Load<Texture2D>("res://assets/sprites/atlases/cursor/plant_arrow.png"));
}
}

View file

@ -1,5 +1,4 @@
using Godot;
using System;
//
// Class that gives access to level data, pools and etc.
@ -11,8 +10,10 @@ public partial class LevelController : Node
private bool _isLevelRunning = false;
// Frequently accessed level elements
public RuntimeLevelData LevelData { get; set; }
public PoolContainer Pools { get; set; }
public PlantField PlantField { get; set; }
public override void _EnterTree()
{
@ -24,6 +25,11 @@ public partial class LevelController : Node
Instance = null;
}
/// <summary>
///
/// </summary>
/// <param name="levelTileset">Scene that will be loaded</param>
/// <param name="levelScript">Optional script that will be attached to loaded scene</param>
public void StartLevel(PackedScene levelTileset, Script levelScript = null)
{
if (_isLevelRunning)
@ -44,6 +50,7 @@ public partial class LevelController : Node
LevelData = null;
Pools = null;
PlantField = null;
_isLevelRunning = false;
}

View file

@ -0,0 +1,22 @@
using Godot;
using System;
public partial class PlantSlot : Node
{
[Export] private PlantResource _resource;
[Export] private Label _cost;
[Export] private TextureRect _icon;
public void SetPlantResource( PlantResource resource )
{
_resource = resource;
UpdateContents();
}
private void UpdateContents()
{
_cost.Text = _resource.Cost.ToString();
_icon.Texture = _resource.Preview;
}
}

View file

@ -0,0 +1,34 @@
using Godot;
public partial class PlantField : Node2D
{
private Area2D _plantSetter;
private readonly Vector2 tile = new Vector2(Utility.TileWidth, Utility.TileHeight);
private bool _canPlace;
public override void _Ready()
{
LevelController.Instance.PlantField = this;
_plantSetter = GetChild<Area2D>(0);
}
public override void _Process(double delta)
{
var mouse_pos = GetGlobalMousePosition();
_plantSetter.GlobalPosition = mouse_pos;
var expected_pos = (_plantSetter.GlobalPosition / tile).Ceil() * tile - new Vector2(20, 14);
if (expected_pos.X > Utility.LeftFieldBoundary.X && expected_pos.X < Utility.RightFieldBoundary.X && expected_pos.Y > Utility.LeftFieldBoundary.Y && expected_pos.Y < Utility.RightFieldBoundary.Y)
{
_canPlace = true;
Material.Set("shader_parameter/amount", 0);
Cursor.Instance.SetPlantCursor();
_plantSetter.GlobalPosition = expected_pos;
}
else
{
_canPlace = false;
Cursor.Instance.SetDefaultCursor();
Material.Set("shader_parameter/amount", 1);
}
}
}

View file

@ -0,0 +1,41 @@
using Godot;
using System;
public partial class EatBox : Area2D
{
// Rewrite this class completely when field system will be introduced.
[Export] private int _damage;
[Export] private AnimationTree _animationTree;
private RuntimePlantData plant;
public void Bite()
{
plant.TakeDamage(_damage);
}
public void OnAreaEntered(Area2D area)
{
var parent = area.GetParent();
if (parent != null && parent is RuntimePlantData plantData)
{
plant = plantData;
_animationTree.Set("parameters/conditions/eat", true);
_animationTree.Set("parameters/conditions/end_eat", false);
}
}
public void OnAreaExited(Area2D area)
{
var parent = area.GetParent();
if (parent == plant)
{
plant = null;
_animationTree.Set("parameters/conditions/eat", false);
_animationTree.Set("parameters/conditions/end_eat", true);
}
}
}

View file

@ -0,0 +1,24 @@
using Godot;
using System;
public partial class ZombieMover : Node
{
private float _speed;
private Node2D _zombie;
public override void _Ready()
{
_zombie = GetParent<Node2D>();
}
public override void _PhysicsProcess(double delta)
{
_zombie.Position -= _zombie.Transform.X * _speed * (float)delta * Utility.TileWidth;
}
public void SetSpeed(float speed)
{
_speed = speed;
}
}

View file

@ -0,0 +1,18 @@
using Godot;
using System;
public partial class BasicZombieBehaviour : Node
{
[Export] private AnimationTree _animationTree;
public void StartEating()
{
_animationTree.Set("parameters/conditions/eat",true);
_animationTree.Set("parameters/conditions/end_eat", false);
GD.Print("StartEating");
}
public void EndEating()
{
_animationTree.Set("parameters/conditions/eat", false);
_animationTree.Set("parameters/conditions/end_eat", true);
}
}

View file

@ -13,5 +13,5 @@ public partial class PlantResource : Resource
[Export]
public float StartReloadTime;
[Export]
public Texture Preview;
public Texture2D Preview;
}