start working on inputs

- InputType enum is now flags, can be combined together
This commit is contained in:
minenice55
2022-07-28 19:12:21 -04:00
parent 94bd62d5a2
commit 859e719e3c
13 changed files with 491 additions and 466 deletions

View File

@ -0,0 +1,81 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio;
using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_KarateMan
{
public class KarateManJoeNew : MonoBehaviour
{
public Animator anim;
public GameEvent bop = new GameEvent();
float lastPunchTime = Single.MinValue;
int inComboId = -1;
public void SetComboId(int id) { inComboId = id; }
private void Awake()
{
}
private void Update()
{
var cond = Conductor.instance;
if (cond.ReportBeat(ref bop.lastReportedBeat, bop.startBeat % 1, false) && cond.songPositionInBeats > bop.startBeat)
{
anim.Play("Beat", -1, 0);
}
if (PlayerInput.Pressed(true))
{
if (!KarateManNew.instance.IsExpectingInputNow())
{
Punch(1);
Jukebox.PlayOneShotGame("karateman/swingNoHit", forcePlay: true);
}
}
else if (PlayerInput.AltPressedUp())
{
if (!KarateManNew.instance.IsExpectingInputNow())
{
if (inComboId != -1 && !KarateManNew.instance.IsExpectingInputNow())
{
//let go too early, make joe spin later
inComboId = -1;
}
}
}
}
public void Punch(int forceHand = 0)
{
var cond = Conductor.instance;
switch (forceHand)
{
case 0:
if (cond.songPositionInBeats - lastPunchTime < 0.25f + (Minigame.LateTime() - 1f))
{
lastPunchTime = Single.MinValue;
anim.Play("Straight", -1, 0);
}
else
{
lastPunchTime = cond.songPositionInBeats;
anim.Play("Jab", -1, 0);
}
break;
case 1:
anim.Play("Jab", -1, 0);
break;
case 2:
anim.Play("Straight", -1, 0);
break;
}
bop.startBeat = cond.songPositionInBeats + 0.5f;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e6ef00cb3bdcfd647bd634066ce4107d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -15,7 +15,7 @@ namespace HeavenStudio.Games.Loaders
return new Minigame("karateManNew", "Karate Man [INDEV REWORK]", "70A8D8", false, false, new List<GameAction>()
{
new GameAction("bop", delegate { }, 0.5f, true),
new GameAction("hit", delegate{}, 2, false,
new GameAction("hit", delegate { var e = eventCaller.currentEntity; KarateManNew.instance.CreateItem(e.beat, e.type); }, 2, false,
new List<Param>()
{
new Param("type", KarateManNew.HitType.Pot, "Object", "The object to fire")
@ -27,7 +27,7 @@ namespace HeavenStudio.Games.Loaders
new Param("colorA", new Color(), "Custom Color", "The color to use when the bulb type is set to Custom")
}),
new GameAction("kick", delegate { }, 4.5f),
new GameAction("combo", delegate { }, 4f),
new GameAction("combo", delegate { var e = eventCaller.currentEntity; KarateManNew.instance.Combo(e.beat); }, 4f),
new GameAction("hit3", delegate { }, 1f, false,
new List<Param>()
{
@ -131,15 +131,16 @@ namespace HeavenStudio.Games
public Transform[] CameraPosition;
Vector3 cameraPosition;
//pot trajectory stuff
public Transform[] HitPosition;
static Vector2 StartPositionOffset = new Vector2(-3f, -8f);
//https://www.desmos.com/calculator/ycn9v62i4f
public Transform ItemHolder;
public GameObject Item;
public KarateManJoeNew Joe;
private void Awake()
{
instance = this;
KarateManPotNew.ResetLastCombo();
cameraPosition = CameraPosition[0].position;
}
@ -152,5 +153,71 @@ namespace HeavenStudio.Games
{
GameCamera.additionalPosition = cameraPosition - GameCamera.defaultPosition;
}
public void CreateItem(float beat, int type)
{
string outSound;
switch (type)
{
case (int) HitType.Pot:
if (Starpelly.Mathp.GetDecimalFromFloat(beat) == 0f)
outSound = "karateman/objectOut";
else
outSound = "karateman/offbeatObjectOut";
CreateItemInstance(beat, "Item00");
break;
default:
if (Starpelly.Mathp.GetDecimalFromFloat(beat) == 0f)
outSound = "karateman/objectOut";
else
outSound = "karateman/offbeatObjectOut";
CreateItemInstance(beat, "Item00");
break;
}
Jukebox.PlayOneShotGame(outSound, forcePlay: true);
}
public void Combo(float beat)
{
Jukebox.PlayOneShotGame("karateman/barrelOutCombos", forcePlay: true);
int comboId = KarateManPotNew.GetNewCombo();
BeatAction.New(gameObject, new List<BeatAction.Action>()
{
new BeatAction.Action(beat, delegate { CreateItemInstance(beat, "Item00", KarateManPotNew.ItemType.ComboPot1, comboId); }),
new BeatAction.Action(beat + 0.25f, delegate { CreateItemInstance(beat + 0.25f, "Item00", KarateManPotNew.ItemType.ComboPot2, comboId); }),
new BeatAction.Action(beat + 0.5f, delegate { CreateItemInstance(beat + 0.5f, "Item00", KarateManPotNew.ItemType.ComboPot3, comboId); }),
new BeatAction.Action(beat + 0.75f, delegate { CreateItemInstance(beat + 0.75f, "Item00", KarateManPotNew.ItemType.ComboPot4, comboId); }),
new BeatAction.Action(beat + 1f, delegate { CreateItemInstance(beat + 1f, "Item00", KarateManPotNew.ItemType.ComboPot5, comboId); }),
new BeatAction.Action(beat + 1.5f, delegate { CreateItemInstance(beat + 1.5f, "Item05", KarateManPotNew.ItemType.ComboBarrel, comboId); }),
});
MultiSound.Play(new MultiSound.Sound[]
{
new MultiSound.Sound("karateman/punchy1", beat + 1f),
new MultiSound.Sound("karateman/punchy2", beat + 1.25f),
new MultiSound.Sound("karateman/punchy3", beat + 1.5f),
new MultiSound.Sound("karateman/punchy4", beat + 1.75f),
new MultiSound.Sound("karateman/ko", beat + 2f),
new MultiSound.Sound("karateman/pow", beat + 2.5f)
}, forcePlay: true);
}
GameObject CreateItemInstance(float beat, string awakeAnim, KarateManPotNew.ItemType type = KarateManPotNew.ItemType.Pot, int comboId = -1)
{
GameObject mobj = GameObject.Instantiate(Item, ItemHolder);
KarateManPotNew mobjDat = mobj.GetComponent<KarateManPotNew>();
mobjDat.type = type;
mobjDat.startBeat = beat;
mobjDat.awakeAnim = awakeAnim;
mobjDat.comboId = comboId;
mobj.SetActive(true);
return mobj;
}
}
}

View File

@ -11,7 +11,18 @@ namespace HeavenStudio.Games.Scripts_KarateMan
public float startBeat;
public ItemType type;
public int path = 1;
int status = 0;
public GameObject Shadow;
public GameObject ShadowInstance;
public string awakeAnim;
FlyStatus status = FlyStatus.Fly;
public int comboId = -1;
static int _lastCombo = -1;
public static int LastCombo { get { return _lastCombo; } }
public static int GetNewCombo() { _lastCombo++; return _lastCombo; }
public static void ResetLastCombo() { _lastCombo = -1; }
public enum ItemType {
Pot, // path 1
@ -43,26 +54,28 @@ namespace HeavenStudio.Games.Scripts_KarateMan
//pot trajectory stuff
public Transform[] HitPosition;
public float[] HitPositionOffset;
static Vector3 StartPositionOffset = new Vector3(3f, 0f, -8f);
public Vector3[] StartPositionOffset;
public float[] ItemSlipRt;
float ProgressToHitPosition(float progress) {
return progress + (HitPositionOffset[path] -0.5f);
return progress + (HitPositionOffset[path] - 0.5f);
}
Vector3 ProgressToFlyPosition()
{
var cond = Conductor.instance;
float progress = Mathf.Min(cond.GetPositionFromBeat(startBeat, 2f), 1f);
float progress = Mathf.Min(cond.GetPositionFromBeat(startBeat, 2f), 1f - ItemSlipRt[path]);
float progressToHitPosition = ProgressToHitPosition(progress);
Vector3 hitPosition = HitPosition[path].position;
//https://www.desmos.com/calculator/ycn9v62i4f
float offset = HitPositionOffset[path];
float flyHeight = (progressToHitPosition*(progressToHitPosition-1f))/(offset*(offset-1f));
float floorHeight = HitPosition[0].position.y;
Vector3 startPosition = transform.position + StartPositionOffset;
Vector3 endPosition = transform.position - StartPositionOffset;
Vector3 startPosition = hitPosition + StartPositionOffset[path];
Vector3 endPosition = hitPosition - StartPositionOffset[path];
Vector3 flyPosition = new Vector3(
Mathf.Lerp(startPosition.x, endPosition.x, progress),
floorHeight + (HitPosition[path].position.y - floorHeight) * flyHeight,
@ -74,5 +87,140 @@ namespace HeavenStudio.Games.Scripts_KarateMan
}
return flyPosition;
}
void Awake()
{
switch (type)
{
case ItemType.ComboPot1:
KarateManNew.instance.ScheduleInput(startBeat, 1f, InputType.STANDARD_ALT_DOWN, ComboStartJustOrNg, ComboStartThrough, ComboStartOut);
path = 1;
break;
case ItemType.ComboPot2:
path = 1;
break;
case ItemType.ComboPot3:
path = 2;
break;
case ItemType.ComboPot4:
path = 3;
//if the button isn't held anymore make Joe spin
break;
case ItemType.ComboPot5:
path = 4;
break;
case ItemType.ComboBarrel:
path = 5;
//check for button release
break;
default:
KarateManNew.instance.ScheduleInput(startBeat, 1f, InputType.STANDARD_DOWN | InputType.DIRECTION_DOWN, ItemJustOrNg, ItemThrough, ItemOut);
path = 1;
comboId = -1;
break;
}
float floorHeight = HitPosition[0].position.y;
transform.position = ProgressToFlyPosition();
Animator mobjAnim = GetComponent<Animator>();
mobjAnim.Play(awakeAnim, -1, 0);
transform.rotation = Quaternion.Euler(0, 0, transform.rotation.eulerAngles.z + (-360f * Time.deltaTime) + UnityEngine.Random.Range(0f, 360f));
ShadowInstance = GameObject.Instantiate(Shadow, KarateManNew.instance.ItemHolder);
ShadowInstance.SetActive(true);
ShadowInstance.transform.position = new Vector3(transform.position.x, floorHeight - 0.5f, transform.position.z);
}
void Update()
{
var cond = Conductor.instance;
float floorHeight = HitPosition[0].position.y;
ShadowInstance.transform.position = new Vector3(transform.position.x, floorHeight - 0.5f, transform.position.z);
switch (status)
{
case FlyStatus.Fly:
float prog = cond.GetPositionFromBeat(startBeat, 2f);
transform.position = ProgressToFlyPosition();
if (prog >= 2f) {
GameObject.Destroy(ShadowInstance.gameObject);
GameObject.Destroy(gameObject);
return;
}
else if (prog < 1f - ItemSlipRt[path]) {
transform.rotation = Quaternion.Euler(0, 0, transform.rotation.eulerAngles.z + (90f * Time.deltaTime * (1/cond.pitchedSecPerBeat)));
}
break;
case FlyStatus.Hit:
//TEMPORARY
GameObject.Destroy(ShadowInstance.gameObject);
GameObject.Destroy(gameObject);
return;
case FlyStatus.NG:
//TEMPORARY
GameObject.Destroy(ShadowInstance.gameObject);
GameObject.Destroy(gameObject);
return;
case FlyStatus.HitWeak:
break;
}
}
public void ItemJustOrNg(PlayerActionEvent caller, float state)
{
if (status == FlyStatus.Fly) {
KarateManNew.instance.Joe.Punch();
if (state <= -1f || state >= 1f) {
Jukebox.PlayOneShot("miss");
status = FlyStatus.NG;
}
else {
Jukebox.PlayOneShotGame("karateman/potHit", forcePlay: true);
status = FlyStatus.Hit;
}
}
}
public void ItemWrongAction(PlayerActionEvent caller, float state)
{
//hitting a normal object with the alt input
}
public void ItemOut(PlayerActionEvent caller) {}
public void ItemThrough(PlayerActionEvent caller)
{
BeatAction.New(gameObject, new List<BeatAction.Action>()
{
new BeatAction.Action(startBeat + 2f, delegate {
//TODO: play miss sound
//deduct flow if applicable
})
});
}
public void ComboStartJustOrNg(PlayerActionEvent caller, float state)
{
if (status == FlyStatus.Fly) {
KarateManNew.instance.Joe.Punch(1);
KarateManNew.instance.Joe.SetComboId(comboId);
if (state <= -1f || state >= 1f) {
Jukebox.PlayOneShot("miss");
status = FlyStatus.NG;
}
else {
Jukebox.PlayOneShotGame("karateman/potHit", forcePlay: true);
status = FlyStatus.Hit;
}
}
}
public void ComboStartOut(PlayerActionEvent caller) {}
public void ComboStartThrough(PlayerActionEvent caller) {}
public void ComboStartWrongAction(PlayerActionEvent caller, float state)
{
//hitting a combo start object with the normal input
}
}
}

View File

@ -101,22 +101,22 @@ namespace HeavenStudio.Games
// Forgive me for those input type names
return (
//General inputs, both down and up
(PlayerInput.Pressed() && inputType == InputType.STANDARD_DOWN) ||
(PlayerInput.AltPressed() && inputType == InputType.STANDARD_ALT_DOWN) ||
(PlayerInput.GetAnyDirectionDown() && inputType == InputType.DIRECTION_DOWN) ||
(PlayerInput.PressedUp() && inputType == InputType.STANDARD_UP) ||
(PlayerInput.AltPressedUp() && inputType == InputType.STANDARD_ALT_UP) ||
(PlayerInput.GetAnyDirectionUp() && inputType == InputType.DIRECTION_UP) ||
(PlayerInput.Pressed() && inputType.HasFlag(InputType.STANDARD_DOWN)) ||
(PlayerInput.AltPressed() && inputType.HasFlag(InputType.STANDARD_ALT_DOWN)) ||
(PlayerInput.GetAnyDirectionDown() && inputType.HasFlag(InputType.DIRECTION_DOWN)) ||
(PlayerInput.PressedUp() && inputType.HasFlag(InputType.STANDARD_UP)) ||
(PlayerInput.AltPressedUp() && inputType.HasFlag(InputType.STANDARD_ALT_UP)) ||
(PlayerInput.GetAnyDirectionUp() && inputType.HasFlag(InputType.DIRECTION_UP)) ||
//Specific directional inputs
(PlayerInput.GetSpecificDirectionDown(PlayerInput.DOWN) && inputType == InputType.DIRECTION_DOWN_DOWN) ||
(PlayerInput.GetSpecificDirectionDown(PlayerInput.UP) && inputType == InputType.DIRECTION_UP_DOWN) ||
(PlayerInput.GetSpecificDirectionDown(PlayerInput.LEFT) && inputType == InputType.DIRECTION_LEFT_DOWN) ||
(PlayerInput.GetSpecificDirectionDown(PlayerInput.RIGHT) && inputType == InputType.DIRECTION_RIGHT_DOWN) ||
(PlayerInput.GetSpecificDirectionDown(PlayerInput.DOWN) && inputType.HasFlag(InputType.DIRECTION_DOWN_DOWN)) ||
(PlayerInput.GetSpecificDirectionDown(PlayerInput.UP) && inputType.HasFlag(InputType.DIRECTION_UP_DOWN)) ||
(PlayerInput.GetSpecificDirectionDown(PlayerInput.LEFT) && inputType.HasFlag(InputType.DIRECTION_LEFT_DOWN)) ||
(PlayerInput.GetSpecificDirectionDown(PlayerInput.RIGHT) && inputType.HasFlag(InputType.DIRECTION_RIGHT_DOWN)) ||
(PlayerInput.GetSpecificDirectionUp(PlayerInput.DOWN) && inputType == InputType.DIRECTION_DOWN_UP) ||
(PlayerInput.GetSpecificDirectionUp(PlayerInput.UP) && inputType == InputType.DIRECTION_UP_UP) ||
(PlayerInput.GetSpecificDirectionUp(PlayerInput.LEFT) && inputType == InputType.DIRECTION_LEFT_UP) ||
(PlayerInput.GetSpecificDirectionUp(PlayerInput.RIGHT) && inputType == InputType.DIRECTION_RIGHT_UP)
(PlayerInput.GetSpecificDirectionUp(PlayerInput.DOWN) && inputType.HasFlag(InputType.DIRECTION_DOWN_UP)) ||
(PlayerInput.GetSpecificDirectionUp(PlayerInput.UP) && inputType.HasFlag(InputType.DIRECTION_UP_UP)) ||
(PlayerInput.GetSpecificDirectionUp(PlayerInput.LEFT) && inputType.HasFlag(InputType.DIRECTION_LEFT_UP)) ||
(PlayerInput.GetSpecificDirectionUp(PlayerInput.RIGHT) && inputType.HasFlag(InputType.DIRECTION_RIGHT_UP))
);
}

View File

@ -5,30 +5,31 @@ using UnityEngine;
namespace HeavenStudio
{
[System.Flags]
public enum InputType : int {
//General
//-------
//Down
STANDARD_DOWN = 0,
STANDARD_ALT_DOWN = 1,
DIRECTION_DOWN = 2,
STANDARD_DOWN = 1<<0,
STANDARD_ALT_DOWN = 1<<1,
DIRECTION_DOWN = 1<<2,
//Up
STANDARD_UP = 3,
STANDARD_ALT_UP = 4,
DIRECTION_UP = 5,
STANDARD_UP = 1<<3,
STANDARD_ALT_UP = 1<<4,
DIRECTION_UP = 1<<5,
//Specific
//--------
//Down
DIRECTION_DOWN_DOWN = 6,
DIRECTION_UP_DOWN = 7,
DIRECTION_LEFT_DOWN = 8,
DIRECTION_RIGHT_DOWN = 9,
DIRECTION_DOWN_DOWN = 1<<6,
DIRECTION_UP_DOWN = 1<<7,
DIRECTION_LEFT_DOWN = 1<<8,
DIRECTION_RIGHT_DOWN = 1<<9,
//Up
DIRECTION_DOWN_UP = 10,
DIRECTION_UP_UP = 11,
DIRECTION_LEFT_UP = 12,
DIRECTION_RIGHT_UP = 13
DIRECTION_DOWN_UP = 1<<10,
DIRECTION_UP_UP = 1<<11,
DIRECTION_LEFT_UP = 1<<12,
DIRECTION_RIGHT_UP = 1<<13
}
}