public void IncreaseSlide()
 {
     if ((int)currentInstractionState < slides.Length - 1)
     {
         currentInstractionState = (InstructionState)((int)currentInstractionState + 1);
         ShowSlide((int)currentInstractionState);
     }
 }
Пример #2
0
 protected override void prepareContent(ContentManager content)
 {
     texBackground   = content.Load <Texture2D>("Images/splashBackground");
     texPharaoh      = content.Load <Texture2D>("Images/pharaohSkull");
     vtPharaohCenter = new Vector2(texPharaoh.Width / 2, 154);
     vtPharaoh       = new Vector2(800 / 2 - 18 * 20, 480 / 2);
     _state          = InstructionState.FadeIn;
     _pageAlpha      = 0;
 }
Пример #3
0
 public void ForceInstructions()
 {
     DisplayVisualComponents(true);
     HideManomotionComponents();
     currentInstractionState = InstructionState.BackgroundModeSelection;
     ShowSlide((int)currentInstractionState);
     PlayerPrefs.SetInt("hasSeenInstructions", 1);
     GetPreviousManoVisualizationValues();
     TurnOffManovizualizationValues();
 }
Пример #4
0
        public Menus(GameState gameState, InstructionState instructionState,
                     GraphicsDevice graphicsDevice,
                     float stringScale, double ScreenWidth, double ScreenHeight,
                     SpriteFont bigFont, SpriteFont font1,
                     Texture2D selecterArrowTexture, Texture2D splashScreenTexture, Texture2D allPurposeTexture,
                     Rectangle splashScreen)
        {
            this.g                    = graphicsDevice;
            this.stringScale          = stringScale;
            this.ScreenWidth          = ScreenWidth;
            this.ScreenHeight         = ScreenHeight;
            this.bigFont              = bigFont;
            this.font1                = font1;
            this.selecterArrowTexture = selecterArrowTexture;
            this.splashScreenTexture  = splashScreenTexture;
            this.splashScreen         = splashScreen;
            this.allPurposeTexture    = allPurposeTexture;

            quitButtonPos   = new Vector2((int)ScreenWidth / 3 - 10, (int)(ScreenHeight / 1.40));
            restartButonPos = new Vector2((int)ScreenWidth / 3 - 10, (int)(ScreenHeight / 1.50));

            red               = 0;
            green             = 0;
            blue              = 0;
            splashScreenColor = new Color(red, green, blue);

            roundOverTimer  = 0;
            gameOverTimer   = 0;
            round           = 1;
            seconds         = 0;
            gameOverSeconds = 0;
            p1Wins          = 0;
            p2Wins          = 0;

            roundString         = "Round Over";
            roundCountString    = "Next round starts in ";
            gameOverString      = "Game Over";
            gameOverCountString = "Return to Start Screen in ";
            p1RoundWin          = "Player 1 wins the round!";
            p2RoundWin          = "Player 2 wins the round!";
            p1GameWin           = "Player 1 Wins!";
            p2GameWin           = "Player 2 Wins!";

            selecterArrow = new Rectangle(g.Viewport.Width / 3, 500, 50, 50);
            pausedArrow   = new Rectangle((int)ScreenWidth / 3 - 50, (int)ScreenHeight / 2, 50, 50);
            timer         = 0;
            AspectRatio   = (float)ScreenWidth / (float)ScreenHeight;

            p1 = new Player(true, new Rectangle(200, 100, 20, 20), allPurposeTexture);
            p2 = new Player(false, new Rectangle(240, 100, 20, 20), allPurposeTexture);

            currentP1Points = p1.points;
            currentP2Points = p1.points;
        }
Пример #5
0
 public Cpu(Memory memory)
 {
     Memory = memory;
     PC     = 0x0000;
     S      = 0xff;
     P      = ProcessorStatus._;
     A      = 0;
     X      = 0;
     Y      = 0;
     _currentInstructionState = InstructionState.FetchOpCode;
     _currentCycle            = 0;
 }
Пример #6
0
 public Menus(GameState gameState, InstructionState instructionState, GraphicsDevice graphicsDevice, float stringScale, double ScreenWidth, double ScreenHeight, SpriteFont bigFont, SpriteFont font1, Texture2D selecterArrowTexture)
 {
     g                         = graphicsDevice;
     selecterArrow             = new Rectangle(g.Viewport.Width / 3, 500, 50, 50);
     this.stringScale          = stringScale;
     this.ScreenWidth          = ScreenWidth;
     this.ScreenHeight         = ScreenHeight;
     this.bigFont              = bigFont;
     this.font1                = font1;
     AspectRatio               = (float)ScreenWidth / (float)ScreenHeight;
     this.selecterArrowTexture = selecterArrowTexture;
 }
Пример #7
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // escape key missing

            // Add your update logic here
            KeyboardState kb = Keyboard.GetState();

            // Methods from the Menus class to run the menus
            menus.Navigations(gameState, instructionState, kb, CurrentBackgroundC, oldKb, timer, gameOverTimer);
            gameState        = menus.GameStateValue();
            instructionState = menus.InstructionStateValue();

            if (gameState == GameState.Game)
            {
                // Update Player collision with map obstacles.
                firstMap.MapPlayerCollisions(p1);
                firstMap.MapPlayerCollisions(p2);

                CurrentBackgroundC = firstMap.FLOORCOLOR;

                p1.update(1, p2);
                p2.update(2, p1);

                RoundOverCheck();
            }
            if (menus.ReturnTimer() >= 240)
            {
                //Reset
                //p1.Reset();
                //p2.Reset();
                //CurrentBackgroundC = Color.Black;
            }

            // Keep so the player can choose to exit the game
            if (gameState == GameState.Exit)
            {
                this.Exit();
            }

            // Splash screen timer
            timer++;

            if (MediaPlayer.State == MediaState.Stopped)
            {
                MediaPlayer.Play(songs[0]);
            }

            oldKb = kb;

            base.Update(gameTime);
        }
Пример #8
0
 public void Emit()
 {
     State = InstructionState.Success;
     foreach (var instr in instrs)
     {
         instr.Emit();
         if (instr.State != InstructionState.Success)
         {
             State = InstructionState.Failure;
             break;
         }
     }
     command.OnNotifyInstructionComplete(this);
 }
Пример #9
0
 public void Emit()
 {
     State = InstructionState.Success;
     foreach (var instr in instrs)
     {
         instr.Emit();
         if (instr.State != InstructionState.Success)
         {
             State = InstructionState.Failure;
             break;
         }
     }
     command.OnNotifyInstructionComplete(this);
 }
Пример #10
0
 void Start()
 {
     rigidbody               = GetComponent <Rigidbody2D> ();
     current                 = InstructionState.none;
     rigidbody.velocity      = new Vector2(0, 0);
     IsTouchingDeflater      = false;
     IsTouchingDeflaterCover = false;
     currentDeflater         = null;
     currentIndicator        = null;
     IsOnGround              = false;
     ResidualClick           = false;
     WasRestGood             = true;
     Time.timeScale          = 0;
     TurnOffGround           = false;
 }
Пример #11
0
 //----------------------------------------------------------------------------------------------------
 /// <summary>
 /// 命令状態の更新
 /// </summary>
 void UpdateInstructionState()
 {
     //タイムライン
     if (m_countTimeInstruction >= m_instructionAppearanceTime + m_instructionDisplayTime)
     {
         m_instructionState = InstructionState.Withdraw;
     }
     else if (m_countTimeInstruction >= m_instructionAppearanceTime)
     {
         m_instructionState = InstructionState.Display;
     }
     else
     {
         m_instructionState = InstructionState.Appearance;
     }
 }
Пример #12
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            gameState        = GameState.StartScreen;
            instructionState = InstructionState.Page1;
            selecterArrow    = new Rectangle(GraphicsDevice.Viewport.Width / 3, 500, 50, 50);

            AspectRatio        = ScreenWidth / ScreenHeight;
            CurrentBackgroundC = Color.Black;

            oldKb = Keyboard.GetState();

            IsMouseVisible = true;

            base.Initialize();
        }
Пример #13
0
 public void StartInstructions()
 {
     GetPreviousManoVisualizationValues();
     if (PlayerPrefs.GetInt("hasSeenInstructions") == 0)
     {
         Debug.Log("has seen is 0");
         DisplayVisualComponents(true);
         HideManomotionComponents();
         currentInstractionState = InstructionState.BackgroundModeSelection;
         ShowSlide((int)currentInstractionState);
         PlayerPrefs.SetInt("hasSeenInstructions", 1);
         GetPreviousManoVisualizationValues();
         TurnOffManovizualizationValues();
     }
     else
     {
         Debug.Log("has seen is 1");
         StopShowingInstructions();
         ShowManomotionComponents();
     }
 }
Пример #14
0
 public void Emit()
 {
     using (var scope = ObjectHost.Host.BeginLifetimeScope())
     {
         lock (syncRoot)
         {
             State = InstructionState.Emit;
             var session = scope.Resolve <SerialShell>().Open();
             session.RemoveAttribute(KeyName.INSTRUCTION);
             session.SetAttribute(KeyName.INSTRUCTION, this);
             session.Write(this.BuildPacket(parameter));
             timing.Start();
             if (!Monitor.Wait(syncRoot, Timeout))
             {
                 timing.Stop();
                 State = InstructionState.Failure;
                 Retry();
             }
         }
     }
 }
Пример #15
0
 public void Emit()
 {
     using (var scope = ObjectHost.Host.BeginLifetimeScope())
     {
         lock (syncRoot)
         {
             State = InstructionState.Emit;
             var session = scope.Resolve<SerialShell>().Open();
             session.RemoveAttribute(KeyName.INSTRUCTION);
             session.SetAttribute(KeyName.INSTRUCTION, this);
             session.Write(this.BuildPacket(parameter));
             timing.Start();
             if (!Monitor.Wait(syncRoot, Timeout))
             {
                 timing.Stop();
                 State = InstructionState.Failure;
                 Retry();
             }
         }
     }
 }
Пример #16
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Add your update logic here
            KeyboardState kb = Keyboard.GetState();

            menus.Navigations(gameState, instructionState, kb, CurrentBackgroundC, oldKb);
            gameState        = menus.GameStateValue();
            instructionState = menus.InstructionStateValue();

            if (gameState == GameState.Game)
            {
                CurrentBackgroundC = firstMap.FLOORCOLOR;
                p1.update(1, p2);
                p2.update(2, p1);
                p1Border = new Rectangle(p1.pRect.X + 3, p1.pRect.Y + 3, p1.pRect.Width - 6, p1.pRect.Height - 6);
                p2Border = new Rectangle(p2.pRect.X + 3, p2.pRect.Y + 3, p2.pRect.Width - 6, p2.pRect.Height - 6);
            }
            oldKb = kb;

            base.Update(gameTime);
        }
Пример #17
0
        private void InterceptOutput(object sender, BigInteger e)
        {
            switch (_instructionState)
            {
            case InstructionState.XIndex:
                _xCoordinate      = (int)e;
                _instructionState = InstructionState.YIndex;
                break;

            case InstructionState.YIndex:
                _yCoordinate      = (int)e;
                _instructionState = InstructionState.TileType;
                break;

            case InstructionState.TileType:
                _instructionState = InstructionState.XIndex;

                Track((_xCoordinate, _yCoordinate), (int)e);
                break;
            }
            ;
        }
Пример #18
0
        private void Advance(object sender, BigInteger e)
        {
            switch (_instructionState)
            {
            case InstructionState.XIndex:
                _xCoordinate      = (int)e;
                _instructionState = InstructionState.YIndex;
                break;

            case InstructionState.YIndex:
                _yCoordinate      = (int)e;
                _instructionState = InstructionState.TileType;
                break;

            case InstructionState.TileType:
                _gameView.Draw(new Coordinate(_xCoordinate, _yCoordinate), (int)e);
                _instructionState = InstructionState.XIndex;

                _gameState.Advance(e);
                break;
            }
            ;
        }
Пример #19
0
        public void RunCycle()
        {
            _currentCycle++;

            if (_currentInstructionState == InstructionState.FetchOpCode)
            {
                var opCode = Memory.Mem[PC];
                if (!Operands.List.TryGetValue(opCode, out _currentOperand))
                {
                    _logger.Fatal($"Unknown operand for opCode {opCode}, pc={PC}.");
                    throw new NotImplementedException();
                }

                _currentInstructionState = InstructionState.RunOp;
            }

            _currentOperand = _currentOperand.Run(_currentOperand, this);

            if (_currentOperand.Tim > _currentOperand.MaxTim)
            {
                _currentInstructionState = InstructionState.FetchOpCode;
            }
        }
Пример #20
0
    private static LocalVar MergeLocals(List <LocalVar> locals, Dictionary <long, LocalVar> localByStoreSite, LocalVar l1, LocalVar l2)
    {
        Debug.Assert(l1 != l2);
        Debug.Assert(l1.local == l2.local);
        for (int i = 0; i < locals.Count; i++)
        {
            if (locals[i] == l2)
            {
                locals.RemoveAt(i);
                i--;
            }
        }
        Dictionary <long, LocalVar> temp = new Dictionary <long, LocalVar>(localByStoreSite);

        localByStoreSite.Clear();
        foreach (KeyValuePair <long, LocalVar> kv in temp)
        {
            localByStoreSite[kv.Key] = kv.Value == l2 ? l1 : kv.Value;
        }
        l1.isArg |= l2.isArg;
        l1.type   = InstructionState.FindCommonBaseType(l1.type, l2.type);
        Debug.Assert(l1.type != VerifierTypeWrapper.Invalid);
        return(l1);
    }
Пример #21
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.name.Equals("click detector"))
        {
            //Assign the click indicator
            currentIndicator = col.transform.parent.GetChild(0).GetChild(1).GetComponent <ClickIndicator>();
            if (col.tag.Equals("quarter"))
            {
                current = InstructionState.quarter_note;
            }
            else if (col.tag.Equals("half"))
            {
                current = InstructionState.half_note;
            }
            else if (col.tag.Equals("eight note 1"))
            {
                current = InstructionState.eight_note_1;
            }
            else if (col.tag.Equals("eight note 2"))
            {
                current = InstructionState.eight_note_2;
            }
            else if (col.tag.Equals("rest"))
            {
                current = InstructionState.rest;
                currentIndicator.ChangeColor(Color.yellow);
            }
            else if (col.tag.Equals("whole"))
            {
                current          = InstructionState.whole;
                manager.groundY -= manager.stepHeight;
            }
        }

        if (col.tag.Equals("flag"))
        {
            manager.SetGameState(GameManager.GameState.FINISHED);
        }

        if (col.tag.Equals("soundbar"))
        {
            manager.playBeat();
        }
        else if (col.tag.Equals("musicbar"))
        {
            manager.playMusic();
        }
        else if (col.tag.Equals("deflater"))
        {
            IsTouchingDeflater = true;
        }
        else if (col.tag.Equals("deflater cover"))
        {
            IsTouchingDeflaterCover = true;
            currentDeflater         = col.GetComponentInParent <DeflaterManager> ();
        }
        else if (col.tag.Equals("pogo") || col.tag.Equals("last pogo"))
        {
            if (Input.GetMouseButton(0))
            {
                rigidbody.gravityScale = gravityScaleSingleJump;
                manager.OnBallTouchPogo(
                    col.transform.parent.GetChild(1),
                    velocity,
                    rigidbody.gravityScale * 9.81f
                    );
            }
            if (col.tag.Equals("pogo"))
            {
                if (Input.GetMouseButton(0))
                {
                    manager.IncreaseScore(10);
                }
            }
            else
            {
                if (Input.GetMouseButton(0))
                {
                    TurnOffGround = true;
                    manager.IncreaseScore(5);
                }
            }
        }
        if (col.tag.Equals("pogo"))
        {
            manager.groundY -= manager.stepHeight;
        }

        // For tutorial
        if (col.tag.Equals("tut_click"))
        {
            manager.TutClick();
        }
        else if (col.tag.Equals("tut_unclick"))
        {
            manager.TutUnclick();
        }
    }
Пример #22
0
	public void UpdateInstruction(InstructionState instructionState){
		for(int i=0; i<(int)CharacterIndex.SIZE; i++){
			_instructionList[i].sprite = _instructionSpriteList[(int)instructionState];
		}
	}
Пример #23
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // escape key missing

            // Add your update logic here
            KeyboardState kb = Keyboard.GetState();

            // Code for start screen
            if (gameState == GameState.StartScreen)
            {
                CurrentBackgroundC = Color.Black;

                if (kb.IsKeyDown(Keys.Up) && oldKb != kb)
                {
                    selecterArrow.Y = selecterArrow.Y - 100;
                }

                if (kb.IsKeyDown(Keys.Down) && oldKb != kb)
                {
                    selecterArrow.Y = selecterArrow.Y + 100;
                }

                if (selecterArrow.Y < 500)
                {
                    selecterArrow.Y = 700;
                }

                if (selecterArrow.Y > 700)
                {
                    selecterArrow.Y = 500;
                }

                if (kb.IsKeyDown(Keys.Enter) && selecterArrow.Y == 500)
                {
                    gameState = GameState.Instructions;
                }

                if (kb.IsKeyDown(Keys.Enter) && selecterArrow.Y == 600)
                {
                    gameState = GameState.Game;
                }

                if (kb.IsKeyDown(Keys.Enter) && selecterArrow.Y == 700)
                {
                    this.Exit();
                }
            }

            // Code for insturction screen
            if (gameState == GameState.Instructions)
            {
                if (kb.IsKeyDown(Keys.Escape) && oldKb != kb)
                {
                    gameState = GameState.StartScreen;
                }

                if (kb.IsKeyDown(Keys.Right) && instructionState == InstructionState.Page1 && oldKb != kb)
                {
                    instructionState = InstructionState.Page2;
                }

                else if (kb.IsKeyDown(Keys.Right) && instructionState == InstructionState.Page2 && oldKb != kb)
                {
                    instructionState = InstructionState.Page3;
                }

                else if (kb.IsKeyDown(Keys.Left) && instructionState == InstructionState.Page3 && oldKb != kb)
                {
                    instructionState = InstructionState.Page2;
                }

                else if (kb.IsKeyDown(Keys.Left) && instructionState == InstructionState.Page2 && oldKb != kb)
                {
                    instructionState = InstructionState.Page1;
                }
            }

            if (gameState == GameState.Game)
            {
                CurrentBackgroundC = firstMap.FLOORCOLOR;
                p1.update(1, p2);
                p2.update(2, p1);
                p1Border = new Rectangle(p1.pRect.X + 3, p1.pRect.Y + 3, p1.pRect.Width - 6, p1.pRect.Height - 6);
                p2Border = new Rectangle(p2.pRect.X + 3, p2.pRect.Y + 3, p2.pRect.Width - 6, p2.pRect.Height - 6);
            }
            oldKb = kb;

            base.Update(gameTime);
        }
Пример #24
0
        // Method for menu navigations and splash screen. Round over and game over screens still need work
        public void Navigations(GameState gameState, InstructionState instructionState, KeyboardState kb, Color CurrentBackgroundC, KeyboardState oldKb,
                                int timer, int gameOverTimer)
        {
            // Code for start screen
            if (gameState == GameState.StartScreen)
            {
                CurrentBackgroundC = Color.Black;

                if (kb.IsKeyDown(Keys.Up) && oldKb != kb)
                {
                    selecterArrow.Y = selecterArrow.Y - 100;
                }

                if (kb.IsKeyDown(Keys.Down) && oldKb != kb)
                {
                    selecterArrow.Y = selecterArrow.Y + 100;
                }

                if (selecterArrow.Y < 500)
                {
                    selecterArrow.Y = 700;
                }

                if (selecterArrow.Y > 700)
                {
                    selecterArrow.Y = 500;
                }

                if (kb.IsKeyDown(Keys.Enter) && selecterArrow.Y == 500 && !oldKb.IsKeyDown(Keys.Enter))
                {
                    this.MenuGameState = GameState.Instructions;
                }

                if (kb.IsKeyDown(Keys.Enter) && selecterArrow.Y == 600)
                {
                    this.MenuGameState = GameState.Game;
                }

                if (kb.IsKeyDown(Keys.Enter) && selecterArrow.Y == 700)
                {
                    this.MenuGameState = GameState.Exit;
                }
            }

            // Code for instruction screen
            if (gameState == GameState.Instructions)
            {
                if (kb.IsKeyDown(Keys.Escape) && oldKb != kb)
                {
                    this.MenuGameState = GameState.StartScreen;
                }

                if (kb.IsKeyDown(Keys.Right) && instructionState == InstructionState.Page1 && oldKb != kb)
                {
                    this.instructionState = InstructionState.Page2;
                }

                else if (kb.IsKeyDown(Keys.Left) && instructionState == InstructionState.Page2 && oldKb != kb)
                {
                    this.instructionState = InstructionState.Page1;
                }
            }

            // Splash Screen code
            if (gameState == GameState.SplashScreen)
            {
                timer++;

                if (timer >= 370)
                {
                    this.MenuGameState = GameState.StartScreen;
                }
            }

            // Code for round over screen
            if (gameState == GameState.RoundOver)
            {
                selecterArrow.Y = (int)(restartButonPos.Y);

                if (round == 3)
                {
                    MenuGameState = GameState.GameOver;
                }

                if (round != 3)
                {
                    if (roundOverTimer <= 60)
                    {
                        seconds = 3;
                    }

                    else if (roundOverTimer <= 120)
                    {
                        seconds = 2;
                    }

                    else if (roundOverTimer <= 180)
                    {
                        seconds = 1;
                    }

                    if (roundOverTimer >= 240)
                    {
                        if (p1.points == 50)
                        {
                            p2Wins += 1;
                        }

                        else if (p2.points == 50)
                        {
                            p1Wins += 1;
                        }

                        seconds = 0;
                        // Resets game
                        this.MenuGameState = GameState.Game;
                        roundOverTimer     = 0;
                        round++;
                    }
                }

                roundOverTimer++;
            }

            // Code for game over screen
            if (gameState == GameState.GameOver)
            {
                if (gameOverTimer <= 60)
                {
                    gameOverSeconds = 3;
                }

                else if (gameOverTimer <= 120)
                {
                    gameOverSeconds = 2;
                }

                else if (gameOverTimer <= 180)
                {
                    gameOverSeconds = 1;
                }

                if (gameOverTimer >= 240)
                {
                    gameOverSeconds    = 0;
                    this.MenuGameState = GameState.StartScreen;
                    gameOverTimer      = 0;
                }

                selecterArrow.X = (int)(quitButtonPos.X * 0.9);

                if (selecterArrow.Y == quitButtonPos.Y && kb != oldKb && kb.IsKeyDown(Keys.Up))
                {
                    selecterArrow.Y = (int)(restartButonPos.Y); // was here
                }
                else if (selecterArrow.Y == restartButonPos.Y && kb != oldKb && kb.IsKeyDown(Keys.Down))
                {
                    selecterArrow.Y = (int)(quitButtonPos.Y);
                }

                if (selecterArrow.Y == quitButtonPos.Y && kb.IsKeyDown(Keys.Enter))
                {
                    MenuGameState = GameState.Exit;
                }
                else if (selecterArrow.Y == restartButonPos.Y && kb.IsKeyDown(Keys.Enter))
                {
                    MenuGameState = GameState.StartScreen;
                    resetMenus();
                }



                gameOverTimer++;
            }

            if (gameState == GameState.Paused)
            {
                if (kb.IsKeyDown(Keys.Down) && oldKb != kb)
                {
                    pausedArrow.Y += 60;
                }

                if (kb.IsKeyDown(Keys.Up) && oldKb != kb)
                {
                    pausedArrow.Y -= 60;
                }

                if (pausedArrow.Y > (int)ScreenHeight / 2 + 60)
                {
                    pausedArrow.Y = (int)ScreenHeight / 2;
                }

                if (pausedArrow.Y < (int)ScreenHeight / 2)
                {
                    pausedArrow.Y = (int)ScreenHeight / 2 + 60;
                }

                if (kb.IsKeyDown(Keys.Enter) && pausedArrow.Y == (int)ScreenHeight / 2)
                {
                    gameState = GameState.Game;
                }

                if (kb.IsKeyDown(Keys.Enter) && pausedArrow.Y == (int)ScreenHeight / 2 + 60)
                {
                    gameState = GameState.StartScreen;
                }
            }
        }
Пример #25
0
        // Draws the splash screen, menus, round over and game over screens
        public void drawMenus(SpriteBatch spriteBatch, GameState gameState, InstructionState instructionState, int timer, String winner)
        {
            // Start screen
            if (gameState == GameState.StartScreen)
            {
                spriteBatch.DrawString(bigFont, "Crazy Mazey Tag", new Vector2(g.Viewport.Width / 5, 25), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(bigFont, "Crazy Mazey Tag", new Vector2(g.Viewport.Width / 5, 25), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale, SpriteEffects.None,
                                       0f);
                spriteBatch.DrawString(font1, "Use the Arrow Keys to move the arrow", new Vector2(g.Viewport.Width / 4 - 30, 200), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                       SpriteEffects.None, 0f);
                spriteBatch.DrawString(font1, "Use the Enter Key to select an option", new Vector2(g.Viewport.Width / 4 - 30, 250), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                       SpriteEffects.None, 0f);
                spriteBatch.DrawString(font1, "Instructions", new Vector2(g.Viewport.Width / 3 + 100, 500), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(font1, "Start Game", new Vector2(g.Viewport.Width / 3 + 100, 600), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(font1, "Exit", new Vector2(g.Viewport.Width / 3 + 100, 700), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.Draw(selecterArrowTexture, selecterArrow, Color.White);
            }

            // Instruction screen
            if (gameState == GameState.Instructions)
            {
                if (instructionState == InstructionState.Page1)
                {
                    spriteBatch.DrawString(bigFont, "Instructions", new Vector2((int)ScreenWidth / 4, 25), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(bigFont, "Instructions", new Vector2((int)ScreenWidth / 4, 25), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Controls:\nPlayer 1: W - Up, A - Left, S - Down, D - Right\nPlayer 2: Arrow Keys", new Vector2(g.Viewport.Width / 4, 200),
                                           Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Red Square - Tagger", new Vector2(g.Viewport.Width / 4, 400), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "White Square - Runner", new Vector2(g.Viewport.Width / 4, 450), Color.White, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Player 1 has a Blue Border", new Vector2(g.Viewport.Width / 4, 500), Color.CornflowerBlue, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Player 2 has a Green Border", new Vector2(g.Viewport.Width / 4, 550), Color.Green, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Press Escape to go back", new Vector2(g.Viewport.Width / 4, 800), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Next Page - Right Arrow Key", new Vector2(g.Viewport.Width / 4, 850), Color.Red, 0f, Vector2.Zero,
                                           (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                }

                else if (instructionState == InstructionState.Page2)
                {
                    spriteBatch.DrawString(bigFont, "Instructions", new Vector2((int)ScreenWidth / 4, 25), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(bigFont, "Instructions", new Vector2((int)ScreenWidth / 4, 25), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Tiles:", new Vector2(g.Viewport.Width / 6, 200), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Door - Opens for a limited time when player uses it", new Vector2(g.Viewport.Width / 6, 250), Color.Red, 0f, Vector2.Zero,
                                           (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Speed Tiles - Has the chance to either increase or decrease\nthe player's speed temporarily", new Vector2(g.Viewport.Width / 6, 300),
                                           Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Press Escape to go back", new Vector2(g.Viewport.Width / 4, 800), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Next Page - Right Arrow Key\nPrevious Page - Left Arrow Key", new Vector2(g.Viewport.Width / 4, 850), Color.Red, 0f, Vector2.Zero,
                                           (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                }
            }

            // Splash screen
            if (gameState == GameState.SplashScreen)
            {
                if (timer > 0 && timer < 120)
                {
                    red               = red + 3;
                    blue              = blue + 3;
                    green             = green + 3;
                    splashScreenColor = new Color(red, green, blue);
                    spriteBatch.Draw(splashScreenTexture, splashScreen, splashScreenColor);
                }

                if (timer > 119 && timer < 241)
                {
                    spriteBatch.Draw(splashScreenTexture, splashScreen, splashScreenColor);
                }

                if (timer > 240 && timer < 360)
                {
                    red               = red - 3;
                    blue              = blue - 3;
                    green             = green - 3;
                    splashScreenColor = new Color(red, green, blue);
                    spriteBatch.Draw(splashScreenTexture, splashScreen, splashScreenColor);
                }
            }

            // Round over screen
            if (gameState == GameState.RoundOver)
            {
                spriteBatch.DrawString(bigFont, roundString, new Vector2((int)ScreenWidth / 3 - 50, (int)ScreenHeight / 3), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(bigFont, roundString, new Vector2((int)ScreenWidth / 3 - 50, (int)ScreenHeight / 3), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);

                if (p2.points == 50)
                {
                    spriteBatch.DrawString(font1, p1RoundWin, new Vector2((int)ScreenWidth / 3 + 25, (int)ScreenHeight / 2), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                }

                else if (p1.points == 50)
                {
                    spriteBatch.DrawString(font1, p2RoundWin, new Vector2((int)ScreenWidth / 3 + 25, (int)ScreenHeight / 2), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                }

                spriteBatch.DrawString(font1, roundCountString + seconds, new Vector2((int)ScreenWidth / 3 + 25, (int)ScreenHeight / 2 + 30), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
            }

            // Game over screen
            if (gameState == GameState.GameOver)
            {
                spriteBatch.DrawString(bigFont, gameOverString, new Vector2((int)ScreenWidth / 3 - 50, (int)ScreenHeight / 3), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(bigFont, gameOverString, new Vector2((int)ScreenWidth / 3 - 50, (int)ScreenHeight / 3), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);

                if (round == 3 && (p2Wins == 2 || p2Wins == 3))
                {
                    spriteBatch.DrawString(font1, p2GameWin, new Vector2((int)ScreenWidth / 3 + 25, (int)ScreenHeight / 2), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                }

                else if (round == 3 && (p1Wins == 2 || p1Wins == 3))
                {
                    spriteBatch.DrawString(font1, p1GameWin, new Vector2((int)ScreenWidth / 3 + 25, (int)ScreenHeight / 2), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                }

                spriteBatch.DrawString(font1, gameOverCountString + seconds, new Vector2((int)ScreenWidth / 3 - 10, (int)ScreenHeight / 2), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);

                if (winner == "Player 1 has won")
                {
                    spriteBatch.DrawString(font1, "Player 1 has won", new Vector2((int)ScreenWidth / 3 - 10, (int)(ScreenHeight / 1.75)), Color.Black, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Player 1 has won", new Vector2((int)ScreenWidth / 3 - 10, (int)(ScreenHeight / 1.75)), Color.Green, 0f, new Vector2(5, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                }
                else
                {
                    spriteBatch.DrawString(font1, "Player 2 has won", new Vector2((int)ScreenWidth / 3 - 10, (int)(ScreenHeight / 1.75)), Color.Black, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Player 2 has won", new Vector2((int)ScreenWidth / 3 - 10, (int)(ScreenHeight / 1.75)), Color.Blue, 0f, new Vector2(5, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                }

                // put go back button and quit button.
                spriteBatch.DrawString(font1, "Go Back?", restartButonPos, Color.Blue, 0f, new Vector2(5, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(font1, "Quit?", quitButtonPos, Color.Blue, 0f, new Vector2(5, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.Draw(selecterArrowTexture, selecterArrow, Color.White);
            }

            // Pause screen
            if (gameState == GameState.Paused)
            {
                spriteBatch.DrawString(bigFont, "Paused", new Vector2((int)ScreenWidth / 3 - 50, (int)ScreenHeight / 3), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(bigFont, "Paused", new Vector2((int)ScreenWidth / 3 - 50, (int)ScreenHeight / 3), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale,
                                       SpriteEffects.None, 0f);
                spriteBatch.DrawString(font1, "Resume Game", new Vector2((int)ScreenWidth / 3 + 25, (int)ScreenHeight / 2), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(font1, "Exit", new Vector2((int)ScreenWidth / 3 + 25, (int)ScreenHeight / 2 + 60), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.Draw(selecterArrowTexture, pausedArrow, Color.White);
            }
        }
Пример #26
0
    internal LocalVarInfo(CodeInfo ma, ClassFile classFile, ClassFile.Method method, UntangledExceptionTable exceptions, MethodWrapper mw, ClassLoaderWrapper classLoader)
    {
        Dictionary <int, string>[] localStoreReaders = FindLocalVariables(ma, mw, classFile, method);

        // now that we've done the code flow analysis, we can do a liveness analysis on the local variables
        ClassFile.Method.Instruction[] instructions     = method.Instructions;
        Dictionary <long, LocalVar>    localByStoreSite = new Dictionary <long, LocalVar>();
        List <LocalVar> locals = new List <LocalVar>();

        for (int i = 0; i < localStoreReaders.Length; i++)
        {
            if (localStoreReaders[i] != null)
            {
                VisitLocalLoads(ma, method, locals, localByStoreSite, localStoreReaders[i], i, classLoader.EmitDebugInfo);
            }
        }
        Dictionary <LocalVar, LocalVar> forwarders = new Dictionary <LocalVar, LocalVar>();

        if (classLoader.EmitDebugInfo)
        {
            InstructionFlags[] flags = MethodAnalyzer.ComputePartialReachability(ma, method.Instructions, exceptions, 0, false);
            // if we're emitting debug info, we need to keep dead stores as well...
            for (int i = 0; i < instructions.Length; i++)
            {
                if ((flags[i] & InstructionFlags.Reachable) != 0 &&
                    IsStoreLocal(instructions[i].NormalizedOpCode))
                {
                    if (!localByStoreSite.ContainsKey(MakeKey(i, instructions[i].NormalizedArg1)))
                    {
                        LocalVar v = new LocalVar();
                        v.local = instructions[i].NormalizedArg1;
                        v.type  = ma.GetStackTypeWrapper(i, 0);
                        FindLvtEntry(v, method, i);
                        locals.Add(v);
                        localByStoreSite.Add(MakeKey(i, v.local), v);
                    }
                }
            }
            // to make the debugging experience better, we have to trust the
            // LocalVariableTable (unless it's clearly bogus) and merge locals
            // together that are the same according to the LVT
            for (int i = 0; i < locals.Count - 1; i++)
            {
                for (int j = i + 1; j < locals.Count; j++)
                {
                    LocalVar v1 = (LocalVar)locals[i];
                    LocalVar v2 = (LocalVar)locals[j];
                    if (v1.name != null && v1.name == v2.name && v1.start_pc == v2.start_pc && v1.end_pc == v2.end_pc)
                    {
                        // we can only merge if the resulting type is valid (this protects against incorrect
                        // LVT data, but is also needed for constructors, where the uninitialized this is a different
                        // type from the initialized this)
                        TypeWrapper tw = InstructionState.FindCommonBaseType(v1.type, v2.type);
                        if (tw != VerifierTypeWrapper.Invalid)
                        {
                            v1.isArg |= v2.isArg;
                            v1.type   = tw;
                            forwarders.Add(v2, v1);
                            locals.RemoveAt(j);
                            j--;
                        }
                    }
                }
            }
        }
        else
        {
            for (int i = 0; i < locals.Count - 1; i++)
            {
                for (int j = i + 1; j < locals.Count; j++)
                {
                    LocalVar v1 = (LocalVar)locals[i];
                    LocalVar v2 = (LocalVar)locals[j];
                    // if the two locals are the same, we merge them, this is a small
                    // optimization, it should *not* be required for correctness.
                    if (v1.local == v2.local && v1.type == v2.type)
                    {
                        v1.isArg |= v2.isArg;
                        forwarders.Add(v2, v1);
                        locals.RemoveAt(j);
                        j--;
                    }
                }
            }
        }
        invokespecialLocalVars = new LocalVar[instructions.Length][];
        localVars = new LocalVar[instructions.Length];
        for (int i = 0; i < localVars.Length; i++)
        {
            LocalVar v = null;
            if (localStoreReaders[i] != null)
            {
                Debug.Assert(IsLoadLocal(instructions[i].NormalizedOpCode));
                // lame way to look up the local variable for a load
                // (by indirecting through a corresponding store)
                foreach (int store in localStoreReaders[i].Keys)
                {
                    v = localByStoreSite[MakeKey(store, instructions[i].NormalizedArg1)];
                    break;
                }
            }
            else
            {
                if (instructions[i].NormalizedOpCode == NormalizedByteCode.__invokespecial)
                {
                    invokespecialLocalVars[i] = new LocalVar[method.MaxLocals];
                    for (int j = 0; j < invokespecialLocalVars[i].Length; j++)
                    {
                        localByStoreSite.TryGetValue(MakeKey(i, j), out invokespecialLocalVars[i][j]);
                    }
                }
                else
                {
                    localByStoreSite.TryGetValue(MakeKey(i, instructions[i].NormalizedArg1), out v);
                }
            }
            if (v != null)
            {
                LocalVar fwd;
                if (forwarders.TryGetValue(v, out fwd))
                {
                    v = fwd;
                }
                localVars[i] = v;
            }
        }
        this.allLocalVars = locals.ToArray();
    }
			internal JsrMethodAnalyzer(MethodWrapper mw, ClassFile classFile, ClassFile.Method method, ClassLoaderWrapper classLoader, InstructionFlags[] flags)
			{
				if (method.VerifyError != null)
				{
					throw new VerifyError(method.VerifyError);
				}

				this.classFile = classFile;
				state = new InstructionState[method.Instructions.Length];
				callsites = new List<int>[method.Instructions.Length];
				returnsites = new List<int>[method.Instructions.Length];

				// because types have to have identity, the subroutine return address types are cached here
				Dictionary<int, SimpleType> returnAddressTypes = new Dictionary<int, SimpleType>();

				try
				{
					// ensure that exception blocks and handlers start and end at instruction boundaries
					for (int i = 0; i < method.ExceptionTable.Length; i++)
					{
						int start = method.ExceptionTable[i].startIndex;
						int end = method.ExceptionTable[i].endIndex;
						int handler = method.ExceptionTable[i].handlerIndex;
						if (start >= end || start == -1 || end == -1 || handler <= 0)
						{
							throw new IndexOutOfRangeException();
						}
					}
				}
				catch (IndexOutOfRangeException)
				{
					throw new ClassFormatError(string.Format("Illegal exception table (class: {0}, method: {1}, signature: {2}", classFile.Name, method.Name, method.Signature));
				}

				// start by computing the initial state, the stack is empty and the locals contain the arguments
				state[0] = new InstructionState(method.MaxLocals, method.MaxStack);
				SimpleType thisType;
				int firstNonArgLocalIndex = 0;
				if (!method.IsStatic)
				{
					thisType = SimpleType.Object;
					state[0].SetLocalType(firstNonArgLocalIndex++, thisType, -1);
				}
				else
				{
					thisType = null;
				}
				TypeWrapper[] argTypeWrappers = mw.GetParameters();
				for (int i = 0; i < argTypeWrappers.Length; i++)
				{
					TypeWrapper tw = argTypeWrappers[i];
					SimpleType type;
					if (tw.IsWidePrimitive)
					{
						type = SimpleType.WidePrimitive;
					}
					else if (tw.IsPrimitive)
					{
						type = SimpleType.Primitive;
					}
					else
					{
						type = SimpleType.Object;
					}
					state[0].SetLocalType(firstNonArgLocalIndex++, type, -1);
					if (type.IsWidePrimitive)
					{
						firstNonArgLocalIndex++;
					}
				}
				SimpleType[] argumentsByLocalIndex = new SimpleType[firstNonArgLocalIndex];
				for (int i = 0; i < argumentsByLocalIndex.Length; i++)
				{
					argumentsByLocalIndex[i] = state[0].GetLocalTypeEx(i);
				}
				InstructionState s = state[0].Copy();
				bool done = false;
				ClassFile.Method.Instruction[] instructions = method.Instructions;
				while (!done)
				{
					done = true;
					for (int i = 0; i < instructions.Length; i++)
					{
						if (state[i] != null && state[i].changed)
						{
							try
							{
								//Console.WriteLine(method.Instructions[i].PC + ": " + method.Instructions[i].OpCode.ToString());
								done = false;
								state[i].changed = false;
								// mark the exception handlers reachable from this instruction
								for (int j = 0; j < method.ExceptionTable.Length; j++)
								{
									if (method.ExceptionTable[j].startIndex <= i && i < method.ExceptionTable[j].endIndex)
									{
										MergeExceptionHandler(method.ExceptionTable[j].handlerIndex, state[i]);
									}
								}
								state[i].CopyTo(s);
								ClassFile.Method.Instruction instr = instructions[i];
								switch (instr.NormalizedOpCode)
								{
									case NormalizedByteCode.__aload:
										{
											SimpleType type = s.GetLocalType(instr.NormalizedArg1);
											if (type == SimpleType.Invalid || type.IsPrimitive)
											{
												throw new VerifyError("Object reference expected");
											}
											s.PushType(type);
											break;
										}
									case NormalizedByteCode.__astore:
										s.SetLocalType(instr.NormalizedArg1, s.PopObjectType(), i);
										break;
									case NormalizedByteCode.__aconst_null:
										s.PushObject();
										break;
									case NormalizedByteCode.__aaload:
										s.PopPrimitive();
										s.PopObjectType();
										s.PushObject();
										break;
									case NormalizedByteCode.__aastore:
										s.PopObjectType();
										s.PopPrimitive();
										s.PopObjectType();
										break;
									case NormalizedByteCode.__baload:
										s.PopPrimitive();
										s.PopObjectType();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__bastore:
										s.PopPrimitive();
										s.PopPrimitive();
										s.PopObjectType();
										break;
									case NormalizedByteCode.__caload:
										s.PopPrimitive();
										s.PopObjectType();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__castore:
										s.PopPrimitive();
										s.PopPrimitive();
										s.PopObjectType();
										break;
									case NormalizedByteCode.__saload:
										s.PopPrimitive();
										s.PopObjectType();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__sastore:
										s.PopPrimitive();
										s.PopPrimitive();
										s.PopObjectType();
										break;
									case NormalizedByteCode.__iaload:
										s.PopPrimitive();
										s.PopObjectType();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__iastore:
										s.PopPrimitive();
										s.PopPrimitive();
										s.PopObjectType();
										break;
									case NormalizedByteCode.__laload:
										s.PopPrimitive();
										s.PopObjectType();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__lastore:
										s.PopWidePrimitive();
										s.PopPrimitive();
										s.PopObjectType();
										break;
									case NormalizedByteCode.__daload:
										s.PopPrimitive();
										s.PopObjectType();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__dastore:
										s.PopWidePrimitive();
										s.PopPrimitive();
										s.PopObjectType();
										break;
									case NormalizedByteCode.__faload:
										s.PopPrimitive();
										s.PopObjectType();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__fastore:
										s.PopPrimitive();
										s.PopPrimitive();
										s.PopObjectType();
										break;
									case NormalizedByteCode.__arraylength:
										s.PopObjectType();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__iconst:
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__if_icmpeq:
									case NormalizedByteCode.__if_icmpne:
									case NormalizedByteCode.__if_icmplt:
									case NormalizedByteCode.__if_icmpge:
									case NormalizedByteCode.__if_icmpgt:
									case NormalizedByteCode.__if_icmple:
										s.PopPrimitive();
										s.PopPrimitive();
										break;
									case NormalizedByteCode.__ifeq:
									case NormalizedByteCode.__ifge:
									case NormalizedByteCode.__ifgt:
									case NormalizedByteCode.__ifle:
									case NormalizedByteCode.__iflt:
									case NormalizedByteCode.__ifne:
										s.PopPrimitive();
										break;
									case NormalizedByteCode.__ifnonnull:
									case NormalizedByteCode.__ifnull:
										s.PopObjectType();
										break;
									case NormalizedByteCode.__if_acmpeq:
									case NormalizedByteCode.__if_acmpne:
										s.PopObjectType();
										s.PopObjectType();
										break;
									case NormalizedByteCode.__getstatic:
										s.PushType(GetFieldref(instr.Arg1).Signature);
										break;
									case NormalizedByteCode.__putstatic:
										s.PopType(GetFieldref(instr.Arg1).Signature);
										break;
									case NormalizedByteCode.__getfield:
										s.PopObjectType();
										s.PushType(GetFieldref(instr.Arg1).Signature);
										break;
									case NormalizedByteCode.__putfield:
										s.PopType(GetFieldref(instr.Arg1).Signature);
										s.PopObjectType();
										break;
									case NormalizedByteCode.__ldc:
										{
											switch (GetConstantPoolConstantType(instr.Arg1))
											{
												case ClassFile.ConstantType.Double:
													s.PushWidePrimitive();
													break;
												case ClassFile.ConstantType.Float:
													s.PushPrimitive();
													break;
												case ClassFile.ConstantType.Integer:
													s.PushPrimitive();
													break;
												case ClassFile.ConstantType.Long:
													s.PushWidePrimitive();
													break;
												case ClassFile.ConstantType.String:
												case ClassFile.ConstantType.Class:
													s.PushObject();
													break;
												default:
													// NOTE this is not a VerifyError, because it cannot happen (unless we have
													// a bug in ClassFile.GetConstantPoolConstantType)
													throw new InvalidOperationException();
											}
											break;
										}
									case NormalizedByteCode.__invokevirtual:
									case NormalizedByteCode.__invokespecial:
									case NormalizedByteCode.__invokeinterface:
									case NormalizedByteCode.__invokestatic:
										{
											ClassFile.ConstantPoolItemMI cpi = GetMethodref(instr.Arg1);
											s.MultiPopAnyType(cpi.GetArgTypes().Length);
											if (instr.NormalizedOpCode != NormalizedByteCode.__invokestatic)
											{
												s.PopType();
											}
											string sig = cpi.Signature;
											sig = sig.Substring(sig.IndexOf(')') + 1);
											if (sig != "V")
											{
												s.PushType(sig);
											}
											break;
										}
									case NormalizedByteCode.__goto:
										break;
									case NormalizedByteCode.__istore:
										s.PopPrimitive();
										s.SetLocalPrimitive(instr.NormalizedArg1, i);
										break;
									case NormalizedByteCode.__iload:
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__ineg:
										s.PopPrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__iadd:
									case NormalizedByteCode.__isub:
									case NormalizedByteCode.__imul:
									case NormalizedByteCode.__idiv:
									case NormalizedByteCode.__irem:
									case NormalizedByteCode.__iand:
									case NormalizedByteCode.__ior:
									case NormalizedByteCode.__ixor:
									case NormalizedByteCode.__ishl:
									case NormalizedByteCode.__ishr:
									case NormalizedByteCode.__iushr:
										s.PopPrimitive();
										s.PopPrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__lneg:
										s.PopWidePrimitive();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__ladd:
									case NormalizedByteCode.__lsub:
									case NormalizedByteCode.__lmul:
									case NormalizedByteCode.__ldiv:
									case NormalizedByteCode.__lrem:
									case NormalizedByteCode.__land:
									case NormalizedByteCode.__lor:
									case NormalizedByteCode.__lxor:
										s.PopWidePrimitive();
										s.PopWidePrimitive();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__lshl:
									case NormalizedByteCode.__lshr:
									case NormalizedByteCode.__lushr:
										s.PopPrimitive();
										s.PopWidePrimitive();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__fneg:
										s.PopPrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__fadd:
									case NormalizedByteCode.__fsub:
									case NormalizedByteCode.__fmul:
									case NormalizedByteCode.__fdiv:
									case NormalizedByteCode.__frem:
										s.PopPrimitive();
										s.PopPrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__dneg:
										s.PopWidePrimitive();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__dadd:
									case NormalizedByteCode.__dsub:
									case NormalizedByteCode.__dmul:
									case NormalizedByteCode.__ddiv:
									case NormalizedByteCode.__drem:
										s.PopWidePrimitive();
										s.PopWidePrimitive();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__new:
										s.PushObject();
										break;
									case NormalizedByteCode.__multianewarray:
										{
											if (instr.Arg2 < 1)
											{
												throw new VerifyError("Illegal dimension argument");
											}
											for (int j = 0; j < instr.Arg2; j++)
											{
												s.PopPrimitive();
											}
											s.PushObject();
											break;
										}
									case NormalizedByteCode.__anewarray:
										s.PopPrimitive();
										s.PushObject();
										break;
									case NormalizedByteCode.__newarray:
										s.PopPrimitive();
										s.PushObject();
										break;
									case NormalizedByteCode.__swap:
										{
											SimpleType t1 = s.PopType();
											SimpleType t2 = s.PopType();
											s.PushType(t1);
											s.PushType(t2);
											break;
										}
									case NormalizedByteCode.__dup:
										{
											SimpleType t = s.PopType();
											s.PushType(t);
											s.PushType(t);
											break;
										}
									case NormalizedByteCode.__dup2:
										{
											SimpleType t = s.PopAnyType();
											if (t.IsWidePrimitive)
											{
												s.PushType(t);
												s.PushType(t);
											}
											else
											{
												SimpleType t2 = s.PopType();
												s.PushType(t2);
												s.PushType(t);
												s.PushType(t2);
												s.PushType(t);
											}
											break;
										}
									case NormalizedByteCode.__dup_x1:
										{
											SimpleType value1 = s.PopType();
											SimpleType value2 = s.PopType();
											s.PushType(value1);
											s.PushType(value2);
											s.PushType(value1);
											break;
										}
									case NormalizedByteCode.__dup2_x1:
										{
											SimpleType value1 = s.PopAnyType();
											if (value1.IsWidePrimitive)
											{
												SimpleType value2 = s.PopType();
												s.PushType(value1);
												s.PushType(value2);
												s.PushType(value1);
											}
											else
											{
												SimpleType value2 = s.PopType();
												SimpleType value3 = s.PopType();
												s.PushType(value2);
												s.PushType(value1);
												s.PushType(value3);
												s.PushType(value2);
												s.PushType(value1);
											}
											break;
										}
									case NormalizedByteCode.__dup_x2:
										{
											SimpleType value1 = s.PopType();
											SimpleType value2 = s.PopAnyType();
											if (value2.IsWidePrimitive)
											{
												s.PushType(value1);
												s.PushType(value2);
												s.PushType(value1);
											}
											else
											{
												SimpleType value3 = s.PopType();
												s.PushType(value1);
												s.PushType(value3);
												s.PushType(value2);
												s.PushType(value1);
											}
											break;
										}
									case NormalizedByteCode.__dup2_x2:
										{
											SimpleType value1 = s.PopAnyType();
											if (value1.IsWidePrimitive)
											{
												SimpleType value2 = s.PopAnyType();
												if (value2.IsWidePrimitive)
												{
													// Form 4
													s.PushType(value1);
													s.PushType(value2);
													s.PushType(value1);
												}
												else
												{
													// Form 2
													SimpleType value3 = s.PopType();
													s.PushType(value1);
													s.PushType(value3);
													s.PushType(value2);
													s.PushType(value1);
												}
											}
											else
											{
												SimpleType value2 = s.PopType();
												SimpleType value3 = s.PopAnyType();
												if (value3.IsWidePrimitive)
												{
													// Form 3
													s.PushType(value2);
													s.PushType(value1);
													s.PushType(value3);
													s.PushType(value2);
													s.PushType(value1);
												}
												else
												{
													// Form 4
													SimpleType value4 = s.PopType();
													s.PushType(value2);
													s.PushType(value1);
													s.PushType(value4);
													s.PushType(value3);
													s.PushType(value2);
													s.PushType(value1);
												}
											}
											break;
										}
									case NormalizedByteCode.__pop:
										s.PopType();
										break;
									case NormalizedByteCode.__pop2:
										{
											SimpleType type = s.PopAnyType();
											if (!type.IsWidePrimitive)
											{
												s.PopType();
											}
											break;
										}
									case NormalizedByteCode.__monitorenter:
									case NormalizedByteCode.__monitorexit:
										s.PopObjectType();
										break;
									case NormalizedByteCode.__return:
										break;
									case NormalizedByteCode.__areturn:
										s.PopObjectType();
										break;
									case NormalizedByteCode.__ireturn:
										s.PopPrimitive();
										break;
									case NormalizedByteCode.__lreturn:
										s.PopWidePrimitive();
										break;
									case NormalizedByteCode.__freturn:
										s.PopPrimitive();
										break;
									case NormalizedByteCode.__dreturn:
										s.PopWidePrimitive();
										break;
									case NormalizedByteCode.__fload:
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__fstore:
										s.PopPrimitive();
										s.SetLocalPrimitive(instr.NormalizedArg1, i);
										break;
									case NormalizedByteCode.__dload:
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__dstore:
										s.PopWidePrimitive();
										s.SetLocalWidePrimitive(instr.NormalizedArg1, i);
										break;
									case NormalizedByteCode.__lload:
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__lstore:
										s.PopWidePrimitive();
										s.SetLocalWidePrimitive(instr.NormalizedArg1, i);
										break;
									case NormalizedByteCode.__lconst_0:
									case NormalizedByteCode.__lconst_1:
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__fconst_0:
									case NormalizedByteCode.__fconst_1:
									case NormalizedByteCode.__fconst_2:
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__dconst_0:
									case NormalizedByteCode.__dconst_1:
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__lcmp:
										s.PopWidePrimitive();
										s.PopWidePrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__fcmpl:
									case NormalizedByteCode.__fcmpg:
										s.PopPrimitive();
										s.PopPrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__dcmpl:
									case NormalizedByteCode.__dcmpg:
										s.PopWidePrimitive();
										s.PopWidePrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__checkcast:
										s.PopObjectType();
										s.PushObject();
										break;
									case NormalizedByteCode.__instanceof:
										s.PopObjectType();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__iinc:
										break;
									case NormalizedByteCode.__athrow:
										s.PopObjectType();
										break;
									case NormalizedByteCode.__tableswitch:
									case NormalizedByteCode.__lookupswitch:
										s.PopPrimitive();
										break;
									case NormalizedByteCode.__i2b:
										s.PopPrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__i2c:
										s.PopPrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__i2s:
										s.PopPrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__i2l:
										s.PopPrimitive();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__i2f:
										s.PopPrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__i2d:
										s.PopPrimitive();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__l2i:
										s.PopWidePrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__l2f:
										s.PopWidePrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__l2d:
										s.PopWidePrimitive();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__f2i:
										s.PopPrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__f2l:
										s.PopPrimitive();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__f2d:
										s.PopPrimitive();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__d2i:
										s.PopWidePrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__d2f:
										s.PopWidePrimitive();
										s.PushPrimitive();
										break;
									case NormalizedByteCode.__d2l:
										s.PopWidePrimitive();
										s.PushWidePrimitive();
										break;
									case NormalizedByteCode.__jsr:
										// TODO make sure we're not calling a subroutine we're already in
										break;
									case NormalizedByteCode.__ret:
										{
											// TODO if we're returning from a higher level subroutine, invalidate
											// all the intermediate return addresses
											int subroutineIndex = s.GetLocalRet(instr.Arg1);
											s.CheckSubroutineActive(subroutineIndex);
											break;
										}
									case NormalizedByteCode.__nop:
										if (i + 1 == instructions.Length)
										{
											throw new VerifyError("Falling off the end of the code");
										}
										break;
									case NormalizedByteCode.__invokedynamic:
										// it is impossible to have a valid invokedynamic in a pre-7.0 class file
										throw new VerifyError("Illegal type in constant pool");
									default:
										throw new NotImplementedException(instr.NormalizedOpCode.ToString());
								}
								if (s.GetStackHeight() > method.MaxStack)
								{
									throw new VerifyError("Stack size too large");
								}
								for (int j = 0; j < method.ExceptionTable.Length; j++)
								{
									if (method.ExceptionTable[j].endIndex == i + 1)
									{
										MergeExceptionHandler(method.ExceptionTable[j].handlerIndex, s);
									}
								}
								try
								{
									// another big switch to handle the opcode targets
									switch (instr.NormalizedOpCode)
									{
										case NormalizedByteCode.__tableswitch:
										case NormalizedByteCode.__lookupswitch:
											for (int j = 0; j < instr.SwitchEntryCount; j++)
											{
												state[instr.GetSwitchTargetIndex(j)] += s;
											}
											state[instr.DefaultTarget] += s;
											break;
										case NormalizedByteCode.__ifeq:
										case NormalizedByteCode.__ifne:
										case NormalizedByteCode.__iflt:
										case NormalizedByteCode.__ifge:
										case NormalizedByteCode.__ifgt:
										case NormalizedByteCode.__ifle:
										case NormalizedByteCode.__if_icmpeq:
										case NormalizedByteCode.__if_icmpne:
										case NormalizedByteCode.__if_icmplt:
										case NormalizedByteCode.__if_icmpge:
										case NormalizedByteCode.__if_icmpgt:
										case NormalizedByteCode.__if_icmple:
										case NormalizedByteCode.__if_acmpeq:
										case NormalizedByteCode.__if_acmpne:
										case NormalizedByteCode.__ifnull:
										case NormalizedByteCode.__ifnonnull:
											state[i + 1] += s;
											state[instr.TargetIndex] += s;
											break;
										case NormalizedByteCode.__goto:
											state[instr.TargetIndex] += s;
											break;
										case NormalizedByteCode.__jsr:
											{
												int index = instr.TargetIndex;
												s.SetSubroutineId(index);
												SimpleType retAddressType;
												if (!returnAddressTypes.TryGetValue(index, out retAddressType))
												{
													retAddressType = SimpleType.MakeRet(index);
													returnAddressTypes[index] = retAddressType;
												}
												s.PushType(retAddressType);
												state[index] += s;
												List<int> returns = GetReturnSites(i);
												if (returns != null)
												{
													foreach (int returnIndex in returns)
													{
														state[i + 1] = InstructionState.MergeSubroutineReturn(state[i + 1], s, state[returnIndex], state[returnIndex].GetLocalsModified(index));
													}
												}
												AddCallSite(index, i);
												break;
											}
										case NormalizedByteCode.__ret:
											{
												// HACK if the ret is processed before all of the jsr instructions to this subroutine
												// we wouldn't be able to properly merge, so that is why we track the number of callsites
												// for each subroutine instruction (see Instruction.AddCallSite())
												int subroutineIndex = s.GetLocalRet(instr.Arg1);
												int[] cs = GetCallSites(subroutineIndex);
												bool[] locals_modified = s.GetLocalsModified(subroutineIndex);
												for (int j = 0; j < cs.Length; j++)
												{
													AddReturnSite(cs[j], i);
													state[cs[j] + 1] = InstructionState.MergeSubroutineReturn(state[cs[j] + 1], state[cs[j]], s, locals_modified);
												}
												break;
											}
										case NormalizedByteCode.__ireturn:
										case NormalizedByteCode.__lreturn:
										case NormalizedByteCode.__freturn:
										case NormalizedByteCode.__dreturn:
										case NormalizedByteCode.__areturn:
										case NormalizedByteCode.__return:
										case NormalizedByteCode.__athrow:
											break;
										default:
											state[i + 1] += s;
											break;
									}
								}
								catch (IndexOutOfRangeException)
								{
									// we're going to assume that this always means that we have an invalid branch target
									// NOTE because PcIndexMap returns -1 for illegal PCs (in the middle of an instruction) and
									// we always use that value as an index into the state array, any invalid PC will result
									// in an IndexOutOfRangeException
									throw new VerifyError("Illegal target of jump or branch");
								}
							}
							catch (VerifyError x)
							{
								string opcode = instructions[i].NormalizedOpCode.ToString();
								if (opcode.StartsWith("__"))
								{
									opcode = opcode.Substring(2);
								}
								throw new VerifyError(string.Format("{5} (class: {0}, method: {1}, signature: {2}, offset: {3}, instruction: {4})",
									classFile.Name, method.Name, method.Signature, instructions[i].PC, opcode, x.Message), x);
							}
						}
					}
				}

				// Now we do another pass to compute reachability
				done = false;
				flags[0] |= InstructionFlags.Reachable;
				while (!done)
				{
					done = true;
					bool didJsrOrRet = false;
					for (int i = 0; i < instructions.Length; i++)
					{
						if ((flags[i] & (InstructionFlags.Reachable | InstructionFlags.Processed)) == InstructionFlags.Reachable)
						{
							done = false;
							flags[i] |= InstructionFlags.Processed;
							// mark the exception handlers reachable from this instruction
							for (int j = 0; j < method.ExceptionTable.Length; j++)
							{
								if (method.ExceptionTable[j].startIndex <= i && i < method.ExceptionTable[j].endIndex)
								{
									flags[method.ExceptionTable[j].handlerIndex] |= InstructionFlags.Reachable | InstructionFlags.BranchTarget;
								}
							}
							// mark the successor instructions
							switch (instructions[i].NormalizedOpCode)
							{
								case NormalizedByteCode.__tableswitch:
								case NormalizedByteCode.__lookupswitch:
									{
										bool hasbackbranch = false;
										for (int j = 0; j < instructions[i].SwitchEntryCount; j++)
										{
											hasbackbranch |= instructions[i].GetSwitchTargetIndex(j) < i;
											flags[instructions[i].GetSwitchTargetIndex(j)] |= InstructionFlags.Reachable | InstructionFlags.BranchTarget;
										}
										hasbackbranch |= instructions[i].DefaultTarget < i;
										flags[instructions[i].DefaultTarget] |= InstructionFlags.Reachable | InstructionFlags.BranchTarget;
										break;
									}
								case NormalizedByteCode.__goto:
									flags[instructions[i].TargetIndex] |= InstructionFlags.Reachable | InstructionFlags.BranchTarget;
									break;
								case NormalizedByteCode.__ifeq:
								case NormalizedByteCode.__ifne:
								case NormalizedByteCode.__iflt:
								case NormalizedByteCode.__ifge:
								case NormalizedByteCode.__ifgt:
								case NormalizedByteCode.__ifle:
								case NormalizedByteCode.__if_icmpeq:
								case NormalizedByteCode.__if_icmpne:
								case NormalizedByteCode.__if_icmplt:
								case NormalizedByteCode.__if_icmpge:
								case NormalizedByteCode.__if_icmpgt:
								case NormalizedByteCode.__if_icmple:
								case NormalizedByteCode.__if_acmpeq:
								case NormalizedByteCode.__if_acmpne:
								case NormalizedByteCode.__ifnull:
								case NormalizedByteCode.__ifnonnull:
									flags[instructions[i].TargetIndex] |= InstructionFlags.Reachable | InstructionFlags.BranchTarget;
									flags[i + 1] |= InstructionFlags.Reachable;
									break;
								case NormalizedByteCode.__jsr:
									flags[instructions[i].TargetIndex] |= InstructionFlags.Reachable | InstructionFlags.BranchTarget;
									// Note that we don't mark the next instruction as reachable,
									// because that depends on the corresponding ret actually being
									// reachable. We handle this in the loop below.
									didJsrOrRet = true;
									break;
								case NormalizedByteCode.__ret:
									// Note that we can't handle ret here, because we might encounter the ret
									// before having seen all the corresponding jsr instructions, so we can't
									// update all the call sites.
									// We handle ret in the loop below.
									didJsrOrRet = true;
									break;
								case NormalizedByteCode.__ireturn:
								case NormalizedByteCode.__lreturn:
								case NormalizedByteCode.__freturn:
								case NormalizedByteCode.__dreturn:
								case NormalizedByteCode.__areturn:
								case NormalizedByteCode.__return:
								case NormalizedByteCode.__athrow:
									break;
								default:
									flags[i + 1] |= InstructionFlags.Reachable;
									break;
							}
						}
					}
					if (didJsrOrRet)
					{
						for (int i = 0; i < instructions.Length; i++)
						{
							if (instructions[i].NormalizedOpCode == NormalizedByteCode.__ret
								&& (flags[i] & InstructionFlags.Reachable) != 0)
							{
								int subroutineIndex = state[i].GetLocalRet(instructions[i].Arg1);
								int[] cs = GetCallSites(subroutineIndex);
								for (int j = 0; j < cs.Length; j++)
								{
									if ((flags[cs[j]] & InstructionFlags.Reachable) != 0)
									{
										flags[cs[j] + 1] |= InstructionFlags.Reachable | InstructionFlags.BranchTarget;
									}
								}
							}
						}
					}
				}
			}
Пример #28
0
 //----------------------------------------------------------------------------------------------------
 /// <summary>
 /// ダンジョンの命令開始
 /// </summary>
 public void StartDungeonInstruction()
 {
     m_instructionState              = InstructionState.Appearance;
     m_countTimeInstruction          = 0;
     DefeatBossBeyondDungeon.enabled = true;
 }
Пример #29
0
        // Draws the splash screen and menus
        public void drawMenus(SpriteBatch spriteBatch, GameState gameState, InstructionState instructionState, int timer)
        {
            if (gameState == GameState.StartScreen)
            {
                spriteBatch.DrawString(bigFont, "Crazy Mazey Tag", new Vector2(g.Viewport.Width / 5, 25), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(bigFont, "Crazy Mazey Tag", new Vector2(g.Viewport.Width / 5, 25), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale, SpriteEffects.None,
                                       0f);
                spriteBatch.DrawString(font1, "Use the Arrow Keys to move the arrow", new Vector2(g.Viewport.Width / 4 - 30, 200), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                       SpriteEffects.None, 0f);
                spriteBatch.DrawString(font1, "Use the Enter Key to select an option", new Vector2(g.Viewport.Width / 4 - 30, 250), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                       SpriteEffects.None, 0f);
                spriteBatch.DrawString(font1, "Instructions", new Vector2(g.Viewport.Width / 3 + 100, 500), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(font1, "Start Game", new Vector2(g.Viewport.Width / 3 + 100, 600), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(font1, "Exit", new Vector2(g.Viewport.Width / 3 + 100, 700), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.Draw(selecterArrowTexture, selecterArrow, Color.White);
            }

            if (gameState == GameState.Instructions)
            {
                if (instructionState == InstructionState.Page1)
                {
                    spriteBatch.DrawString(bigFont, "Instructions", new Vector2((int)ScreenWidth / 4, 25), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(bigFont, "Instructions", new Vector2((int)ScreenWidth / 4, 25), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Controls:\nPlayer 1: W - Up, A - Left, S - Down, D - Right\nPlayer 2: Arrow Keys", new Vector2(g.Viewport.Width / 4, 200),
                                           Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Red Square - Tagger", new Vector2(g.Viewport.Width / 4, 400), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "White Square - Runner", new Vector2(g.Viewport.Width / 4, 450), Color.White, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Player 1 has a Blue Border", new Vector2(g.Viewport.Width / 4, 500), Color.CornflowerBlue, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Player 2 has a Green Border", new Vector2(g.Viewport.Width / 4, 550), Color.Green, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Press Escape to go back", new Vector2(g.Viewport.Width / 4, 800), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Next Page - Right Arrow Key", new Vector2(g.Viewport.Width / 4, 850), Color.Red, 0f, Vector2.Zero,
                                           (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                }

                else if (instructionState == InstructionState.Page2)
                {
                    spriteBatch.DrawString(bigFont, "Instructions", new Vector2((int)ScreenWidth / 4, 25), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(bigFont, "Instructions", new Vector2((int)ScreenWidth / 4, 25), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Tiles:", new Vector2(g.Viewport.Width / 6, 200), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Door - Opens for a limited time when player uses it", new Vector2(g.Viewport.Width / 6, 250), Color.Red, 0f, Vector2.Zero,
                                           (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Speed Tiles - Has the chance to either increase or decrease\nthe player's speed temporarily", new Vector2(g.Viewport.Width / 6, 300),
                                           Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Slow Block - Player's speed will be decreased for a short time", new Vector2(g.Viewport.Width / 6, 400), Color.Red, 0f, Vector2.Zero,
                                           (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Speed Block - Player's speed will be increased for a short time", new Vector2(g.Viewport.Width / 6, 450), Color.Red, 0f, Vector2.Zero,
                                           (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Press Escape to go back", new Vector2(g.Viewport.Width / 4, 800), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Next Page - Right Arrow Key\nPrevious Page - Left Arrow Key", new Vector2(g.Viewport.Width / 4, 850), Color.Red, 0f, Vector2.Zero,
                                           (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                }

                else if (instructionState == InstructionState.Page3)
                {
                    spriteBatch.DrawString(bigFont, "Instructions", new Vector2((int)ScreenWidth / 4, 25), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(bigFont, "Instructions", new Vector2((int)ScreenWidth / 4, 25), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Power-Ups:", new Vector2(g.Viewport.Width / 6, 200), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Thunderbolt - Stuns other players for one second.\nRunner and Tagger can use this", new Vector2(g.Viewport.Width / 6, 250), Color.Red, 0f,
                                           Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Ghost - Ignore tile effects. Can pass through doors at any time.\nGhost cannot be tagged. Lasts for a few seconds",
                                           new Vector2(g.Viewport.Width / 6, 350), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Flicker - Screen flashes, making it more difficult for\nplayers to see for 5 seconds", new Vector2(g.Viewport.Width / 6, 450),
                                           Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Press Escape to go back", new Vector2(g.Viewport.Width / 4, 800), Color.Red, 0f, Vector2.Zero, (float)AspectRatio * stringScale,
                                           SpriteEffects.None, 0f);
                    spriteBatch.DrawString(font1, "Previous Page - Left Arrow Key", new Vector2(g.Viewport.Width / 4, 850), Color.Red, 0f, Vector2.Zero,
                                           (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                }
            }

            if (gameState == GameState.SplashScreen)
            {
                if (timer > 0 && timer < 120)
                {
                    red               = red + 3;
                    blue              = blue + 3;
                    green             = green + 3;
                    splashScreenColor = new Color(red, green, blue);
                    spriteBatch.Draw(splashScreenTexture, splashScreen, splashScreenColor);
                }

                if (timer > 119 && timer < 241)
                {
                    spriteBatch.Draw(splashScreenTexture, splashScreen, splashScreenColor);
                }

                if (timer > 240 && timer < 360)
                {
                    red               = red - 3;
                    blue              = blue - 3;
                    green             = green - 3;
                    splashScreenColor = new Color(red, green, blue);
                    spriteBatch.Draw(splashScreenTexture, splashScreen, splashScreenColor);
                }
            }

            if (gameState == GameState.RoundOver)
            {
                spriteBatch.DrawString(bigFont, roundString, new Vector2((int)ScreenWidth / 4, (int)ScreenHeight / 2), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(bigFont, roundString, new Vector2((int)ScreenWidth / 4, (int)ScreenHeight / 2), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
            }

            if (gameState == GameState.GameOver)
            {
                spriteBatch.DrawString(bigFont, gameOverString, new Vector2((int)ScreenWidth / 4, (int)ScreenHeight / 2), Color.Blue, 0f, Vector2.Zero, (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
                spriteBatch.DrawString(bigFont, gameOverString, new Vector2((int)ScreenWidth / 4, (int)ScreenHeight / 2), Color.White, 0f, new Vector2(10, 0), (float)AspectRatio * stringScale, SpriteEffects.None, 0f);
            }
        }
Пример #30
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // escape key missing

            // Add your update logic here
            KeyboardState kb = Keyboard.GetState();

            if (kb.IsKeyDown(Keys.Back) && !oldKb.IsKeyDown(Keys.Back))
            {
                this.Exit();
            }

            // Methods from the Menus class to run the menus
            menus.Navigations(gameState, instructionState, kb, CurrentBackgroundC, oldKb, timer, gameOverTimer);
            gameState        = menus.GameStateValue();
            instructionState = menus.InstructionStateValue();

            if (gameState == GameState.Game)
            {
                if (changeSongs == false)
                {
                    changeSongs = true;
                    MediaPlayer.Stop();
                }

                // Pauses game. Currently does not work
                if (kb.IsKeyDown(Keys.P) && oldKb != kb)
                {
                    gameState = GameState.Paused;
                }

                // Update Player collision with map obstacles.
                firstMap.MapPlayerCollisions(p1);
                firstMap.MapPlayerCollisions(p2);

                CurrentBackgroundC = firstMap.FLOORCOLOR;

                p1.update(1, p2);
                p2.update(2, p1);


                RoundOverCheck();
            }

            if (gameState == GameState.StartScreen)
            {
                p1.Reset();
                p2.Reset();
                p1.TotalReset();
                p2.TotalReset();
                CurrentBackgroundC = Color.Black;
            }

            if (menus.ReturnTimer() >= 240)
            {
                //Reset
                p1.Reset();
                p2.Reset();
                while (p1.pRect.Intersects(p2.pRect))
                {
                    p2.newRandomStart();
                }
                //CurrentBackgroundC = Color.Black;
            }

            // Keep so the player can choose to exit the game
            if (gameState == GameState.Exit)
            {
                this.Exit();
            }

            // Splash screen timer
            timer++;

            if ((gameState == GameState.StartScreen || gameState == GameState.Instructions) && (MediaPlayer.State == MediaState.Stopped || changeSongs == true))
            {
                if (changeSongs == true)
                {
                    changeSongs = false;
                    MediaPlayer.Stop();
                }

                MediaPlayer.Play(songs[0]);
            }

            if (gameState == GameState.Game && MediaPlayer.State == MediaState.Stopped)
            {
                MediaPlayer.Play(songs[1]);
            }

            if (gameState == GameState.RoundOver)
            {
                MediaPlayer.Pause();
            }
            else
            {
                MediaPlayer.Resume();
            }
            if (gameState == GameState.GameOver)
            {
                MediaPlayer.Pause();
                changeSongs = true;
            }

            oldKb = kb;

            base.Update(gameTime);
        }
			private void MergeExceptionHandler(int handlerIndex, InstructionState curr)
			{
				// NOTE this used to be CopyLocalsAndSubroutines, but it doesn't (always) make
				// sense to copy the subroutine state
				// TODO figure out if there are circumstances under which it does make sense
				// to copy the active subroutine state
				// UPDATE subroutines must be copied as well, but I think I now have a better
				// understanding of subroutine merges, so the problems that triggered the previous
				// change here hopefully won't arise anymore
				InstructionState ex = curr.CopyLocalsAndSubroutines();
				ex.PushObject();
				state[handlerIndex] += ex;
			}
				internal void CopyTo(InstructionState target)
				{
					target.flags = ShareFlags.All;
					target.stack = stack;
					target.stackSize = stackSize;
					target.stackEnd = stackEnd;
					target.locals = locals;
					target.subroutines = subroutines;
					target.callsites = callsites;
					target.changed = true;
				}
				internal InstructionState CopyLocalsAndSubroutines()
				{
					InstructionState copy = new InstructionState(new SimpleType[stack.Length], 0, stack.Length, locals, subroutines, callsites);
					copy.flags &= ~ShareFlags.Stack;
					return copy;
				}
Пример #34
0
 /// <summary>
 /// Interrupt instruction (not safe).
 /// </summary>
 internal void Interrupt()
 {
     currentState = InstructionState.Interrupted;
 }
Пример #35
0
    void Update()
    {
        if (manager.GetGameState() == GameManager.GameState.PLAYING)
        {
            if (rigidbody.velocity.x > velocity || rigidbody.velocity.x < velocity)
            {
                velocityVector     = rigidbody.velocity;
                velocityVector.x   = velocity;
                rigidbody.velocity = velocityVector;
            }

            switch (current)
            {
            case InstructionState.quarter_note:
                //Left click down
                if (Input.GetMouseButtonDown(0) && currentIndicator != null)
                {
                    float x = (rigidbody.position.x % 10);
                    if (x < 0)
                    {
                        x += 10;
                    }
                    if (x >= 0 && x <= 2 && IsOnGround)
                    {
                        rigidbody.gravityScale = gravityScaleSingleJump;
                        velocityVector.y       = 0;
                        rigidbody.velocity     = velocityVector;
                        rigidbody.AddForce(new Vector2(0, singleJumpForce));
                        currentIndicator.GetComponentInParent <Bumper> ().StartMoving();
                        IsOnGround = false;

                        if (x < 0.3f)
                        {
                            manager.IndicateClick(currentIndicator, Color.green);
                            manager.IncreaseScore(5);
                        }
                        else if (x < 0.8f)
                        {
                            manager.IndicateClick(currentIndicator, Color.yellow);
                            manager.IncreaseScore(3);
                        }
                        else
                        {
                            manager.IndicateClick(currentIndicator, Color.red);
                        }
                    }
                    else if (x > 5)
                    {
                        ResidualClick = true;
                        if (x > 9.7f)
                        {
                            manager.IndicateClick(currentIndicator, Color.green);
                            manager.IncreaseScore(5);
                        }
                        else if (x > 9.2f)
                        {
                            manager.IndicateClick(currentIndicator, Color.yellow);
                            manager.IncreaseScore(3);
                        }
                        else
                        {
                            manager.IndicateClick(currentIndicator, Color.red);
                        }
                    }
                }

                if (ResidualClick && IsOnGround)
                {
                    rigidbody.gravityScale = gravityScaleSingleJump;
                    velocityVector.y       = 0;
                    rigidbody.velocity     = velocityVector;
                    rigidbody.AddForce(new Vector2(0, singleJumpForce));
                    currentIndicator.GetComponentInParent <Bumper> ().StartMoving();

                    ResidualClick = false;
                    IsOnGround    = false;
                }

                //Left click up
                if (Input.GetMouseButtonUp(0))
                {
                    if (IsTouchingDeflater && !IsTouchingDeflaterCover)
                    {
                        Vector2 targetPos = new Vector2();
                        float   x         = rigidbody.position.x;
                        targetPos.x        = x - x % 10 + 9.9f;
                        targetPos.y        = manager.groundY;
                        rigidbody.velocity = manager.GetReqVelocity(
                            rigidbody.gravityScale * 9.81f,
                            rigidbody.position,
                            targetPos,
                            velocity
                            );
                        currentDeflater.ChangeColor(Color.green);
                        manager.IncreaseScore(5);
                    }
                    else
                    {
                        rigidbody.gravityScale = gravityScaleHigh;
                        if (IsTouchingDeflaterCover)
                        {
                            currentDeflater.ChangeColor(Color.yellow);
                            manager.IncreaseScore(3);
                        }
                    }
                }
                break;

            case InstructionState.half_note:
                //Left click down

                if (Input.GetMouseButtonDown(0) && currentIndicator != null)
                {
                    float x = rigidbody.position.x % 10;
                    if (x < 0)
                    {
                        x += 10;
                    }
                    if (x >= 0 && x <= 2 && IsOnGround)
                    {
                        rigidbody.gravityScale = gravityScaleDoubleJump;
                        velocityVector.y       = 0;
                        rigidbody.velocity     = velocityVector;
                        rigidbody.AddForce(new Vector2(0, doubleJumpForce));
                        currentIndicator.GetComponentInParent <Bumper> ().StartMoving();
                        IsOnGround = false;

                        if (x < 0.3f)
                        {
                            manager.IndicateClick(currentIndicator, Color.green);
                            manager.IncreaseScore(10);
                        }
                        else if (x < 0.8f)
                        {
                            manager.IndicateClick(currentIndicator, Color.yellow);
                            manager.IncreaseScore(6);
                        }
                        else
                        {
                            manager.IndicateClick(currentIndicator, Color.red);
                        }
                    }
                    else if (x > 5)
                    {
                        ResidualClick = true;
                        if (x > 9.7f)
                        {
                            manager.IndicateClick(currentIndicator, Color.green);
                            manager.IncreaseScore(10);
                        }
                        else if (x > 9.2f)
                        {
                            manager.IndicateClick(currentIndicator, Color.yellow);
                            manager.IncreaseScore(6);
                        }
                        else
                        {
                            manager.IndicateClick(currentIndicator, Color.red);
                        }
                        //print ("Residual click");
                    }
                }

                if (ResidualClick && IsOnGround)
                {
                    rigidbody.gravityScale = gravityScaleDoubleJump;
                    velocityVector.y       = 0;
                    rigidbody.velocity     = velocityVector;
                    rigidbody.AddForce(new Vector2(0, doubleJumpForce));
                    currentIndicator.GetComponentInParent <Bumper> ().StartMoving();

                    ResidualClick = false;
                    IsOnGround    = false;
                }

                //Left click up
                if (Input.GetMouseButtonUp(0))
                {
                    if (IsTouchingDeflater && !IsTouchingDeflaterCover)
                    {
                        Vector2 targetPos = new Vector2();
                        float   x         = rigidbody.position.x;
                        targetPos.x        = Mathf.Round(x / 10) * 10 + 9.7f;
                        targetPos.y        = manager.groundY;
                        rigidbody.velocity = manager.GetReqVelocity(
                            rigidbody.gravityScale * 9.81f,
                            rigidbody.position,
                            targetPos,
                            velocity
                            );
                        currentDeflater.ChangeColor(Color.green);
                        manager.IncreaseScore(10);
                    }
                    else
                    {
                        rigidbody.gravityScale = gravityScaleHigh;
                        if (IsTouchingDeflater)
                        {
                            currentDeflater.ChangeColor(Color.yellow);
                            manager.IncreaseScore(6);
                        }
                    }
                }
                break;

            case InstructionState.eight_note_1:

                //			if (canClick && Input.GetMouseButtonDown (0)) {
                //				rigidbody.gravityScale = gravityScaleInvert;
                //				rigidbody.AddForce (new Vector2 (0, singleJumpForce));
                //				manager.setCommentText ();
                //			}

                //Left click
                if (Input.GetMouseButtonDown(0) && currentIndicator != null)
                {
                    float x = (rigidbody.position.x % 10);
                    if (x < 0)
                    {
                        x += 10;
                    }
                    if (x >= 0 && x <= 2 && IsOnGround)
                    {
                        rigidbody.gravityScale = gravityScaleSingleJump * 0.65f;

                        Vector2 targetPos = new Vector2();
                        float   X         = rigidbody.position.x;
                        targetPos.x        = Mathf.Round(X / 10) * 10 + 9.8f;
                        targetPos.y        = manager.groundY;
                        rigidbody.velocity = manager.GetReqVelocity(
                            rigidbody.gravityScale * 9.81f,
                            rigidbody.position,
                            targetPos,
                            velocity
                            );

                        currentIndicator.GetComponentInParent <Bumper> ().StartMoving();
                        IsOnGround = false;

                        if (x < 0.3f)
                        {
                            manager.IndicateClick(currentIndicator, Color.green);
                            manager.IncreaseScore(5);
                        }
                        else if (x < 0.8f)
                        {
                            manager.IndicateClick(currentIndicator, Color.yellow);
                            manager.IncreaseScore(3);
                        }
                        else
                        {
                            manager.IndicateClick(currentIndicator, Color.red);
                        }
                    }
                    else if (x > 5)
                    {
                        ResidualClick = true;
                        if (x > 9.7f)
                        {
                            manager.IndicateClick(currentIndicator, Color.green);
                            manager.IncreaseScore(5);
                        }
                        else if (x > 9.2f)
                        {
                            manager.IndicateClick(currentIndicator, Color.yellow);
                            manager.IncreaseScore(3);
                        }
                        else
                        {
                            manager.IndicateClick(currentIndicator, Color.red);
                        }
                    }
                }

                if (ResidualClick && IsOnGround)
                {
                    rigidbody.gravityScale = gravityScaleSingleJump * 0.65f;

                    Vector2 targetPos = new Vector2();
                    float   X         = rigidbody.position.x;
                    targetPos.x        = Mathf.Round(X / 10) * 10 + 9.8f;
                    targetPos.y        = manager.groundY;
                    rigidbody.velocity = manager.GetReqVelocity(
                        rigidbody.gravityScale * 9.81f,
                        rigidbody.position,
                        targetPos,
                        velocity
                        );
                    currentIndicator.GetComponentInParent <Bumper> ().StartMoving();

                    ResidualClick = false;
                    IsOnGround    = false;
                }
                break;

            case InstructionState.eight_note_2:

                if (Input.GetMouseButtonDown(0) && currentIndicator != null)
                {
                    float x = (rigidbody.position.x % 10);
                    if (x < 0)
                    {
                        x += 10;
                    }
                    if (x >= 4.2f && x <= 5.8f)
                    {
                        if (x < 5.3f && x > 4.7f)
                        {
                            manager.IndicateClick(currentIndicator, Color.green);
                            manager.IncreaseScore(5);
                        }
                        else if (x < 5.8f && x > 4.2f)
                        {
                            manager.IndicateClick(currentIndicator, Color.yellow);
                            manager.IncreaseScore(3);
                            rigidbody.gravityScale = gravityScaleHigh;
                            currentIndicator.transform.parent.parent.GetChild(1).GetChild(0).gameObject.SetActive(true);
                        }
                    }
                    else if (x < 4.2f)
                    {
                        manager.IndicateClick(currentIndicator, Color.red);
                        rigidbody.gravityScale = gravityScaleHigh;
                        currentIndicator.transform.parent.parent.GetChild(1).GetChild(0).gameObject.SetActive(true);
                    }
                }

                if ((rigidbody.position.x % 10) > 5.8f &&
                    currentIndicator != null &&
                    currentIndicator.GetColor() == Color.white
                    )
                {
                    rigidbody.gravityScale = gravityScaleHigh;
                    manager.IndicateClick(currentIndicator, Color.red);
                    currentIndicator.transform.parent.parent.GetChild(1).GetChild(0).gameObject.SetActive(true);
                    current = InstructionState.none;
                }

                break;

            case InstructionState.whole:
                //Left click down
                if (Input.GetMouseButtonDown(0) && currentIndicator != null)
                {
                    float x = (rigidbody.position.x % 10);
                    if (x < 0)
                    {
                        x += 10;
                    }
                    if (x >= 0 && x <= 2)
                    {
                        rigidbody.gravityScale = gravityScaleSingleJump;
                        velocityVector.y       = 0;
                        rigidbody.velocity     = velocityVector;
                        rigidbody.AddForce(new Vector2(0, singleJumpForce * 1.24f));
                        currentIndicator.GetComponentInParent <Bumper> ().StartMoving();
                        IsOnGround = false;

                        if (x < 0.3f)
                        {
                            manager.IndicateClick(currentIndicator, Color.green);
                            manager.IncreaseScore(10);
                        }
                        else if (x < 0.8f)
                        {
                            manager.IndicateClick(currentIndicator, Color.yellow);
                            manager.IncreaseScore(6);
                        }
                        else
                        {
                            manager.IndicateClick(currentIndicator, Color.red);
                        }
                    }
                    else if (x > 5)
                    {
                        ResidualClick = true;
                        if (x > 9.7f)
                        {
                            manager.IndicateClick(currentIndicator, Color.green);
                            manager.IncreaseScore(10);
                        }
                        else if (x > 9.2f)
                        {
                            manager.IndicateClick(currentIndicator, Color.yellow);
                            manager.IncreaseScore(6);
                        }
                        else
                        {
                            manager.IndicateClick(currentIndicator, Color.red);
                        }
                    }
                }

                if (ResidualClick && IsOnGround)
                {
                    rigidbody.gravityScale = gravityScaleSingleJump;
                    velocityVector.y       = 0;
                    rigidbody.velocity     = velocityVector;
                    rigidbody.AddForce(new Vector2(0, singleJumpForce * 1.24f));
                    currentIndicator.GetComponentInParent <Bumper> ().StartMoving();

                    ResidualClick = false;
                    IsOnGround    = false;
                }

                //Left click up
                if (Input.GetMouseButtonUp(0))
                {
                    if (!IsTouchingDeflaterCover && IsTouchingDeflater)
                    {
                        Vector2 targetPos = new Vector2();
                        float   x         = rigidbody.position.x;
                        targetPos.x = x - x % 10 + 9.7f;
                        targetPos.y = manager.groundY;

                        rigidbody.velocity = manager.GetReqVelocity(
                            rigidbody.gravityScale * 9.81f,
                            rigidbody.position,
                            targetPos,
                            velocity
                            );
                        currentDeflater.ChangeColor(Color.green);
                        manager.IncreaseScore(5);
                    }
                    else
                    {
                        if (IsTouchingDeflaterCover)
                        {
                            currentDeflater.ChangeColor(Color.yellow);
                            manager.IncreaseScore(3);
                        }
                    }
                }
                break;

            case InstructionState.rest:
                if (Input.GetMouseButtonDown(0) && currentIndicator != null)
                {
                    WasRestGood = false;
                    currentIndicator.ChangeColor(Color.red);
                }
                break;

            case InstructionState.none:

                break;
            }
        }
        else if (manager.GetGameState() == GameManager.GameState.FINISHED)
        {
            velocityVector     = rigidbody.velocity;
            velocityVector.x   = Mathf.Lerp(0, velocityVector.x, 59 * Time.deltaTime);
            rigidbody.velocity = velocityVector;
        }
    }
Пример #36
0
        // Method for menu navigations and splash screen. Round over and game over screens still need work
        public void Navigations(GameState gameState, InstructionState instructionState, KeyboardState kb, Color CurrentBackgroundC, KeyboardState oldKb,
                                int timer, int gameOverTimer)
        {
            // Code for start screen
            if (gameState == GameState.StartScreen)
            {
                CurrentBackgroundC = Color.Black;

                if (kb.IsKeyDown(Keys.Up) && oldKb != kb)
                {
                    selecterArrow.Y = selecterArrow.Y - 100;
                }

                if (kb.IsKeyDown(Keys.Down) && oldKb != kb)
                {
                    selecterArrow.Y = selecterArrow.Y + 100;
                }

                if (selecterArrow.Y < 500)
                {
                    selecterArrow.Y = 700;
                }

                if (selecterArrow.Y > 700)
                {
                    selecterArrow.Y = 500;
                }

                if (kb.IsKeyDown(Keys.Enter) && selecterArrow.Y == 500)
                {
                    this.gameState = GameState.Instructions;
                }

                if (kb.IsKeyDown(Keys.Enter) && selecterArrow.Y == 600)
                {
                    this.gameState = GameState.Game;
                }

                if (kb.IsKeyDown(Keys.Enter) && selecterArrow.Y == 700)
                {
                    this.gameState = GameState.Exit;
                }
            }

            // Code for instruction screen
            if (gameState == GameState.Instructions)
            {
                if (kb.IsKeyDown(Keys.Escape) && oldKb != kb)
                {
                    this.gameState = GameState.StartScreen;
                }

                if (kb.IsKeyDown(Keys.Right) && instructionState == InstructionState.Page1 && oldKb != kb)
                {
                    this.instructionState = InstructionState.Page2;
                }

                else if (kb.IsKeyDown(Keys.Right) && instructionState == InstructionState.Page2 && oldKb != kb)
                {
                    this.instructionState = InstructionState.Page3;
                }

                else if (kb.IsKeyDown(Keys.Left) && instructionState == InstructionState.Page3 && oldKb != kb)
                {
                    this.instructionState = InstructionState.Page2;
                }

                else if (kb.IsKeyDown(Keys.Left) && instructionState == InstructionState.Page2 && oldKb != kb)
                {
                    this.instructionState = InstructionState.Page1;
                }
            }

            // Splash Screen code
            if (gameState == GameState.SplashScreen)
            {
                timer++;

                if (timer >= 370)
                {
                    this.gameState = GameState.StartScreen;
                }
            }

            // Code for round over screen
            if (gameState == GameState.RoundOver)
            {
                roundOverTimer++;
                Console.WriteLine(roundOverTimer);

                if (round != 4)
                {
                    if (roundOverTimer >= 240)
                    {
                        // Reset
                        this.gameState = GameState.Game;
                        roundOverTimer = 0;
                        round++;
                    }
                }

                if (round == 4)
                {
                    gameState = GameState.GameOver;
                }
            }

            // Code for game over screen
            if (gameState == GameState.GameOver)
            {
                gameOverTimer++;

                if (gameOverTimer >= 240)
                {
                    this.gameState = GameState.StartScreen;
                    gameOverTimer  = 0;
                }
            }
        }
Пример #37
0
    private static void VisitLocalLoads(CodeInfo codeInfo, ClassFile.Method method, List <LocalVar> locals, Dictionary <long, LocalVar> localByStoreSite, Dictionary <int, string> storeSites, int instructionIndex, bool debug)
    {
        Debug.Assert(IsLoadLocal(method.Instructions[instructionIndex].NormalizedOpCode));
        LocalVar    local      = null;
        TypeWrapper type       = VerifierTypeWrapper.Null;
        int         localIndex = method.Instructions[instructionIndex].NormalizedArg1;
        bool        isArg      = false;

        foreach (int store in storeSites.Keys)
        {
            if (store == -1)
            {
                // it's a method argument, it has no initial store, but the type is simply the parameter type
                type  = InstructionState.FindCommonBaseType(type, codeInfo.GetLocalTypeWrapper(0, localIndex));
                isArg = true;
            }
            else
            {
                if (method.Instructions[store].NormalizedOpCode == NormalizedByteCode.__invokespecial)
                {
                    type = InstructionState.FindCommonBaseType(type, codeInfo.GetLocalTypeWrapper(store + 1, localIndex));
                }
                else if (method.Instructions[store].NormalizedOpCode == NormalizedByteCode.__static_error)
                {
                    // it's an __invokespecial that turned into a __static_error
                    // (since a __static_error doesn't continue, we don't need to set type)
                }
                else
                {
                    Debug.Assert(IsStoreLocal(method.Instructions[store].NormalizedOpCode));
                    type = InstructionState.FindCommonBaseType(type, codeInfo.GetStackTypeWrapper(store, 0));
                }
            }
            // we can't have an invalid type, because that would have failed verification earlier
            Debug.Assert(type != VerifierTypeWrapper.Invalid);

            LocalVar l;
            if (localByStoreSite.TryGetValue(MakeKey(store, localIndex), out l))
            {
                if (local == null)
                {
                    local = l;
                }
                else if (local != l)
                {
                    // If we've already defined a LocalVar and we find another one, then we merge them
                    // together.
                    // This happens for the following code fragment:
                    //
                    // int i = -1;
                    // try { i = 0; for(; ; ) System.out.println(i); } catch(Exception x) {}
                    // try { i = 0; for(; ; ) System.out.println(i); } catch(Exception x) {}
                    // System.out.println(i);
                    //
                    local = MergeLocals(locals, localByStoreSite, local, l);
                }
            }
        }
        if (local == null)
        {
            local       = new LocalVar();
            local.local = localIndex;
            if (VerifierTypeWrapper.IsThis(type))
            {
                local.type = ((VerifierTypeWrapper)type).UnderlyingType;
            }
            else
            {
                local.type = type;
            }
            local.isArg = isArg;
            if (debug)
            {
                FindLvtEntry(local, method, instructionIndex);
            }
            locals.Add(local);
        }
        else
        {
            local.isArg |= isArg;
            local.type   = InstructionState.FindCommonBaseType(local.type, type);
            Debug.Assert(local.type != VerifierTypeWrapper.Invalid);
        }
        foreach (int store in storeSites.Keys)
        {
            LocalVar v;
            if (!localByStoreSite.TryGetValue(MakeKey(store, localIndex), out v))
            {
                localByStoreSite[MakeKey(store, localIndex)] = local;
            }
            else if (v != local)
            {
                local = MergeLocals(locals, localByStoreSite, local, v);
            }
        }
    }
Пример #38
0
	public void UpdateInstruction(InstructionState instructionState, CharacterIndex charIndex){
		_instructionList[(int)charIndex].sprite = _instructionSpriteList[(int)instructionState];
	}
				internal static InstructionState MergeSubroutineReturn(InstructionState jsrSuccessor, InstructionState jsr, InstructionState ret, bool[] locals_modified)
				{
					InstructionState next = ret.Copy();
					next.LocalsCopyOnWrite();
					for (int i = 0; i < locals_modified.Length; i++)
					{
						if (!locals_modified[i])
						{
							next.locals[i] = jsr.locals[i];
						}
					}
					next.flags |= ShareFlags.Subroutines;
					next.subroutines = jsr.subroutines;
					next.callsites = jsr.callsites;
					return jsrSuccessor + next;
				}
				private void MergeSubroutineHelper(InstructionState s2)
				{
					if (subroutines == null || s2.subroutines == null)
					{
						if (subroutines != null)
						{
							subroutines = null;
							changed = true;
						}
					}
					else
					{
						SubroutinesCopyOnWrite();
						List<Subroutine> ss1 = subroutines;
						subroutines = new List<Subroutine>();
						foreach (Subroutine ss2 in s2.subroutines)
						{
							foreach (Subroutine ss in ss1)
							{
								if (ss.SubroutineIndex == ss2.SubroutineIndex)
								{
									subroutines.Add(ss);
									for (int i = 0; i < ss.LocalsModified.Length; i++)
									{
										if (ss2.LocalsModified[i] && !ss.LocalsModified[i])
										{
											ss.LocalsModified[i] = true;
											changed = true;
										}
									}
								}
							}
						}
						if (ss1.Count != subroutines.Count)
						{
							changed = true;
						}
					}

					if (s2.callsites > callsites)
					{
						//Console.WriteLine("s2.callsites = {0}, callsites = {1}", s2.callsites, callsites);
						callsites = s2.callsites;
						changed = true;
					}
				}