
Untitled
By: a guest on
Feb 8th, 2013 | syntax:
C# | size: 2.09 KB | hits: 5 | expires: Never
using System;
using SFML.Graphics;
using SFML.Window;
namespace Blashyrkh.Game
{
public class Player : Character
{
public View View;
public Player(string name, string race, Vector2u position)
: base(name, race, position)
{
uint x = (this.Position.X) / 2;
uint y = (this.Position.Y) / 2;
this.View = new View(new Vector2f((float)x,(float)y),
new Vector2f((float)this.Position.X,(float)this.Position.Y));
this.Position.X = x - this.Size.X / 2;
this.Position.Y = y - this.Size.Y / 2;
}
private float CurrentSpeed {
get {
if (Keyboard.IsKeyPressed(Controls.Keyboard["Sprint"]))
return this.Speed[1] + 10 *
this[AttributeName.MiscAgility].Current;
else if (Keyboard.IsKeyPressed(Controls.Keyboard["Walk"]))
return this.Speed[0];
else
return this.Speed[1];
}
}
public override void Move(Direction direction, float time, FloatRect rect)
{
uint distance = (uint)(this.CurrentSpeed * time);
switch(direction) {
case Direction.Down:
this.View.Move(new Vector2f(0, distance));
break;
case Direction.Left:
this.View.Move(new Vector2f(-(int)distance, 0));
break;
case Direction.Right:
this.View.Move(new Vector2f(distance, 0));
break;
case Direction.Up:
this.View.Move(new Vector2f(0, -(int)distance));
break;
}
base.Move(direction, time, rect);
}
public void Attack(int which)
{
this.AttachLabel(String.Format("Attack {0}!", which + 1));
}
public override void Activate()
{
this.AttachLabel(String.Format("Player {0}", this.Name));
}
}
}