mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-26 19:43:01 +00:00
89 lines
No EOL
2.2 KiB
C#
89 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:
|
|
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;
|
|
}
|
|
}
|
|
} |