Advertisement
Guest User

Untitled

a guest
Feb 8th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. using System;
  2. using SFML.Graphics;
  3. using SFML.Window;
  4.  
  5. namespace Blashyrkh.Game
  6. {
  7.     public class Player : Character
  8.     {
  9.         public View View;
  10.    
  11.         public Player(string name, string race, Vector2u position)
  12.         : base(name, race, position)
  13.         {
  14.             uint x = (this.Position.X) / 2;
  15.             uint y = (this.Position.Y) / 2;
  16.             this.View = new View(new Vector2f((float)x,(float)y),
  17.                 new Vector2f((float)this.Position.X,(float)this.Position.Y));
  18.             this.Position.X = x - this.Size.X / 2;
  19.             this.Position.Y = y - this.Size.Y / 2;
  20.         }
  21.  
  22.         private float CurrentSpeed {
  23.             get {
  24.                 if (Keyboard.IsKeyPressed(Controls.Keyboard["Sprint"]))
  25.                     return this.Speed[1] + 10 *
  26.                         this[AttributeName.MiscAgility].Current;
  27.                 else if (Keyboard.IsKeyPressed(Controls.Keyboard["Walk"]))
  28.                     return this.Speed[0];
  29.                 else
  30.                     return this.Speed[1];
  31.             }
  32.         }
  33.  
  34.         public override void Move(Direction direction, float time, FloatRect rect)
  35.         {
  36.             uint distance = (uint)(this.CurrentSpeed * time);
  37.             switch(direction) {
  38.             case Direction.Down:
  39.                 this.View.Move(new Vector2f(0, distance));
  40.                 break;
  41.             case Direction.Left:
  42.                 this.View.Move(new Vector2f(-(int)distance, 0));
  43.                 break;
  44.             case Direction.Right:
  45.                 this.View.Move(new Vector2f(distance, 0));
  46.                 break;
  47.             case Direction.Up:
  48.                 this.View.Move(new Vector2f(0, -(int)distance));
  49.                 break;
  50.             }
  51.             base.Move(direction, time, rect);
  52.         }
  53.        
  54.         public void Attack(int which)
  55.         {
  56.             this.AttachLabel(String.Format("Attack {0}!", which + 1));    
  57.         }
  58.        
  59.         public override void Activate()
  60.         {
  61.             this.AttachLabel(String.Format("Player {0}", this.Name));
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement