コード例 #1
0
ファイル: GatherZone.cs プロジェクト: er1/c376p1
 public void draw(Camera cam)
 {
     foreach (Gatherer g in gatherers)
         g.draw(cam);
     foreach (Mineral m in minerals)
         m.draw(cam);
 }
コード例 #2
0
ファイル: Mineral.cs プロジェクト: er1/c376p1
 public void draw(Camera cam)
 {
     foreach (ModelMesh mesh in model.Meshes)
     {
         foreach (BasicEffect effect in mesh.Effects)
         {
             effect.EnableDefaultLighting();
             effect.World = Matrix.CreateTranslation(position + Vector3.UnitY * ((float)life / 10f - 10f));
             effect.View = cam.view;
             effect.Projection = cam.projection;
             effect.CurrentTechnique.Passes[0].Apply();
         }
         mesh.Draw();
     }
 }
コード例 #3
0
ファイル: Gatherer.cs プロジェクト: er1/c376p1
        public void draw(Camera cam)
        {
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = Matrix.CreateFromAxisAngle(Vector3.UnitY, (float)Math.Atan2(direction.X, direction.Z)) * Matrix.CreateTranslation(position);
                    effect.View = cam.view;
                    effect.Projection = cam.projection;
                    effect.CurrentTechnique.Passes[0].Apply();
                }

                mesh.Draw();
            }
        }
コード例 #4
0
ファイル: model.cs プロジェクト: er1/c376p1
        public void DrawModel(Camera cam)
        {
            foreach (ModelMesh mesh in currentModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    //effect.LightingEnabled = true;
                    //effect.DirectionalLight1.DiffuseColor = new Vector3(1f, 1f, 1f);
                    //effect.DirectionalLight1.Direction = new Vector3(0, 1, 0);
                    //effect.DirectionalLight1.SpecularColor = new Vector3(1, 1, 1);
                    //effect.AmbientLightColor = new Vector3(0.4f, 0.4f, 0.4f);
                    effect.World = getWorld() * mesh.ParentBone.Transform;
                    effect.View = cam.view;
                    effect.Projection = cam.projection;
                    //effect.CurrentTechnique.Passes[0].Apply();
                }

                mesh.Draw();
            }
        }
コード例 #5
0
ファイル: ParticleExplosion.cs プロジェクト: er1/c376p1
        public void Draw(Camera camera)
        {
            graphicsDevice.SetVertexBuffer(particleVertexBuffer);

            // Only draw if there are live particles
            if (endOfLiveParticlesIndex - endOfDeadParticlesIndex > 0)
            {
                for (int i = endOfDeadParticlesIndex; i < endOfLiveParticlesIndex; ++i)
                {
                    particleEffect.Parameters["WorldViewProjection"].SetValue(
                        camera.view * camera.projection);
                    particleEffect.Parameters["particleColor"].SetValue(vertexColorArray[i].ToVector4());
                    // Draw particles
                    foreach (EffectPass pass in particleEffect.CurrentTechnique.Passes)
                    {
                        pass.Apply();

                        graphicsDevice.DrawUserPrimitives<VertexPositionTexture>(
                            PrimitiveType.TriangleStrip,
                            verts, i * 4, 2);

                    }
                }
            }
        }
コード例 #6
0
ファイル: Game1.cs プロジェクト: er1/c376p1
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
            #region Menus (GAMESTATES)

            #region Main Menu
            //Credits
            if (gameState == -1)
            {
                if (!creditsMusik)
                {
                    MediaPlayer.Stop();
                    menuMusik = false;
                    MediaPlayer.Play(creditsMusic);
                    creditsMusik = true;
                }
                if ((Keyboard.GetState().IsKeyDown(Keys.Enter) || gamePadState.Buttons.B == ButtonState.Pressed) && !aButton)
                {
                    aButton = true;
                    gameState = 0;

                }

                if ((gamePadState.Buttons.B == ButtonState.Released) && (Keyboard.GetState().IsKeyUp(Keys.Enter)))
                {
                    aButton = false;
                }

            }
            if (gameState == 0)
            {
                if (!menuMusik)
                {
                    MediaPlayer.Stop();
                    creditsMusik = false;
                    gameMusik = false;
                    MediaPlayer.Play(menuMusic);
                    menuMusik = true;
                }

                if (!started)
                {
                    Components.Remove(cameraMain);
                    Components.Remove(spriteManager);
                    Components.Remove(spriteManager.frames);

                    cameraMain = new Camera(this, new Vector3(0, 200, 199), new Vector3(0, -5, 1), Vector3.Up, MainScreen, true, worldSize);
                    spriteManager = new SpriteManager(this);

                    Components.Add(cameraMain);
                    Components.Add(spriteManager);
                    started = true;
                }
                if((Keyboard.GetState().IsKeyDown(Keys.Up)||gamePadState.DPad.Up== ButtonState.Pressed) && !dPadUp)
                {
                    dPadUp = true;
                    menuState--;
                    if (menuState < 0)
                        menuState = 2;

                }
                if ((Keyboard.GetState().IsKeyDown(Keys.Down)||gamePadState.DPad.Down == ButtonState.Pressed) && !dPadDown)
                {
                    dPadDown = true;
                    menuState++;

                    if (menuState > 2)
                        menuState = 0;

                }
                if ((Keyboard.GetState().IsKeyDown(Keys.Enter) || gamePadState.Buttons.A == ButtonState.Pressed) && !aButton)
                {
                    aButton = true;
                    if (menuState == 0)
                    {
                        gameState = 1;
                    }
                    if (menuState == 1)
                    {
                        gameState = -1;
                    }
                    if (menuState == 2)
                    {
                        this.Exit();
                    }

                }
                if ((Keyboard.GetState().IsKeyDown(Keys.Escape)|| gamePadState.Buttons.A == ButtonState.Pressed) && !aButton )
                {
                    aButton = true;
                    if (menuState == 2)
                    {
                        this.Exit();
                    }
                }

                if ((gamePadState.Buttons.B == ButtonState.Released) && (Keyboard.GetState().IsKeyUp(Keys.Z)))
                {
                    bButton = false;
                }
                if ((gamePadState.Buttons.A == ButtonState.Released) && (Keyboard.GetState().IsKeyUp(Keys.Enter)))
                {
                    aButton = false;
                }
                if ((gamePadState.DPad.Up == ButtonState.Released) && (Keyboard.GetState().IsKeyUp(Keys.Up)))
                {
                    dPadUp = false;
                }
                if ((gamePadState.DPad.Down == ButtonState.Released) && (Keyboard.GetState().IsKeyUp(Keys.Down)))
                {
                    dPadDown = false;
                }

            }
            #endregion
            // game

            #region Win/Lose
            else if ((gameState == 3) || (gameState == 4))
            {
                if ((Keyboard.GetState().IsKeyDown(Keys.Enter) || gamePadState.Buttons.A == ButtonState.Pressed) && !aButton)
                {
                    wavesLevel.Clear();

                    aButton = true;
                    LIFE = 1000;
                    gameState = 0;
                    wavesLevel.Clear();
                    towers.Clear();
                    projectiles.Clear();
                    monsters.Clear();
                    resourcemanager = new ResourceManager();
                    gatherzone = new GatherZone(resourcemanager, this);
                    chosenTile = new TileCoord(0, 0);
                    started = false;
                    base.Initialize();
                }

                if ((gamePadState.Buttons.A == ButtonState.Released) && Keyboard.GetState().IsKeyUp(Keys.Enter))
                {
                    aButton = false;
                }
                if ((gamePadState.DPad.Up == ButtonState.Released) && (Keyboard.GetState().IsKeyUp(Keys.Up)))
                {
                    dPadUp = false;
                }
                if ((gamePadState.DPad.Down == ButtonState.Released) && (Keyboard.GetState().IsKeyUp(Keys.Down)))
                {
                    dPadDown = false;
                }

            }
            #endregion

            #region Main Game
            else if (gameState == 1)
            {

                if (!gameMusik)
                {
                    MediaPlayer.Stop();
                    menuMusik = false;
                    MediaPlayer.Play(gameMusic);
                    gameMusik = true;
                }
                base.Update(gameTime);

                if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                {
                    gameState = 2;
                }
                if (gamePadState.Buttons.Start == ButtonState.Pressed)
                {
                    gameState = 2;
                }

            }
            #endregion

            #region Pause Menu
            //pause
            else if (gameState == 2)
            {
                if ((Keyboard.GetState().IsKeyDown(Keys.Up) || gamePadState.DPad.Up == ButtonState.Pressed) && !dPadUp)
                {
                    dPadUp = true;
                    pauseState--;
                    if (pauseState < 0)
                        pauseState = 1;

                }
                if ((Keyboard.GetState().IsKeyDown(Keys.Down) || gamePadState.DPad.Down == ButtonState.Pressed) && !dPadDown)
                {
                    dPadDown = true;
                    pauseState++;

                    if (pauseState > 1)
                        pauseState = 0;

                }
                if ((Keyboard.GetState().IsKeyDown(Keys.Enter) || gamePadState.Buttons.A == ButtonState.Pressed) && !aButton)
                {
                    aButton = true;
                    if (pauseState == 0)
                    {
                        gameState = 1;
                    }
                    if (pauseState == 1)
                    {
                        LIFE = 1000;
                        gameState = 0;
                        wavesLevel.Clear();
                        towers.Clear();
                        projectiles.Clear();
                        monsters.Clear();
                        resourcemanager = new ResourceManager();
                        gatherzone = new GatherZone(resourcemanager, this);
                        chosenTile = new TileCoord(0, 0);
                        started = false;
                        base.Initialize();
                    }

                }

                if ((gamePadState.Buttons.A == ButtonState.Released) && (Keyboard.GetState().IsKeyUp(Keys.Enter)))
                {
                    aButton = false;
                }
                if ((gamePadState.DPad.Up == ButtonState.Released) && (Keyboard.GetState().IsKeyUp(Keys.Up)))
                {
                    dPadUp = false;
                }
                if ((gamePadState.DPad.Down == ButtonState.Released) && (Keyboard.GetState().IsKeyUp(Keys.Down)))
                {
                    dPadDown = false;
                }

            }
            #endregion

            #endregion

            #region GAMESTATE 1 = playing
            if (gameState == 1)
            {
                if (gamePadState.Buttons.Start == ButtonState.Pressed)
                    gameState = 2;
                #region Update Level
                //Level 1
                if (currentWave < wavesLevel.Count)
                {
                    wavesLevel[currentWave].UpdateWave(gameTime);
                    spriteManager.drawHUD(wavesLevel[currentWave].levelTimer, wavesLevel[currentWave].level, curResource);
                    //Check if this Waves Timer is done or monsters are all dead (so wave is done)
                    if (((wavesLevel[currentWave].levelDone && wavesLevel[currentWave].spawn <= 1) && monsters.Count<1 ))
                    {
                        //Game.Exit();
                        //System.GC.Collect();
                        currentWave++;
                    }
                    //If Level isn't done then check the Timer to add monsters at invervals
                    else if (wavesLevel[currentWave].canSpawn && wavesLevel[currentWave].spawn > 0)
                    {

                        int z = RandomNumber(-80, 60);
                        wavesLevel[currentWave].spawn--;
                        wavesLevel[currentWave].canSpawn = false;
                        chance = RandomNumber(1, wavesLevel[currentWave].level);

                        if (chance == 1)
                        {
                            monsters.Add(new monster1(ref Monster1, new Vector3(-390 + 1, 5, z), new Vector3(1, 0, 0), this), true);
                            spriteManager.addLifeBarsMonsters(new Vector2(-390 + 1, z));
                        }
                        if (chance == 2)
                        {
                            monsters.Add(new monster2(ref Monster2, new Vector3(-390 + 1, 5, z), new Vector3(1, 0, 0), this), true);
                            spriteManager.addLifeBarsMonsters(new Vector2(-390 + 1, z));
                        }
                        if (chance == 3)
                        {
                            monsters.Add(new monster3(ref Monster3, new Vector3(-390 + 1, 5, z), new Vector3(1, 0, 0), this), true);
                            spriteManager.addLifeBarsMonsters(new Vector2(-390 + 1, z));
                        }
                        if (chance >= 4)
                        {
                            monsters.Add(new monster4(ref Monster4, new Vector3(-390 + 1, 5, z), new Vector3(1, 0, 0), this), true);
                            spriteManager.addLifeBarsMonsters(new Vector2(-390 + 1, z));
                        }
                    }
                }
                else
                {
                    gameState = 3;
                }

                if (LIFE <= 0)
                {
                    gameState = 4;
                }
                #endregion

                #region Update Drawing the Map
                //update Map
                map.Update();
                //Selected tile
                chosenTile = cameraMain.getCurrentTC();
                SelectionTile.Update(gameTime);

                #endregion

                RemoveDeadEntities();
                UpdateExplosions(gameTime);
                //Has some key input here
                //Selecting Resources
                if (curResource > 0)
                {
                    if (((gamePadState.Buttons.X == ButtonState.Pressed) || (Keyboard.GetState().IsKeyDown(Keys.Q))) && !SpaceBar)//
                    {
                        curResource--;
                        SpaceBar = true;
                    }
                }
                if (curResource < 5)
                {
                    if (((gamePadState.Buttons.Y == ButtonState.Pressed) || (Keyboard.GetState().IsKeyDown(Keys.E))) && !SpaceBar)//
                    {
                        curResource++;
                        SpaceBar = true;
                    }
                }

                #region Update Monster, Tower, bullets + a little logic

                #region monster
                foreach (KeyValuePair<monster, bool> pair in monsters)
                {
                    /*
                    percentage = 0;

                    if ((pair.Key.life / 100) * 100 == 100)
                    {
                        percentage = 100;
                    }
                    else if ((pair.Key.life / 100) * 100 > 75 && (pair.Key.life / 100) * 100 <= 99)
                    {
                        percentage = 100;
                    }
                    else if ((pair.Key.life / 100) * 100 > 51 && (pair.Key.life / 100) * 100 <= 75)
                    {
                        percentage = 75;
                    }
                    else if ((pair.Key.life / 100) * 100 > 25 && (pair.Key.life / 100) * 100 <= 51)
                    {
                        percentage = 50;
                    }
                    else if ((pair.Key.life / 100) * 100 <= 25)
                    {
                        percentage = 25;
                    }
                    */

                    pair.Key.Update(gameTime);
                    //spriteManager.updateLifeBarsMonsters(0, percentage, pair.Key.getPosition(), cameraMain, MainScreen);
                    TileCoord monsterLocation
                        =
                        new TileCoord((int)Math.Floor((pair.Key.getPosition().X + 10) / 20.0), (int)Math.Floor((pair.Key.getPosition().Z + 10) / 20.0));

                    map.GetTile(monsterLocation).addEntity(pair.Key);
                    // HIT THE COLONY NOT FINISHED ( REMOVE LIFE AND BLAH BLAH)
                    //if (pair.Key.hitColony)
                    //{

                    //    //pair.Key.life -= 100;
                    //    //spriteManager.removeLifeBarsMonsters(pair.Key);
                    //    //LIFE -= 10;
                    //}
                }
                #endregion

                #region towers
                //Draws Tower list
                foreach (KeyValuePair<tower, bool> pair in towers)
                {
                    pair.Key.Update();
                    pair.Key.game = this;

                    TileCoord towerLocation
                        =
                        new TileCoord((int)Math.Floor((pair.Key.getPosition().X + 10) / 20.0), (int)Math.Floor((pair.Key.getPosition().Z + 10) / 20.0));

                    map.GetTile(towerLocation).addEntity(pair.Key);

                    //Shoots a projectile based on a Timer from tower
                    if ((pair.Key.iWantToShoot(gameTime)) && (pair.Key.lookForTarget(map)))
                    {
                        if (pair.Key.shooting)
                        {
                            pair.Key.shooting = false;
                            //towers[i].timer = TimeSpan.FromSeconds(3.0);
                            pair.Key.Shoot();
                            //addProject(towers[i].getPosition() + new Vector3(0, 25, 0), new Vector3(-1, 0, 0));
                        }
                    }
                }
                #endregion

                #region projectiles
                //updates projectile list
                foreach (KeyValuePair<projectile, bool> pair in projectiles)
                {
                    pair.Key.Update(gameTime);

                    TileCoord projectileLocation
                        =
                        new TileCoord((int)Math.Floor((pair.Key.getPosition().X + 10) / 20.0), (int)Math.Floor((pair.Key.getPosition().Z + 10) / 20.0));

                    map.GetTile(projectileLocation).addEntity(pair.Key);

                    //Check if projectile Timer is at zero to remove
                    if (pair.Key.removeProject(gameTime))
                    {
                        projectiles.Remove(pair.Key);
                        break;
                    }
                }
                #endregion

                #region Collision detection
                //CheckBoxCollision();
                foreach (KeyValuePair<TileCoord, Tile> pair in map.getDictionary())
                {
                    if ((pair.Value.anyMonster()) && (pair.Value.anyTower()))
                    {
                        List<model> test = pair.Value.getEntities();
                        for (int i = 0; i < test.Count(); i++)
                        {
                            if (test[i] is tower)
                            {
                                foreach (KeyValuePair<tower, bool> pairA in towers)
                                {
                                    if (pairA.Key.getID() == test[i].getID())
                                    {
                                        ((tower)pairA.Key).life -= 25;
                                        break;
                                    }
                                }
                            }
                            if (test[i] is monster)
                            {
                                ((monster)test[i]).life -= 1000;
                            }

                        }
                    }

                    if ((pair.Value.anyMonster()) && (pair.Value.anyProjectile()))
                    {
                        List<model> test = pair.Value.getEntities();
                        for (int i = 0; i < test.Count(); i++)
                        {
                            if (test[i] is monster)
                            {
                                ((monster)test[i]).life -= 25;
                            }
                            if (test[i] is projectile)
                            {
                                foreach (KeyValuePair<projectile, bool> pairA in projectiles)
                                {
                                    if (pairA.Key.getID() == test[i].getID())
                                    {
                                        projectiles.Remove(pairA.Key);
                                        break;
                                    }
                                }
                            }
                        }
                        //CheckTileCollision(pair.Value.getEntities());
                    }
                }
                #endregion

                #region Tower Adding

                //Add Gatherer
                if ((Keyboard.GetState().IsKeyDown(Keys.Z)) || (gamePadState.Buttons.B == ButtonState.Pressed)) {
                    if (bButton == false) {
                        if (resourcemanager.resourceA >= 8) {
                            Gatherer g = new Gatherer(gatherzone, new Vector3(100, 8, 0));
                            g.targetPosition = new Vector3(250, 8, 0);
                            gatherzone.add(g);
                            resourcemanager.resourceA -= 8;
                        }
                    }
                    bButton = true;
                }

                if ((Keyboard.GetState().IsKeyUp(Keys.Z)) && (gamePadState.Buttons.B == ButtonState.Released)) {
                    bButton = false;
                }

                if (((Keyboard.GetState().IsKeyDown(Keys.Space)) && (!map.GetTile(chosenTile).anyTower()) && !SpaceBar) ||
                    ((gamePadState.Buttons.A == ButtonState.Pressed) && (!map.GetTile(chosenTile).anyTower()) && !SpaceBar))
                {
                    SpaceBar = true;

                    tower towerToAdd;
                    //Add Gun Tower
                    if ((curResource == 0) && (resourcemanager.resourceA >= 5))
                    {
                        resourcemanager.resourceA -= 5;
                        towerToAdd = new GunTower(ref gunTower, (new Vector3(chosenTile.x * 20, 5, chosenTile.y * 20)), chosenTile);
                        towers.Add(towerToAdd, true);
                        map.GetTile(chosenTile).addEntity(towerToAdd);
                    }
                    //Add Cannon Tower
                    else if ((curResource == 1) && (resourcemanager.resourceA >= 5) && (resourcemanager.resourceB >= 8))
                    {
                        resourcemanager.resourceA -= 5;
                        resourcemanager.resourceB -= 8;
                        towerToAdd = new CanonTower(ref cannonTower, (new Vector3(chosenTile.x * 20, 5, chosenTile.y * 20)), chosenTile);
                        towers.Add(towerToAdd, true);
                        map.GetTile(chosenTile).addEntity(towerToAdd);
                    }
                    //Add missile tower
                    else if ((curResource == 2) && (resourcemanager.resourceB >= 5) && (resourcemanager.resourceC >= 10))
                    {
                        resourcemanager.resourceB -= 5;
                        resourcemanager.resourceC -= 10;
                        towerToAdd = new MissileTower(ref missileTower, (new Vector3(chosenTile.x * 20, 5, chosenTile.y * 20)), chosenTile);
                        towers.Add(towerToAdd, true);
                        map.GetTile(chosenTile).addEntity(towerToAdd);
                    }
                    //Add Fire Tower
                    else if ((curResource == 3) && (resourcemanager.resourceC >= 10) && (resourcemanager.resourceD >= 10))
                    {
                        resourcemanager.resourceC -= 10;
                        resourcemanager.resourceD -= 10;
                        towerToAdd = new FireTower(ref fireTower, (new Vector3(chosenTile.x * 20, 5, chosenTile.y * 20)), chosenTile);
                        towers.Add(towerToAdd, true);
                        map.GetTile(chosenTile).addEntity(towerToAdd);
                    }
                    //Add Electric Tower
                    else if ((curResource == 4) && (resourcemanager.resourceC >= 15))
                    {
                        resourcemanager.resourceC -= 15;
                        towerToAdd = new ElectricTower(ref electricTower, (new Vector3(chosenTile.x * 20, 5, chosenTile.y * 20)), chosenTile);
                        towers.Add(towerToAdd, true);
                        map.GetTile(chosenTile).addEntity(towerToAdd);
                    }
                    //Add Chicken tower
                    else if ((curResource == 5) && (resourcemanager.resourceD >= 20))
                    {
                        resourcemanager.resourceD -= 20;
                        towerToAdd = new ChickenTower(ref chickenTower, (new Vector3(chosenTile.x * 20, 5, chosenTile.y * 20)), chosenTile);
                        towers.Add(towerToAdd, true);
                        map.GetTile(chosenTile).addEntity(towerToAdd);
                    }

                }

                if (
                    (Keyboard.GetState().IsKeyUp(Keys.Space)) &&
                    (Keyboard.GetState().IsKeyUp(Keys.Q)) &&
                    (Keyboard.GetState().IsKeyUp(Keys.E)) &&
                    (gamePadState.Buttons.A == ButtonState.Released) &&
                    (gamePadState.Buttons.X == ButtonState.Released) &&
                    (gamePadState.Buttons.Y == ButtonState.Released)
                )
                {
                    SpaceBar = false;
                }

                #endregion

                #endregion

                #region Update Resource Manager
                gatherzone.update();
                #endregion
            }
            #endregion
        }
コード例 #7
0
ファイル: Game1.cs プロジェクト: er1/c376p1
        protected override void Initialize()
        {
            LIFE = 1000;

            worldHeight = graphics.PreferredBackBufferHeight;
            worldWidth = graphics.PreferredBackBufferWidth;
            map = new Map();
            #region Viewport stuff
            MainScreen = new Viewport();
            MainScreen.X = 0;
            MainScreen.Y = 0;
            MainScreen.Width = worldWidth;
            MainScreen.Height = worldHeight;
            MainScreen.MinDepth = 0;
            MainScreen.MaxDepth = 1;
            #endregion

            #region init Game components
            Components.Remove(cameraMain);
            Components.Remove(spriteManager);
            cameraMain = new Camera(this, new Vector3(0, 200, 199), new Vector3(0, -5, 1), Vector3.Up, MainScreen, true, worldSize);
            spriteManager = new SpriteManager(this);
            Components.Add(cameraMain);
            Components.Add(spriteManager);
            #endregion

            chosenTile = cameraMain.getCurrentTC();
            this.IsFixedTimeStep = false;
            this.TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 20);

            // resource management
            resourcemanager = new ResourceManager();
            gatherzone = new GatherZone(resourcemanager, this);

            base.Initialize();
        }
コード例 #8
0
ファイル: player.cs プロジェクト: er1/c376p1
        public void Update(Camera cam)
        {
            #region world Wrap
            //World wrapping
            //X coordinates
            if (world.M41 >= worldSize)
            { world = Matrix.CreateTranslation(new Vector3(-worldSize + 1, world.M42, world.M43)); }
            if (world.M41 <= -worldSize)
            { world = Matrix.CreateTranslation(new Vector3(worldSize - 1, world.M42, world.M43)); }

            //Y coordinates
            if (world.M42 >= worldSize)
            { world = Matrix.CreateTranslation(new Vector3(world.M41, -worldSize + 1, world.M43)); }
            if (world.M42 <= -worldSize)
            { world = Matrix.CreateTranslation(new Vector3(world.M41, worldSize - 1, world.M43)); }

            // Z coordinates
            if (world.M43 >= worldSize)
            { world = Matrix.CreateTranslation(new Vector3(world.M41, world.M42, -worldSize + 1)); }
            if (world.M43 <= -worldSize)
            { world = Matrix.CreateTranslation(new Vector3(world.M41, world.M42, worldSize - 1)); }
            #endregion

            #region UBER rotations with Quaternions!!!
            yaw = 0;
            pitch = 0;

            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                yaw += ((MathHelper.PiOver4 / 150) * moveYaw);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                yaw += ((MathHelper.PiOver4 / 150) * -moveYaw);
            }

            // Pitch rotation
            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                float pitchRotation = (MathHelper.PiOver4 / 180) * movePitch;
                if (Math.Abs(currentPitch + pitchRotation) < maxPitch)
                {
                    pitch += MathHelper.ToRadians(movePitch);
                    currentPitch += pitchRotation;
                }
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                float pitchRotation = (MathHelper.PiOver4 / 180) * -movePitch;
                if (Math.Abs(currentPitch + pitchRotation) < maxPitch)
                {
                    pitch += MathHelper.ToRadians(-movePitch);
                    currentPitch += pitchRotation;
                }
            }
            Quaternion rot = Quaternion.CreateFromAxisAngle(Vector3.Right, pitch) * Quaternion.CreateFromAxisAngle(Vector3.Up, yaw) * Quaternion.CreateFromAxisAngle(Vector3.Backward, roll);
            rotation *= rot;
            position += Vector3.Transform(position, Matrix.CreateFromQuaternion(rotation));
            world = Matrix.CreateTranslation(position);

            #endregion
        }
コード例 #9
0
ファイル: SpriteManager.cs プロジェクト: er1/c376p1
 //Updates the life bar texture
 public void updateLifeBarsMonsters(int i,int percentage, Vector3 position, Camera cam, Viewport viewport)
 {
     Vector3 posi = viewport.Project(position, cam.projection, cam.view, Matrix.Identity);
     Vector2 pos = new Vector2(posi.X, posi.Y) + new Vector2(-40 ,-40);
     //pos = new Vector2(0, 0);
     if (percentage == 100)
         monstersLife[i].Update(ref life100, pos);
     if (percentage == 75)
         monstersLife[i].Update(ref life75, pos);
     if (percentage == 50)
         monstersLife[i].Update(ref life50, pos);
     if (percentage == 25)
         monstersLife[i].Update(ref life25, pos);
 }