2023-02-20 05:48:50 +00:00
|
|
|
using System;
|
2021-12-25 12:16:40 +00:00
|
|
|
using System.Collections.Generic;
|
2023-02-20 05:48:50 +00:00
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Util;
|
2021-12-25 12:16:40 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio.Games.Scripts_Spaceball
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
|
|
|
public class SpaceballPlayer : MonoBehaviour
|
|
|
|
{
|
2023-02-20 05:48:50 +00:00
|
|
|
private Animator _anim;
|
|
|
|
private int _currentCostume;
|
2021-12-26 07:25:17 +00:00
|
|
|
|
|
|
|
public SpriteRenderer PlayerSprite;
|
2023-02-20 05:48:50 +00:00
|
|
|
public SpriteRenderer Hat;
|
|
|
|
|
|
|
|
public HatSprite HatSprites1 = new HatSprite();
|
|
|
|
public HatSprite HatSprites2 = new HatSprite();
|
2021-12-26 07:25:17 +00:00
|
|
|
|
2023-02-20 05:48:50 +00:00
|
|
|
[Serializable]
|
|
|
|
public struct HatSprite
|
2021-12-26 07:25:17 +00:00
|
|
|
{
|
2023-02-20 05:48:50 +00:00
|
|
|
public List<Vector2> Offsets;
|
|
|
|
public List<Sprite> Sprites;
|
2021-12-26 07:25:17 +00:00
|
|
|
}
|
|
|
|
|
2021-12-25 12:16:40 +00:00
|
|
|
public static SpaceballPlayer instance { get; set; }
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
instance = this;
|
2023-02-20 05:48:50 +00:00
|
|
|
_anim = GetComponent<Animator>();
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (PlayerInput.Pressed())
|
|
|
|
{
|
2022-01-23 07:01:59 +00:00
|
|
|
Swing(null);
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 05:48:50 +00:00
|
|
|
public void SetCostume(Material mat, int costumeIndex)
|
2021-12-26 07:25:17 +00:00
|
|
|
{
|
2023-02-20 05:48:50 +00:00
|
|
|
PlayerSprite.material = mat;
|
|
|
|
_currentCostume = costumeIndex;
|
|
|
|
_anim.Play("Idle", 0, 0);
|
2021-12-26 07:25:17 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
public void Swing(SpaceballBall b)
|
2021-12-25 12:16:40 +00:00
|
|
|
{
|
2022-01-23 07:01:59 +00:00
|
|
|
if (b == null)
|
2022-01-17 05:00:26 +00:00
|
|
|
{
|
2022-01-21 01:24:30 +00:00
|
|
|
Jukebox.PlayOneShotGame("spaceball/swing");
|
2022-01-23 07:01:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-26 07:25:17 +00:00
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
}
|
2023-02-20 05:48:50 +00:00
|
|
|
_anim.Play("Swing", 0, 0);
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 05:48:50 +00:00
|
|
|
public void SetHatFrame(int frame)
|
2021-12-26 07:25:17 +00:00
|
|
|
{
|
2023-02-20 05:48:50 +00:00
|
|
|
// Unity can't serialize lists inside lists in this version, so that's annoying.
|
|
|
|
var sprites = new HatSprite();
|
|
|
|
switch (_currentCostume)
|
|
|
|
{
|
|
|
|
case 0:
|
2023-04-12 22:34:15 +00:00
|
|
|
Hat.sprite = null;
|
2023-02-20 05:48:50 +00:00
|
|
|
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;
|
2021-12-26 07:25:17 +00:00
|
|
|
}
|
2021-12-25 12:16:40 +00:00
|
|
|
}
|
|
|
|
}
|