public bool isGameRunning; //Is the gameplay part of the game currently active? // Start is called before the first frame update void Start() { isGameRunning = true; scoreText.text = "Score: " + currentScore; gameMusic.Play(); myFoodSpawner = GameObject.Find("FoodSpawner").GetComponent <FoodSpawner>(); }
// This routine finds the closest Food gameObject to the animal public virtual GameObject ChooseNearestFood() { // Variables used for finding closest food float distToClosestFood = Mathf.Infinity; GameObject closestFood = null; // Makes sure the we have access to the Food Spawner's script if (FoodSpawnerScript == null) { FoodSpawnerScript = FindObjectOfType <FoodSpawner>(); } // Go through each Food item in the Foods List foreach (GameObject Food in FoodSpawnerScript.Foods) { if (Food != null) { // Work out the distance from each Food item to the animal float distToFood = (Food.transform.position - this.transform.position).sqrMagnitude; // If the distance is smaller than the distance to the current closest Food if (distToFood < distToClosestFood) { // Overwite the closest Food item distToClosestFood = distToFood; // Set the closestFood GameObject to this Food closestFood = Food; } } } // Return the closestFood GameObject return(closestFood); }
void Start() { headChefTransform = GameObject.Find("Head Chef").GetComponent <Transform>(); foodSpawner = GameObject.Find("Scene Manager").GetComponent <FoodSpawner>(); scoreLogic = GameObject.Find("Scene Manager").GetComponent <ScoreLogic>(); foodInteraction = GameObject.Find("Detection Trigger").GetComponent <FoodInteraction>(); }
void MakeInstance() { if (instance == null) { instance = this; } }
// Start is called before the first frame update void Start() { _petMovement = GetComponent <PetMovement>(); _jellyMesh = GetComponent <JellyMesh>(); _renderer = GetComponent <MeshRenderer>(); _animator = GetComponent <Animator>(); _foodSpawner = GameObject.Find("FoodSpawner").GetComponent <FoodSpawner>(); _interactor = GetComponent <PetInteractor>(); _sounds = GetComponent <PetSounds>(); _stats = GetComponent <PetStats>(); string debugActionList = ""; // Use reflection to find every type that inherits from BasePetAction, instansiate it, and stick it in _actions foreach (var type in System.AppDomain.CurrentDomain.GetAllDerivedTypes(typeof(BasePetAction))) { var action = (BasePetAction)Activator.CreateInstance(type); action.Init(gameObject); _actions.Add(action); debugActionList += type.ToString() + " "; } Debug.Log("Loaded " + _actions.Count + " pet actions: " + debugActionList); StartCoroutine(Tick()); }
public void BeforeEveryTest() { _board = new Board(4); _snake = new Snake(); _input = new PlayerInput(new ConstInputSourceMock(KeyCode.UpArrow)); _foodSpawner = new FoodSpawner(new AlwaysMinRandomMock()); _manager = new GameManager(_board, _snake, _input, _foodSpawner); }
public void Food_Spawned_Correctly() { var board = new Board(2); var foodSpawner = new FoodSpawner(new AlwaysMinRandomMock()); foodSpawner.SpawnFood(board); Assert.That(board.Tiles[0].HasFood, Is.True); }
public void Gracefully_Fail_If_No_Remaining_Spawn_Locations() { var board = new Board(1); var foodSpawner = new FoodSpawner(new AlwaysMinRandomMock()); board.Tiles[0].HasSnake = true; Assert.That(foodSpawner.SpawnFood(board), Is.False); }
void Awake() { if (instance != null) { Debug.LogError("More than one food spawner in scene!"); return; } instance = this; }
private void Initialize() { _organ = FindObjectOfType <GameStateManager>().gameStateData.organs[_organIndex]; _effect = _organ.effects[_effectIndex]; player = GameObject.Find("Player"); foodSpawner = FindObjectOfType <FoodSpawner>(); ContainerSprite.SetActive(false); }
void Start() { dialogueCanvas.gameObject.SetActive(true); dialogueText.text = ""; StartCoroutine("Type"); foodSpawner = GetComponent <FoodSpawner>(); playerMovement = GameObject.Find("Player").GetComponent <PlayerMovement>(); animationInput = GameObject.Find("Player").GetComponent <AnimationInput>(); ScriptsAffectedByDialogue(false); }
private void Awake() { if (_instance != null) { Destroy(this); } _instance = this; billy = FindObjectOfType <BillyController>(); spawner = FindObjectOfType <FoodSpawner>(); }
private void Awake() { snake = GameObject.FindGameObjectWithTag("Player"); foodManager = GameObject.Find("FoodController"); foodScript = foodManager.GetComponent <FoodSpawner>(); if (spawnParticles) { ParticleSystem partSys = Instantiate(spawnParticles, transform.position, transform.rotation); partSys.transform.parent = transform; } }
// Use this for initialization void Start() { gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>(); foodSpawn = GameObject.FindGameObjectWithTag("Grid").GetComponent <FoodSpawner>(); grid = foodSpawn.gameObject.GetComponent <Grid>(); direction = Vector3.up; for (int i = 0; i < startLength; i++) { AddTail(); } }
private void Awake() { if (_instance != null && _instance != this) { Destroy(this.gameObject); } else { _instance = this; } }
public void Board_Has_One_Food_Tile() { var board = new Board(3); var snake = new Snake(); var input = new PlayerInput(new ConstInputSourceMock(KeyCode.LeftArrow)); var foodSpawner = new FoodSpawner(new AlwaysMinRandomMock()); var manager = new GameManager(board, snake, input, foodSpawner); Assert.That(board.Tiles[0].HasFood, Is.True); }
public void Odd_Board_Size_Snake_Head_Tile_Set_Correctly() { var board = new Board(3); var snake = new Snake(); var input = new PlayerInput(new ConstInputSourceMock(KeyCode.LeftArrow)); var foodSpawner = new FoodSpawner(new AlwaysMinRandomMock()); var manager = new GameManager(board, snake, input, foodSpawner); Assert.That(snake.Head.Tile, Is.Not.Null); Assert.That(snake.Head.Tile, Is.EqualTo(board.Tiles[4])); }
/// <summary> /// Pull the relevant scripts from the Pet gameobject, called once at start of game /// </summary> /// <param name="pet"></param> public void Init(GameObject pet) { _petMovement = pet.GetComponent <PetMovement>(); _foodSpawner = GameObject.Find("FoodSpawner").GetComponent <FoodSpawner>(); _stockpileArea = GameObject.Find("StockpileArea").GetComponent <StockpileArea>(); _interactor = pet.GetComponent <PetInteractor>(); _sounds = pet.GetComponent <PetSounds>(); _stats = pet.GetComponent <PetStats>(); _observer = pet.GetComponent <PetObserver>(); this._pet = pet; }
private void Start() { inGameUI = FindObjectOfType <InGameUI>(); levMan = FindObjectOfType <LevelManager>(); foodSpawner = FindObjectOfType <FoodSpawner>(); if (snakeSpeed == 0) { snakeSpeed = 4; } InvokeRepeating("SnakeMoving", 0.000001f, 1f / snakeSpeed); }
// Start is called before the first frame update void Start() { _petMovement = GetComponent <PetMovement>(); _jellyMesh = GetComponent <JellyMesh>(); _renderer = GetComponent <MeshRenderer>(); _animator = GetComponent <Animator>(); _foodSpawner = GameObject.Find("FoodSpawner").GetComponent <FoodSpawner>(); _stockpileArea = GameObject.Find("StockpileArea").GetComponent <StockpileArea>(); _interactor = GetComponent <PetInteractor>(); _sounds = GetComponent <PetSounds>(); StartCoroutine(Tick()); }
public void spawnSpawnsFood() { GameObject foodSpawnerContainer = new GameObject(); FoodSpawner spawner = foodSpawnerContainer.AddComponent <FoodSpawner>(); GameObject food = new GameObject(); spawner.food = new GameObject[] { food }; GameObject newFood = spawner.spawn(foodSpawnerContainer.transform.position, foodSpawnerContainer.transform.rotation, 0); Assert.IsNotNull(newFood); }
private void Start() { foreach (Transform child in transform) { spawnPoints.Add(child); } if (spawnPoints.Count == 0) { Debug.LogError("No food spawning points!"); } Singleton = this; }
// Start is called before the first frame update void Start() { foodSpawner = GameObject.Find("FoodSpawner").GetComponent <FoodSpawner>(); levelBounds = GameObject.Find("Floor").gameObject.GetComponent <MeshRenderer>().bounds; Debug.Log(levelBounds); moveStep = Vector3.left; currentPos = new List <Vector3>(); currentPos.Add(transform.position); foreach (Transform child in snakeBody.transform) { currentPos.Add(child.position); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Boundary") || collision.CompareTag("Body")) { Debug.Log("Killed"); Destroy(gameObject); } else if (collision.CompareTag("Food")) { FoodSpawner spawner = collision.GetComponentInParent <FoodSpawner>(); spawner.SpawnFood(); Destroy(collision.gameObject); justAte = true; } }
void Awake() { instance = this; player = Object.FindObjectOfType(typeof(PlayerController)) as PlayerController; nymphSpawner = Object.FindObjectOfType(typeof(NymphSpawner)) as NymphSpawner; foodSpawner = Object.FindObjectOfType(typeof(FoodSpawner)) as FoodSpawner; enemy1Spawner = Object.FindObjectOfType(typeof(Enemy1Spawner)) as Enemy1Spawner; enemy2Spawner = Object.FindObjectOfType(typeof(Enemy2Spawner)) as Enemy2Spawner; player.gameObject.SetActive(false); nymphSpawner.gameObject.SetActive(false); foodSpawner.gameObject.SetActive(false); enemy1Spawner.gameObject.SetActive(false); enemy2Spawner.gameObject.SetActive(false); }
// Use this for initialization void Start() { gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>(); pathFinder = GetComponent <PlayerPathFinder>(); foodSpawn = GameObject.FindGameObjectWithTag("Grid").GetComponent <FoodSpawner>(); grid = foodSpawn.gameObject.GetComponent <Grid>(); direction = Vector3.up; for (int i = 0; i < startLength; i++) { AddTail(); } targetFood = FindFood(); waypoints = pathFinder.FindPath(transform.position, targetFood.position, UnwalkableArea()); }
// Use this for initialization void Start() { //getting the text theText = GetComponent <Text>(); //Start with meal time so that the players don't start with hunger damage [hungerDamage()] startingTime = mealTime; //initialize which scripts to access for stat changes. p1Stats = player1.GetComponent <StatsManager>(); p2Stats = player2.GetComponent <StatsManager>(); spawner = eventSystem.GetComponent <FoodSpawner>(); //start by spawning food spawner.RespawnFood(); }
// Use this for initialization void Awake() { foodPlaceByLevel = new List <int[, ]>(); foodSpawner = GameObject.Find("FoodSpawner").GetComponent <FoodSpawner>(); asset = Resources.Load("pickupObjectPosition") as TextAsset; Debug.Log(asset); data = JsonUtility.FromJson <JsonData>(asset.text); //Inserting 14 level arrays for (int i = 0; i < 14; i++) { foodPlaceByLevel.Insert(foodPlaceByLevel.Count, new int[3, 6]); } buildTiles(); }
public override void _Ready() { _foodLoader = new FoodLoader(true); _orderCreator = new OrderCreator(_foodLoader); _plates = GetNode <Plates>("Plates"); _foodContainer = GetNode <Node2D>("FoodContainer"); _orderContainer = GetNode <Node2D>("OrderContainer"); _foodSpawnerTimer = GetNode <Timer>("Timers/FoodSpawner"); _foodSpawnerTimer.Connect("timeout", this, nameof(SpawnFood)); _gameOverHover = GetNode <Node2D>("GameOverHover"); _scoreContainer = GetNode <Node2D>("ScoreContainer"); _scoreContainer.GetNode <Button>("QuitGameButton").Connect("pressed", this, nameof(QuitGame)); _scoreContainer.GetNode <Button>("NewGameButton").Connect("pressed", this, nameof(StartNewGame)); _twitter1 = GetNode <LinkButton>("Twitter"); _twitter2 = GetNode <LinkButton>("Twitter2"); _twitter1.Connect("pressed", this, nameof(Twitter), new Godot.Collections.Array { "G4MR" }); _twitter2.Connect("pressed", this, nameof(Twitter), new Godot.Collections.Array { "IMG4MR" }); var audio = GetNode <Node>("Audio"); _soundtrack = audio.GetNode <AudioStreamPlayer>("Soundtrack"); _gameoverSoundtrack = audio.GetNode <AudioStreamPlayer>("Gameover"); _itemClick = audio.GetNode <AudioStreamPlayer>("SFX/ItemClick"); _buttonClick = audio.GetNode <AudioStreamPlayer>("SFX/ButtonClick"); _foodSpawner = new FoodSpawner(_plates, _foodLoader, _foodContainer); SpawnEmptyStartOrders(); LoadHighscore(); }
public void Only_One_Food_Per_Board() { var board = new Board(2); var foodSpawner = new FoodSpawner(new LinearRandomMock()); foodSpawner.SpawnFood(board); Assert.That(foodSpawner.SpawnFood(board), Is.False); int tilesWithFood = 0; foreach (Tile tile in board.Tiles) { if (tile.HasFood) { tilesWithFood++; } } Assert.That(tilesWithFood, Is.EqualTo(1)); }