You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Otter;
namespace OtterApp
{
class PlayerEntity : Entity
{
// Create a simple white rectangle to use for the image.
Image image = Image.CreateRectangle(30);
// Create a BoxCollider to pick up collectables with (and give it the Player tag)
BoxCollider collider = new BoxCollider(30, 30, Tags.Player);
public PlayerEntity(float x, float y) : base(x, y) {
// Add the image for rendering.
AddGraphic(image);
// Center the origin of the image.
image.CenterOrigin();
// Add the collider. Must be added or it cant check for collision!
AddCollider(collider);
// Center the origin of the collider so it aligns with the image.
collider.CenterOrigin();
}
public override void Update()
{
base.Update();
// Basic movement with WASD.
if (Input.KeyDown(Key.W))
{
Y -= 3;
}
if (Input.KeyDown(Key.S))
{
Y += 3;
}
if (Input.KeyDown(Key.A))
{
X -= 3;
}
if (Input.KeyDown(Key.D))
{
X += 3;
}
if (collider.Overlap(X, Y, Tags.World))
{
Y -= 3;
}
}
public override void Render()
{
base.Render();
// Uncomment the following line to see the collider.
collider.Render();
}
}
enum Tags
{
Player,
Collectable,
World
}
}