Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.IO;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Audio;
  7. using Microsoft.Xna.Framework.Content;
  8. using Microsoft.Xna.Framework.GamerServices;
  9. using Microsoft.Xna.Framework.Graphics;
  10. using Microsoft.Xna.Framework.Input;
  11. using Microsoft.Xna.Framework.Media;
  12. using Microsoft.Xna.Framework.Net;
  13. using Microsoft.Xna.Framework.Storage;
  14.  
  15. namespace Platformer
  16. {
  17.     public class Game1 : Microsoft.Xna.Framework.Game
  18.     {
  19.         GraphicsDeviceManager graphics;
  20.         SpriteBatch spriteBatch;
  21.  
  22.         Texture2D tankright;
  23.         Texture2D tankleft;
  24.         Texture2D tankup;
  25.         Texture2D tankdown;
  26.  
  27.         Texture2D fal;
  28.  
  29.         Level szint;
  30.  
  31.         Tank player1;
  32.         Tank player2;
  33.  
  34.         SpriteFont Verdana;
  35.  
  36.         public Game1()
  37.         {
  38.             graphics = new GraphicsDeviceManager(this);
  39.             graphics.PreferredBackBufferHeight = 640;
  40.             graphics.PreferredBackBufferWidth = 640;
  41.             graphics.ApplyChanges();
  42.  
  43.             Content.RootDirectory = "Content";
  44.         }
  45.  
  46.         protected override void Initialize()
  47.         {
  48.             Window.Title = "Tankos játék - By $0undX";
  49.  
  50.             base.Initialize();
  51.         }
  52.  
  53.         protected override void LoadContent()
  54.         {
  55.             // Create a new SpriteBatch, which can be used to draw textures.
  56.             spriteBatch = new SpriteBatch(GraphicsDevice);
  57.  
  58.             tankup = Content.Load<Texture2D>("tankfel");
  59.             tankdown = Content.Load<Texture2D>("tankle");
  60.             tankleft = Content.Load<Texture2D>("tankbalra");
  61.             tankright = Content.Load<Texture2D>("tankjobbra");
  62.             fal = Content.Load<Texture2D>("fal");
  63.             Verdana = Content.Load<SpriteFont>("Verdana");
  64.  
  65.             player1 = new Tank(true, tankleft, tankright, tankup, tankdown);
  66.             player2 = new Tank(false, tankleft, tankright, tankup, tankdown);
  67.  
  68.             szint = new Level(new StreamReader("palya.txt"), ref player1, ref player2);
  69.         }
  70.  
  71.         protected override void UnloadContent()
  72.         {
  73.        
  74.         }
  75.  
  76.         protected override void Update(GameTime gameTime)
  77.         {
  78.             // Allows the game to exit
  79.             if (Keyboard.GetState().IsKeyDown(Keys.Escape))
  80.                 this.Exit();
  81.  
  82.             DoKeyBoardActions(Keyboard.GetState());
  83.  
  84.             base.Update(gameTime);
  85.         }
  86.        
  87.         protected override void Draw(GameTime gameTime)
  88.         {
  89.             GraphicsDevice.Clear(Color.CornflowerBlue);
  90.             spriteBatch.Begin();
  91.  
  92.             DrawTheGame(szint);
  93.  
  94.             spriteBatch.End();
  95.             base.Draw(gameTime);
  96.         }
  97.  
  98.         public void DoKeyBoardActions(KeyboardState bill)
  99.         {
  100.             player1.DoKeyBoardActions(bill);
  101.             player2.DoKeyBoardActions(bill);
  102.         }
  103.  
  104.         public void DrawBlock(int x, int y)
  105.         {
  106.             spriteBatch.Draw(fal, new Rectangle(x * 64, y * 64, 64, 64), Color.White);
  107.         }
  108.  
  109.         public void DrawTheGame(Level palya)
  110.         {
  111.             for (int i = 0; i < palya.GetContentX().Length; i++)
  112.             {
  113.                 if (i <= 1)
  114.                 {
  115.                     if(i == 0)
  116.                     {
  117.                         player1.Draw(spriteBatch);
  118.                     }
  119.  
  120.                     if (i == 1)
  121.                     {
  122.                         player2.Draw(spriteBatch);
  123.                     }
  124.                 }
  125.                 else
  126.                     DrawBlock(palya.GetContentX()[i], palya.GetContentY()[i]);
  127.             }
  128.         }
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement