111 lines
No EOL
2.2 KiB
C#
111 lines
No EOL
2.2 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
public class Game
|
|
{
|
|
Vector3Int[] poss = new Vector3Int[9 * 7 * 9]; // not bounds compliant...
|
|
|
|
public delegate void Step(int full);
|
|
public static event Step OnStep;
|
|
|
|
public delegate void Eat(Vector3 pos);
|
|
public static event Eat OnEat;
|
|
|
|
public delegate void Smell();
|
|
public static event Smell OnSmell;
|
|
|
|
public delegate void Bump(Vector3 dir);
|
|
public static event Bump OnBump;
|
|
|
|
public delegate void Crash(Vector3 dir);
|
|
public static event Crash OnCrash;
|
|
|
|
|
|
bool danger;
|
|
public void SnakeStep(Main main, Design design) // snake data?
|
|
{
|
|
OnStep(main.growQueue);
|
|
|
|
Vector3Int future = main.snake[0] + main.dir;
|
|
if (main.snake.Contains(future) || Main.OutOfBounds(future, design.bounds))
|
|
{
|
|
if (!danger)
|
|
{
|
|
// main.snake.RemoveAt(0);
|
|
OnBump(main.dir);
|
|
|
|
danger = true;
|
|
}
|
|
else
|
|
{
|
|
main.snake.Insert(0, future);
|
|
|
|
OnCrash(main.dir);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
danger = false;
|
|
|
|
if (Vector3.Distance(future, main.food) <= 1)
|
|
{
|
|
OnSmell();
|
|
}
|
|
|
|
// Grow System (OOP *don't run into tail)
|
|
if (main.growQueue > 0)
|
|
{
|
|
main.growQueue--;
|
|
}
|
|
else
|
|
{
|
|
main.space.Add(main.snake[main.snake.Count - 1]);
|
|
main.snake.RemoveAt(main.snake.Count - 1);
|
|
}
|
|
|
|
main.space.Remove(future);
|
|
main.snake.Insert(0, future); // Grow
|
|
|
|
if (main.fastQueue > 0)
|
|
{
|
|
main.fastQueue--;
|
|
}
|
|
|
|
// Eat Packing Peanut
|
|
if (main.food == future)
|
|
{
|
|
main.growQueue += design.foodValue;
|
|
main.justAte = 0;
|
|
|
|
main.food = main.space[Random.Range(0, main.space.Count)];
|
|
main.graphX.foodScale = 0;
|
|
|
|
OnEat(future);
|
|
}
|
|
|
|
if (main.space.Count <= 1)
|
|
{
|
|
PlayerPrefs.SetInt("BoxFills", 1 + PlayerPrefs.GetInt("BoxFills", 0));
|
|
}
|
|
|
|
// Eat main.Core Piece
|
|
for (int i = 0; i < main.core.Count; i++)
|
|
{
|
|
if (main.core[i] == future)
|
|
{
|
|
main.core.RemoveAt(i);
|
|
|
|
main.growQueue += design.foodValue;
|
|
main.justAte = 0;
|
|
|
|
main.fastQueue += design.foodValue;
|
|
|
|
OnEat(future);
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} |