second commit
This commit is contained in:
@@ -3,7 +3,9 @@ using Godot;
|
|||||||
public partial class Attack : RigidBody2D
|
public partial class Attack : RigidBody2D
|
||||||
{
|
{
|
||||||
public bool _hovered = false;
|
public bool _hovered = false;
|
||||||
|
public int _damage = 1;
|
||||||
public Vector2 _speed;
|
public Vector2 _speed;
|
||||||
|
public Player _playerOwner;
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
@@ -18,12 +20,19 @@ public partial class Attack : RigidBody2D
|
|||||||
_speed = FORCE;
|
_speed = FORCE;
|
||||||
GravityScale = 1;
|
GravityScale = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void TakeAction(Node BODY)
|
||||||
|
{
|
||||||
|
if (BODY is Enemy enemy)
|
||||||
|
{
|
||||||
|
enemy.TakeDamage(_damage, _playerOwner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void OnMouseEntered(){
|
public void OnMouseEntered(){
|
||||||
GD.Print("Hovered");
|
|
||||||
_hovered = true;
|
_hovered = true;
|
||||||
}
|
}
|
||||||
public void OnMouseExited(){
|
public void OnMouseExited(){
|
||||||
GD.Print("Not Hovered");
|
|
||||||
_hovered = true;
|
_hovered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
using Godot;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public partial class Enemy : StaticBody2D
|
||||||
|
{
|
||||||
|
[Signal]
|
||||||
|
public delegate void TurnDoneEventHandler();
|
||||||
|
public bool _toMove = false;
|
||||||
|
public int _speed = 100, _reach = 200, _damage = 1, _health = 2;
|
||||||
|
public float _movement = 0;
|
||||||
|
public Player _player;
|
||||||
|
public override void _PhysicsProcess(double delta)
|
||||||
|
{
|
||||||
|
base._PhysicsProcess(delta);
|
||||||
|
if (_toMove)
|
||||||
|
{
|
||||||
|
Vector2 moveVector = (_player.Position - Position) * (float)delta;
|
||||||
|
if ((_movement += moveVector.Length()) <= _speed )
|
||||||
|
{
|
||||||
|
MoveAndCollide(moveVector);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((_player.Position - Position).Length() <= _reach)
|
||||||
|
{
|
||||||
|
Attack(_player);
|
||||||
|
}
|
||||||
|
_toMove = false;
|
||||||
|
_movement = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Attack(Player PLAYER)
|
||||||
|
{
|
||||||
|
PLAYER.TakeDamage(_damage, this);
|
||||||
|
QueueFree();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TakeDamage(int DAMAGE, Player ATTACKER)
|
||||||
|
{
|
||||||
|
_health -= DAMAGE;
|
||||||
|
GD.Print($"Taking {DAMAGE}, Health is now {_health}");
|
||||||
|
if (_health <= 0)
|
||||||
|
{
|
||||||
|
QueueFree();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TakeTurn()
|
||||||
|
{
|
||||||
|
_toMove = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://dfba4vq6jv0a6
|
||||||
@@ -1,6 +1,50 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public partial class Main : Node
|
public partial class Main : Node
|
||||||
{
|
{
|
||||||
|
public bool _isPlayerTurn = true;
|
||||||
|
public Player _player;
|
||||||
|
public PackedScene _enemyScene = GD.Load<PackedScene>("res://Enemy.tscn");
|
||||||
|
public List<Enemy> _enemies = new();
|
||||||
|
public Random _rng = new();
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
base._Ready();
|
||||||
|
_player = GetNode<Player>("Player");
|
||||||
|
_player.TurnDone += ChangeTurn;
|
||||||
|
AddEnemy();
|
||||||
|
_player.StartTurn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeTurn()
|
||||||
|
{
|
||||||
|
_isPlayerTurn = !_isPlayerTurn;
|
||||||
|
if (_isPlayerTurn)
|
||||||
|
{
|
||||||
|
GD.Print("Starting Player turn");
|
||||||
|
_player.StartTurn();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GD.Print("Starting Enemy turn");
|
||||||
|
for (int i = 0; i < _enemies.Count; i++)
|
||||||
|
{
|
||||||
|
_enemies[i].TakeTurn();
|
||||||
|
}
|
||||||
|
AddEnemy();
|
||||||
|
ChangeTurn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddEnemy()
|
||||||
|
{
|
||||||
|
Enemy newEnemy = _enemyScene.Instantiate<Enemy>();
|
||||||
|
newEnemy.TurnDone += ChangeTurn;
|
||||||
|
newEnemy.Position = new Vector2(_rng.Next((int)_player.GetViewportRect().Size.X), _player.GetViewportRect().Size.Y - 100);
|
||||||
|
newEnemy._player = _player;
|
||||||
|
_enemies.Add(newEnemy);
|
||||||
|
AddChild(newEnemy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
public partial class Player : Node2D
|
public partial class Player : Sprite2D
|
||||||
{
|
{
|
||||||
|
[Signal]
|
||||||
|
public delegate void TurnDoneEventHandler();
|
||||||
public bool _aiming = false;
|
public bool _aiming = false;
|
||||||
|
public int _health = 10;
|
||||||
public PackedScene _attackScene = GD.Load<PackedScene>("res://Attack.tscn");
|
public PackedScene _attackScene = GD.Load<PackedScene>("res://Attack.tscn");
|
||||||
public Attack _currentAttack;
|
public Attack _currentAttack;
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
base._Process(delta);
|
base._Process(delta);
|
||||||
if (_currentAttack == null){
|
if (_currentAttack != null)
|
||||||
GD.Print("Loading attack");
|
{
|
||||||
_currentAttack = _attackScene.Instantiate<Attack>();
|
|
||||||
_currentAttack.GravityScale = 0;
|
|
||||||
_currentAttack.Position = GetViewportRect().Size / 2;
|
|
||||||
AddChild(_currentAttack);
|
|
||||||
}
|
|
||||||
if (Input.IsActionJustPressed("leftClick")){
|
if (Input.IsActionJustPressed("leftClick")){
|
||||||
if (_currentAttack._hovered){
|
if (_currentAttack._hovered){
|
||||||
_aiming = true;
|
_aiming = true;
|
||||||
@@ -30,6 +28,30 @@ public partial class Player : Node2D
|
|||||||
if (_currentAttack.Position.Y > GetViewportRect().Size.Y + 50){
|
if (_currentAttack.Position.Y > GetViewportRect().Size.Y + 50){
|
||||||
_currentAttack.QueueFree();
|
_currentAttack.QueueFree();
|
||||||
_currentAttack = null;
|
_currentAttack = null;
|
||||||
|
EmitSignal(SignalName.TurnDone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartTurn()
|
||||||
|
{
|
||||||
|
if (_currentAttack == null){
|
||||||
|
GD.Print("Loading attack");
|
||||||
|
_currentAttack = _attackScene.Instantiate<Attack>();
|
||||||
|
_currentAttack._playerOwner = this;
|
||||||
|
_currentAttack.GravityScale = 0;
|
||||||
|
AddChild(_currentAttack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TakeDamage(int DAMAGE, Enemy ATTACKER)
|
||||||
|
{
|
||||||
|
_health -= DAMAGE;
|
||||||
|
if (_health <= 0)
|
||||||
|
{
|
||||||
|
GD.Print("GAME OVER");
|
||||||
|
GetTree().Quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,5 +16,6 @@ shape = SubResource("CircleShape2D_7yfhp")
|
|||||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1583277900]
|
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1583277900]
|
||||||
texture = ExtResource("2_hqc8w")
|
texture = ExtResource("2_hqc8w")
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="TakeAction"]
|
||||||
[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"]
|
[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"]
|
||||||
[connection signal="mouse_exited" from="." to="." method="OnMouseExited"]
|
[connection signal="mouse_exited" from="." to="." method="OnMouseExited"]
|
||||||
|
|||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
[gd_scene format=3 uid="uid://drt7w0eqp13tu"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dfba4vq6jv0a6" path="res://Enemy.cs" id="1_4gyqm"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://circle25r.png" id="1_7k104"]
|
||||||
|
|
||||||
|
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"]
|
||||||
|
bounce = 0.5
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_4gyqm"]
|
||||||
|
radius = 25.0
|
||||||
|
|
||||||
|
[node name="Enemy" type="StaticBody2D" unique_id=1417697759]
|
||||||
|
physics_material_override = SubResource("PhysicsMaterial_7k104")
|
||||||
|
script = ExtResource("1_4gyqm")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1762191899]
|
||||||
|
shape = SubResource("CircleShape2D_4gyqm")
|
||||||
|
|
||||||
|
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605]
|
||||||
|
texture = ExtResource("1_7k104")
|
||||||
@@ -7,3 +7,4 @@
|
|||||||
script = ExtResource("1_ig7tw")
|
script = ExtResource("1_ig7tw")
|
||||||
|
|
||||||
[node name="Player" parent="." unique_id=203629164 instance=ExtResource("2_0xm2m")]
|
[node name="Player" parent="." unique_id=203629164 instance=ExtResource("2_0xm2m")]
|
||||||
|
position = Vector2(576, 100)
|
||||||
|
|||||||
+1
-1
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
[ext_resource type="Script" uid="uid://b2kj0rc3g1hkm" path="res://Player.cs" id="1_4flbx"]
|
[ext_resource type="Script" uid="uid://b2kj0rc3g1hkm" path="res://Player.cs" id="1_4flbx"]
|
||||||
|
|
||||||
[node name="Player" type="Node2D" unique_id=203629164]
|
[node name="Player" type="Sprite2D" unique_id=1378094015]
|
||||||
script = ExtResource("1_4flbx")
|
script = ExtResource("1_4flbx")
|
||||||
|
|||||||
Reference in New Issue
Block a user