Waternode

Game Entity Namespace

Feb 3rd, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.47 KB | None | 0 0
  1. using System;
  2. using SFML.Window;
  3. using SFML.Graphics;
  4. using MWM;
  5.  
  6. namespace Entity
  7. {
  8.     class Player
  9.     {
  10.         private Texture t = null;
  11.         private Sprite player = null;
  12.         private int velocity = 0;
  13.         private Sprite[] solidObjects = null;
  14.         private bool jumpable = false;
  15.         private bool jumpSwitch = false;
  16.         public Player(String loc, Vector2f Position)
  17.         {
  18.             t = new Texture(loc);
  19.             player = new Sprite(t);
  20.             player.Position = Position;
  21.         }
  22.  
  23.         public void walk(String direction, double speed)
  24.         {
  25.             speed = speed * 8;
  26.             int rounded = (int)Math.Round(speed, 0);
  27.             if (direction == "left")
  28.             {
  29.                 Vector2f pos = player.Position;
  30.                 player.Position = new Vector2f(pos.X - rounded, pos.Y);
  31.             }
  32.             if (direction == "right")
  33.             {
  34.                 Vector2f pos = player.Position;
  35.                 player.Position = new Vector2f(pos.X + rounded, pos.Y);
  36.             }
  37.         }
  38.  
  39.         public void jump(double height)
  40.         {
  41.             if (jumpable)
  42.             {
  43.                 height = height * 8;
  44.                 int rounded = (int)Math.Round(height, 0);
  45.                 velocity += rounded;
  46.                 jumpable = false;
  47.             }
  48.         }
  49.  
  50.         public void draw(ref RenderWindow window)
  51.         {
  52.             window.Draw(player);
  53.         }
  54.  
  55.         public void updateV(ref RenderWindow window)
  56.         {
  57.             if (jumpSwitch)
  58.             {
  59.                 Vector2f pos = player.Position;
  60.                 player.Position = new Vector2f(pos.X, pos.Y - velocity);
  61.                 Console.WriteLine(velocity);
  62.                 if (pos.Y + 128 > window.Size.Y)
  63.                 {
  64.                     jumpable = true;
  65.                     if (velocity <= 0){
  66.                         velocity = 0;
  67.                     }
  68.                 }
  69.                 else if (velocity > MWM.Program.gravity * -8)
  70.                 {
  71.                     velocity -= MWM.Program.gravity;
  72.                     Console.WriteLine(velocity);
  73.                 }
  74.             }
  75.             else
  76.             {
  77.                 jumpSwitch = true;
  78.             }
  79.         }
  80.  
  81.         public Vector2f getPos()
  82.         {
  83.             return player.Position;
  84.         }
  85.  
  86.         public void setSolids(Sprite[] solids)
  87.         {
  88.             solidObjects = solids;
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment