public override void LoadContent() { System.Threading.Thread.Sleep(10); levelstart = true; animList = new List<AnimatedSprite>(); if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); sound = content.Load<SoundEffect>("Sounds\\explode"); explosionTexture = content.Load<Texture2D>("sprites/explosion2"); playerTexture = content.Load<Texture2D>("manwalk"); mouseTexture = content.Load<Texture2D>("cursor"); playerSpawn = new Vector2(150,150); player = new Player(playerTexture, mouseTexture, playerSpawn, content); player.name = name; if (!isFirstLevel) { player.level = pLevel; player.score = pScore; player._health = pHealth; player._lives = pLives; } if (diff == GameDifficulty.HARD_MODE) player.MAX_SHOTS = 3; heart = content.Load<Texture2D>("1up"); isLevelComplete = false; enemyDeleteList = new List<Enemy>(); bulletDeleteList = new List<Bullet>(); eBulletDeleteList = new List<Bullet>(); cam = new Camera(new Vector2(0,0)); particleComponent = new ParticleComponent(ScreenManager.Game); ScreenManager.Game.Components.Add(particleComponent); if (player.level == 1) { objList = new List<TileObject>(); objList = TileHandler.getTileObjectLayout(content, "Content/Layers/LevelOneObjects.txt"); enemyList = new List<Enemy>(); if (diff == GameDifficulty.EASY_MODE ) enemyList = TileHandler.getEnemyLayout(content, "Content/Layers/LevelOneEnemyEasy.txt"); if (diff == GameDifficulty.HARD_MODE) enemyList = TileHandler.getEnemyLayout(content, "Content/Layers/LevelOneEnemyHard.txt"); spriteFont = content.Load<SpriteFont>("SpriteFont1"); backgroundLayer = TileLayer.FromFile(content, "Content/Layers/LevelOneBackgroundLayer.txt"); } if (player.level == 2) { objList = new List<TileObject>(); objList = TileHandler.getTileObjectLayout(content, "Content/Layers/LevelTwoObjects.txt"); enemyList = new List<Enemy>(); if (diff == GameDifficulty.EASY_MODE) enemyList = TileHandler.getEnemyLayout(content, "Content/Layers/LevelTwoEnemyEasy.txt"); if (diff == GameDifficulty.HARD_MODE) enemyList = TileHandler.getEnemyLayout(content, "Content/Layers/LevelTwoEnemyHard.txt"); spriteFont = content.Load<SpriteFont>("SpriteFont1"); backgroundLayer = TileLayer.FromFile(content, "Content/Layers/LevelOneBackgroundLayer.txt"); } if (player.level == 3) { objList = new List<TileObject>(); objList = TileHandler.getTileObjectLayout(content, "Content/Layers/LevelThreeObjects.txt"); enemyList = new List<Enemy>(); if (diff == GameDifficulty.EASY_MODE) enemyList = TileHandler.getEnemyLayout(content, "Content/Layers/LevelThreeEnemyEasy.txt"); if (diff == GameDifficulty.HARD_MODE) enemyList = TileHandler.getEnemyLayout(content, "Content/Layers/LevelThreeEnemyHard.txt"); spriteFont = content.Load<SpriteFont>("SpriteFont1"); backgroundLayer = TileLayer.FromFile(content, "Content/Layers/LevelTwoBackgroundLayer.txt"); Emitter testEmitter2 = new Emitter(); testEmitter2.Active = true; testEmitter2.TextureList.Add(content.Load<Texture2D>("raindrop")); testEmitter2.RandomEmissionInterval = new RandomMinMax(16.0d); testEmitter2.ParticleLifeTime = 1000; testEmitter2.ParticleDirection = new RandomMinMax(170); testEmitter2.ParticleSpeed = new RandomMinMax(10.0f); testEmitter2.ParticleRotation = new RandomMinMax(0); testEmitter2.RotationSpeed = new RandomMinMax(0f); testEmitter2.ParticleFader = new ParticleFader(false, true, 800); testEmitter2.ParticleScaler = new ParticleScaler(false, 1.0f); testEmitter2.Opacity = 255; particleComponent.particleEmitterList.Add(testEmitter2); } ScreenManager.AddScreen(new MessageBoxScreen("", mouseTexture), null); }
public void Update(GameTime gameTime, List<TileObject> t, Camera cam) { //Calculate Sprite Rotation _playerPrevPos = _playerPos; Vector2 direction = _playerPos - _mouse.position; direction.Normalize(); _playerRot = (float)Math.Atan2(direction.Y, direction.X) + (float)(Math.PI * 0.5f); previous = current; current = Keyboard.GetState(); if (isAlive) { if (current.IsKeyDown(Keys.W) && !collision(new Vector2(0, -3), t) && !cam.isMovingUp) { if (_playerPos.Y >= 0 + _playerRec.Height / 2) _playerPos.Y -= 3; } if (current.IsKeyDown(Keys.S) && !collision(new Vector2(0, 3), t) && !cam.isMovingDown) { if (_playerPos.Y <= 600 - _playerRec.Height / 2) _playerPos.Y += 3; } if (current.IsKeyDown(Keys.A) && !collision(new Vector2(-3, 0), t) && !cam.isMovingLeft) { if (_playerPos.X >= 0 + _playerRec.Width / 2) _playerPos.X -= 3; } if (current.IsKeyDown(Keys.D) && !collision(new Vector2(3, 0), t) && !cam.isMovingRight) { if (_playerPos.X <= 800 - _playerRec.Width / 2) _playerPos.X += 3; } } if (_mouse.newLeftClick) { if (bulletList.Count < MAX_SHOTS) { bulletList.Add(new Bullet(_bulletTexture, _mouse.position, this._playerPos)); shot.Play(); } } if (bulletList != null ) { foreach (Bullet b in bulletList) { b.Update(); } removeBullets(bulletList); } if (_health <= 0) { isAlive = false; pSprite = dieSprite; } if (_playerPos == _playerPrevPos && !cam.isMovingUp && !cam.isMovingDown && !cam.isMovingLeft && !cam.isMovingRight && isAlive) pmState = PlayerMovementState.IDLE; else if (_playerPos != _playerPrevPos && isAlive) pmState = PlayerMovementState.WALKING; if (pmState == PlayerMovementState.IDLE && isAlive) { pSprite = idleSprite; } if (pmState == PlayerMovementState.WALKING && isAlive) { pSprite = moveSprite; } if (!isAlive & pSprite.isFinished) { dieSprite = new AnimatedSprite(die, AnimatedSprite.AnimType.FLASH, 1, 2, 0.5f, new Vector2(200, 200), 2.5f); _playerPos = new Vector2(150, 150); _lives--; isAlive = true; _health = 100; pState = PlayerState.ALIVE; pmState = PlayerMovementState.IDLE; } _playerRec.X = (int)_playerPos.X; _playerRec.Y = (int)_playerPos.Y; pSprite.Update(gameTime); _mouse.Update(); }