reworking effects, turning them into their own scene for replicability
This commit is contained in:
@@ -1,77 +1,54 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
public partial class Contact : Sprite2D
|
||||
{
|
||||
public bool _clickable = false, _interval = false;
|
||||
public int _number, _calls = 0, _maxCalls = 0;
|
||||
public Timer _timer, _cooldown;
|
||||
public Action _action;
|
||||
public Actor _owner;
|
||||
public int _number;
|
||||
public List<Effect> _effects;
|
||||
public PhoneButton _button;
|
||||
// public
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_timer = GetNode<Timer>("Timer");
|
||||
_cooldown = GetNode<Timer>("Cooldown");
|
||||
_action = GetNode<Action>("Action");
|
||||
_action._contact = this;
|
||||
|
||||
}
|
||||
|
||||
public virtual void CallAction()
|
||||
public virtual void FireEffect()
|
||||
{
|
||||
if (_cooldown.TimeLeft == 0 || _action._cooldownSeconds == 0)
|
||||
{
|
||||
GD.Print("Action fired!!");
|
||||
_action.Fire();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public virtual void End()
|
||||
{
|
||||
_effects.ForEach(e=>e.End());
|
||||
}
|
||||
|
||||
public void LoadEffect(string EFFECT_NAME, string EFFECT_TYPE)
|
||||
{
|
||||
PackedScene scene = ResourceLoader.Load<PackedScene>("res://Gameplay/Effects/"+EFFECT_TYPE+"/"+EFFECT_NAME+".tscn");
|
||||
Effect instance = scene.Instantiate<Effect>();
|
||||
|
||||
AddChild(instance);
|
||||
Effect newEffect = (Effect)GetChildren().Single(c=>c==instance);
|
||||
|
||||
newEffect.SetContact(this);
|
||||
// TimeEffect1 newEffect = scene.Instantiate();
|
||||
// AddChild(newEffect);
|
||||
// GD.Print(newEffect);
|
||||
// newEffect._contact = this;
|
||||
// _effects.Add(newEffect);
|
||||
}
|
||||
|
||||
public void PassNumber(int NUMBER)
|
||||
{
|
||||
_number = NUMBER;
|
||||
}
|
||||
public void PassOwner(Actor OWNER)
|
||||
{
|
||||
_owner = OWNER;
|
||||
}
|
||||
|
||||
public void SetTimer(float SECONDS)
|
||||
public virtual void Start()
|
||||
{
|
||||
_action._timerSeconds = SECONDS;
|
||||
_interval = true;
|
||||
_clickable = false;
|
||||
}
|
||||
|
||||
public void SetCooldown(float SECONDS)
|
||||
{
|
||||
_action._cooldownSeconds = SECONDS;
|
||||
_interval = false;
|
||||
_clickable = true;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
// GD.Print(_action._timerSeconds);
|
||||
if (_action._timerSeconds > 0)
|
||||
{
|
||||
_timer.Start(_action._timerSeconds);
|
||||
_calls = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTimerTimeout()
|
||||
{
|
||||
if (_calls <= _maxCalls || _maxCalls == 0)
|
||||
{
|
||||
CallAction();
|
||||
_timer.Start(_action._timerSeconds);
|
||||
_calls++;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCooldownTimeout()
|
||||
{
|
||||
|
||||
_effects.ForEach(e=>e.Start());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user