public void PlayerHit(GameGridManager manager) { manager.FlyOutOfView(); var v3 = gameObject.transform.position; Instantiate(ShipExplosion, v3, Quaternion.identity); Destroy(gameObject); }
public void GenerateMap(GameGrid grid, Texture2D map, GameGridManager manager) { for (int widthIndex = 0; widthIndex < map.width; ++widthIndex) { for (int heightIndex = 0; heightIndex < map.height; ++heightIndex) { GenerateObjectForPixel(grid, map, widthIndex, heightIndex, manager); } } }
private void BtnRetry_OnClick(object sender, RoutedEventArgs e) { GameGridManager.Clear(); if (TopFrameManager.Instance.MainFrame.Content is GamePage) { (TopFrameManager.Instance.MainFrame.Content as GamePage).EndGame(disconnect: false); } //Recreate the gamepage TopFrameManager.Instance.MainFrame.Navigate(new GamePage(pt, et, level)); //Close the overlay TopFrameManager.Instance.ClearOverlayFrame(); }
public void GoToMainMenu() { //End the game completely if running if (MainFrame.Content is GamePage) { GameGridManager.Clear(); GamePage gp = (GamePage)MainFrame.Content; gp.EndGame(); } //Clear the overlay frame ClearOverlayFrame(); //Clear the main frame while (MainFrame.CanGoBack) { MainFrame.GoBack(); } }
// Use this for initialization void Start() { GameMusicSource = Instantiate(GameMusicSource); PlayScreenInstance = Instantiate(PlayScreen); PlayScreenInstance.gameObject.SetActive(false); var playText = PlayScreenInstance.GetComponentsInChildren <Text>(); foreach (var text in playText) { if (text.name == "ScoreText") { ScoreText = text; } else if (text.name == "LevelDisplayText") { LevelDisplayText = text; } else if (text.name == "PlayerCount") { PlayerCount = text; } } _manager = GetComponent <GameGridManager>(); enemyController = new EnemyController { GameManager = gameObject, DoomdayShip = DoomdayShip, Enemy1Ship = Enemy1Ship, Enemy2Ship = Enemy2Ship, Enemy3Ship = Enemy3Ship, MarchSpeed = marchSpeed, MaxNumberOfShots = maxFireCount }; displayCredits = false; StartLevel1(); }
internal void GenerateMap(GameObject testobject, GameGrid grid, Texture2D map, GameGridManager manager) { for (int widthIndex = 0; widthIndex < map.width; ++widthIndex) { for (int heightIndex = 0; heightIndex < map.height; ++heightIndex) { if (widthIndex == 3 && heightIndex == 3) { GameObject generatedObject = GameObject.Instantiate(testobject); GridSpace newGridSpace = new GridSpace(widthIndex, heightIndex, generatedObject, generatedObject.GetComponent <WorldObject>().BlocksSquare()); generatedObject.transform.position = new Vector3(widthIndex, heightIndex, -0.1f); grid.AddObjectToGrid(generatedObject); grid.AddGridSpacetoArray(newGridSpace, widthIndex, heightIndex); generatedObject.SetActive(true); generatedObject.GetComponent <TestUnit>().Initialize(map.width, map.height, widthIndex, heightIndex); } GenerateObjectForPixel(grid, map, widthIndex, heightIndex, manager); } } }
private void InitializeGameGrid() { gridManager = gridManagerObject.GetComponent <GameGridManager>(); }
public void Start() { _manager = GetComponentInParent <GameGridManager>(); _lastPos = transform.position; }
/// <summary> /// Creates an instance of GamePage /// </summary> /// <param name="pt">The type of protagonist to generate</param> /// <param name="et">The type of enemy to generate</param> public GamePage(ProtagonistType pt, EnemyType et, Level.Level _level, double protagonistWeight = 1, double enemyWeight = 1) { InitializeComponent(); level = _level; Protagonist = pt; Enemy = et; //Sets up the grid by decoding the int array and placing everything on the canvas level.SetupGrid(ref cvsPlayArea, ref cvsExitArea, pt, et); //Set the characters weights (for turning moments) GameGridManager.Instance.Characters[0].Weight = protagonistWeight; GameGridManager.Instance.Characters[1].Weight = enemyWeight; //Set the canvas of the singleton for easier access to the canvas (so the canvas does //not need to be referenced every tick for the collision detection visualisation to work) GameGridManager.Instance.GameCanvas = cvsPlayArea; //Setup the angles that open the exits ExitingManager.FindAnglesNeededToOpen(level.ExitLocation.HeightFromAnchor, level.ExitLocation.Length); keyboardInputTimer = new DispatcherTimer() { //Every ~1/1000 of a second update Interval = new TimeSpan(0, 0, 0, 0, 1) }; //Have the timer use the timertick event keyboardInputTimer.Tick += KeyboardInputTimerTick; rotationTimer = new DispatcherTimer() { //Update every 1/4 second Interval = new TimeSpan(0, 0, 0, 0, 250) }; rotationTimer.Tick += (s, e) => { double rotation = Rotation.AbsAngleDelta() * Algorithms.Rotation.RotationMultiplier(GameGridManager.Instance.Characters); GameGridManager.RotateStoryBoard((int)rotation); }; //If there is some networking involved within characters then start the communication manager and tie it to the message manager if (gameType == GameType.Networked) { CommunicationManager.Instance.SetupEnemyTypes(pt, et); //Also tell the server that it has received and loaded the map messageInstance = MessageManager.Instance; messageInstance.MessageHandler += HandleMessage; messageInstance.SendMessage("received"); //Also start the timers StartTimers(); } //Setups up AI timer if this is a singleplayer game if (gameType == GameType.Singleplayer) { aiTimer = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 0, 0, 400) }; aiTimer.Tick += AiTimerOnTick; //Also show path tickbox chkShowPath.Visibility = Visibility.Visible; } //Allow keydown so that starts the game etc allowKeyDown = true; }
private void SetManager() { gridManager = GameObject.Find("GameGridManager").GetComponent <GameGridManager>(); }
private void GenerateObjectForPixel(GameGrid grid, Texture2D map, int widthIndex, int heightIndex, GameGridManager manager) { Color pixelColor = map.GetPixel(widthIndex, heightIndex); if (pixelColor.a == 0) { return; } foreach (var colorPrefab in colorToPrefabs) { if (colorPrefab.IsColor(pixelColor)) { GameObject generatedObject = GameObject.Instantiate(colorPrefab.ReturnGameObject()); GridSpace newGridSpace = new GridSpace(widthIndex, heightIndex, generatedObject, generatedObject.GetComponent <WorldObject>().BlocksSquare()); generatedObject.GetComponent <WorldObject>().SetCoordinates(widthIndex, heightIndex); generatedObject.transform.localPosition = new Vector3(widthIndex, heightIndex, -0.1f); grid.AddObjectToGrid(generatedObject); grid.AddGridSpacetoArray(newGridSpace, widthIndex, heightIndex); generatedObject.GetComponent <GridElementClickEvents>().SetGrid(widthIndex, heightIndex); } } }
/// <summary> /// Converts the integer array for the start locations into the grid items, grid views, characters, characters' views, and exitable items /// </summary> /// <param name="protagonistType">The type of protagonist to instantiate</param> /// <param name="enemyType">The type of enemy to instantiate</param> private void DecodeGridStartLocations(ProtagonistType protagonistType, EnemyType enemyType) { GridItem[,] gridItems = new GridItem[yLength(), xLength()]; Character[] characters = new Character[2]; CharacterItem[] charactersView = new CharacterItem[2]; List <Exitable> exitables = new List <Exitable>(); int exitableIndex = 0; for (int y = 0; y < yLength(); y++) { for (int x = 0; x < xLength(); x++) { switch (GridStartLocations[y, x]) { //walkable object case 0: Walkable walkable = new Walkable() { Position = new Position(x, y) }; gridItems[y, x] = walkable; break; //non-walkable object case 1: NonWalkable nonWalkable = new NonWalkable() { Position = new Position(x, y) }; gridItems[y, x] = nonWalkable; break; //player 1 case 2: PlayerOne playerOne = new PlayerOne() { Position = new Position(x, y) }; CharacterItem playerOneItem = new CharacterItem(playerOne); //gridItems[y, x] = playerOneItem; gridItems[y, x] = new Walkable() { Position = new Position(x, y) }; charactersView[0] = playerOneItem; characters[0] = playerOne; break; //Enemy case 3: //Choose which type of Enemy: Enemy enemy = new Enemy(); enemy.Position = new Position(x, y); var enemyItem = new CharacterItem(enemy); gridItems[y, x] = new Walkable { Position = new Position(x, y) }; charactersView[1] = enemyItem; characters[1] = enemy; break; //Exitable block case 5: //Set the array index to the correct value and immedietly increment Exitable exitable = new Exitable(exitableIndex++) { Position = new Position(x, y) }; gridItems[y, x] = exitable; exitables.Add(exitable); break; default: throw new NotImplementedException($"The value of {GridStartLocations[y,x]} is not implemented in Level.Level.GridStartLocation()"); } } } _gridManager = GameGridManager.NewGameGrid(characters, charactersView, gridItems, exitables.ToArray()); }
void Start() { _manager = GetComponentInParent <GameGridManager>(); }