Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Included Classes.
- Game1.cs
- sprite.cs
- Player.cs
- ZombieMob.cs
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Game1.cs @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- namespace Mini_Stalkers
- {
- /// <summary>
- /// This is the main type for your game
- /// </summary>
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- SpriteBatch spriteBatchHud;
- Texture2D PlayerRight;
- Texture2D PlayerLeft;
- Texture2D PlayerRight2;
- Texture2D PlayerLeft2;
- Texture2D PlayerAttackLeft1;
- Texture2D PlayerAttackRight1;
- Texture2D UndeadRight;
- Texture2D UndeadLeft;
- Texture2D UndeadRight2;
- Texture2D UndeadLeft2;
- Texture2D BoarRight;
- Texture2D BoarLeft;
- Texture2D BoarRight2;
- Texture2D BoarLeft2;
- Texture2D HealthUpgradeTexture;
- Texture2D AttackUpgradeTexture;
- Texture2D SpeedUpgradeTexture;
- Texture2D RestTownTexture;
- Texture2D ShopTownTexture;
- Texture2D QuestTownTexture;
- Texture2D TreeTexture1;
- Texture2D TreeTexture2;
- Texture2D TreeTexture3;
- Texture2D TreeTexture4;
- Texture2D Corpse;
- Texture2D BloodSplat;
- Texture2D BloodSplat2;
- Texture2D grassTexture;
- Texture2D HudPanalTexture;
- Texture2D HPFullTexture;
- Texture2D ExpBarTexture;
- Texture2D TownTexture1;
- SpriteFont StatusText;
- SoundEffect soundHurt;
- SoundEffect soundMiss;
- SoundEffect soundAttack;
- SoundEffect soundZGroan1;
- SoundEffect soundZGroan2;
- Song MusicEncounter;
- bool songstart = false;
- List<ZombieMob> MobList;
- List<Sprite> TownList;
- List<Sprite> grassIndex;
- List<Sprite> TreesIndex;
- List<Sprite> Corpses;
- List<Sprite> HitBoxs;
- List<Sprite> MenuIcons;
- Sprite BloodSplatter;
- Sprite HudPanal;
- Sprite SelectorPanel;
- Player Player;
- int speedDelay = 0;
- int GroanDelay = 0;
- int PlayerSpeed = 1;
- int PlayerAnimationTick;
- int menuTick;
- int menuBeginHalt = 20;
- int startmenupoint = 1;
- int MobAttackDelay;
- bool newGame = true;
- Random newRand;
- private void MoveWorldUp(int moveMultiplyer)
- {
- for (int A = 0; A < moveMultiplyer; A++)
- {
- for (int I = 0; I < MobList.Count; I++)
- {
- MobList[I].Position.Y -= PlayerSpeed;
- }
- for (int I = 0; I < grassIndex.Count; I++)
- {
- grassIndex[I].Position.Y -= PlayerSpeed;
- }
- for (int I = 0; I < Corpses.Count; I++)
- {
- Corpses[I].Position.Y -= PlayerSpeed;
- }
- for (int I = 0; I < TreesIndex.Count; I++)
- {
- TreesIndex[I].Position.Y -= PlayerSpeed;
- }
- for (int I = 0; I < TownList.Count; I++)
- {
- TownList[I].Position.Y -= PlayerSpeed;
- }
- }
- }
- private void MoveWorldDown(int moveMultiplyer)
- {
- for (int A = 0; A < moveMultiplyer; A++)
- {
- for (int I = 0; I < MobList.Count; I++)
- {
- MobList[I].Position.Y += PlayerSpeed;
- }
- for (int I = 0; I < grassIndex.Count; I++)
- {
- grassIndex[I].Position.Y += PlayerSpeed;
- }
- for (int I = 0; I < Corpses.Count; I++)
- {
- Corpses[I].Position.Y += PlayerSpeed;
- }
- for (int I = 0; I < TreesIndex.Count; I++)
- {
- TreesIndex[I].Position.Y += PlayerSpeed;
- }
- for (int I = 0; I < TownList.Count; I++)
- {
- TownList[I].Position.Y += PlayerSpeed;
- }
- }
- }
- private void MoveWorldLeft(int moveMultiplyer)
- {
- for (int A = 0; A < moveMultiplyer; A++)
- {
- for (int I = 0; I < MobList.Count; I++)
- {
- MobList[I].Position.X -= PlayerSpeed;
- }
- for (int I = 0; I < grassIndex.Count; I++)
- {
- grassIndex[I].Position.X -= PlayerSpeed;
- }
- for (int I = 0; I < Corpses.Count; I++)
- {
- Corpses[I].Position.X -= PlayerSpeed;
- }
- for (int I = 0; I < TreesIndex.Count; I++)
- {
- TreesIndex[I].Position.X -= PlayerSpeed;
- }
- for (int I = 0; I < TownList.Count; I++)
- {
- TownList[I].Position.X -= PlayerSpeed;
- }
- }
- }
- private void MoveWorldRight(int moveMultiplyer)
- {
- for (int A = 0; A < moveMultiplyer; A++)
- {
- for (int I = 0; I < MobList.Count; I++)
- {
- MobList[I].Position.X += PlayerSpeed;
- }
- for (int I = 0; I < grassIndex.Count; I++)
- {
- grassIndex[I].Position.X += PlayerSpeed;
- }
- for (int I = 0; I < Corpses.Count; I++)
- {
- Corpses[I].Position.X += PlayerSpeed;
- }
- for (int I = 0; I < TreesIndex.Count; I++)
- {
- TreesIndex[I].Position.X += PlayerSpeed;
- }
- for (int I = 0; I < TownList.Count; I++)
- {
- TownList[I].Position.X += PlayerSpeed;
- }
- }
- }
- private void GenerateMobs(int MobsTotal)
- {
- MobList.Clear();
- int SpawnBoundsX = 0;
- int SpawnBoundsY = 10000;
- //Walkers
- for (int I = 0; I < MobsTotal; I++)
- {
- int mobPosX = newRand.Next(SpawnBoundsX, SpawnBoundsY);
- int mobPosY = newRand.Next(SpawnBoundsX, SpawnBoundsY);
- Vector2 mobPos = new Vector2(mobPosX, mobPosY);
- ZombieMob newMob = new ZombieMob();
- int newLvL = newRand.Next(1, Player.LvL + 4);
- int MobRaceChooser = newRand.Next(0, 2);
- if (MobRaceChooser == 0)
- {
- //Zombie
- newMob.Initialize(UndeadLeft, UndeadRight, UndeadLeft2, UndeadRight2, mobPos, "Walker", StatusText, newLvL, Player);
- }
- else
- {
- //Boar
- newMob.Initialize(BoarLeft, BoarRight, BoarLeft2, BoarRight2, mobPos, "Boar", StatusText, newLvL, Player);
- }
- MobList.Add(newMob);
- }
- }
- private void GenerateTowns(int TownsTotal)
- {
- TownList.Clear();
- int SpawnBoundsX = 400;
- int SpawnBoundsY = 9600;
- for (int I = 0; I < TownsTotal; I++)
- {
- int TownPosX = newRand.Next(SpawnBoundsX, SpawnBoundsY);
- int TownPosY = newRand.Next(SpawnBoundsX, SpawnBoundsY);
- Vector2 TownPos = new Vector2(TownPosX, TownPosY);
- Rectangle TempTownRect = new Rectangle(TownPosX, TownPosX, TownTexture1.Width, TownTexture1.Height);
- for (int tree = 0; tree < TreesIndex.Count; tree++)
- {
- if (TempTownRect.Intersects(TreesIndex[tree].TreeTrunkRect))
- {
- TownPos = new Vector2(newRand.Next(SpawnBoundsX, SpawnBoundsY), newRand.Next(SpawnBoundsX, SpawnBoundsY));
- TempTownRect = new Rectangle(TownPosX, TownPosX, TownTexture1.Width, TownTexture1.Height);
- }
- else
- {
- Sprite newTown = new Sprite();
- newTown.Initialize(TownTexture1, TownPos, "Town");
- TownList.Add(newTown);
- break;
- }
- }
- }
- }
- private void GenerateGround()
- {
- grassIndex.Clear();
- int GrassPosX = 0;
- int GrassPosY = 0;
- int GrassTileTotal = 400;
- for (int I = 0; I < GrassTileTotal; I++)
- {
- Vector2 NewGrassPos = new Vector2(GrassPosX, GrassPosY);
- Sprite newSprite = new Sprite();
- newSprite.Initialize(grassTexture, NewGrassPos, "Grass");
- GrassPosX += 500;
- grassIndex.Add(newSprite);
- if (GrassPosX >= 10000)
- {
- GrassPosX = 0;
- GrassPosY += 500;
- }
- }
- }
- private void GenerateTrees()
- {
- TreesIndex.Clear();
- int TreesTotal = 1000;
- for (int I = 0; I < TreesTotal; I++)
- {
- Vector2 NewTreePos = new Vector2(newRand.Next(0, 10000), newRand.Next(0, 10000));
- Sprite newTree = new Sprite();
- int type = newRand.Next(0, 4);
- if (type == 0)
- {
- newTree.Initialize(TreeTexture1, NewTreePos, "Tree1");
- newTree.FrameHeight += newRand.Next(0, 50);
- newTree.FrameWidth += newRand.Next(0, 40);
- }
- if (type == 1)
- {
- newTree.Initialize(TreeTexture2, NewTreePos, "Tree2");
- newTree.FrameHeight += newRand.Next(0, 50);
- newTree.FrameWidth += newRand.Next(0, 40);
- }
- if (type == 2)
- {
- newTree.Initialize(TreeTexture3, NewTreePos, "Tree3");
- newTree.FrameHeight += newRand.Next(0, 50);
- newTree.FrameWidth += newRand.Next(0, 40);
- }
- if (type == 3)
- {
- newTree.Initialize(TreeTexture4, NewTreePos, "Tree4");
- newTree.FrameHeight += newRand.Next(0, 50);
- newTree.FrameWidth += newRand.Next(0, 40);
- }
- TreesIndex.Add(newTree);
- }
- }
- private void PlayerInput()
- {
- Vector2 keepPosition = Player.Position;
- KeyboardState keyState = Keyboard.GetState();
- if (keyState.IsKeyDown(Keys.Down))
- {
- if (Player.Position.Y > grassIndex[grassIndex.Count - 1].Position.Y-100 )
- {
- return;
- }
- if (PlayerAnimationTick > 10)
- {
- Player.Texture = PlayerRight;
- }
- else
- {
- Player.Texture = PlayerRight2;
- }
- MoveWorldUp(1);
- }
- if (keyState.IsKeyDown(Keys.Up))
- {
- if (Player.Position.Y < grassIndex[0].Position.Y+400)
- {
- return;
- }
- if (PlayerAnimationTick > 10)
- {
- Player.Texture = PlayerLeft;
- }
- else
- {
- Player.Texture = PlayerLeft2;
- }
- MoveWorldDown(1);
- }
- if (keyState.IsKeyDown(Keys.Left))
- {
- Player.PlayerDirection = "Left";
- if (Player.Position.X < grassIndex[0].Position.X + 800)
- {
- return;
- }
- if (PlayerAnimationTick > 10)
- {
- Player.Texture = PlayerLeft;
- }
- else
- {
- Player.Texture = PlayerLeft2;
- }
- MoveWorldRight(1);
- }
- if (keyState.IsKeyDown(Keys.Right))
- {
- Player.PlayerDirection = "Right";
- if (Player.Position.X > grassIndex[grassIndex.Count - 1].Position.X - 500)
- {
- return;
- }
- if (PlayerAnimationTick > 10)
- {
- Player.Texture = PlayerRight;
- }
- else
- {
- Player.Texture = PlayerRight2;
- }
- MoveWorldLeft(1);
- }
- //ATTACK
- if (keyState.IsKeyDown(Keys.Space))
- {
- //Aim Left
- if (Player.PlayerDirection == "Left")
- {
- Player.Texture = PlayerAttackLeft1;
- for (int I = 0; I < MobList.Count; I++)
- {
- if (Player.AttackRectLeft.Intersects(MobList[I].ObjectRect) && Player.CanAttack == true)
- {
- int tempDam = newRand.Next(Player.DamageLow, Player.DamageHigh);
- soundAttack.Play();
- MobList[I].Health -=tempDam;
- MobList[I].Position.X -= 50;
- //HitBox
- Sprite newHitBox = new Sprite();
- newHitBox.Initialize(BloodSplat,new Vector2(MobList[I].Position.X,MobList[I].Position.Y),"HitBox");
- newHitBox.HitBoxPos = new Vector2(MobList[I].Position.X + MobList[I].TextureM.Width / 4 + 10, MobList[I].Position.Y + MobList[I].TextureM.Height /4);
- newHitBox.DamgeHitBox = tempDam;
- newHitBox.StatusText = StatusText;
- HitBoxs.Add(newHitBox);
- }
- }
- Player.CanAttack = false;
- }
- //Aim Right
- if (Player.PlayerDirection == "Right")
- {
- Player.Texture = PlayerAttackRight1;
- for (int I = 0; I < MobList.Count; I++)
- {
- if (Player.AttackRectRight.Intersects(MobList[I].ObjectRect) && Player.CanAttack == true)
- {
- int tempDam = newRand.Next(Player.DamageLow, Player.DamageHigh);
- soundAttack.Play();
- MobList[I].Health -= tempDam;
- MobList[I].Position.X += 50;
- //HitBox
- Sprite newHitBox = new Sprite();
- newHitBox.Initialize(BloodSplat, new Vector2(MobList[I].Position.X + MobList[I].TextureM.Width / 4, MobList[I].Position.Y), "HitBox");
- newHitBox.HitBoxPos = new Vector2(MobList[I].Position.X + MobList[I].TextureM.Width / 4+20, MobList[I].Position.Y+ MobList[I].TextureM.Height / 4);
- newHitBox.DamgeHitBox = tempDam;
- newHitBox.StatusText = StatusText;
- HitBoxs.Add(newHitBox);
- }
- }
- Player.CanAttack = false;
- }
- if (Player.CanAttack == true)
- {
- soundMiss.Play();
- Player.CanAttack = false;
- }
- }
- }
- private void UpdateMobAI(GameTime gameTime)
- {
- int jitter = 1;
- for (int I = 0; I < MobList.Count-1; I++)
- {
- MobAttackDelay++;
- GroanDelay++;
- if (MobAttackDelay > 40)
- {
- MobAttackDelay = 0;
- }
- //Jitter
- if (MobList[I].ObjectRect.Intersects(Player.ObjectRect))
- {
- jitter = 20;
- }
- int randomJitter = newRand.Next(0, 5);
- if (randomJitter == 10)
- {
- MobList[I].Position.Y += jitter;
- }
- if (randomJitter == 10)
- {
- MobList[I].Position.Y -= jitter;
- }
- if (randomJitter == 2)
- {
- MobList[I].Position.X += jitter;
- }
- if (randomJitter == 3)
- {
- MobList[I].Position.X -= jitter;
- }
- jitter = 2;
- //Clear DeActives and add corpses
- if (MobList[I].Active == false)
- {
- Vector2 corpsePos = MobList[I].Position;
- MobList.Remove(MobList[I]);
- Sprite newCorpse = new Sprite();
- newCorpse.Initialize(Corpse, corpsePos, "Corpse");
- Corpses.Add(newCorpse);
- }
- int tempHealth = Player.Health;
- MobList[I].Update(gameTime);
- if (MobList[I].TextureM == MobList[I].TextureR2 || MobList[I].TextureM == MobList[I].TextureL2)
- {
- if (MobList[I].HitRect.Intersects(Player.DetectionRect))
- {
- if (MobList[I].GroanTick > MobList[I].GroanDelay)
- {
- MobList[I].GroanTick = 0;
- MobList[I].GroanDelay = newRand.Next(300,1000);
- int randomGroan = newRand.Next(0, 2);
- if (randomGroan == 1)
- {
- soundZGroan1.Play();
- }
- else
- {
- soundZGroan2.Play();
- }
- }
- }
- }
- if (tempHealth > Player.Health)
- {
- soundHurt.Play();
- }
- }
- //Count Threats
- int AmountofThreat = 0;
- for (int I = 0; I < MobList.Count; I++)
- {
- if (MobList[I].ObjectRect.Intersects(Player.DetectionRect))
- {
- AmountofThreat++;
- }
- }
- if (AmountofThreat > 0)
- {
- if (!songstart)
- {
- MediaPlayer.Play(MusicEncounter);
- MediaPlayer.Volume = 0.4f;
- songstart = true;
- }
- }
- else
- {
- MediaPlayer.Stop();
- songstart = false;
- }
- }
- private void UpdatePlayerAI(GameTime gameTime)
- {
- if(Player.Texture == PlayerAttackLeft1)
- {
- Player.Texture = PlayerLeft;
- }
- if (Player.Texture == PlayerAttackRight1)
- {
- Player.Texture = PlayerRight;
- }
- PlayerAnimationTick++;
- if (PlayerAnimationTick > 20)
- {
- PlayerAnimationTick = 0;
- }
- PlayerInput();
- Player.Update(gameTime);
- for (int I = 0; I < TownList.Count;I++)
- {
- if (Player.HitRect.Intersects(TownList[I].ObjectRect))
- {
- Player.EnterTown = true;
- }
- }
- if (Player.Texture == PlayerAttackLeft1)
- {
- Player.ObjectRect = new Rectangle(Player.ObjectRect.X - 30, Player.ObjectRect.Y, Player.Texture.Width, Player.Texture.Height);
- }
- }
- private void SideCollision(GameTime gameTime)
- {
- for (int I = 0; I < MobList.Count; I++)
- {
- if (MobList[I].Position.X < grassIndex[0].Position.X)
- {
- MobList[I].Position.X += 50;
- }
- if (MobList[I].Position.X > grassIndex[grassIndex.Count - 1].Position.X + 500)
- {
- MobList[I].Position.X -= 50;
- }
- if (MobList[I].Position.Y < grassIndex[0].Position.Y)
- {
- MobList[I].Position.Y += 50;
- }
- if (MobList[I].Position.Y > grassIndex[grassIndex.Count - 1].Position.Y + 500)
- {
- MobList[I].Position.Y -= 50;
- }
- }
- }
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- graphics.PreferredBackBufferWidth = 1024;
- graphics.PreferredBackBufferHeight = 786;
- //graphics.ToggleFullScreen();
- graphics.ApplyChanges();
- }
- protected override void Initialize()
- {
- // TODO: Add your initialization logic here
- Player = new Player();
- HudPanal = new Sprite();
- SelectorPanel = new Sprite();
- BloodSplatter = new Sprite();
- MobList = new List<ZombieMob>();
- TreesIndex = new List<Sprite>();
- grassIndex = new List<Sprite>();
- Corpses = new List<Sprite>();
- HitBoxs = new List<Sprite>();
- TownList = new List<Sprite>();
- MenuIcons = new List<Sprite>();
- newRand = new Random(DateTime.Now.Millisecond);
- base.Initialize();
- }
- protected override void LoadContent()
- {
- // Create a new SpriteBatch, which can be used to draw textures.
- spriteBatch = new SpriteBatch(GraphicsDevice);
- spriteBatchHud = new SpriteBatch(GraphicsDevice);
- PlayerRight = Content.Load<Texture2D>("PlayerRight");
- PlayerLeft = Content.Load<Texture2D>("PlayerLeft");
- PlayerRight2 = Content.Load<Texture2D>("PlayerRight2");
- PlayerLeft2 = Content.Load<Texture2D>("PlayerLeft2");
- PlayerAttackLeft1 = Content.Load<Texture2D>("PlayerAttackLeft1");
- PlayerAttackRight1 = Content.Load<Texture2D>("PlayerAttackRight1");
- TreeTexture1 = Content.Load<Texture2D>("tree1");
- TreeTexture2 = Content.Load<Texture2D>("tree2");
- TreeTexture3 = Content.Load<Texture2D>("tree3");
- TreeTexture4 = Content.Load<Texture2D>("tree4");
- TownTexture1 = Content.Load<Texture2D>("Town");
- StatusText = Content.Load<SpriteFont>("StatusText");
- soundHurt = Content.Load<SoundEffect>("Hurt");
- soundAttack = Content.Load<SoundEffect>("Attack");
- soundZGroan1 = Content.Load<SoundEffect>("ZGroan1");
- soundZGroan2 = Content.Load<SoundEffect>("ZGroan2");
- soundMiss = Content.Load<SoundEffect>("Miss");
- MusicEncounter = Content.Load<Song>("encounter");
- MediaPlayer.IsRepeating = true;
- UndeadRight = Content.Load<Texture2D>("UndeadRight");
- UndeadLeft = Content.Load<Texture2D>("UndeadLeft");
- UndeadRight2 = Content.Load<Texture2D>("UndeadRight2");
- UndeadLeft2 = Content.Load<Texture2D>("UndeadLeft2");
- BoarRight = Content.Load<Texture2D>("BoarRight1");
- BoarLeft = Content.Load<Texture2D>("BoarLeft1");
- BoarRight2 = Content.Load<Texture2D>("BoarRight2");
- BoarLeft2 = Content.Load<Texture2D>("BoarLeft2");
- HudPanalTexture = Content.Load<Texture2D>("HudPanel");
- HealthUpgradeTexture = Content.Load<Texture2D>("HealthUpgrade");
- SpeedUpgradeTexture = Content.Load<Texture2D>("SpeedUpgrade");
- AttackUpgradeTexture = Content.Load<Texture2D>("AttackUpgrade");
- RestTownTexture = Content.Load<Texture2D>("RestIcon");
- ShopTownTexture = Content.Load<Texture2D>("ShopIcon");
- QuestTownTexture = Content.Load<Texture2D>("QuestIcon");
- ExpBarTexture = Content.Load<Texture2D>("ExpBar");
- HPFullTexture = Content.Load<Texture2D>("HpFull");
- grassTexture = Content.Load<Texture2D>("grass");
- Corpse = Content.Load<Texture2D>("Corpse");
- BloodSplat = Content.Load<Texture2D>("BloodSplat");
- BloodSplat2 = Content.Load<Texture2D>("BloodSplat2");
- // TODO: use this.Content to load your game content here
- }
- protected override void UnloadContent()
- {
- // TODO: Unload any non ContentManager content here
- }
- protected override void Update(GameTime gameTime)
- {
- #region Newgame
- if (newGame == true)
- {
- GenerateGround();
- GenerateTrees();
- GenerateMobs(100);
- GenerateTowns(20);
- Vector2 HudPos = new Vector2(500, 830);
- HudPanal.Initialize(HudPanalTexture,HudPos, "HUD");
- BloodSplatter.Initialize(BloodSplat, Player.Position, "Blood");
- BloodSplatter.Active = false;
- newGame = false;
- int StartInn = newRand.Next(0, TownList.Count);
- Player.Initialize(PlayerRight, new Vector2(5000, 5000), "Citizen", StatusText);
- for (int I = 0; I < 4488+(Player.Texture.Width/2); I++)
- {
- Player.Position.X--;
- MoveWorldLeft(1);
- }
- for (int I = 0; I < 4632 ; I++)
- {
- MoveWorldUp(1);
- Player.Position.Y--;
- }
- Player.Health = Player.HealthLimit;
- Player.EXP = 0;
- }
- #endregion
- #region UpgradeMenu
- if (Player.CanUpgrade == true)
- {
- if (menuBeginHalt > 0)
- {
- menuBeginHalt--;
- }
- else
- {
- //Create Menu
- MenuIcons.Clear();
- HudPanal.ObjectRect = new Rectangle((int)Player.Position.X - 590, (int)Player.Position.Y - 300, 1400, 600);
- Sprite newMenubox1 = new Sprite();
- newMenubox1.Initialize(HealthUpgradeTexture, new Vector2((int)Player.Position.X - 475 + 100, (int)Player.Position.Y - 100), "Icon");
- MenuIcons.Add(newMenubox1);
- Sprite newMenubox2 = new Sprite();
- newMenubox2.Initialize(AttackUpgradeTexture, new Vector2((int)Player.Position.X - 475 + 400, (int)Player.Position.Y - 100), "Icon");
- MenuIcons.Add(newMenubox2);
- Sprite newMenubox3 = new Sprite();
- newMenubox3.Initialize(SpeedUpgradeTexture, new Vector2((int)Player.Position.X - 475 + 700, (int)Player.Position.Y - 100), "Icon");
- MenuIcons.Add(newMenubox3);
- //Update Menu
- if (menuTick > 0)
- {
- menuTick--;
- }
- KeyboardState keyState = Keyboard.GetState();
- if (keyState.IsKeyDown(Keys.Left) && menuTick == 0)
- {
- if (startmenupoint != 0)
- {
- startmenupoint--;
- }
- menuTick = 10;
- }
- if (keyState.IsKeyDown(Keys.Right) && menuTick == 0)
- {
- if (startmenupoint != 2)
- {
- startmenupoint++;
- }
- menuTick = 10;
- }
- if (keyState.IsKeyDown(Keys.Space) && menuTick == 0)
- {
- //Health
- if (startmenupoint == 0)
- {
- Player.HealthLimit += 20;
- }
- //Attack
- else if (startmenupoint == 1)
- {
- Player.DamageLow += 10;
- Player.DamageHigh += 10;
- }
- //Speed
- else if (startmenupoint == 2)
- {
- Player.Speed += 1;
- }
- Player.CanUpgrade = false;
- menuBeginHalt = 20;
- }
- Player.Update(gameTime);
- HudPanal.Update(gameTime);
- SelectorPanel.Update(gameTime);
- SelectorPanel.ObjectRect = new Rectangle(MenuIcons[startmenupoint].ObjectRect.X - 40, MenuIcons[startmenupoint].ObjectRect.Y - 40, 280, 280);
- for (int I = 0; I < MenuIcons.Count; I++)
- {
- MenuIcons[I].Update(gameTime);
- }
- }
- }
- #endregion
- #region TownMenu
- if (Player.EnterTown == true)
- {
- //Create Menu
- MenuIcons.Clear();
- HudPanal.ObjectRect = new Rectangle((int)Player.Position.X - 590, (int)Player.Position.Y - 300, 1400, 600);
- Sprite newMenubox1 = new Sprite();
- newMenubox1.Initialize(RestTownTexture, new Vector2((int)Player.Position.X - 475 + 100, (int)Player.Position.Y - 100), "Icon");
- MenuIcons.Add(newMenubox1);
- Sprite newMenubox2 = new Sprite();
- newMenubox2.Initialize(ShopTownTexture, new Vector2((int)Player.Position.X - 475 + 400, (int)Player.Position.Y - 100), "Icon");
- MenuIcons.Add(newMenubox2);
- Sprite newMenubox3 = new Sprite();
- newMenubox3.Initialize(QuestTownTexture, new Vector2((int)Player.Position.X - 475 + 700, (int)Player.Position.Y - 100), "Icon");
- MenuIcons.Add(newMenubox3);
- //Update Menu
- if (menuTick > 0)
- {
- menuTick--;
- }
- //GrabKeys
- KeyboardState keyState = Keyboard.GetState();
- if (keyState.IsKeyDown(Keys.Left) && menuTick == 0)
- {
- if (startmenupoint != 0)
- {
- startmenupoint--;
- }
- menuTick = 10;
- }
- if (keyState.IsKeyDown(Keys.Right) && menuTick == 0)
- {
- if (startmenupoint != 2)
- {
- startmenupoint++;
- }
- menuTick = 10;
- }
- //QuitTown
- if (keyState.IsKeyDown(Keys.Escape) && menuTick == 0)
- {
- Player.EnterTown = false;
- Player.Position.Y += 20;
- MoveWorldUp(15);
- }
- if (keyState.IsKeyDown(Keys.Space) && menuTick == 0)
- {
- //Rest
- if (startmenupoint == 0)
- {
- Player.Health = Player.HealthLimit;
- }
- //Shop
- else if (startmenupoint == 1)
- {
- }
- //Quest
- else if (startmenupoint == 2)
- {
- }
- menuBeginHalt = 20;
- }
- Player.Update(gameTime);
- HudPanal.Update(gameTime);
- SelectorPanel.Update(gameTime);
- SelectorPanel.ObjectRect = new Rectangle(MenuIcons[startmenupoint].ObjectRect.X - 40, MenuIcons[startmenupoint].ObjectRect.Y - 40, 280, 280);
- for (int I = 0; I < MenuIcons.Count; I++)
- {
- MenuIcons[I].Update(gameTime);
- }
- }
- #endregion
- #region Update Tick
- else
- {
- speedDelay++;
- speedDelay = 0;
- // Allows the game to exit
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- this.Exit();
- for (int I = 0; I < TreesIndex.Count; I++)
- {
- TreesIndex[I].Update(gameTime);
- }
- for (int I = 0; I < TownList.Count; I++)
- {
- TownList[I].Update(gameTime);
- }
- for (int I = 0; I < Corpses.Count; I++)
- {
- Corpses[I].Update(gameTime);
- }
- for (int I = 0; I < HitBoxs.Count; I++)
- {
- HitBoxs[I].Update(gameTime);
- if (HitBoxs[I].Active == false)
- {
- HitBoxs.Remove(HitBoxs[I]);
- }
- }
- for (int I = 0; I < grassIndex.Count; I++)
- {
- grassIndex[I].Update(gameTime);
- }
- if (Player.Health < 0)
- {
- newGame = true;
- }
- BloodSplatter.Update(gameTime);
- SideCollision(gameTime);
- UpdateMobAI(gameTime);
- UpdatePlayerAI(gameTime);
- PlayerSpeed = Player.Speed;
- }
- base.Update(gameTime);
- #endregion
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.ForestGreen);
- // TODO: Add your drawing code here
- spriteBatch.Begin(SpriteSortMode.FrontToBack,null);
- //Draw Grass
- for (int I = 0; I < grassIndex.Count; I++)
- {
- grassIndex[I].Draw(spriteBatch);
- //spriteBatch.DrawString(StatusText, I+"", grassIndex[I].Position, Color.White);
- }
- //Draw Trees
- for (int I = 0; I < TreesIndex.Count; I++)
- {
- TreesIndex[I].Draw(spriteBatch);
- }
- //Draw Towns
- for (int I = 0; I < TownList.Count; I++)
- {
- TownList[I].Draw(spriteBatch);
- }
- //Draw Corpses
- for (int I = 0; I < Corpses.Count; I++)
- {
- Corpses[I].Draw(spriteBatch);
- }
- //Draw Player
- Player.Draw(spriteBatch);
- //Draw Mobs
- for (int I = 0; I < MobList.Count; I++)
- {
- MobList[I].Draw(spriteBatch);
- }
- spriteBatch.End();
- spriteBatchHud.Begin();
- //UPgrade Screen
- if (Player.CanUpgrade == true)
- {
- spriteBatchHud.Draw(HudPanalTexture, HudPanal.ObjectRect, Color.White);
- spriteBatchHud.Draw(BloodSplat2, SelectorPanel.ObjectRect, Color.White);
- for (int I = 0; I < MenuIcons.Count; I++)
- {
- MenuIcons[I].Draw(spriteBatchHud);
- }
- }
- //Town Screen
- if (Player.EnterTown == true)
- {
- spriteBatchHud.Draw(HudPanalTexture, HudPanal.ObjectRect, Color.White);
- spriteBatchHud.Draw(BloodSplat2, SelectorPanel.ObjectRect, Color.White);
- for (int I = 0; I < MenuIcons.Count; I++)
- {
- MenuIcons[I].Draw(spriteBatchHud);
- }
- }
- else
- {
- //Draw HUD
- //HudPanal.Draw(spriteBatchHud);
- spriteBatchHud.Draw(HudPanalTexture, Player.StatusBoxPos, Color.White);
- //Draw STATUS BARS
- //LVL/EXPBar
- spriteBatchHud.Draw(ExpBarTexture, Player.ExpStatusPos, Color.White);
- string tempLvlstring = Player.LvL.ToString();
- Vector2 temppos = new Vector2(Player.ExpStatusPos.X - 37, Player.ExpStatusPos.Y);
- spriteBatchHud.DrawString(StatusText, tempLvlstring, temppos, Color.Gold);
- //HealthAmount/HealthBar
- spriteBatchHud.Draw(HPFullTexture, Player.HPStatusPos, Color.White);
- string tempHpstring = Player.Health.ToString();
- temppos = new Vector2(Player.HPStatusPos.X - 37, Player.HPStatusPos.Y - 10);
- spriteBatchHud.DrawString(StatusText, tempHpstring, temppos, Color.ForestGreen);
- //Draw Mob Text
- for (int I = 0; I < MobList.Count; I++)
- {
- if (MobList[I].ObjectRect.Intersects(Player.DetectionRect))
- {
- spriteBatchHud.Draw(HPFullTexture, MobList[I].StatusPos, Color.White);
- }
- }
- //Draw Hitboxes
- for (int I = 0; I < HitBoxs.Count; I++)
- {
- HitBoxs[I].Draw(spriteBatchHud);
- }
- }
- spriteBatchHud.End();
- base.Draw(gameTime);
- }
- }
- }
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ sprite.cs @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- using System;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- namespace Mini_Stalkers
- {
- class Sprite
- {
- public string ID;
- public int FrameWidth;
- public int FrameHeight;
- public bool Active;
- public SpriteFont StatusText;
- public Texture2D Texture;
- public Vector2 Position;
- public Vector2 HitBoxPos;
- public Rectangle ObjectRect;
- public Rectangle TreeTrunkRect;
- public int DamgeHitBox;
- Color Color;
- public int HitboxLife;
- public void Initialize(Texture2D texture, Vector2 position, string Name)
- {
- Texture = texture;
- Position = position;
- ID = Name;
- Color = Color.White;
- FrameWidth = Texture.Width;
- FrameHeight = Texture.Height;
- Active = true;
- ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, FrameWidth, FrameHeight);
- TreeTrunkRect = new Rectangle((int)Position.X/5*2, (int)Position.Y+(Texture.Height/4)*3, FrameWidth/5, Texture.Height/4);
- }
- public void Update(GameTime gameTime)
- {
- if (ID == "HitBox")
- {
- Position.Y--;
- HitBoxPos.Y--;
- HitboxLife++;
- if (HitboxLife > 25)
- {
- Active = false;
- }
- }
- //If found DeActive, quit
- if (Active == false)
- return;
- //Update Boundry
- if (ID == "HUD" || ID == "Icon")
- {
- }
- else
- {
- ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, FrameWidth, FrameHeight);
- }
- }
- public void Draw(SpriteBatch spriteBatch)
- {
- if (ID == "HitBox")
- {
- string tempDamagedone = DamgeHitBox.ToString();
- spriteBatch.Draw(Texture, ObjectRect,Color.White);
- spriteBatch.DrawString(StatusText, tempDamagedone, HitBoxPos, Color.White);
- }
- else if (ID == "Grass" || ID == "Icon")
- {
- spriteBatch.Draw(Texture, ObjectRect, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);
- }
- else
- {
- spriteBatch.Draw(Texture, ObjectRect, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, (Position.Y + FrameHeight) / 1200);
- }
- }
- }
- }
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Player.cs @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- using System;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- namespace Mini_Stalkers
- {
- class Player
- {
- public string ID;
- public int FrameWidth;
- public int FrameHeight;
- public bool Active;
- public bool CanAttack;
- public int AttackDelay;
- public int Health;
- public int HealthLimit;
- public int RegenTick;
- public int LvL;
- public int EXP;
- public int DamageHigh;
- public int DamageLow;
- public int EXPLimit;
- public int Speed;
- public bool CanUpgrade;
- public bool EnterTown;
- public Texture2D Texture;
- public Vector2 Position;
- public Rectangle HPStatusPos;
- public Rectangle ExpStatusPos;
- public Rectangle StatusBoxPos;
- public Rectangle ObjectRect;
- public Rectangle DetectionRect;
- public Rectangle HitRect;
- public Rectangle AttackRectLeft;
- public Rectangle AttackRectRight;
- public SpriteFont Statustext;
- public Vector2 StatustextPos;
- public string PlayerDirection;
- Color Color;
- public void Initialize(Texture2D texture, Vector2 position, string Name, SpriteFont StatusText)
- {
- CanUpgrade = false;
- EnterTown = false;
- CanAttack = true;
- Texture = texture;
- Position = position;
- ID = Name;
- LvL = 1;
- Color = Color.White;
- FrameWidth = Texture.Width;
- FrameHeight = Texture.Height;
- Statustext = StatusText;
- Active = true;
- Health = 300;
- HealthLimit = 100;
- EXP = 0;
- RegenTick = 0;
- EXPLimit = LvL*400;
- DamageLow = 20;
- DamageHigh = 50;
- HitRect = new Rectangle((int)Position.X + 24, (int)Position.Y + 15, 17, 36);
- ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, FrameWidth, FrameHeight);
- DetectionRect = new Rectangle((int)Position.X - 300, (int)Position.Y - 300, 600, 600);
- AttackRectLeft = new Rectangle((int)Position.X - 300, (int)Position.Y, 300, 70);
- AttackRectRight = new Rectangle((int)Position.X + 300, (int)Position.Y, 300, 70);
- Speed = 1;
- }
- public void Update(GameTime gameTime)
- {
- //AttackDelayCheck
- if (CanAttack == false)
- {
- AttackDelay++;
- if(AttackDelay > 40)
- {
- AttackDelay = 0;
- CanAttack = true;
- }
- }
- //If found DeActive, quit
- if (Active == false)
- return;
- //Regen
- if (Health < HealthLimit)
- {
- RegenTick++;
- if (RegenTick > 100 )
- {
- Health += LvL;
- RegenTick = 0;
- }
- }
- //Level up
- if (EXP >= EXPLimit)
- {
- int tempexpchange = EXPLimit-EXP;
- EXP = 0 + tempexpchange;
- LvL++;
- CanUpgrade = true;
- }
- EXPLimit = LvL * 100;
- StatustextPos = new Vector2((int)Position.X, (int)Position.Y - 70);
- ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height);
- AttackRectLeft = new Rectangle((int)Position.X - 30, (int)Position.Y, 110, 70);
- AttackRectRight = new Rectangle((int)Position.X , (int)Position.Y, 110, 70);
- DetectionRect = new Rectangle((int)Position.X - 520, (int)Position.Y - 393, 1024, 786);
- HitRect = new Rectangle((int)Position.X + 24, (int)Position.Y + 15, 17, 36);
- if (LvL > 3)
- {
- ID = "Survivor";
- }
- if (LvL > 6)
- {
- ID = "Stalker";
- }
- //STATUS BAR
- int HpBarSize = Convert.ToInt32(((Health * 100 / HealthLimit)*.7));
- int ExpBarSize = Convert.ToInt32(((EXP * 100 / EXPLimit) * .7));
- HPStatusPos = new Rectangle((int)Position.X, (int)Position.Y - 20,HpBarSize, 10);
- ExpStatusPos = new Rectangle((int)Position.X, (int)Position.Y - 10, ExpBarSize, 5);
- StatusBoxPos = new Rectangle((int)Position.X-40, (int)Position.Y - 29, 40, 45);
- }
- public void Draw(SpriteBatch spriteBatch)
- {
- if (Active)
- {
- spriteBatch.Draw(Texture, ObjectRect, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, (Position.Y + FrameHeight) / 1200);
- }
- }
- }
- }
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ZombieMob.cs @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- using System;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- namespace Mini_Stalkers
- {
- class ZombieMob
- {
- public string ID;
- public int FrameWidth;
- public int FrameHeight;
- public bool Active;
- public bool CanAttack;
- public int AttackDelay;
- public int Health;
- public int RegenTick;
- public int HealthLimit;
- public Texture2D TextureM;
- public Texture2D TextureL;
- public Texture2D TextureR;
- public Texture2D TextureL2;
- public Texture2D TextureR2;
- public Vector2 Position;
- public Rectangle ObjectRect;
- public SpriteFont Statustext;
- public Vector2 StatustextPos;
- public Vector2 StatustextPos2;
- public Rectangle HitRect;
- public Rectangle StatusPos;
- public int AnimationTick;
- public int GroanTick;
- public int GroanDelay;
- public int Lvl;
- public int speed;
- public int TaskDuration;
- public int RoamYDirection;
- public int RoamXDirection;
- Player Player;
- Random newRand = new Random(DateTime.Now.Millisecond);
- Color Color;
- public void Initialize(Texture2D textureL, Texture2D textureR, Texture2D textureL2, Texture2D textureR2, Vector2 position, string Name, SpriteFont StatusText, int LvL, Player player)
- {
- CanAttack = true;
- TextureL = textureL;
- TextureR = textureR;
- TextureL2 = textureL2;
- TextureR2 = textureR2;
- TextureM = TextureR;
- Position = position;
- ID = Name;
- Lvl = LvL;
- Color = Color.White;
- FrameWidth = TextureM.Width;
- FrameHeight = TextureM.Height;
- Statustext = StatusText;
- Active = true;
- Health = Lvl*50;
- RegenTick = 0;
- HealthLimit = Lvl * 50;
- AnimationTick = 0;
- Player = player;
- if (ID == "Walker")
- {
- speed = 1;
- }
- if (ID == "Infected")
- {
- speed = 3;
- }
- if (ID == "Unique")
- {
- speed = 5;
- }
- if (ID == "Boar")
- {
- speed = 1;
- }
- ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, FrameWidth, FrameHeight);
- HitRect = new Rectangle((int)Position.X + 16, (int)Position.Y + 11, 25, 30);
- GroanDelay = 0;
- }
- public void Update(GameTime gameTime)
- {
- newRand = new Random(DateTime.Now.Millisecond);
- //ATTCK DELAY
- if (CanAttack == false)
- {
- AttackDelay++;
- if (AttackDelay > 100)
- {
- AttackDelay = 0;
- CanAttack = true;
- }
- }
- //ANimation delay
- AnimationTick+= newRand.Next(0,3);
- GroanTick++;
- if (AnimationTick > 40)
- {
- AnimationTick = 0;
- }
- //If found DeActive, quit
- if (Health < 0)
- {
- Player.EXP += Lvl * 25;
- Active = false;
- }
- if (Active == false)
- return;
- //REGEN
- if (Health < HealthLimit)
- {
- RegenTick++;
- if (RegenTick > 10)
- {
- Health++;
- RegenTick = 0;
- }
- }
- //Update Boundry
- if (AnimationTick > 10)
- {
- TextureM = TextureR;
- }
- else
- {
- TextureM = TextureR2;
- }
- //Detection Zombie
- if (ID == "Walker" && ObjectRect.Intersects(Player.DetectionRect))
- {
- //Follow
- if (Position.X > Player.Position.X)
- {
- Position.X -= speed;
- if (AnimationTick > 20)
- {
- TextureM = TextureL;
- }
- else
- {
- TextureM = TextureL2;
- }
- }
- if (Position.X < Player.Position.X)
- {
- Position.X += speed;
- if (AnimationTick > 10)
- {
- TextureM = TextureR;
- }
- else
- {
- TextureM = TextureR2;
- }
- }
- if (Position.Y > Player.Position.Y)
- {
- Position.Y -= speed;
- }
- if (Position.Y < Player.Position.Y)
- {
- Position.Y += speed;
- }
- }
- //Wander
- else
- {
- TaskDuration--;
- if (TaskDuration < 0)
- {
- RoamYDirection = newRand.Next(0, 3);
- RoamXDirection = newRand.Next(2, 5);
- TaskDuration = newRand.Next(500, 1000);
- }
- if (RoamYDirection == 1)
- {
- Position.Y -= speed;
- }
- if (RoamYDirection == 2)
- {
- Position.Y += speed;
- }
- if (RoamXDirection == 3)
- {
- Position.X += speed;
- if (AnimationTick > 10)
- {
- TextureM = TextureR;
- }
- else
- {
- TextureM = TextureR2;
- }
- }
- if (RoamXDirection == 4)
- {
- Position.X -= speed;
- if (AnimationTick > 10)
- {
- TextureM = TextureL;
- }
- else
- {
- TextureM = TextureL2;
- }
- }
- }
- //DAMAGE DONE
- if (HitRect.Intersects(Player.HitRect) && CanAttack == true)
- {
- Player.Health -= 50;
- CanAttack = false;
- if (Player.HitRect.X+Player.HitRect.Width/2 < HitRect.X)
- {
- Position.X += 10;
- }
- else if (Player.HitRect.X > HitRect.X+HitRect.Width/2)
- {
- Position.X -= 10;
- }
- }
- //STATUS BAR
- int HpBarSize = Convert.ToInt32((Health * 100 / HealthLimit) * 0.7);
- StatusPos = new Rectangle((int)Position.X, (int)Position.Y -10, HpBarSize, 10);
- StatustextPos = new Vector2(StatusPos.X,StatusPos.Y);
- ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, FrameWidth + Lvl * 10, FrameHeight + Lvl * 10);
- HitRect = new Rectangle((int)Position.X + TextureM.Width/2, (int)Position.Y +TextureM.Height/2, 25,30 );
- }
- public void Draw(SpriteBatch spriteBatch)
- {
- if (Active)
- {
- spriteBatch.Draw(TextureM, ObjectRect, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, (Position.Y + FrameHeight) / 1200);
- }
- }
- }
- }
- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- Good Luck mate!
- Contact me at 'sirquote@gmail.com' if you have any problems :)
Add Comment
Please, Sign In to add comment