Sun scoring and zombie hat impulse

This commit is contained in:
Rendo 2025-06-28 03:36:18 +05:00
commit 6608fb8389
9 changed files with 62 additions and 7 deletions

View file

@ -6,27 +6,44 @@ namespace Newlon;
public partial class Sun : Area2D
{
public static Control Counter;
[Export] public int amount = 25;
[Export] private Timer _deathTimer;
[Export] private AnimationPlayer _rotation;
[Export] private AnimationPlayer _fade;
private bool scoring;
public override void _Ready()
{
_rotation.SpeedScale = 1.0f + GD.Randf() / 2.0f;
}
public override void _InputEvent(Viewport viewport, InputEvent @event, int shapeIdx)
{
if (scoring) return;
if (@event.IsActionPressed("primary_action"))
{
RuntimeLevelData.Instance.AddSun(amount);
QueueFree();
_fade.Stop();
scoring = true;
var tween = CreateTween();
tween.TweenInterval(0.1);
tween.TweenProperty(this, "global_position", GetCanvasTransform().AffineInverse() * (Counter.GlobalPosition + Counter.PivotOffset), 0.5).SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
tween.TweenCallback(Callable.From(() =>
{
RuntimeLevelData.Instance.AddSun(amount);
QueueFree();
}));
}
}
public override void _Process(double delta)
{
if (_deathTimer.TimeLeft/_deathTimer.WaitTime <= 0.25)
if (scoring) return;
if (_deathTimer.TimeLeft / _deathTimer.WaitTime <= 0.25)
{
_fade.Play("main");
}

View file

@ -0,0 +1,11 @@
using Godot;
using Newlon;
using System;
public partial class SunCounterImage : Control
{
public override void _Ready()
{
Sun.Counter = this;
}
}

View file

@ -0,0 +1 @@
uid://0ekxnoq6cyt4

View file

@ -33,6 +33,7 @@ public partial class RuntimeLevelData : Node
{
SunCount += amount;
}
public void SpendSun(int amount)
{
SunCount -= amount;

View file

@ -1,12 +1,16 @@
using Godot;
using Newlon.Components.Level;
using Newlon.Components.Zombies;
using System;
public partial class FallParticle : RigidBody2D
{
[Export] private RuntimeZombieData data;
[Export] private Timer deathTimer;
[Export] private Vector2 falloffImpulseMin = Vector2.Zero;
[Export] private Vector2 falloffImpulseMax = Vector2.Zero;
[Export] private Vector2 falloffOffsetMin = Vector2.Zero;
[Export] private Vector2 falloffOffsetMax = Vector2.Zero;
[Export] private float Impulse;
public void FallOff()
{
SetDeferred("freeze", false);
@ -14,7 +18,17 @@ public partial class FallParticle : RigidBody2D
{
AddCollisionExceptionWith(floor);
}
Callable.From(()=>{ Reparent(PoolContainer.Instance.Zombies); }).CallDeferred();
Callable.From(() =>
{
Reparent(PoolContainer.Instance.Zombies);
ApplyImpulse(RandomVector(falloffImpulseMin, falloffImpulseMax).Normalized() * Impulse, RandomVector(falloffOffsetMin, falloffOffsetMax));
}).CallDeferred();
deathTimer.Start();
}
private Vector2 RandomVector(Vector2 min, Vector2 max)
{
return new Vector2((float)GD.RandRange(min.X,max.X),(float)GD.RandRange(min.Y,max.Y));
}
}