Hi guys,
Recently I had the time to implement a tiny library introducing some basic AI behaviours for the AGK.
You can download the lib and try it by yourself.
The code is ridiculous simple because I want to focus on the usage of the functions
All you need to do is to include two header files in your code and the libraries in your linking
For the usage please read the "Steering.h" file
#include "main.h"
#include "Utils.h"
#include "Steering.h"
app App;
void DrawMark(float x, float y, float size=1.0f, unsigned int r=0, unsigned int g=255, unsigned int b=0);
void DrawV(double x, double y, double heading, double size=1.0, unsigned int r=255, unsigned int g=255, unsigned int b=255);
double entX = 50.0;
double entY = 50.0;
double entSpeed = 0.3;
double entSpeedX;
double entSpeedY;
double entHeading = HalfPi;
double destX = 20.0;
double destY = 20.0;
void app::Begin(void)
{
agk::SetDisplayAspect((float)agk::GetDeviceWidth()/(float)agk::GetDeviceHeight());
}
void app::Loop(void)
{
Seek(entX, entY, destX, destY, entSpeedX, entSpeedY, entHeading, entSpeed);
entX += entSpeedX;
entY += entSpeedY;
DrawMark((float)destX, (float)destY);
DrawV((float)entX, (float)entY, entHeading);
agk::Sync();
}
void app::End(void)
{
}
void DrawMark(float x, float y, float size, unsigned int r, unsigned int g, unsigned int b)
{
agk::DrawLine(x-size/2.0f, y, x+size/2.0f, y, r, g, b);
agk::DrawLine(x, y-size/2.0f, x, y+size/2.0f, r, g, b);
}
void DrawV(double xcenter, double ycenter, double heading, double size, unsigned int r, unsigned int g, unsigned int b)
{
double x[3], y[3];
double angle = HalfPi+QuarterPi;
x[0] = xcenter + size*cos(heading);
y[0] = ycenter + size*sin(heading);
x[1] = xcenter + size*cos(heading+angle);
y[1] = ycenter + size*sin(heading+angle);
x[2] = xcenter + size*cos(heading-angle);
y[2] = ycenter + size*sin(heading-angle);
agk::DrawLine((float)x[0], (float)y[0], (float)x[1], (float)y[1], r, g, b);
agk::DrawLine((float)x[0], (float)y[0], (float)x[2], (float)y[2], r, g, b);
}
If you don't understand how it works then it is better for you to look at the interpreter
I've plans for more behaviours, in order to make this library useful for your game projects.
It is, and will remain, pure C/C++ code and it can be used by other platforms except the AGK
Any comments are welcome