Guest User

Untitled

a guest
Nov 16th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 55.84 KB | None | 0 0
  1. Included Classes.
  2. Game1.cs
  3. sprite.cs
  4. Player.cs
  5. ZombieMob.cs
  6.  
  7.  
  8. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Game1.cs @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  9.  
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Audio;
  15. using Microsoft.Xna.Framework.Content;
  16. using Microsoft.Xna.Framework.GamerServices;
  17. using Microsoft.Xna.Framework.Graphics;
  18. using Microsoft.Xna.Framework.Input;
  19. using Microsoft.Xna.Framework.Media;
  20.  
  21. namespace Mini_Stalkers
  22. {
  23.     /// <summary>
  24.     /// This is the main type for your game
  25.     /// </summary>
  26.     public class Game1 : Microsoft.Xna.Framework.Game
  27.     {
  28.         GraphicsDeviceManager graphics;
  29.         SpriteBatch spriteBatch;
  30.         SpriteBatch spriteBatchHud;
  31.  
  32.         Texture2D PlayerRight;
  33.         Texture2D PlayerLeft;
  34.         Texture2D PlayerRight2;
  35.         Texture2D PlayerLeft2;
  36.         Texture2D PlayerAttackLeft1;
  37.         Texture2D PlayerAttackRight1;
  38.  
  39.         Texture2D UndeadRight;
  40.         Texture2D UndeadLeft;
  41.         Texture2D UndeadRight2;
  42.         Texture2D UndeadLeft2;
  43.  
  44.         Texture2D BoarRight;
  45.         Texture2D BoarLeft;
  46.         Texture2D BoarRight2;
  47.         Texture2D BoarLeft2;
  48.         Texture2D HealthUpgradeTexture;
  49.         Texture2D AttackUpgradeTexture;
  50.         Texture2D SpeedUpgradeTexture;
  51.         Texture2D RestTownTexture;
  52.         Texture2D ShopTownTexture;
  53.         Texture2D QuestTownTexture;
  54.  
  55.         Texture2D TreeTexture1;
  56.         Texture2D TreeTexture2;
  57.         Texture2D TreeTexture3;
  58.         Texture2D TreeTexture4;
  59.  
  60.         Texture2D Corpse;
  61.         Texture2D BloodSplat;
  62.         Texture2D BloodSplat2;
  63.         Texture2D grassTexture;
  64.         Texture2D HudPanalTexture;
  65.         Texture2D HPFullTexture;
  66.         Texture2D ExpBarTexture;
  67.         Texture2D TownTexture1;
  68.  
  69.         SpriteFont StatusText;
  70.  
  71.         SoundEffect soundHurt;
  72.         SoundEffect soundMiss;
  73.         SoundEffect soundAttack;
  74.         SoundEffect soundZGroan1;
  75.         SoundEffect soundZGroan2;
  76.         Song MusicEncounter;
  77.         bool songstart = false;
  78.        
  79.  
  80.         List<ZombieMob> MobList;
  81.         List<Sprite> TownList;
  82.  
  83.         List<Sprite> grassIndex;
  84.         List<Sprite> TreesIndex;
  85.         List<Sprite> Corpses;
  86.         List<Sprite> HitBoxs;
  87.         List<Sprite> MenuIcons;
  88.  
  89.         Sprite BloodSplatter;
  90.         Sprite HudPanal;
  91.         Sprite SelectorPanel;
  92.         Player Player;
  93.         int speedDelay = 0;
  94.         int GroanDelay = 0;
  95.         int PlayerSpeed = 1;
  96.         int PlayerAnimationTick;
  97.  
  98.         int menuTick;
  99.         int menuBeginHalt = 20;
  100.         int startmenupoint = 1;
  101.         int MobAttackDelay;
  102.         bool newGame = true;
  103.        
  104.         Random newRand;
  105.  
  106.         private void MoveWorldUp(int moveMultiplyer)
  107.         {
  108.             for (int A = 0; A < moveMultiplyer; A++)
  109.             {
  110.                 for (int I = 0; I < MobList.Count; I++)
  111.                 {
  112.                     MobList[I].Position.Y -= PlayerSpeed;
  113.                 }
  114.                 for (int I = 0; I < grassIndex.Count; I++)
  115.                 {
  116.                     grassIndex[I].Position.Y -= PlayerSpeed;
  117.                 }
  118.                 for (int I = 0; I < Corpses.Count; I++)
  119.                 {
  120.                     Corpses[I].Position.Y -= PlayerSpeed;
  121.                 }
  122.                 for (int I = 0; I < TreesIndex.Count; I++)
  123.                 {
  124.                     TreesIndex[I].Position.Y -= PlayerSpeed;
  125.                 }
  126.                 for (int I = 0; I < TownList.Count; I++)
  127.                 {
  128.                     TownList[I].Position.Y -= PlayerSpeed;
  129.                 }
  130.             }
  131.         }
  132.         private void MoveWorldDown(int moveMultiplyer)
  133.         {
  134.             for (int A = 0; A < moveMultiplyer; A++)
  135.             {
  136.  
  137.                 for (int I = 0; I < MobList.Count; I++)
  138.                 {
  139.                     MobList[I].Position.Y += PlayerSpeed;
  140.                 }
  141.                 for (int I = 0; I < grassIndex.Count; I++)
  142.                 {
  143.                     grassIndex[I].Position.Y += PlayerSpeed;
  144.                 }
  145.                 for (int I = 0; I < Corpses.Count; I++)
  146.                 {
  147.                     Corpses[I].Position.Y += PlayerSpeed;
  148.                 }
  149.                 for (int I = 0; I < TreesIndex.Count; I++)
  150.                 {
  151.                     TreesIndex[I].Position.Y += PlayerSpeed;
  152.                 }
  153.                 for (int I = 0; I < TownList.Count; I++)
  154.                 {
  155.                     TownList[I].Position.Y += PlayerSpeed;
  156.                 }
  157.             }
  158.         }
  159.         private void MoveWorldLeft(int moveMultiplyer)
  160.         {
  161.             for (int A = 0; A < moveMultiplyer; A++)
  162.             {
  163.                 for (int I = 0; I < MobList.Count; I++)
  164.                 {
  165.                     MobList[I].Position.X -= PlayerSpeed;
  166.                 }
  167.                 for (int I = 0; I < grassIndex.Count; I++)
  168.                 {
  169.                     grassIndex[I].Position.X -= PlayerSpeed;
  170.                 }
  171.                 for (int I = 0; I < Corpses.Count; I++)
  172.                 {
  173.                     Corpses[I].Position.X -= PlayerSpeed;
  174.  
  175.                 }
  176.                 for (int I = 0; I < TreesIndex.Count; I++)
  177.                 {
  178.                     TreesIndex[I].Position.X -= PlayerSpeed;
  179.                 }
  180.                 for (int I = 0; I < TownList.Count; I++)
  181.                 {
  182.                     TownList[I].Position.X -= PlayerSpeed;
  183.                 }
  184.             }
  185.         }
  186.         private void MoveWorldRight(int moveMultiplyer)
  187.         {
  188.             for (int A = 0; A < moveMultiplyer; A++)
  189.             {
  190.                 for (int I = 0; I < MobList.Count; I++)
  191.                 {
  192.                     MobList[I].Position.X += PlayerSpeed;
  193.                 }
  194.                 for (int I = 0; I < grassIndex.Count; I++)
  195.                 {
  196.                     grassIndex[I].Position.X += PlayerSpeed;
  197.                 }
  198.                 for (int I = 0; I < Corpses.Count; I++)
  199.                 {
  200.                     Corpses[I].Position.X += PlayerSpeed;
  201.                 }
  202.                 for (int I = 0; I < TreesIndex.Count; I++)
  203.                 {
  204.                     TreesIndex[I].Position.X += PlayerSpeed;
  205.                 }
  206.                 for (int I = 0; I < TownList.Count; I++)
  207.                 {
  208.                     TownList[I].Position.X += PlayerSpeed;
  209.                 }
  210.             }
  211.         }
  212.  
  213.         private void GenerateMobs(int MobsTotal)
  214.         {
  215.             MobList.Clear();
  216.             int SpawnBoundsX = 0;
  217.             int SpawnBoundsY = 10000;
  218.             //Walkers
  219.             for (int I = 0; I < MobsTotal; I++)
  220.             {
  221.                 int mobPosX = newRand.Next(SpawnBoundsX, SpawnBoundsY);
  222.                 int mobPosY = newRand.Next(SpawnBoundsX, SpawnBoundsY);
  223.                 Vector2 mobPos = new Vector2(mobPosX, mobPosY);
  224.                 ZombieMob newMob = new ZombieMob();
  225.                 int newLvL = newRand.Next(1, Player.LvL + 4);
  226.                 int MobRaceChooser = newRand.Next(0, 2);
  227.                 if (MobRaceChooser == 0)
  228.                 {
  229.                     //Zombie
  230.                     newMob.Initialize(UndeadLeft, UndeadRight, UndeadLeft2, UndeadRight2, mobPos, "Walker", StatusText, newLvL, Player);
  231.                 }
  232.                 else
  233.                 {
  234.                     //Boar
  235.                     newMob.Initialize(BoarLeft, BoarRight, BoarLeft2, BoarRight2, mobPos, "Boar", StatusText, newLvL, Player);
  236.                 }
  237.  
  238.  
  239.                 MobList.Add(newMob);
  240.             }
  241.  
  242.         }
  243.         private void GenerateTowns(int TownsTotal)
  244.         {
  245.             TownList.Clear();
  246.            
  247.             int SpawnBoundsX = 400;
  248.             int SpawnBoundsY = 9600;
  249.  
  250.             for (int I = 0; I < TownsTotal; I++)
  251.             {
  252.                 int TownPosX = newRand.Next(SpawnBoundsX, SpawnBoundsY);
  253.                 int TownPosY = newRand.Next(SpawnBoundsX, SpawnBoundsY);
  254.                 Vector2 TownPos = new Vector2(TownPosX, TownPosY);
  255.                 Rectangle TempTownRect = new Rectangle(TownPosX, TownPosX, TownTexture1.Width, TownTexture1.Height);
  256.                 for (int tree = 0; tree < TreesIndex.Count; tree++)
  257.                 {
  258.                     if (TempTownRect.Intersects(TreesIndex[tree].TreeTrunkRect))
  259.                     {
  260.                         TownPos = new Vector2(newRand.Next(SpawnBoundsX, SpawnBoundsY), newRand.Next(SpawnBoundsX, SpawnBoundsY));
  261.                         TempTownRect = new Rectangle(TownPosX, TownPosX, TownTexture1.Width, TownTexture1.Height);
  262.                     }
  263.                     else
  264.                     {
  265.                         Sprite newTown = new Sprite();
  266.                         newTown.Initialize(TownTexture1, TownPos, "Town");
  267.                         TownList.Add(newTown);
  268.                         break;
  269.                     }
  270.                 }
  271.             }
  272.         }
  273.         private void GenerateGround()
  274.         {
  275.             grassIndex.Clear();
  276.             int GrassPosX = 0;
  277.             int GrassPosY = 0;
  278.             int GrassTileTotal = 400;
  279.             for (int I = 0; I < GrassTileTotal; I++)
  280.             {
  281.  
  282.                 Vector2 NewGrassPos = new Vector2(GrassPosX, GrassPosY);
  283.                 Sprite newSprite = new Sprite();
  284.  
  285.                 newSprite.Initialize(grassTexture, NewGrassPos, "Grass");
  286.                 GrassPosX += 500;
  287.                 grassIndex.Add(newSprite);
  288.  
  289.                 if (GrassPosX >= 10000)
  290.                 {
  291.                     GrassPosX = 0;
  292.                     GrassPosY += 500;
  293.                 }
  294.  
  295.             }
  296.         }
  297.         private void GenerateTrees()
  298.         {
  299.             TreesIndex.Clear();
  300.  
  301.  
  302.             int TreesTotal = 1000;
  303.             for (int I = 0; I < TreesTotal; I++)
  304.             {
  305.  
  306.                 Vector2 NewTreePos = new Vector2(newRand.Next(0, 10000), newRand.Next(0, 10000));
  307.                 Sprite newTree = new Sprite();
  308.                 int type = newRand.Next(0, 4);
  309.                 if (type == 0)
  310.                 {
  311.                     newTree.Initialize(TreeTexture1, NewTreePos, "Tree1");
  312.                     newTree.FrameHeight += newRand.Next(0, 50);
  313.                     newTree.FrameWidth += newRand.Next(0, 40);
  314.                 }
  315.                 if (type == 1)
  316.                 {
  317.                     newTree.Initialize(TreeTexture2, NewTreePos, "Tree2");
  318.                     newTree.FrameHeight += newRand.Next(0, 50);
  319.                     newTree.FrameWidth += newRand.Next(0, 40);
  320.                 }
  321.                 if (type == 2)
  322.                 {
  323.                     newTree.Initialize(TreeTexture3, NewTreePos, "Tree3");
  324.                     newTree.FrameHeight += newRand.Next(0, 50);
  325.                     newTree.FrameWidth += newRand.Next(0, 40);
  326.                 }
  327.                 if (type == 3)
  328.                 {
  329.                     newTree.Initialize(TreeTexture4, NewTreePos, "Tree4");
  330.                     newTree.FrameHeight += newRand.Next(0, 50);
  331.                     newTree.FrameWidth += newRand.Next(0, 40);
  332.                 }
  333.  
  334.  
  335.                 TreesIndex.Add(newTree);
  336.  
  337.  
  338.  
  339.             }
  340.         }
  341.         private void PlayerInput()
  342.         {
  343.             Vector2 keepPosition = Player.Position;
  344.             KeyboardState keyState = Keyboard.GetState();
  345.             if (keyState.IsKeyDown(Keys.Down))
  346.             {
  347.                
  348.                 if (Player.Position.Y > grassIndex[grassIndex.Count - 1].Position.Y-100 )
  349.                 {    
  350.                     return;
  351.                 }
  352.                
  353.                 if (PlayerAnimationTick > 10)
  354.                 {
  355.                     Player.Texture = PlayerRight;
  356.                 }
  357.                 else
  358.                 {
  359.                     Player.Texture = PlayerRight2;
  360.                 }
  361.                 MoveWorldUp(1);
  362.                
  363.             }
  364.             if (keyState.IsKeyDown(Keys.Up))
  365.             {
  366.                
  367.                 if (Player.Position.Y < grassIndex[0].Position.Y+400)
  368.                 {
  369.                     return;
  370.                 }
  371.                
  372.                 if (PlayerAnimationTick > 10)
  373.                 {
  374.                     Player.Texture = PlayerLeft;
  375.                 }
  376.                 else
  377.                 {
  378.                     Player.Texture = PlayerLeft2;
  379.                 }
  380.                 MoveWorldDown(1);
  381.                
  382.             }
  383.             if (keyState.IsKeyDown(Keys.Left))
  384.             {
  385.                 Player.PlayerDirection = "Left";
  386.                 if (Player.Position.X < grassIndex[0].Position.X + 800)
  387.                 {
  388.                     return;
  389.                 }
  390.                 if (PlayerAnimationTick > 10)
  391.                 {
  392.                     Player.Texture = PlayerLeft;
  393.                 }
  394.                 else
  395.                 {
  396.                     Player.Texture = PlayerLeft2;
  397.                 }
  398.                 MoveWorldRight(1);
  399.                
  400.             }
  401.             if (keyState.IsKeyDown(Keys.Right))
  402.             {
  403.                 Player.PlayerDirection = "Right";
  404.                 if (Player.Position.X > grassIndex[grassIndex.Count - 1].Position.X - 500)
  405.                 {
  406.                     return;
  407.                 }
  408.                 if (PlayerAnimationTick > 10)
  409.                 {
  410.                     Player.Texture = PlayerRight;
  411.                 }
  412.                 else
  413.                 {
  414.                     Player.Texture = PlayerRight2;
  415.                 }
  416.                 MoveWorldLeft(1);
  417.             }
  418.             //ATTACK
  419.             if (keyState.IsKeyDown(Keys.Space))
  420.             {
  421.                 //Aim Left
  422.                 if (Player.PlayerDirection == "Left")
  423.                 {
  424.                     Player.Texture = PlayerAttackLeft1;
  425.                     for (int I = 0; I < MobList.Count; I++)
  426.                     {
  427.                         if (Player.AttackRectLeft.Intersects(MobList[I].ObjectRect) && Player.CanAttack == true)
  428.  
  429.                         {
  430.                             int tempDam = newRand.Next(Player.DamageLow, Player.DamageHigh);
  431.                             soundAttack.Play();
  432.                             MobList[I].Health -=tempDam;
  433.                             MobList[I].Position.X -= 50;
  434.                             //HitBox
  435.                             Sprite  newHitBox = new Sprite();
  436.                             newHitBox.Initialize(BloodSplat,new Vector2(MobList[I].Position.X,MobList[I].Position.Y),"HitBox");
  437.                             newHitBox.HitBoxPos = new Vector2(MobList[I].Position.X + MobList[I].TextureM.Width / 4 + 10, MobList[I].Position.Y + MobList[I].TextureM.Height /4);
  438.                             newHitBox.DamgeHitBox = tempDam;
  439.                             newHitBox.StatusText = StatusText;
  440.                             HitBoxs.Add(newHitBox);
  441.                         }        
  442.                     }
  443.                     Player.CanAttack = false;                
  444.                 }
  445.                 //Aim Right
  446.                 if (Player.PlayerDirection == "Right")
  447.                 {
  448.                     Player.Texture = PlayerAttackRight1;
  449.                     for (int I = 0; I < MobList.Count; I++)
  450.                     {
  451.                         if (Player.AttackRectRight.Intersects(MobList[I].ObjectRect) && Player.CanAttack == true)
  452.                         {
  453.                             int tempDam = newRand.Next(Player.DamageLow, Player.DamageHigh);
  454.                             soundAttack.Play();
  455.                             MobList[I].Health -= tempDam;
  456.                             MobList[I].Position.X += 50;
  457.                             //HitBox
  458.                             Sprite newHitBox = new Sprite();
  459.                             newHitBox.Initialize(BloodSplat, new Vector2(MobList[I].Position.X + MobList[I].TextureM.Width / 4, MobList[I].Position.Y), "HitBox");
  460.                             newHitBox.HitBoxPos = new Vector2(MobList[I].Position.X + MobList[I].TextureM.Width / 4+20, MobList[I].Position.Y+ MobList[I].TextureM.Height / 4);
  461.                             newHitBox.DamgeHitBox = tempDam;
  462.                             newHitBox.StatusText = StatusText;
  463.                             HitBoxs.Add(newHitBox);
  464.                            
  465.                         }
  466.                        
  467.                     }
  468.                     Player.CanAttack = false;
  469.                    
  470.                 }
  471.                 if (Player.CanAttack == true)
  472.                 {
  473.                    
  474.                     soundMiss.Play();
  475.                     Player.CanAttack = false;
  476.                 }
  477.             }
  478.            
  479.              
  480.         }
  481.  
  482.         private void UpdateMobAI(GameTime gameTime)
  483.         {
  484.            
  485.             int jitter = 1;
  486.             for (int I = 0; I < MobList.Count-1; I++)
  487.             {
  488.                 MobAttackDelay++;
  489.                 GroanDelay++;
  490.                 if (MobAttackDelay > 40)
  491.                 {
  492.                     MobAttackDelay = 0;
  493.  
  494.                 }
  495.                 //Jitter
  496.                 if (MobList[I].ObjectRect.Intersects(Player.ObjectRect))
  497.                 {
  498.                     jitter = 20;
  499.                 }
  500.                 int randomJitter = newRand.Next(0, 5);
  501.                 if (randomJitter == 10)
  502.                 {
  503.                     MobList[I].Position.Y += jitter;
  504.                    
  505.                 }
  506.                 if (randomJitter == 10)
  507.                 {
  508.                     MobList[I].Position.Y -= jitter;
  509.                    
  510.                 }
  511.                 if (randomJitter == 2)
  512.                 {
  513.                     MobList[I].Position.X += jitter;
  514.                    
  515.                 }
  516.                 if (randomJitter == 3)
  517.                 {
  518.                     MobList[I].Position.X -= jitter;
  519.                    
  520.                 }
  521.                 jitter = 2;
  522.                 //Clear DeActives and add corpses
  523.                 if (MobList[I].Active == false)
  524.                 {
  525.                    
  526.                     Vector2 corpsePos = MobList[I].Position;
  527.                     MobList.Remove(MobList[I]);
  528.  
  529.                     Sprite newCorpse = new Sprite();
  530.                     newCorpse.Initialize(Corpse, corpsePos, "Corpse");
  531.                     Corpses.Add(newCorpse);
  532.                    
  533.                 }
  534.                 int tempHealth = Player.Health;
  535.  
  536.                 MobList[I].Update(gameTime);
  537.  
  538.                 if (MobList[I].TextureM == MobList[I].TextureR2 || MobList[I].TextureM == MobList[I].TextureL2)
  539.                 {
  540.                     if (MobList[I].HitRect.Intersects(Player.DetectionRect))
  541.                     {
  542.                         if (MobList[I].GroanTick > MobList[I].GroanDelay)
  543.                         {
  544.                             MobList[I].GroanTick = 0;
  545.                             MobList[I].GroanDelay = newRand.Next(300,1000);
  546.                             int randomGroan = newRand.Next(0, 2);
  547.                             if (randomGroan == 1)
  548.                             {
  549.                                 soundZGroan1.Play();
  550.                             }
  551.                             else
  552.                             {
  553.                                 soundZGroan2.Play();
  554.                             }
  555.                         }
  556.                     }
  557.                 }
  558.                 if (tempHealth > Player.Health)
  559.                 {
  560.                     soundHurt.Play();
  561.                 }
  562.                
  563.             }
  564.             //Count Threats
  565.             int AmountofThreat = 0;
  566.             for (int I = 0; I < MobList.Count; I++)
  567.             {
  568.                 if (MobList[I].ObjectRect.Intersects(Player.DetectionRect))
  569.                 {
  570.                     AmountofThreat++;
  571.                 }
  572.                
  573.             }
  574.             if (AmountofThreat > 0)
  575.             {
  576.             if (!songstart)
  577.                     {
  578.                         MediaPlayer.Play(MusicEncounter);
  579.                         MediaPlayer.Volume = 0.4f;
  580.                         songstart = true;
  581.                     }  
  582.                    
  583.             }
  584.             else
  585.                 {
  586.                     MediaPlayer.Stop();
  587.                     songstart = false;
  588.                 }
  589.         }
  590.         private void UpdatePlayerAI(GameTime gameTime)
  591.         {
  592.             if(Player.Texture == PlayerAttackLeft1)
  593.             {
  594.                 Player.Texture = PlayerLeft;
  595.             }
  596.             if (Player.Texture == PlayerAttackRight1)
  597.             {
  598.                 Player.Texture = PlayerRight;
  599.             }
  600.             PlayerAnimationTick++;
  601.             if (PlayerAnimationTick > 20)
  602.             {
  603.                 PlayerAnimationTick = 0;
  604.             }
  605.  
  606.            
  607.            
  608.             PlayerInput();
  609.             Player.Update(gameTime);
  610.             for (int I = 0; I < TownList.Count;I++)
  611.             {
  612.                 if (Player.HitRect.Intersects(TownList[I].ObjectRect))
  613.                 {
  614.                     Player.EnterTown = true;
  615.                 }
  616.             }
  617.             if (Player.Texture == PlayerAttackLeft1)
  618.             {
  619.                 Player.ObjectRect = new Rectangle(Player.ObjectRect.X - 30, Player.ObjectRect.Y, Player.Texture.Width, Player.Texture.Height);
  620.             }
  621.         }
  622.        
  623.         private void SideCollision(GameTime gameTime)
  624.         {
  625.  
  626.             for (int I = 0; I < MobList.Count; I++)
  627.             {
  628.                 if (MobList[I].Position.X < grassIndex[0].Position.X)
  629.                 {
  630.                     MobList[I].Position.X += 50;
  631.                 }
  632.                 if (MobList[I].Position.X > grassIndex[grassIndex.Count - 1].Position.X + 500)
  633.                 {
  634.                     MobList[I].Position.X -= 50;
  635.                 }
  636.                 if (MobList[I].Position.Y < grassIndex[0].Position.Y)
  637.                 {
  638.                     MobList[I].Position.Y += 50;
  639.                 }
  640.                 if (MobList[I].Position.Y > grassIndex[grassIndex.Count - 1].Position.Y + 500)
  641.                 {
  642.                     MobList[I].Position.Y -= 50;
  643.                 }
  644.  
  645.             }
  646.  
  647.         }
  648.        
  649.    
  650.         public Game1()
  651.         {
  652.             graphics = new GraphicsDeviceManager(this);
  653.             Content.RootDirectory = "Content";
  654.            
  655.             graphics.PreferredBackBufferWidth = 1024;
  656.             graphics.PreferredBackBufferHeight = 786;
  657.             //graphics.ToggleFullScreen();
  658.             graphics.ApplyChanges();
  659.         }
  660.  
  661.         protected override void Initialize()
  662.         {
  663.             // TODO: Add your initialization logic here
  664.             Player = new Player();
  665.             HudPanal = new Sprite();
  666.             SelectorPanel = new Sprite();
  667.             BloodSplatter = new Sprite();
  668.             MobList = new List<ZombieMob>();
  669.             TreesIndex = new List<Sprite>();
  670.             grassIndex = new List<Sprite>();
  671.             Corpses = new List<Sprite>();
  672.             HitBoxs = new List<Sprite>();
  673.             TownList = new List<Sprite>();
  674.             MenuIcons = new List<Sprite>();
  675.             newRand = new Random(DateTime.Now.Millisecond);
  676.            
  677.             base.Initialize();
  678.         }
  679.  
  680.         protected override void LoadContent()
  681.         {
  682.             // Create a new SpriteBatch, which can be used to draw textures.
  683.             spriteBatch = new SpriteBatch(GraphicsDevice);
  684.             spriteBatchHud = new SpriteBatch(GraphicsDevice);
  685.  
  686.             PlayerRight = Content.Load<Texture2D>("PlayerRight");
  687.             PlayerLeft = Content.Load<Texture2D>("PlayerLeft");
  688.             PlayerRight2 = Content.Load<Texture2D>("PlayerRight2");
  689.             PlayerLeft2 = Content.Load<Texture2D>("PlayerLeft2");
  690.             PlayerAttackLeft1 = Content.Load<Texture2D>("PlayerAttackLeft1");
  691.             PlayerAttackRight1 = Content.Load<Texture2D>("PlayerAttackRight1");
  692.  
  693.             TreeTexture1 = Content.Load<Texture2D>("tree1");
  694.             TreeTexture2 = Content.Load<Texture2D>("tree2");
  695.             TreeTexture3 = Content.Load<Texture2D>("tree3");
  696.             TreeTexture4 = Content.Load<Texture2D>("tree4");
  697.  
  698.             TownTexture1 = Content.Load<Texture2D>("Town");
  699.            
  700.             StatusText = Content.Load<SpriteFont>("StatusText");
  701.  
  702.             soundHurt = Content.Load<SoundEffect>("Hurt");
  703.             soundAttack = Content.Load<SoundEffect>("Attack");
  704.             soundZGroan1 = Content.Load<SoundEffect>("ZGroan1");
  705.             soundZGroan2 = Content.Load<SoundEffect>("ZGroan2");
  706.             soundMiss = Content.Load<SoundEffect>("Miss");
  707.             MusicEncounter = Content.Load<Song>("encounter");
  708.             MediaPlayer.IsRepeating = true;
  709.            
  710.             UndeadRight = Content.Load<Texture2D>("UndeadRight");
  711.             UndeadLeft = Content.Load<Texture2D>("UndeadLeft");
  712.             UndeadRight2 = Content.Load<Texture2D>("UndeadRight2");
  713.             UndeadLeft2 = Content.Load<Texture2D>("UndeadLeft2");
  714.  
  715.             BoarRight = Content.Load<Texture2D>("BoarRight1");
  716.             BoarLeft = Content.Load<Texture2D>("BoarLeft1");
  717.             BoarRight2 = Content.Load<Texture2D>("BoarRight2");
  718.             BoarLeft2 = Content.Load<Texture2D>("BoarLeft2");
  719.  
  720.             HudPanalTexture = Content.Load<Texture2D>("HudPanel");
  721.            
  722.             HealthUpgradeTexture = Content.Load<Texture2D>("HealthUpgrade");
  723.             SpeedUpgradeTexture = Content.Load<Texture2D>("SpeedUpgrade");
  724.             AttackUpgradeTexture = Content.Load<Texture2D>("AttackUpgrade");
  725.             RestTownTexture = Content.Load<Texture2D>("RestIcon");
  726.             ShopTownTexture = Content.Load<Texture2D>("ShopIcon");
  727.             QuestTownTexture = Content.Load<Texture2D>("QuestIcon");
  728.             ExpBarTexture = Content.Load<Texture2D>("ExpBar");
  729.             HPFullTexture = Content.Load<Texture2D>("HpFull");
  730.  
  731.             grassTexture = Content.Load<Texture2D>("grass");
  732.             Corpse = Content.Load<Texture2D>("Corpse");
  733.             BloodSplat = Content.Load<Texture2D>("BloodSplat");
  734.             BloodSplat2 = Content.Load<Texture2D>("BloodSplat2");
  735.             // TODO: use this.Content to load your game content here
  736.         }
  737.  
  738.         protected override void UnloadContent()
  739.         {
  740.             // TODO: Unload any non ContentManager content here
  741.         }
  742.  
  743.         protected override void Update(GameTime gameTime)
  744.         {
  745. #region Newgame
  746.             if (newGame == true)
  747.             {
  748.  
  749.                 GenerateGround();
  750.                 GenerateTrees();
  751.                 GenerateMobs(100);
  752.                 GenerateTowns(20);
  753.                 Vector2 HudPos = new Vector2(500, 830);
  754.                 HudPanal.Initialize(HudPanalTexture,HudPos, "HUD");
  755.                 BloodSplatter.Initialize(BloodSplat, Player.Position, "Blood");
  756.                 BloodSplatter.Active = false;
  757.                 newGame = false;
  758.                 int StartInn = newRand.Next(0, TownList.Count);        
  759.  
  760.                 Player.Initialize(PlayerRight, new Vector2(5000, 5000), "Citizen", StatusText);
  761.  
  762.                 for (int I = 0; I < 4488+(Player.Texture.Width/2); I++)
  763.                 {
  764.                     Player.Position.X--;
  765.                     MoveWorldLeft(1);
  766.                 }
  767.                 for (int I = 0; I < 4632 ; I++)
  768.                 {
  769.                     MoveWorldUp(1);
  770.                     Player.Position.Y--;
  771.                 }
  772.  
  773.                 Player.Health = Player.HealthLimit;
  774.                 Player.EXP = 0;  
  775.             }
  776. #endregion
  777. #region UpgradeMenu
  778.             if (Player.CanUpgrade == true)
  779.             {
  780.  
  781.                 if (menuBeginHalt > 0)
  782.                 {
  783.                     menuBeginHalt--;
  784.                 }
  785.                 else
  786.                 {
  787.                     //Create Menu
  788.                     MenuIcons.Clear();
  789.                     HudPanal.ObjectRect = new Rectangle((int)Player.Position.X - 590, (int)Player.Position.Y - 300, 1400, 600);
  790.  
  791.                     Sprite newMenubox1 = new Sprite();
  792.                     newMenubox1.Initialize(HealthUpgradeTexture, new Vector2((int)Player.Position.X - 475 + 100, (int)Player.Position.Y - 100), "Icon");
  793.                     MenuIcons.Add(newMenubox1);
  794.  
  795.                     Sprite newMenubox2 = new Sprite();
  796.                     newMenubox2.Initialize(AttackUpgradeTexture, new Vector2((int)Player.Position.X - 475 + 400, (int)Player.Position.Y - 100), "Icon");
  797.                     MenuIcons.Add(newMenubox2);
  798.  
  799.                     Sprite newMenubox3 = new Sprite();
  800.                     newMenubox3.Initialize(SpeedUpgradeTexture, new Vector2((int)Player.Position.X - 475 + 700, (int)Player.Position.Y - 100), "Icon");
  801.                     MenuIcons.Add(newMenubox3);
  802.  
  803.                    
  804.  
  805.                     //Update Menu
  806.                     if (menuTick > 0)
  807.                     {
  808.                         menuTick--;
  809.                     }
  810.  
  811.                     KeyboardState keyState = Keyboard.GetState();
  812.                     if (keyState.IsKeyDown(Keys.Left) && menuTick == 0)
  813.                     {
  814.                         if (startmenupoint != 0)
  815.                         {
  816.                             startmenupoint--;
  817.                         }
  818.                         menuTick = 10;
  819.                     }
  820.                     if (keyState.IsKeyDown(Keys.Right) && menuTick == 0)
  821.                     {
  822.                         if (startmenupoint != 2)
  823.                         {
  824.                             startmenupoint++;
  825.                         }
  826.                         menuTick = 10;
  827.                     }
  828.                     if (keyState.IsKeyDown(Keys.Space) && menuTick == 0)
  829.                     {
  830.                         //Health
  831.                         if (startmenupoint == 0)
  832.                         {
  833.                             Player.HealthLimit += 20;
  834.                            
  835.                         }
  836.                         //Attack
  837.                         else if (startmenupoint == 1)
  838.                         {
  839.                             Player.DamageLow += 10;
  840.                             Player.DamageHigh += 10;
  841.                         }
  842.                         //Speed
  843.                         else if (startmenupoint == 2)
  844.                         {
  845.                             Player.Speed += 1;
  846.                         }
  847.                         Player.CanUpgrade = false;
  848.                         menuBeginHalt = 20;
  849.                     }
  850.                     Player.Update(gameTime);
  851.                     HudPanal.Update(gameTime);
  852.                     SelectorPanel.Update(gameTime);
  853.                     SelectorPanel.ObjectRect = new Rectangle(MenuIcons[startmenupoint].ObjectRect.X - 40, MenuIcons[startmenupoint].ObjectRect.Y - 40, 280, 280);
  854.                     for (int I = 0; I < MenuIcons.Count; I++)
  855.                     {
  856.                         MenuIcons[I].Update(gameTime);
  857.                     }
  858.                 }
  859.             }
  860.             #endregion
  861. #region TownMenu
  862.             if (Player.EnterTown == true)
  863.             {
  864.  
  865.                
  866.                
  867.                     //Create Menu
  868.                     MenuIcons.Clear();
  869.                     HudPanal.ObjectRect = new Rectangle((int)Player.Position.X - 590, (int)Player.Position.Y - 300, 1400, 600);
  870.  
  871.                     Sprite newMenubox1 = new Sprite();
  872.                     newMenubox1.Initialize(RestTownTexture, new Vector2((int)Player.Position.X - 475 + 100, (int)Player.Position.Y - 100), "Icon");
  873.                     MenuIcons.Add(newMenubox1);
  874.  
  875.                     Sprite newMenubox2 = new Sprite();
  876.                     newMenubox2.Initialize(ShopTownTexture, new Vector2((int)Player.Position.X - 475 + 400, (int)Player.Position.Y - 100), "Icon");
  877.                     MenuIcons.Add(newMenubox2);
  878.  
  879.                     Sprite newMenubox3 = new Sprite();
  880.                     newMenubox3.Initialize(QuestTownTexture, new Vector2((int)Player.Position.X - 475 + 700, (int)Player.Position.Y - 100), "Icon");
  881.                     MenuIcons.Add(newMenubox3);
  882.  
  883.  
  884.  
  885.                     //Update Menu
  886.                     if (menuTick > 0)
  887.                     {
  888.                         menuTick--;
  889.                     }
  890.                     //GrabKeys
  891.                     KeyboardState keyState = Keyboard.GetState();
  892.                     if (keyState.IsKeyDown(Keys.Left) && menuTick == 0)
  893.                     {
  894.                         if (startmenupoint != 0)
  895.                         {
  896.                             startmenupoint--;
  897.                         }
  898.                         menuTick = 10;
  899.                     }
  900.                     if (keyState.IsKeyDown(Keys.Right) && menuTick == 0)
  901.                     {
  902.                         if (startmenupoint != 2)
  903.                         {
  904.                             startmenupoint++;
  905.                         }
  906.                         menuTick = 10;
  907.                     }
  908.                     //QuitTown
  909.                     if (keyState.IsKeyDown(Keys.Escape) && menuTick == 0)
  910.                     {
  911.                         Player.EnterTown = false;
  912.                         Player.Position.Y += 20;
  913.                         MoveWorldUp(15);
  914.                     }
  915.                     if (keyState.IsKeyDown(Keys.Space) && menuTick == 0)
  916.                     {
  917.                         //Rest
  918.                         if (startmenupoint == 0)
  919.                         {
  920.                             Player.Health = Player.HealthLimit;
  921.                         }
  922.                         //Shop
  923.                         else if (startmenupoint == 1)
  924.                         {
  925.                            
  926.                         }
  927.                         //Quest
  928.                         else if (startmenupoint == 2)
  929.                         {
  930.                            
  931.                         }
  932.                        
  933.                         menuBeginHalt = 20;
  934.                     }
  935.                     Player.Update(gameTime);
  936.                     HudPanal.Update(gameTime);
  937.                     SelectorPanel.Update(gameTime);
  938.                     SelectorPanel.ObjectRect = new Rectangle(MenuIcons[startmenupoint].ObjectRect.X - 40, MenuIcons[startmenupoint].ObjectRect.Y - 40, 280, 280);
  939.                     for (int I = 0; I < MenuIcons.Count; I++)
  940.                     {
  941.                         MenuIcons[I].Update(gameTime);
  942.                     }
  943.                
  944.             }
  945.             #endregion
  946. #region Update Tick
  947.             else
  948.             {
  949.  
  950.             speedDelay++;
  951.            
  952.                 speedDelay = 0;
  953.            
  954.                 // Allows the game to exit
  955.                 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  956.                     this.Exit();
  957.  
  958.                 for (int I = 0; I < TreesIndex.Count; I++)
  959.                 {
  960.                     TreesIndex[I].Update(gameTime);
  961.                 }
  962.                 for (int I = 0; I < TownList.Count; I++)
  963.                 {
  964.                     TownList[I].Update(gameTime);
  965.                 }
  966.                 for (int I = 0; I < Corpses.Count; I++)
  967.                 {
  968.                     Corpses[I].Update(gameTime);
  969.                 }
  970.                
  971.                 for (int I = 0; I < HitBoxs.Count; I++)
  972.                 {
  973.                     HitBoxs[I].Update(gameTime);
  974.                     if (HitBoxs[I].Active == false)
  975.                     {
  976.                         HitBoxs.Remove(HitBoxs[I]);
  977.                     }
  978.                 }
  979.                
  980.                 for (int I = 0; I < grassIndex.Count; I++)
  981.                 {
  982.                     grassIndex[I].Update(gameTime);
  983.                 }
  984.                 if (Player.Health < 0)
  985.                 {
  986.                     newGame = true;
  987.                 }
  988.                 BloodSplatter.Update(gameTime);
  989.                 SideCollision(gameTime);
  990.  
  991.                 UpdateMobAI(gameTime);
  992.                 UpdatePlayerAI(gameTime);
  993.                 PlayerSpeed = Player.Speed;
  994.                
  995.             }
  996.            
  997.             base.Update(gameTime);
  998.             #endregion
  999.         }
  1000.  
  1001.         protected override void Draw(GameTime gameTime)
  1002.         {
  1003.             GraphicsDevice.Clear(Color.ForestGreen);
  1004.             // TODO: Add your drawing code here
  1005.             spriteBatch.Begin(SpriteSortMode.FrontToBack,null);          
  1006.             //Draw Grass
  1007.             for (int I = 0; I <  grassIndex.Count; I++)
  1008.             {
  1009.                 grassIndex[I].Draw(spriteBatch);
  1010.                 //spriteBatch.DrawString(StatusText, I+"", grassIndex[I].Position, Color.White);
  1011.             }
  1012.             //Draw Trees
  1013.             for (int I = 0; I < TreesIndex.Count; I++)
  1014.             {
  1015.                 TreesIndex[I].Draw(spriteBatch);
  1016.             }
  1017.             //Draw Towns
  1018.             for (int I = 0; I < TownList.Count; I++)
  1019.             {
  1020.                 TownList[I].Draw(spriteBatch);
  1021.             }
  1022.             //Draw Corpses
  1023.             for (int I = 0; I < Corpses.Count; I++)
  1024.             {
  1025.                 Corpses[I].Draw(spriteBatch);
  1026.             }
  1027.            
  1028.             //Draw Player
  1029.             Player.Draw(spriteBatch);
  1030.             //Draw Mobs
  1031.             for (int I = 0; I < MobList.Count; I++)
  1032.             {
  1033.                 MobList[I].Draw(spriteBatch);
  1034.             }
  1035.            
  1036.             spriteBatch.End();
  1037.  
  1038.             spriteBatchHud.Begin();
  1039.             //UPgrade Screen
  1040.             if (Player.CanUpgrade == true)
  1041.             {
  1042.                 spriteBatchHud.Draw(HudPanalTexture, HudPanal.ObjectRect, Color.White);
  1043.                 spriteBatchHud.Draw(BloodSplat2, SelectorPanel.ObjectRect, Color.White);
  1044.                 for (int I = 0; I < MenuIcons.Count; I++)
  1045.                 {
  1046.                     MenuIcons[I].Draw(spriteBatchHud);
  1047.                 }
  1048.             }
  1049.             //Town Screen
  1050.             if (Player.EnterTown == true)
  1051.             {
  1052.                 spriteBatchHud.Draw(HudPanalTexture, HudPanal.ObjectRect, Color.White);
  1053.                 spriteBatchHud.Draw(BloodSplat2, SelectorPanel.ObjectRect, Color.White);
  1054.                 for (int I = 0; I < MenuIcons.Count; I++)
  1055.                 {
  1056.                     MenuIcons[I].Draw(spriteBatchHud);
  1057.                 }
  1058.             }
  1059.             else
  1060.             {
  1061.  
  1062.                 //Draw HUD
  1063.                 //HudPanal.Draw(spriteBatchHud);
  1064.  
  1065.                 spriteBatchHud.Draw(HudPanalTexture, Player.StatusBoxPos, Color.White);
  1066.                 //Draw STATUS BARS
  1067.  
  1068.                 //LVL/EXPBar
  1069.                 spriteBatchHud.Draw(ExpBarTexture, Player.ExpStatusPos, Color.White);
  1070.  
  1071.                 string tempLvlstring = Player.LvL.ToString();
  1072.                 Vector2 temppos = new Vector2(Player.ExpStatusPos.X - 37, Player.ExpStatusPos.Y);
  1073.                 spriteBatchHud.DrawString(StatusText, tempLvlstring, temppos, Color.Gold);
  1074.                 //HealthAmount/HealthBar
  1075.                 spriteBatchHud.Draw(HPFullTexture, Player.HPStatusPos, Color.White);
  1076.                 string tempHpstring = Player.Health.ToString();
  1077.                 temppos = new Vector2(Player.HPStatusPos.X - 37, Player.HPStatusPos.Y - 10);
  1078.                 spriteBatchHud.DrawString(StatusText, tempHpstring, temppos, Color.ForestGreen);
  1079.                 //Draw Mob Text
  1080.                 for (int I = 0; I < MobList.Count; I++)
  1081.                 {
  1082.                     if (MobList[I].ObjectRect.Intersects(Player.DetectionRect))
  1083.                     {
  1084.                         spriteBatchHud.Draw(HPFullTexture, MobList[I].StatusPos, Color.White);
  1085.  
  1086.                     }
  1087.                 }
  1088.                 //Draw Hitboxes
  1089.                 for (int I = 0; I < HitBoxs.Count; I++)
  1090.                 {
  1091.                     HitBoxs[I].Draw(spriteBatchHud);
  1092.                 }
  1093.             }
  1094.             spriteBatchHud.End();
  1095.  
  1096.             base.Draw(gameTime);
  1097.         }
  1098.     }
  1099. }
  1100.  
  1101. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ sprite.cs @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1102.  
  1103.  
  1104. using System;
  1105. using Microsoft.Xna.Framework;
  1106. using Microsoft.Xna.Framework.Content;
  1107. using Microsoft.Xna.Framework.Graphics;
  1108.  
  1109. namespace Mini_Stalkers
  1110. {
  1111.     class Sprite
  1112.     {
  1113.         public string ID;
  1114.         public int FrameWidth;
  1115.         public int FrameHeight;
  1116.         public bool Active;
  1117.         public SpriteFont StatusText;
  1118.         public Texture2D Texture;
  1119.         public Vector2 Position;
  1120.         public Vector2 HitBoxPos;
  1121.         public Rectangle ObjectRect;
  1122.         public Rectangle TreeTrunkRect;
  1123.         public int DamgeHitBox;
  1124.         Color Color;
  1125.         public int HitboxLife;
  1126.  
  1127.         public void Initialize(Texture2D texture, Vector2 position, string Name)
  1128.         {
  1129.             Texture = texture;
  1130.             Position = position;
  1131.             ID = Name;
  1132.  
  1133.             Color = Color.White;
  1134.             FrameWidth = Texture.Width;
  1135.             FrameHeight = Texture.Height;
  1136.  
  1137.             Active = true;
  1138.  
  1139.             ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, FrameWidth, FrameHeight);
  1140.             TreeTrunkRect = new Rectangle((int)Position.X/5*2, (int)Position.Y+(Texture.Height/4)*3, FrameWidth/5, Texture.Height/4);
  1141.         }
  1142.         public void Update(GameTime gameTime)
  1143.         {
  1144.             if (ID == "HitBox")
  1145.             {
  1146.                 Position.Y--;
  1147.                 HitBoxPos.Y--;
  1148.                 HitboxLife++;
  1149.                 if (HitboxLife > 25)
  1150.                 {
  1151.                     Active = false;
  1152.                 }
  1153.             }
  1154.             //If found DeActive, quit
  1155.             if (Active == false)
  1156.                 return;
  1157.             //Update Boundry
  1158.             if (ID == "HUD" || ID == "Icon")
  1159.             {
  1160.  
  1161.             }
  1162.             else
  1163.             {
  1164.                 ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, FrameWidth, FrameHeight);
  1165.             }
  1166.            
  1167.            
  1168.         }
  1169.         public void Draw(SpriteBatch spriteBatch)
  1170.         {  
  1171.             if (ID == "HitBox")
  1172.             {
  1173.                 string tempDamagedone = DamgeHitBox.ToString();
  1174.                
  1175.                 spriteBatch.Draw(Texture, ObjectRect,Color.White);
  1176.                 spriteBatch.DrawString(StatusText, tempDamagedone, HitBoxPos, Color.White);
  1177.             }
  1178.             else if (ID == "Grass" || ID == "Icon")
  1179.             {
  1180.                 spriteBatch.Draw(Texture, ObjectRect, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);
  1181.             }
  1182.            
  1183.             else
  1184.             {
  1185.                 spriteBatch.Draw(Texture, ObjectRect, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, (Position.Y + FrameHeight) / 1200);
  1186.             }
  1187.         }
  1188.     }
  1189. }
  1190.  
  1191. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Player.cs @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1192.  
  1193.  
  1194. using System;
  1195. using Microsoft.Xna.Framework;
  1196. using Microsoft.Xna.Framework.Content;
  1197. using Microsoft.Xna.Framework.Graphics;
  1198.  
  1199. namespace Mini_Stalkers
  1200. {
  1201.     class Player
  1202.     {
  1203.         public string ID;
  1204.         public int FrameWidth;
  1205.         public int FrameHeight;
  1206.         public bool Active;
  1207.         public bool CanAttack;
  1208.         public int AttackDelay;
  1209.         public int Health;
  1210.         public int HealthLimit;
  1211.         public int RegenTick;
  1212.         public int LvL;
  1213.         public int EXP;
  1214.         public int DamageHigh;
  1215.         public int DamageLow;
  1216.         public int EXPLimit;
  1217.         public int Speed;
  1218.         public bool CanUpgrade;
  1219.         public bool EnterTown;
  1220.        
  1221.         public Texture2D Texture;
  1222.         public Vector2 Position;
  1223.         public Rectangle HPStatusPos;
  1224.         public Rectangle ExpStatusPos;
  1225.         public Rectangle StatusBoxPos;
  1226.         public Rectangle ObjectRect;
  1227.         public Rectangle DetectionRect;
  1228.         public Rectangle HitRect;
  1229.         public Rectangle AttackRectLeft;
  1230.         public Rectangle AttackRectRight;
  1231.         public SpriteFont Statustext;
  1232.         public Vector2 StatustextPos;
  1233.         public string PlayerDirection;
  1234.  
  1235.         Color Color;
  1236.  
  1237.         public void Initialize(Texture2D texture, Vector2 position, string Name, SpriteFont StatusText)
  1238.         {
  1239.             CanUpgrade = false;
  1240.             EnterTown = false;
  1241.             CanAttack = true;
  1242.             Texture = texture;
  1243.             Position = position;
  1244.             ID = Name;
  1245.             LvL = 1;
  1246.             Color = Color.White;
  1247.             FrameWidth = Texture.Width;
  1248.             FrameHeight = Texture.Height;
  1249.             Statustext = StatusText;
  1250.             Active = true;
  1251.             Health = 300;
  1252.             HealthLimit = 100;
  1253.             EXP = 0;
  1254.             RegenTick = 0;
  1255.             EXPLimit = LvL*400;
  1256.            
  1257.             DamageLow = 20;
  1258.             DamageHigh = 50;
  1259.             HitRect = new Rectangle((int)Position.X + 24, (int)Position.Y + 15, 17, 36);
  1260.             ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, FrameWidth, FrameHeight);
  1261.             DetectionRect = new Rectangle((int)Position.X - 300, (int)Position.Y - 300, 600, 600);
  1262.             AttackRectLeft = new Rectangle((int)Position.X - 300, (int)Position.Y, 300, 70);
  1263.             AttackRectRight = new Rectangle((int)Position.X + 300, (int)Position.Y, 300, 70);
  1264.             Speed = 1;
  1265.         }
  1266.         public void Update(GameTime gameTime)
  1267.         {
  1268.            
  1269.            
  1270.             //AttackDelayCheck
  1271.             if (CanAttack == false)
  1272.             {
  1273.                 AttackDelay++;
  1274.                 if(AttackDelay > 40)
  1275.                 {
  1276.                     AttackDelay = 0;
  1277.                     CanAttack = true;
  1278.                 }
  1279.             }
  1280.             //If found DeActive, quit
  1281.             if (Active == false)
  1282.                 return;
  1283.             //Regen
  1284.             if (Health < HealthLimit)
  1285.             {
  1286.                 RegenTick++;
  1287.                 if (RegenTick > 100 )
  1288.                 {
  1289.                     Health += LvL;
  1290.                     RegenTick = 0;
  1291.                 }
  1292.                
  1293.             }
  1294.             //Level up
  1295.             if (EXP >= EXPLimit)
  1296.             {
  1297.                 int tempexpchange = EXPLimit-EXP;
  1298.                 EXP = 0 + tempexpchange;
  1299.                 LvL++;
  1300.                 CanUpgrade = true;
  1301.             }
  1302.             EXPLimit = LvL * 100;
  1303.            
  1304.            
  1305.            
  1306.             StatustextPos = new Vector2((int)Position.X, (int)Position.Y - 70);
  1307.             ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height);
  1308.             AttackRectLeft = new Rectangle((int)Position.X - 30, (int)Position.Y, 110, 70);
  1309.             AttackRectRight = new Rectangle((int)Position.X , (int)Position.Y, 110, 70);
  1310.             DetectionRect = new Rectangle((int)Position.X - 520, (int)Position.Y - 393, 1024, 786);
  1311.             HitRect = new Rectangle((int)Position.X + 24, (int)Position.Y + 15, 17, 36);
  1312.             if (LvL > 3)
  1313.             {
  1314.                 ID = "Survivor";
  1315.             }
  1316.             if (LvL > 6)
  1317.             {
  1318.                 ID = "Stalker";
  1319.             }
  1320.             //STATUS BAR
  1321.             int HpBarSize = Convert.ToInt32(((Health * 100 / HealthLimit)*.7));
  1322.             int ExpBarSize = Convert.ToInt32(((EXP * 100 / EXPLimit) * .7));
  1323.             HPStatusPos = new Rectangle((int)Position.X, (int)Position.Y - 20,HpBarSize, 10);
  1324.             ExpStatusPos = new Rectangle((int)Position.X, (int)Position.Y - 10, ExpBarSize, 5);
  1325.             StatusBoxPos = new Rectangle((int)Position.X-40, (int)Position.Y - 29, 40, 45);
  1326.  
  1327.         }
  1328.         public void Draw(SpriteBatch spriteBatch)
  1329.         {
  1330.            
  1331.             if (Active)
  1332.             {
  1333.                 spriteBatch.Draw(Texture, ObjectRect, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, (Position.Y + FrameHeight) / 1200);
  1334.                
  1335.             }
  1336.         }
  1337.     }
  1338. }
  1339.  
  1340. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ZombieMob.cs @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1341.  
  1342.  
  1343. using System;
  1344. using Microsoft.Xna.Framework;
  1345. using Microsoft.Xna.Framework.Content;
  1346. using Microsoft.Xna.Framework.Graphics;
  1347.  
  1348. namespace Mini_Stalkers
  1349. {
  1350.     class ZombieMob
  1351.     {
  1352.         public string ID;
  1353.         public int FrameWidth;
  1354.         public int FrameHeight;
  1355.         public bool Active;
  1356.         public bool CanAttack;
  1357.         public int AttackDelay;
  1358.         public int Health;
  1359.         public int RegenTick;
  1360.         public int HealthLimit;
  1361.         public Texture2D TextureM;
  1362.         public Texture2D TextureL;
  1363.         public Texture2D TextureR;
  1364.         public Texture2D TextureL2;
  1365.         public Texture2D TextureR2;
  1366.         public Vector2 Position;
  1367.         public Rectangle ObjectRect;
  1368.         public SpriteFont Statustext;
  1369.         public Vector2 StatustextPos;
  1370.         public Vector2 StatustextPos2;
  1371.         public Rectangle HitRect;
  1372.         public Rectangle StatusPos;
  1373.        
  1374.         public int AnimationTick;
  1375.         public int GroanTick;
  1376.         public int GroanDelay;
  1377.         public int Lvl;
  1378.         public int speed;
  1379.         public int TaskDuration;
  1380.         public int RoamYDirection;
  1381.         public int RoamXDirection;
  1382.        
  1383.         Player Player;
  1384.         Random newRand = new Random(DateTime.Now.Millisecond);
  1385.  
  1386.         Color Color;
  1387.  
  1388.         public void Initialize(Texture2D textureL, Texture2D textureR, Texture2D textureL2, Texture2D textureR2, Vector2 position, string Name, SpriteFont StatusText, int LvL, Player player)
  1389.         {
  1390.             CanAttack = true;
  1391.             TextureL = textureL;
  1392.             TextureR = textureR;
  1393.             TextureL2 = textureL2;
  1394.             TextureR2 = textureR2;
  1395.             TextureM = TextureR;
  1396.             Position = position;
  1397.             ID = Name;
  1398.             Lvl = LvL;
  1399.             Color = Color.White;
  1400.             FrameWidth = TextureM.Width;
  1401.             FrameHeight = TextureM.Height;
  1402.             Statustext = StatusText;
  1403.             Active = true;
  1404.             Health = Lvl*50;
  1405.             RegenTick = 0;
  1406.             HealthLimit = Lvl * 50;
  1407.             AnimationTick = 0;
  1408.             Player = player;
  1409.             if (ID == "Walker")
  1410.             {
  1411.                 speed = 1;
  1412.             }
  1413.             if (ID == "Infected")
  1414.             {
  1415.                 speed = 3;
  1416.             }
  1417.             if (ID == "Unique")
  1418.             {
  1419.                 speed = 5;
  1420.             }
  1421.             if (ID == "Boar")
  1422.             {
  1423.                 speed = 1;
  1424.             }
  1425.  
  1426.             ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, FrameWidth, FrameHeight);
  1427.             HitRect = new Rectangle((int)Position.X + 16, (int)Position.Y + 11, 25, 30);
  1428.             GroanDelay = 0;
  1429.         }
  1430.         public void Update(GameTime gameTime)
  1431.         {
  1432.             newRand = new Random(DateTime.Now.Millisecond);
  1433.             //ATTCK DELAY
  1434.             if (CanAttack == false)
  1435.             {
  1436.                 AttackDelay++;
  1437.                 if (AttackDelay > 100)
  1438.                 {
  1439.                     AttackDelay = 0;
  1440.                     CanAttack = true;
  1441.                 }
  1442.             }
  1443.             //ANimation delay
  1444.            
  1445.             AnimationTick+= newRand.Next(0,3);
  1446.             GroanTick++;
  1447.             if (AnimationTick > 40)
  1448.             {
  1449.                 AnimationTick = 0;
  1450.             }
  1451.             //If found DeActive, quit
  1452.             if (Health < 0)
  1453.             {
  1454.                 Player.EXP += Lvl * 25;
  1455.                 Active = false;  
  1456.             }
  1457.             if (Active == false)
  1458.                 return;
  1459.             //REGEN
  1460.             if (Health < HealthLimit)
  1461.             {
  1462.                 RegenTick++;
  1463.                 if (RegenTick > 10)
  1464.                 {
  1465.                     Health++;
  1466.                     RegenTick = 0;
  1467.                 }  
  1468.             }
  1469.             //Update Boundry
  1470.            
  1471.             if (AnimationTick > 10)
  1472.             {
  1473.                 TextureM = TextureR;
  1474.             }
  1475.             else
  1476.             {
  1477.                 TextureM = TextureR2;
  1478.             }
  1479.            
  1480.             //Detection Zombie
  1481.             if (ID == "Walker" && ObjectRect.Intersects(Player.DetectionRect))
  1482.             {
  1483.                
  1484.                
  1485.                     //Follow
  1486.                     if (Position.X > Player.Position.X)
  1487.                     {
  1488.                         Position.X -= speed;
  1489.                         if (AnimationTick > 20)
  1490.                         {
  1491.                             TextureM = TextureL;
  1492.                         }
  1493.                         else
  1494.                         {
  1495.                             TextureM = TextureL2;
  1496.                         }
  1497.                     }
  1498.                     if (Position.X < Player.Position.X)
  1499.                     {
  1500.                         Position.X += speed;
  1501.                         if (AnimationTick > 10)
  1502.                         {
  1503.                             TextureM = TextureR;
  1504.                         }
  1505.                         else
  1506.                         {
  1507.                             TextureM = TextureR2;
  1508.                         }
  1509.                     }
  1510.                     if (Position.Y > Player.Position.Y)
  1511.                     {
  1512.                         Position.Y -= speed;
  1513.  
  1514.                     }
  1515.                     if (Position.Y < Player.Position.Y)
  1516.                     {
  1517.                         Position.Y += speed;
  1518.  
  1519.                     }
  1520.                
  1521.             }
  1522.            
  1523.             //Wander
  1524.             else
  1525.             {
  1526.                 TaskDuration--;
  1527.                 if (TaskDuration < 0)
  1528.                 {
  1529.                     RoamYDirection = newRand.Next(0, 3);
  1530.                     RoamXDirection = newRand.Next(2, 5);
  1531.                     TaskDuration = newRand.Next(500, 1000);
  1532.                 }
  1533.                 if (RoamYDirection == 1)
  1534.                 {
  1535.                     Position.Y -= speed;
  1536.                    
  1537.                 }
  1538.                 if (RoamYDirection == 2)
  1539.                 {
  1540.                     Position.Y += speed;
  1541.                 }
  1542.                 if (RoamXDirection == 3)
  1543.                 {
  1544.                     Position.X += speed;
  1545.                     if (AnimationTick > 10)
  1546.                     {
  1547.                         TextureM = TextureR;
  1548.                     }
  1549.                     else
  1550.                     {
  1551.                         TextureM = TextureR2;
  1552.                     }
  1553.                 }
  1554.                 if (RoamXDirection == 4)
  1555.                 {
  1556.                     Position.X -= speed;
  1557.                     if (AnimationTick > 10)
  1558.                     {
  1559.                         TextureM = TextureL;
  1560.                     }
  1561.                     else
  1562.                     {
  1563.                         TextureM = TextureL2;
  1564.                     }
  1565.                 }
  1566.                
  1567.             }
  1568.             //DAMAGE DONE
  1569.             if (HitRect.Intersects(Player.HitRect) && CanAttack == true)
  1570.             {
  1571.                
  1572.                 Player.Health -= 50;
  1573.                 CanAttack = false;
  1574.                 if (Player.HitRect.X+Player.HitRect.Width/2 < HitRect.X)
  1575.                 {
  1576.                     Position.X += 10;
  1577.                 }
  1578.                 else if (Player.HitRect.X > HitRect.X+HitRect.Width/2)
  1579.                 {
  1580.                     Position.X -= 10;
  1581.                 }
  1582.  
  1583.             }
  1584.             //STATUS BAR
  1585.             int HpBarSize = Convert.ToInt32((Health * 100 / HealthLimit) * 0.7);
  1586.             StatusPos = new Rectangle((int)Position.X, (int)Position.Y -10, HpBarSize, 10);
  1587.  
  1588.             StatustextPos = new Vector2(StatusPos.X,StatusPos.Y);
  1589.             ObjectRect = new Rectangle((int)Position.X, (int)Position.Y, FrameWidth + Lvl * 10, FrameHeight + Lvl * 10);
  1590.             HitRect = new Rectangle((int)Position.X + TextureM.Width/2, (int)Position.Y +TextureM.Height/2, 25,30 );
  1591.            
  1592.         }
  1593.         public void Draw(SpriteBatch spriteBatch)
  1594.         {
  1595.  
  1596.             if (Active)
  1597.             {
  1598.                 spriteBatch.Draw(TextureM, ObjectRect, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, (Position.Y + FrameHeight) / 1200);
  1599.                
  1600.             }
  1601.         }
  1602.     }
  1603. }
  1604.  
  1605. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  1606. Good Luck mate!
  1607. Contact me at 'sirquote@gmail.com' if you have any problems :)
Add Comment
Please, Sign In to add comment