- using DeltaEngine.Commands;
- using DeltaEngine.Datatypes;
- using DeltaEngine.Entities;
- using DeltaEngine.Input;
- using DeltaEngine.Rendering2D;
- using DeltaEngine.ScreenSpaces;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace FirstBattleRpgOpenTk.AbstractClass
- {
- public class Humanoïd : Sprite, Updateable
- {
- #region # Properties #
- private int life;
- private int mana;
- public int Life
- {
- get { return life; }
- set { life = value; }
- }
- public int Mana
- {
- get { return mana; }
- set { mana = value; }
- }
- #endregion
- float coeff_densite = 0.5f; // density
- float coeff_frottement = 1.5f; // friction
- float gravite = 0.981f;
- public Vector2D Acceleration;
- public Vector2D Velocity;
- public bool jumping = false; // he jumps ?
- private Game game; // for access a debug label (temporary)
- private Vector2D positionBase; // base position
- public Humanoïd(Game game, Vector2D position)
- : base(new DeltaEngine.Content.Material(new Size(10, 30), Color.LightGray), new Rectangle(position.X, position.Y, 0.05f, 0.08f))
- {
- this.game = game;
- this.positionBase = position;
- Displacement();
- }
- public virtual void Displacement()
- {
- //var data = new SimplePhysics.Data { Gravity = new Vector2D(0.0f, 0.1f), Duration = 10 };
- //Add(data);
- //Start<SimplePhysics.Move>();
- new Command(Command.MoveLeft, () => MoveLeft());
- new Command(Command.MoveRight, () => MoveRight());
- new Command(TestJump).Add(new KeyTrigger(Key.Space, State.Pressing));
- }
- public void TestJump()
- {
- if (!jumping)
- {
- Velocity = new Vector2D(0f, 1f); // reset base speed
- Acceleration = Vector2D.Zero; // reset acceleration
- jumping = true; // he jumps
- }
- }
- public virtual void MoveLeft()
- {
- if (this.TopLeft.X <= 0)
- Center = new Vector2D(Center.X, Center.Y);
- else
- Center -= new Vector2D(Time.Delta * 0.5f, 0);
- }
- public virtual void MoveRight()
- {
- if (this.TopLeft.X + this.Size.Width >= ScreenSpace.Current.Right - 0.02f)
- Center = new Vector2D(Center.X, Center.Y);
- else
- Center += new Vector2D(Time.Delta * 0.5f, 0);
- }
- public virtual void Update()
- {
- game.SetDebug("velocity : " + Velocity + " | pos : " + Center + " | acc : " + Acceleration + " | jump : " + jumping);
- if (jumping)
- {
- if (Acceleration.Y >= 0)
- {
- this.Acceleration = new Vector2D(0, gravite * coeff_densite - coeff_frottement * Velocity.Y);
- this.Velocity += this.Acceleration * Time.Delta;
- Center -= new Vector2D(0, this.Velocity.Y * Time.Delta);
- }
- else
- {
- if (Math.Round(Center.Y, 2) <= positionBase.Y)
- {
- this.Velocity -= new Vector2D(0f, gravite + coeff_densite) * Time.Delta;
- if (Math.Round(Center.Y, 2) > positionBase.Y) // i try to limit the fall to the y base position, but it's not work..
- Center = new Vector2D(0, positionBase.Y);
- Center -= new Vector2D(0, this.Velocity.Y * Time.Delta);
- }
- else
- {
- jumping = false;
- }
- }
- }
- }
- public bool IsPauseable { get { return true; } }
- }
- }