HeavenStudioPlus/Assets/Scripts/Games/Spaceball/SpaceballPlayer.cs
Rapandrasmus 5dd0d8a9df Quiz Show (#390)
* I'm a menace to society

* Made some small fixes

* added missing stuff, realignment

* Added Animators

* Unity Shenanigans

* all contestee anims

* mb

* Changed how the contestee is structured in the hierachy

* ymf

* I love quiz show

* more anim implementation

* anim fixes and bg upscale

* oops

* implemented prepare and rest

* oops2

* timer

* Implemented Head Animations

* Added the timer

* Oopsie

* there we go

* changed wizards waltz default length

* Added explosions

* Made consecutive intervals possible

* Implementing counting for the contestant

* The quiz host now has numbers

* host anims

* host anims done

* Implemented all host anims and fixed some stuff

* implemented more stuff

* oops

* anim fixes

* Bug fixes woohoo!

* Fixes

* Fixed something !!!!

* upscale and more

* updated reveal answer to not remove the black on reveal of the number

* new sheet2

* Added ForceExplode

* They now go grey

* upscale done anim stuff

* smoke and explosion

* Stage0 added

* KABOOM

* tweaks

* icon and anim fixes

* Added randomPresses event and prefunction to start interval

* Fixed a bug with random presses and also made the sign change color

* Fixed small bug

* fixed a spaceball bug

* New Metronome

---------

Co-authored-by: ev <85412919+evdial@users.noreply.github.com>
Co-authored-by: saladplainzone <chocolate2890mail@gmail.com>
2023-04-12 22:34:15 +00:00

90 lines
No EOL
2.2 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
using HeavenStudio.Util;
namespace HeavenStudio.Games.Scripts_Spaceball
{
public class SpaceballPlayer : MonoBehaviour
{
private Animator _anim;
private int _currentCostume;
public SpriteRenderer PlayerSprite;
public SpriteRenderer Hat;
public HatSprite HatSprites1 = new HatSprite();
public HatSprite HatSprites2 = new HatSprite();
[Serializable]
public struct HatSprite
{
public List<Vector2> Offsets;
public List<Sprite> Sprites;
}
public static SpaceballPlayer instance { get; set; }
private void Awake()
{
instance = this;
_anim = GetComponent<Animator>();
}
private void Update()
{
if (PlayerInput.Pressed())
{
Swing(null);
}
}
public void SetCostume(Material mat, int costumeIndex)
{
PlayerSprite.material = mat;
_currentCostume = costumeIndex;
_anim.Play("Idle", 0, 0);
}
public void Swing(SpaceballBall b)
{
if (b == null)
{
Jukebox.PlayOneShotGame("spaceball/swing");
}
else
{
}
_anim.Play("Swing", 0, 0);
}
public void SetHatFrame(int frame)
{
// Unity can't serialize lists inside lists in this version, so that's annoying.
var sprites = new HatSprite();
switch (_currentCostume)
{
case 0:
Hat.sprite = null;
return;
case 1:
sprites = HatSprites1;
break;
case 2:
sprites = HatSprites2;
break;
}
if (sprites.Sprites.Count - 1 < frame)
frame = 0;
Hat.sprite = sprites.Sprites[frame];
var offset = Vector2.zero;
if (sprites.Offsets.Count - 1 >= frame)
offset = sprites.Offsets[frame];
Hat.transform.localPosition = offset;
}
}
}