Ahhh right. Well, I was really just wondering out it and how it would work. I think it'd be a nice feature but I'm not gonna die without it.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
#define DIR_DISTANCE 10000
#define DIR_DOWN_LEFT 1
#define DIR_DOWN 2
#define DIR_DOWN_RIGHT 3
#define DIR_LEFT 4
#define DIR_STOP 5
#define DIR_RIGHT 6
#define DIR_UP_LEFT 7
#define DIR_UP 8
#define DIR_UP_RIGHT 9
#define DIR_NONE 0
int PrevDirection;
int isRunning = 0;
int CharId;
int Direct;
int oldDirect;
int newdir;
float characterX;
float characterY;
float animFrame = 0.0;
function TryDiagonalMove(float dist, int dir, int dx, int dy, int slideDirX, int slideDirY)
{
int newDir = dir;
// test that direction
float delta = 0.7071*dist;
float dxf = IntToFloat(dx);
float dyf = IntToFloat(dy);
float newCharacterX = characterX + dxf*delta;
int pixelMove = FloatToInt(newCharacterX) - FloatToInt(characterX);
if (pixelMove != 0)
{
// check the diagonal move
if (GetWalkableAreaAt(player.x + dx, player.y + dy) != 0)
{
// can move that way
float maxDelta = delta;
if (maxDelta > 1.0)
{
maxDelta = 1.0;
dist -= 1.414;
}
else
{
dist = 0.0;
}
characterX += dxf*maxDelta;
characterY += dyf*maxDelta;
}
else
{
// round off the position
characterX = IntToFloat(FloatToInt(characterX)) + 0.5;
characterY = IntToFloat(FloatToInt(characterY)) + 0.5;
if (GetWalkableAreaAt(player.x + dx, player.y) != 0)
{
newDir = slideDirX;
}
else
{
newDir = slideDirY;
}
}
}
else
{
// pixelMove == 0
// didn't change pixel so just move within the pixel
characterX = characterX + dxf*delta;
characterY = characterY + dyf*delta;
// stop
dist = 0.0;
}
return newDir;
}
function TryStraightMove(float dist, int dx, int dy)
{
float delta = dist;
float dxf = IntToFloat(dx);
float dyf = IntToFloat(dy);
float newCharacterX = characterX + dxf*delta;
float newCharacterY = characterY + dyf*delta;
int pixelMoveX = FloatToInt(newCharacterX) - FloatToInt(characterX);
int pixelMoveY = FloatToInt(newCharacterY) - FloatToInt(characterY);
if (pixelMoveX != 0 || pixelMoveY != 0)
{
// check the move
if (GetWalkableAreaAt(player.x + dx, player.y + dy) != 0)
{
// can move that way
float maxDelta = delta;
if (maxDelta > 1.0)
{
maxDelta = 1.0;
dist -= 1.0;
}
else
{
dist = 0.0;
}
characterX += dxf*maxDelta;
characterY += dyf*maxDelta;
}
else
{
// round off the position
characterX = IntToFloat(FloatToInt(characterX)) + 0.5;
characterY = IntToFloat(FloatToInt(characterY)) + 0.5;
// stop moving
dist = 0.0;
}
}
else
{
// pixelMove == 0
// didn't change pixel so just move within the pixel
characterX = characterX + dxf*delta;
characterY = characterY + dyf*delta;
// stop
dist = 0.0;
}
}
function DirectionFromKeyPresses()
{
Direct = DIR_NONE;
if ((IsKeyPressed (371) > 0) || (IsKeyPressed (55) > 0) || ((IsKeyPressed (372) > 0) && (IsKeyPressed (375) > 0))) Direct = DIR_UP_LEFT;
else if ((IsKeyPressed (373) > 0) || (IsKeyPressed (57) > 0) || ((IsKeyPressed (372) > 0) && (IsKeyPressed (377) > 0))) Direct = DIR_UP_RIGHT;
else if ((IsKeyPressed (379) > 0) || (IsKeyPressed (49) > 0) || ((IsKeyPressed (380) > 0) && (IsKeyPressed (375) > 0))) Direct = DIR_DOWN_LEFT;
else if ((IsKeyPressed (381) > 0) || (IsKeyPressed (51) > 0) || ((IsKeyPressed (380) > 0) && (IsKeyPressed (377) > 0))) Direct =DIR_DOWN_RIGHT;
else if ((IsKeyPressed (372) > 0) || (IsKeyPressed (56) > 0)) Direct = DIR_UP;
else if ((IsKeyPressed (375) > 0) || (IsKeyPressed (52) > 0)) Direct = DIR_LEFT;
else if ((IsKeyPressed (376) > 0) || (IsKeyPressed (53) > 0)) Direct = DIR_STOP;
else if ((IsKeyPressed (377) > 0) || (IsKeyPressed (54) > 0)) Direct = DIR_RIGHT;
else if ((IsKeyPressed (380) > 0) || (IsKeyPressed (50) > 0)) Direct = DIR_DOWN;
return Direct;
}
if (IsGamePaused()==0) {
Direct = DirectionFromKeyPresses(); // as before
if (Direct != oldDirect) {
// changing direction, so reset these
characterX = IntToFloat(player.x) + 0.5;
characterY = IntToFloat(player.y) + 0.5;
}
if (Direct != DIR_STOP) {
float dist = 0.75;
if (IsKeyPressed(keya)) {
// running, so go twice the distance
dist = 1.5;
}
int newDir = Direct;
while (dist > 0.0) {
if (newDir == DIR_DOWN_LEFT) {
newDir = TryDiagonalMove(dist, newDir, -1, 1, DIR_LEFT, DIR_DOWN);
}
else if (newDir == DIR_DOWN_RIGHT) {
newDir = TryDiagonalMove(dist, newDir, 1, 1, DIR_RIGHT, DIR_DOWN);
}
else if (newDir == DIR_UP_LEFT) {
newDir = TryDiagonalMove(dist, newDir, -1, -1, DIR_LEFT, DIR_UP);
}
else if (newDir == DIR_UP_RIGHT) {
newDir = TryDiagonalMove(dist, newDir, 1, -1, DIR_RIGHT, DIR_UP);
}
else if (newDir == DIR_LEFT) {
TryStraightMove(dist, -1, 0);
}
else if (newDir == DIR_RIGHT) {
TryStraightMove(dist, 1, 0);
}
else if (newDir == DIR_UP) {
TryStraightMove(dist, 0, -1);
}
else if (newDir == DIR_DOWN) {
TryStraightMove(dist, 0, 1);
}
} /////////////ENDLESS LOOPING/HANGING HERE
// now animate the character
/*animFrame += 0.1;
int animFrameInt = FloatToInt(animFrame);
if (animFrameInt > 4) animFrameInt = 0;*/
// TODO: set the player loop and frame depending on Direct and animFrameInt
}
else {
// TODO: set the standing frame based on oldDirect
}
player.x = FloatToInt(characterX);
player.y = FloatToInt(characterY);
oldDirect = Direct;
} //end if paused
#define DIR_DISTANCE 10000
#define DIR_DOWN_LEFT 1
#define DIR_DOWN 2
#define DIR_DOWN_RIGHT 3
#define DIR_LEFT 4
#define DIR_STOP 5
#define DIR_RIGHT 6
#define DIR_UP_LEFT 7
#define DIR_UP 8
#define DIR_UP_RIGHT 9
if (IsGamePaused()==0) {
Ã,Â
if ((IsKeyPressed (371) > 0) || (IsKeyPressed (55) > 0) || ((IsKeyPressed (372) > 0) && (IsKeyPressed (375) > 0))) Direct = DIR_UP_LEFT;
else if ((IsKeyPressed (373) > 0) || (IsKeyPressed (57) > 0) || ((IsKeyPressed (372) > 0) && (IsKeyPressed (377) > 0))) Direct = DIR_UP_RIGHT;
else if ((IsKeyPressed (379) > 0) || (IsKeyPressed (49) > 0) || ((IsKeyPressed (380) > 0) && (IsKeyPressed (375) > 0))) Direct = DIR_DOWN_LEFT;
else if ((IsKeyPressed (381) > 0) || (IsKeyPressed (51) > 0) || ((IsKeyPressed (380) > 0) && (IsKeyPressed (377) > 0))) Direct =DIR_DOWN_RIGHT;
else if ((IsKeyPressed (372) > 0) || (IsKeyPressed (56) > 0)) Direct = DIR_UP;
else if ((IsKeyPressed (375) > 0) || (IsKeyPressed (52) > 0)) Direct = DIR_LEFT;
else if ((IsKeyPressed (376) > 0) || (IsKeyPressed (53) > 0)) Direct = DIR_STOP;
else if ((IsKeyPressed (377) > 0) || (IsKeyPressed (54) > 0)) Direct = DIR_RIGHT;
else if ((IsKeyPressed (380) > 0) || (IsKeyPressed (50) > 0)) Direct = DIR_DOWN;
else Direct = DIR_STOP;
if (IsKeyPressed(keya)==1) { //RUNNING - 'A' button held down
Ã, Ã, if (isRunning==0) {
Ã, Ã, Ã, StopMoving(GetPlayerCharacter());
Ã, Ã, Ã, SetCharacterSpeed(GetPlayerCharacter(), 12);
Ã, Ã, Ã, isRunning = 1;
Ã, Ã, Ã, ReleaseCharacterView(EGO);
Ã, Ã, Ã, ChangeCharacterView(EGO, 33);
Ã, Ã, Ã, Direct = DIR_STOP;
Ã, Ã, }
}
Ã, else {
Ã, Ã, if (isRunning==1) {
Ã, Ã, Ã, StopMoving(GetPlayerCharacter());
Ã, Ã, Ã, SetCharacterSpeed(GetPlayerCharacter(), 6);
Ã, Ã, Ã, isRunning = 0;
Ã, Ã, Ã, ReleaseCharacterView(EGO);
Ã, Ã, Ã, ChangeCharacterView(EGO, 1);
Ã, Ã, Ã, Direct = DIR_STOP;
Ã, Ã, }
}
if ((PrevDirection != Direct) || (character[EGO].walking == 0)) {
PrevDirection = Direct;
CharId = GetPlayerCharacter ();
if (Direct == DIR_STOP) StopMoving (CharId); // 5 Stop (numeric pad)
else {
if (Direct == DIR_UP_LEFT) {
dx = -DIR_DISTANCE; dy = -DIR_DISTANCE;
StrCopy (direct, "ul");
} // 7 Home (numeric pad)
else if (Direct == DIR_UP) {
dx = 0; dy = -DIR_DISTANCE;
StrCopy (direct, "u");
} // 8 Up arrow
else if (Direct == DIR_UP_RIGHT) {
dx = DIR_DISTANCE; dy = -DIR_DISTANCE;
StrCopy (direct, "ur");
} // 9 PgUp (numeric pad)
else if (Direct == DIR_LEFT) {
dx = -DIR_DISTANCE; dy = 0;
StrCopy (direct, "l");
} // 4 Left arrow
else if (Direct == DIR_RIGHT) {
dx = DIR_DISTANCE; dy = 0;
StrCopy (direct, "r");
} // 6 Right arrow
else if (Direct == DIR_DOWN_LEFT) {
dx = -DIR_DISTANCE; dy = DIR_DISTANCE;
StrCopy (direct, "dl");
} // 1 End (numeric pad)
else if (Direct == DIR_DOWN) {
dx = 0; dy = DIR_DISTANCE;
StrCopy (direct, "d");
} // 2 Down arrow
else if (Direct == DIR_DOWN_RIGHT) {
dx = DIR_DISTANCE; dy = DIR_DISTANCE;
StrCopy (direct, "dr");
} // 3 PgDn (numeric pad)
MoveCharacterStraight (CharId, character [CharId].x + dx, character [CharId].y + dy);
}
}
}
By continuing to use this site you agree to the use of cookies. Please visit this page to see exactly how we use these.
Page created in 0.271 seconds with 15 queries.