Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  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 Tank
  18.     {
  19.         public bool firstplayer;
  20.  
  21.         private Vector2 player_pos;
  22.  
  23.         Texture2D tankfel;
  24.         Texture2D tankle;
  25.         Texture2D tankbalra;
  26.         Texture2D tankjobbra;
  27.  
  28.         private int facing; //0: left , 1: right, 2: up, 3: down
  29.  
  30.         public Tank(bool first, Texture2D bal, Texture2D jobb, Texture2D fel, Texture2D le)
  31.         {
  32.             firstplayer = first;
  33.  
  34.             if (firstplayer)
  35.                 facing = 1;
  36.             else
  37.                 facing = 0;
  38.  
  39.             tankfel = fel;
  40.             tankbalra = bal;
  41.             tankjobbra = jobb;
  42.             tankle = le;
  43.         }
  44.  
  45.         public void Update()
  46.         {
  47.  
  48.         }
  49.  
  50.         public void Draw(SpriteBatch rajz)
  51.         {
  52.             if(facing == 0)
  53.                 rajz.Draw(tankbalra, new Rectangle((int)player_pos.X * 64, (int)player_pos.Y * 64, 64, 64), Color.White);
  54.             else if(facing == 1)
  55.                 rajz.Draw(tankjobbra, new Rectangle((int)player_pos.X * 64, (int)player_pos.Y * 64, 64, 64), Color.White);
  56.             else if(facing == 2)
  57.                 rajz.Draw(tankfel, new Rectangle((int)player_pos.X * 64, (int)player_pos.Y * 64, 64, 64), Color.White);
  58.             else
  59.                 rajz.Draw(tankle, new Rectangle((int)player_pos.X * 64, (int)player_pos.Y * 64, 64, 64), Color.White);
  60.         }
  61.  
  62.         public void DoKeyBoardActions(KeyboardState bill)
  63.         {
  64.             if (firstplayer)
  65.             {
  66.                 if (bill.IsKeyDown(Keys.A))
  67.                     Move(0);
  68.  
  69.                 if (bill.IsKeyDown(Keys.W))
  70.                     Move(1);
  71.  
  72.                 if (bill.IsKeyDown(Keys.S))
  73.                     Move(2);
  74.  
  75.                 if (bill.IsKeyDown(Keys.D))
  76.                     Move(3);
  77.             }
  78.             else
  79.             {
  80.                 if (bill.IsKeyDown(Keys.Left))
  81.                     Move(0);
  82.  
  83.                 if (bill.IsKeyDown(Keys.Up))
  84.                     Move(1);
  85.  
  86.                 if (bill.IsKeyDown(Keys.Down))
  87.                     Move(2);
  88.  
  89.                 if (bill.IsKeyDown(Keys.Right))
  90.                     Move(3);
  91.             }
  92.         }
  93.  
  94.         public void Move(int irany)
  95.         {
  96.             if (firstplayer)
  97.             {
  98.                 if (irany == 0)
  99.                 {
  100.                     player_pos.X += 1;
  101.                     facing = 0;
  102.                 }
  103.  
  104.                 if (irany == 1)
  105.                 {
  106.                     player_pos.Y -= 1;
  107.                     facing = 0;
  108.                 }
  109.  
  110.             }
  111.             else
  112.             {
  113.  
  114.             }
  115.         }
  116.  
  117.         public void SetPos(Vector2 pos)
  118.         {
  119.             player_pos = pos;
  120.         }
  121.  
  122.         public Vector2 GetPos()
  123.         {
  124.             return player_pos;
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement