Initialize game with one script

This commit is contained in:
Starpelly
2022-01-03 17:42:43 -05:00
parent 4c83f7fec0
commit 775fd7e580
32 changed files with 2283 additions and 9446 deletions

View File

@ -20,7 +20,7 @@ namespace RhythmHeavenMania
private void Start()
{
Cursor.visible = false;
// Cursor.visible = false;
}
private void Update()
@ -38,7 +38,7 @@ namespace RhythmHeavenMania
if (PlayerInput.Pressed())
{
Cursor.visible = false;
// Cursor.visible = false;
Circle.transform.DOScale(0, 0.5f).SetEase(Ease.OutExpo);
InnerCircle.SetActive(true);
outerCircleTween.Kill();

View File

@ -7,7 +7,7 @@ using Starpelly;
namespace RhythmHeavenMania
{
[RequireComponent(typeof(AudioSource))]
// [RequireComponent(typeof(AudioSource))]
public class Conductor : MonoBehaviour
{
//Song beats per minute

View File

@ -49,6 +49,7 @@ namespace RhythmHeavenMania
CreateDebugUI(out graphicsDeviceName, true); SetText(graphicsDeviceName, SystemInfo.graphicsDeviceName);
CreateDebugUI(out fps, true);
transform.GetChild(0).GetComponent<Canvas>().worldCamera = GameManager.instance.CursorCam;
}
private void Update()

View File

@ -95,9 +95,9 @@ namespace RhythmHeavenMania
new GameAction("alien", delegate { Spaceball.instance.alien.Show(currentBeat); } ),
new GameAction("cameraZoom", delegate { } ),
}),
new MiniGame("karateman", "F6C135", new List<GameAction>()
new MiniGame("karateman", "70A8D8", new List<GameAction>()
{
new GameAction("bop", delegate { KarateMan.instance.Bop(); } ),
new GameAction("bop", delegate { KarateMan.instance.Bop(currentBeat, currentLength); } ),
new GameAction("pot", delegate { KarateMan.instance.Shoot(currentBeat, 0); }, true ),
new GameAction("bulb", delegate { KarateMan.instance.Shoot(currentBeat, 1); }, true ),
new GameAction("rock", delegate { KarateMan.instance.Shoot(currentBeat, 2); }, true ),

View File

@ -16,7 +16,7 @@ namespace RhythmHeavenMania
private EventCaller eventCaller;
public Beatmap Beatmap;
[HideInInspector] public List<Beatmap.Entity> playerEntities;
[HideInInspector] public List<Beatmap.Entity> playerEntities = new List<Beatmap.Entity>();
public int currentEvent, currentPlayerEvent;
@ -37,15 +37,23 @@ namespace RhythmHeavenMania
private List<GameObject> preloadedGames = new List<GameObject>();
[HideInInspector] public GameObject GamesHolder;
private void Awake()
{
instance = this;
}
// before Start() since this is very important
private void OnEnable()
private void Start()
{
SortEventsList();
this.transform.localScale = new Vector3(3000, 3000);
SpriteRenderer sp = this.gameObject.AddComponent<SpriteRenderer>();
sp.enabled = false;
sp.color = Color.black;
sp.sprite = Resources.Load<Sprite>("Sprites/GeneralPurpose/Square");
sp.sortingOrder = 30000;
this.gameObject.layer = 3;
string json = txt.text;
Beatmap = JsonConvert.DeserializeObject<Beatmap>(json);
@ -54,7 +62,8 @@ namespace RhythmHeavenMania
GlobalGameManager.Init();
eventCaller = GetComponent<EventCaller>();
eventCaller = this.gameObject.AddComponent<EventCaller>();
eventCaller.GamesHolder = GamesHolder.transform;
eventCaller.Init();
Conductor.instance.SetBpm(Beatmap.bpm);
@ -136,9 +145,12 @@ namespace RhythmHeavenMania
if (Beatmap.entities.Count > 0)
{
List<float> entities = Beatmap.entities.Select(c => c.beat).ToList();
List<float> entities_p = playerEntities.Select(c => c.beat).ToList();
if (playerEntities != null)
{
List<float> entities_p = playerEntities.Select(c => c.beat).ToList();
currentPlayerEvent = entities_p.IndexOf(Mathp.GetClosestInList(entities_p, beat));
}
currentEvent = entities.IndexOf(Mathp.GetClosestInList(entities, beat));
currentPlayerEvent = entities_p.IndexOf(Mathp.GetClosestInList(entities_p, beat));
print(currentEvent);

View File

@ -22,6 +22,9 @@ namespace RhythmHeavenMania.Games.KarateMan
private bool bgEnabled;
private int newBeat;
private float bopLength;
private float bopBeat;
[System.Serializable]
public class BGSpriteC
{
@ -35,17 +38,26 @@ namespace RhythmHeavenMania.Games.KarateMan
private void Update()
{
if (bgEnabled)
if (Conductor.instance.songPositionInBeats > newBeat)
{
if (Conductor.instance.songPositionInBeats > newBeat)
if (bgEnabled)
{
if (newBeat % 2 == 0)
BGSprite.sprite = BGSprites[0].Sprites[1];
else
BGSprite.sprite = BGSprites[0].Sprites[2];
newBeat++;
}
if (Conductor.instance.songPositionInBeats >= bopBeat && Conductor.instance.songPositionInBeats < bopBeat + bopLength)
{
if (KarateJoe.anim.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1 && !KarateJoe.anim.IsInTransition(0))
KarateJoe.anim.Play("Bop", 0, 0);
print("bop");
}
newBeat++;
}
}
@ -104,9 +116,10 @@ namespace RhythmHeavenMania.Games.KarateMan
}
}
public void Bop()
public void Bop(float beat, float length)
{
KarateJoe.anim.Play("Bop", 0, 0);
bopLength = length;
bopBeat = beat;
}
}
}

View File

@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania
{
public class Initializer : MonoBehaviour
{
public TextAsset level;
public AudioClip music;
private void Start()
{
GameObject Cameras = Instantiate(Resources.Load<GameObject>("Prefabs/Cameras")); Cameras.name = "Cameras";
GameObject MainCamera = Cameras.transform.GetChild(0).gameObject;
GameObject CursorCamera = Cameras.transform.GetChild(1).gameObject;
GameObject Cursor = Instantiate(Resources.Load<GameObject>("Prefabs/Cursor"));
Cursor.name = "Cursor";
GameObject Games = new GameObject();
Games.name = "Games";
GameObject GameManager = new GameObject();
GameManager.name = "GameManager";
GameManager gameManager = GameManager.AddComponent<GameManager>();
gameManager.txt = level;
gameManager.GamesHolder = Games;
gameManager.CircleCursor = Cursor.transform.GetChild(0).GetComponent<CircleCursor>();
gameManager.GameCamera = MainCamera.GetComponent<Camera>();
gameManager.CursorCam = CursorCamera.GetComponent<Camera>();
GameObject Profiler = Instantiate(Resources.Load<GameObject>("Prefabs/GameProfiler"));
Profiler.name = "GameProfiler";
GameObject Conductor = new GameObject();
Conductor.name = "Conductor";
Conductor.AddComponent<AudioSource>().clip = music;
Conductor.AddComponent<Conductor>();
Conductor.AddComponent<AudioDspTimeKeeper>();
}
}
}

View File

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

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 20cdf044bf1f13b42af96f23ac825cff
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace RhythmHeavenMania.Editor
{
public class Editor : MonoBehaviour
{
private Initializer Initializer;
[Header("Rect")]
[SerializeField] private RenderTexture ScreenRenderTexture;
[SerializeField] private RawImage Screen;
private void Start()
{
Initializer = GetComponent<Initializer>();
GameManager.instance.GameCamera.targetTexture = ScreenRenderTexture;
GameManager.instance.CursorCam.targetTexture = ScreenRenderTexture;
Screen.texture = ScreenRenderTexture;
}
}
}

View File

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