HeavenStudioPlus/Assets/Scripts/Games/CoinToss/CoinToss.cs

113 lines
3.0 KiB
C#
Raw Normal View History

2022-05-01 18:22:00 +00:00
using DG.Tweening;
using NaughtyBezierCurves;
using HeavenStudio.Util;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace HeavenStudio.Games.Loaders
{
using static Minigames;
public static class NtrCoinLoader
{
public static Minigame AddGame(EventCaller eventCaller)
{
return new Minigame("coinToss", "Coin Toss \n [One coin at a time!]", "B4E6F6", false, false, new List<GameAction>()
2022-05-01 18:22:00 +00:00
{
new GameAction("toss", delegate { CoinToss.instance.TossCoin(eventCaller.currentEntity.beat, eventCaller.currentEntity.toggle); }, 7, false, parameters: new List<Param>()
{
new Param("toggle", false, "Audience Reaction", "Enable Audience Reaction"),
}),
2022-05-01 18:22:00 +00:00
});
}
}
}
namespace HeavenStudio.Games
{
//using Scripts_CoinToss;
2022-05-01 18:22:00 +00:00
public class CoinToss : Minigame
{
2022-05-01 22:24:07 +00:00
//Right now, you can only throw one coin at a time.
//..Which makes sense, you only have one coin in the original game
//Though it would need a bit of code rewrite to make it work with multiple coins
2022-05-01 18:22:00 +00:00
public static CoinToss instance { get; set; }
public Boolean isThrowing;
public bool audienceReacting;
2022-05-01 18:22:00 +00:00
[Header("Animators")]
public Animator handAnimator;
public PlayerActionEvent coin;
2022-05-01 18:22:00 +00:00
private void Awake()
{
instance = this;
2022-05-01 22:24:07 +00:00
isThrowing = false;
coin = null;
2022-05-01 18:22:00 +00:00
}
private void Update()
{
//nothing
2022-05-01 18:22:00 +00:00
}
private void LateUpdate()
{
//nothing
2022-05-01 18:22:00 +00:00
}
public void TossCoin(float beat, bool audienceReacting)
2022-05-01 18:22:00 +00:00
{
if (coin != null) return;
2022-05-01 22:24:07 +00:00
//Play sound and animations
2022-05-01 18:22:00 +00:00
Jukebox.PlayOneShotGame("coinToss/throw");
handAnimator.Play("Throw", 0, 0);
2022-05-01 22:24:07 +00:00
//Game state says the hand is throwing the coin
2022-05-01 18:22:00 +00:00
isThrowing = true;
this.audienceReacting = audienceReacting;
coin = ScheduleInput(beat, 6f, InputType.DIRECTION_DOWN, CatchSuccess, CatchMiss, CatchEmpty);
2022-05-01 18:22:00 +00:00
}
public void CatchSuccess(int state)
{
if (state != 1)
{
CatchMiss();
return;
}
Jukebox.PlayOneShotGame("coinToss/catch");
if(this.audienceReacting) Jukebox.PlayOneShotGame("coinToss/applause");
handAnimator.Play("Catch_success", 0, 0);
isThrowing = false;
}
public void CatchMiss()
{
Jukebox.PlayOneShotGame("coinToss/miss");
if(this.audienceReacting) Jukebox.PlayOneShotGame("coinToss/disappointed");
handAnimator.Play("Pickup", 0, 0);
2022-05-01 22:24:07 +00:00
isThrowing = false;
}
public void CatchEmpty()
{
handAnimator.Play("Catch_empty", 0, 0);
isThrowing = false;
coin.CanHit(false);
}
2022-05-01 18:22:00 +00:00
}
}