Ejemplo n.º 1
0
    void CheckEnd()
    {
        int goldenSides = 0;

        foreach (pentagon p in pentagons)
        {
            try
            {
                if (p.GetState() >= 4)
                {
                    goldenSides++;
                }
            }
            catch
            {
            }
        }
        if (goldenSides >= 12)
        {
            // Player wins
            Debug.Log("YOU WIN");
            gamestate = gamestates.inBetween;
            Log("Congratulations. You have covered all your sides in gold. Now, take that perfection and smash it into pieces.");
            Log("You've won the game. Play more? Press N for a new game.");
        }
    }
 // Update is called once per frame
 void Update()
 {
     switch (gameState)
     {
     case gamestates.Playing:
         if (!Healthplayer.isAlive)
         {
             gameState = gamestates.GameOver;
             MainCanvas.SetActive(false);
             GameOver.SetActive(true);
         }
         break;
     }
 }
Ejemplo n.º 3
0
        public void killPlayer()
        {
            CCSimpleAudioEngine.SharedEngine.StopBackgroundMusic();
            CCSimpleAudioEngine.SharedEngine.StopAllEffects();
            CCSimpleAudioEngine.SharedEngine.PlayEffect("music/shipBoom");

            _boom.Position = _rocket.Position;
            _boom.ResetSystem();
            _rocket.Visible = false;
            _jet.StopSystem();             // ->stopSystem();
            _lineContainer._lineType = lineTypes.LINE_NONE;

            _running          = false;
            _state            = gamestates.kGameOver;
            _gameOver.Visible = true;
            _pauseBtn.Visible = false;
        }
Ejemplo n.º 4
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            //init game values
            _screenSize = Window.WindowSizeInPixels;             //CCDirector::sharedDirector()->getWinSize();

            _grid = new List <CCPoint>();

            _drawing       = false;
            _minLineLength = (int)(_screenSize.Width * 0.07f);
            _state         = gamestates.kGameIntro;

            createGameScreen();

#if WINDOWS_PHONE
            createParticlesAsync();
#else
            createParticles();
#endif

            createStarGrid();

            //listen for touches
            lTouch = new CCEventListenerTouchAllAtOnce();
            lTouch.OnTouchesBegan = TouchesBegan;
            lTouch.OnTouchesEnded = TouchesEnded;
            lTouch.OnTouchesMoved = TouchesMoved;

            this.AddEventListener(lTouch, this);


            //create main loop
            //this->schedule(schedule_selector(GameLayer::update));
            Schedule();
        }
Ejemplo n.º 5
0
        protected void TouchesEnded(List <CCTouch> touches, CCEvent touchEvent)
        {
            if (_state == gamestates.kGameIntro && !isLoading)
            {
                _intro.Visible    = false;
                _pauseBtn.Visible = true;
                _state            = gamestates.kGamePlay;
                resetGame();
                return;
            }
            else if (_state == gamestates.kGamePaused)
            {
                //_pauseBtn.DisplayFrame = CCSpriteFrameCache.SharedSpriteFrameCache["btn_pause_off.png"];
                _paused.Visible = false;
                _state          = gamestates.kGamePlay;
                _running        = true;
                return;
            }
            else if (_state == gamestates.kGameOver)
            {
                _gameOver.Visible = false;
                _pauseBtn.Visible = true;
                _state            = gamestates.kGamePlay;
                resetGame();
                return;
            }

            if (!_running)
            {
                return;
            }

            CCTouch touch = touches.FirstOrDefault();

            if (touch != null)
            {
                CCPoint tap = touch.LocationOnScreen;;;                   //??¿¿?¿?
                tap.Y = Window.WindowSizeInPixels.Height - tap.Y;

                if (_pauseBtn.BoundingBox.ContainsPoint(tap))
                {
                    _paused.Visible = true;
                    _state          = gamestates.kGamePaused;
                    //	_pauseBtn.DisplayFrame = CCApplication.SharedApplication.SpriteFrameCache["btn_pause_on.png"]; // CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName ("btn_pause_on.png"));
                    _running = false;
                    return;
                }

                //track if tapping on ship
                _drawing = false;
                _rocket.select(false);

                //if we are showing a temp line
                if (_lineContainer._lineType == lineTypes.LINE_TEMP)
                {
                    //set up dashed line
                    _lineContainer._pivot      = tap;
                    _lineContainer._lineLength = CCPoint.Distance(_rocket.Position, tap);

                    //set up rocket
                    _rocket._pivot = tap;
                    float circle_length = _lineContainer._lineLength * 2 * CCMathHelper.Pi;

                    int iterations = (int)Math.Floor(circle_length / _rocket._speed);
                    _rocket._angularSpeed = 2 * CCMathHelper.Pi / iterations;

                    CCPoint clockwise = CCPoint.PerpendicularCW(_rocket.Position - _rocket._pivot);

                    float dot = CCPoint.Dot(clockwise, _rocket._vector);

                    if (dot > 0)
                    {
                        _rocket._angularSpeed        = (_rocket._angularSpeed * -1);
                        _rocket._rotationOrientation = Rocket.ROTATE_CLOCKWISE;
                        _rocket.setTargetRotation(MathHelper.ToDegrees((float)Math.Atan2(clockwise.Y, clockwise.X)));
                    }
                    else
                    {
                        _rocket._rotationOrientation = Rocket.ROTATE_COUNTER;
                        _rocket._targetRotation      = MathHelper.ToDegrees((float)Math.Atan2(-1 * clockwise.Y, -1 * clockwise.X));
                    }

                    _lineContainer._lineType = lineTypes.LINE_DASHED;
                }
            }
        }
Ejemplo n.º 6
0
		protected override void AddedToScene()
		{
			base.AddedToScene();

			//init game values
			_screenSize = Window.WindowSizeInPixels; //CCDirector::sharedDirector()->getWinSize();

			_grid = new List<CCPoint>();

			_drawing = false;
			_minLineLength = (int)(_screenSize.Width * 0.07f);
			_state = gamestates.kGameIntro;

			createGameScreen();

#if WINDOWS_PHONE
            createParticlesAsync();
#else
			createParticles();
#endif

			createStarGrid();

			//listen for touches
			lTouch = new CCEventListenerTouchAllAtOnce();
			lTouch.OnTouchesBegan = TouchesBegan;
			lTouch.OnTouchesEnded = TouchesEnded;
			lTouch.OnTouchesMoved = TouchesMoved;

			this.AddEventListener(lTouch, this);


			//create main loop
			//this->schedule(schedule_selector(GameLayer::update));
			Schedule();
		}
Ejemplo n.º 7
0
		public void killPlayer()
		{

			CCSimpleAudioEngine.SharedEngine.StopBackgroundMusic();
			CCSimpleAudioEngine.SharedEngine.StopAllEffects();
			CCSimpleAudioEngine.SharedEngine.PlayEffect("music/shipBoom");

			_boom.Position = _rocket.Position;
			_boom.ResetSystem();
			_rocket.Visible = false;
			_jet.StopSystem(); // ->stopSystem();
			_lineContainer._lineType = lineTypes.LINE_NONE;

			_running = false;
			_state = gamestates.kGameOver;
			_gameOver.Visible = true;
			_pauseBtn.Visible = false;

		}
Ejemplo n.º 8
0
		protected void TouchesEnded(List<CCTouch> touches, CCEvent touchEvent)
		{

			if (_state == gamestates.kGameIntro && !isLoading)
			{

				_intro.Visible = false;
				_pauseBtn.Visible = true;
				_state = gamestates.kGamePlay;
				resetGame();
				return;

			}
			else if (_state == gamestates.kGamePaused)
			{

				//_pauseBtn.DisplayFrame = CCSpriteFrameCache.SharedSpriteFrameCache["btn_pause_off.png"];
				_paused.Visible = false;
				_state = gamestates.kGamePlay;
				_running = true;
				return;

			}
			else if (_state == gamestates.kGameOver)
			{

				_gameOver.Visible = false;
				_pauseBtn.Visible = true;
				_state = gamestates.kGamePlay;
				resetGame();
				return;

			}

			if (!_running) return;

			CCTouch touch = touches.FirstOrDefault();

			if (touch != null)
			{

				CCPoint tap = touch.LocationOnScreen; ; ; //??¿¿?¿?
				tap.Y = Window.WindowSizeInPixels.Height - tap.Y;

				if (_pauseBtn.BoundingBox.ContainsPoint(tap))
				{
					_paused.Visible = true;
					_state = gamestates.kGamePaused;
					//	_pauseBtn.DisplayFrame = CCApplication.SharedApplication.SpriteFrameCache["btn_pause_on.png"]; // CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName ("btn_pause_on.png"));
					_running = false;
					return;
				}

				//track if tapping on ship
				_drawing = false;
				_rocket.select(false);

				//if we are showing a temp line
				if (_lineContainer._lineType == lineTypes.LINE_TEMP)
				{
					//set up dashed line
					_lineContainer._pivot = tap;
					_lineContainer._lineLength = CCPoint.Distance(_rocket.Position, tap);

					//set up rocket
					_rocket._pivot = tap;
					float circle_length = _lineContainer._lineLength * 2 * CCMathHelper.Pi;

					int iterations = (int)Math.Floor(circle_length / _rocket._speed);
					_rocket._angularSpeed = 2 * CCMathHelper.Pi / iterations;

					CCPoint clockwise = CCPoint.PerpendicularCW(_rocket.Position - _rocket._pivot);

					float dot = CCPoint.Dot(clockwise, _rocket._vector);

					if (dot > 0)
					{
						_rocket._angularSpeed = (_rocket._angularSpeed * -1);
						_rocket._rotationOrientation = Rocket.ROTATE_CLOCKWISE;
						_rocket.setTargetRotation(MathHelper.ToDegrees((float)Math.Atan2(clockwise.Y, clockwise.X)));
					}
					else
					{

						_rocket._rotationOrientation = Rocket.ROTATE_COUNTER;
						_rocket._targetRotation = MathHelper.ToDegrees((float)Math.Atan2(-1 * clockwise.Y, -1 * clockwise.X));
					}

					_lineContainer._lineType = lineTypes.LINE_DASHED;
				}

			}

		}
Ejemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        if (DebugOn)
        {
            if (Input.GetKeyDown(KeyCode.T))
            {
                UpdateMoveOptions(index);
                index += 1;
                if (index > 11)
                {
                    index = 0;
                }
            }
            if (Input.GetKeyDown(KeyCode.O))
            {
                BuyDrillThrough();
            }
        }

        // Reset stage
        if (Input.GetKeyDown(KeyCode.N))
        {
            SceneManager.LoadScene(0);
        }

        // movement on the grid
        // Q E
        // A D
        //  X

        // S for wait / stand still

        if (gameOver)
        {
            gamestate = gamestates.inBetween;
        }


        // player turn
        if (gamestate == gamestates.playerTurn)
        {
            if (DebugOn)
            {
                if (Input.GetKeyDown(KeyCode.B))
                {
                    SpawnEnemy(enemyTypes.eagle, 2);
                }
                if (Input.GetKeyDown(KeyCode.P))
                {
                    SpawnEnemy(enemyTypes.pelican, 2);
                }
                if (Input.GetKeyDown(KeyCode.L))
                {
                    SpawnEnemy(enemyTypes.lion, 2);
                }
            }

            // Item purchasing
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                BuyDrillThrough();
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                BuyHealing();
            }
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                BuyAttack();
            }
            if (Input.GetKeyDown(KeyCode.R))
            {
//                DropRetort();
            }


            // go fetch new move from player input
            int newMove = Movement(index);


            // Regular moves
            if (newMove != -1)
            {
                index = newMove - 1;


                // move player object
                if (MovePlayerObject(newMove))
                {
                    gamestate = gamestates.opponentTurn;
                    // increment turn
                    turnCounter += 1;
                    // When turns pass, it's time to spawn new enemies
                    // check how many tiles are occupied already, don't spawn if more than x are occupied
                    int tilesOccupied = 0;
                    foreach (pentagon p in pentagons)
                    {
                        if (p.GetOccupied())
                        {
                            tilesOccupied++;
                        }
                    }
                    if (tilesOccupied < 8)
                    {
                        if ((turnCounter - turnLastSpawned) > 5)
                        {
                            int r = Random.Range(0, 10);
                            if (r < 5)
                            {
                                // spawn next enemy
                                turnLastSpawned = turnCounter;
                                // either spawn more toads, or the next in the wave
                                int s = Random.Range(0, 10);
                                if (s < 4)
                                {
                                    // spawn toads, but only if the total sum of live toads
                                    // and tiles that are at status one or more is less than 11
                                    int toadTotal = 0;
                                    foreach (pentagon p in pentagons)
                                    {
                                        try
                                        {
                                            if (p.GetOccupier().transform.tag == "BlackToad")
                                            {
                                                toadTotal++;
                                            }
                                            if (p.GetState() > 0)
                                            {
                                                toadTotal++;
                                            }
                                        }
                                        catch
                                        {
                                            Debug.Log("Could not get occupier of pentagon " + p.GetIndex());
                                        }
                                    }
                                    if (toadTotal < 11)
                                    {
                                        SpawnEnemy(enemyTypes.toad, 2);
                                    }
                                }
                                else
                                {
                                    // spawn something else, and do it in sequence
                                    enemyTypeCounter += 1;
                                    if (enemyTypeCounter > 3)
                                    {
                                        enemyTypeCounter = 0;
                                    }
                                    if (enemyTypeCounter == 1)
                                    {
                                        SpawnEnemy(enemyTypes.eagle, 2);
                                    }
                                    else if (enemyTypeCounter == 2)
                                    {
                                        SpawnEnemy(enemyTypes.lion, 2);
                                    }
                                    else if (enemyTypeCounter == 3)
                                    {
                                        SpawnEnemy(enemyTypes.pelican, 2);
                                        enemyTypeCounter = 1;
                                    }
                                }

                                // sometimes also spawn loot
                                if (Random.Range(0, 10) < 5)
                                {
                                    SpawnEnemy(enemyTypes.gold, 1);
                                }
                            }
                        }
                    }

                    GameObject.Find("MovesTaken").GetComponent <Text>().text = "Moves taken: " + turnCounter.ToString();
                    GameObject.Find("HP").GetComponent <Text>().text         = "HP: " + hp.ToString();
                    GameObject.Find("Gold").GetComponent <Text>().text       = "Gold: " + gold.ToString();

                    // Check for win condition
                    // All tiles golden
                    CheckEnd();

                    // AI moves
                    try
                    {
                        if (toads.Count > 0)
                        {
                            for (int i = 0; i < toads.Count; i++)
                            {
                                BasicAIMove(toads[i]);
                            }
                        }
                        if (eagles.Count > 0)
                        {
                            for (int i = 0; i < eagles.Count; i++)
                            {
                                BasicAIMove(eagles[i]);
                            }
                        }
                        if (lions.Count > 0)
                        {
                            for (int i = 0; i < lions.Count; i++)
                            {
                                BasicAIMove(lions[i]);
                            }
                        }
                        if (pelicans.Count > 0)
                        {
                            for (int i = 0; i < pelicans.Count; i++)
                            {
                                BasicAIMove(pelicans[i]);
                            }
                        }
                    }
                    catch
                    {
                        Debug.Log("No opponents left");
                    }
                    gamestate = gamestates.playerTurn;
                }
            }
            //     UpdateMoveOptions(index);
        }
    }