예제 #1
0
        private void catchCollisionPhase(object sender, bool isCollisionState)
        {
            MovingSprite spriteSender = (MovingSprite)sender;

            if (isCollisionState)
            {
                collisionSprites.Add(spriteSender);
            }
            else
            {
                collisionSprites.Remove(spriteSender);
            }
        }
예제 #2
0
        void LoadingThread()
        {
            // Border
            myBlankTexture = new Texture2D(myGraphicsDevice, 1, 1);
            myBlankTexture.SetData(new[] { Color.White });

            // load level by parsing XML
            lock (locker)
            {
                myLevelSprites.Clear();
                LevelData levelData = myContent.Load <LevelData>("levels/" + myLevelId);
                foreach (SpriteData curSprite in levelData.sprites)
                {
                    // Loads the sprite
                    MovingSprite dummySprite = new MovingSprite(curSprite.textureName, myGraphicsDevice.Viewport.Width, (collisionTypes)curSprite.obstacleType);
                    dummySprite.LoadContent(myContent);

                    // Set the sprite properties
                    dummySprite.scale    = curSprite.scale;
                    dummySprite.color    = curSprite.color;
                    dummySprite.position = curSprite.position;
                    dummySprite.repeat   = curSprite.repeat;
                    dummySprite.setSpeed(curSprite.gameSpeed);
                    dummySprite.rotation          = curSprite.rotation;
                    dummySprite.rotationSpeed     = curSprite.rotationSpeed;
                    dummySprite.rotationDirection = curSprite.rotationDirection;
                    dummySprite.Changed          += new ChangedEventHandler(catchCollisionPhase);

                    // ****** TEMPORARY!!! Until proper collision detection is implemented ******* /
                    if (myCollidedSprite == null && dummySprite.getCollisionType() == collisionTypes.OBSTACLE)
                    {
                        myCollidedSprite = dummySprite;
                    }

                    myLevelSprites.Add(dummySprite);
                }

                // Load players
                myPlayer.LoadContent(myContent);
                myPlayer.Changed += new ChangedEventHandler(catchPlayerState);
                if (!playerList.list().Contains(myPlayer))
                {
                    playerList.list().Add(myPlayer);
                }

                loadedState = LoadingState.complete;
            }
        }
예제 #3
0
        public void Update(GameTime gameTime)
        {
            if (loadedState != LoadingState.complete)
            {
                return;
            }

            if (runningState == CompletionState.dead)
            {
                KeyboardState currentKeyboardState = Keyboard.GetState();
                GamePadState  currentPadState      = GamePad.GetState(myPlayer.getPlayerIndex());
                if (currentKeyboardState.IsKeyDown(Keys.Enter) || currentPadState.IsButtonDown(Buttons.Start))
                {
                    // Reload the level
                    runningState = CompletionState.running;
                    collisionSprites.Clear();
                    myCollidedSprite = null;
                    failString       = null;
                    LoadLevel(myContent);
                }
            }

            else
            {
                // Update all the level sprites for the level
                foreach (Sprite curSprite in myLevelSprites)
                {
                    curSprite.Update(gameTime, myContent);
                }

                foreach (PlayerSprite curPlayer in playerList.list())
                {
                    curPlayer.Update(gameTime, myContent);
                }

                // TODO detect level detection
                detectLevelCollisions();
            }
        }
예제 #4
0
        void LoadingThread()
        {
            // Border
            myBlankTexture = new Texture2D(myGraphicsDevice, 1, 1);
            myBlankTexture.SetData(new[] { Color.White });

            // load level by parsing XML
            lock (locker)
            {
                myLevelSprites.Clear();
                LevelData levelData = myContent.Load<LevelData>("levels/" + myLevelId);
                foreach (SpriteData curSprite in levelData.sprites)
                {
                    // Loads the sprite
                    MovingSprite dummySprite = new MovingSprite(curSprite.textureName, myGraphicsDevice.Viewport.Width, (collisionTypes)curSprite.obstacleType);
                    dummySprite.LoadContent(myContent);

                    // Set the sprite properties
                    dummySprite.scale = curSprite.scale;
                    dummySprite.color = curSprite.color;
                    dummySprite.position = curSprite.position;
                    dummySprite.repeat = curSprite.repeat;
                    dummySprite.setSpeed(curSprite.gameSpeed);
                    dummySprite.rotation = curSprite.rotation;
                    dummySprite.rotationSpeed = curSprite.rotationSpeed;
                    dummySprite.rotationDirection = curSprite.rotationDirection;
                    dummySprite.Changed += new ChangedEventHandler(catchCollisionPhase);

                    // ****** TEMPORARY!!! Until proper collision detection is implemented ******* /
                    if (myCollidedSprite == null && dummySprite.getCollisionType() == collisionTypes.OBSTACLE)
                        myCollidedSprite = dummySprite;

                    myLevelSprites.Add(dummySprite);
                }

                // Load players
                myPlayer.LoadContent(myContent);
                myPlayer.Changed += new ChangedEventHandler(catchPlayerState);
                if (!playerList.list().Contains(myPlayer))
                    playerList.list().Add(myPlayer);

                loadedState = LoadingState.complete;
            }
        }
예제 #5
0
        public void Update(GameTime gameTime)
        {
            if (loadedState != LoadingState.complete)
                return;

            if (runningState == CompletionState.dead)
            {
                KeyboardState currentKeyboardState = Keyboard.GetState();
                GamePadState currentPadState = GamePad.GetState(myPlayer.getPlayerIndex());
                if (currentKeyboardState.IsKeyDown(Keys.Enter) || currentPadState.IsButtonDown(Buttons.Start))
                {
                    // Reload the level
                    runningState = CompletionState.running;
                    collisionSprites.Clear();
                    myCollidedSprite = null;
                    failString = null;
                    LoadLevel(myContent);
                }
            }

            else
            {
                // Update all the level sprites for the level
                foreach (Sprite curSprite in myLevelSprites)
                    curSprite.Update(gameTime, myContent);

                foreach (PlayerSprite curPlayer in playerList.list())
                    curPlayer.Update(gameTime, myContent);

                // TODO detect level detection
                detectLevelCollisions();
            }
        }