Note that there are some explanatory texts on larger screens.

plurals
  1. PO2D 45 degree angled Sloped tiles
    primarykey
    data
    text
    <p>Here is my code that checks the type of tile. If its an inclined tile it then updates the position of the character. As demonstrated in the photo my character does not move along the slope. What am I doing wrong?</p> <pre><code>bool Entity::PosValidTile(Tile* Tile, int tileX, int tileY) { if(Tile-&gt;TypeID == TILE_TYPE_ANGLEUP) { int Slope, Intercept; int newY; Vector P1,P2; P1.X = tileX; P1.Y = tileY + TILE_SIZE; P2.X = tileX + TILE_SIZE; P2.Y = tileY; if(X + (Width/2) &gt; tileX) { Slope = -(P2.Y- P1.Y) / (P2.X - P1.X); Intercept = Slope * (-P1.X + P1.Y); newY = Slope * ((X + Width/2) + Intercept); Y = (newY - Height); return true; } } } </code></pre> <p><img src="https://i.stack.imgur.com/8Y145.png" alt="demonstration"></p> <p>The dimensions of the character are 48 X 96; which are Width and Height respectively. His origin like the tile, is at the upper left corner.</p> <p>Here is how that function is used</p> <pre><code>bool Entity::PosValid(int NewX, int NewY) { bool Return = true; int StartX = (NewX + Col_X) / TILE_SIZE; int StartY = (NewY + Col_Y) / TILE_SIZE; int EndX = ((NewX + Col_X) + Width - Col_Width - 1) / TILE_SIZE; int EndY = ((NewY + Col_Y) + Height - Col_Height - 1) / TILE_SIZE; if(Flags &amp; ENTITY_FLAG_IGNOREMAP) { }else { for(int iY = StartY; iY &lt;= EndY;iY++) { for(int iX = StartX;iX &lt;= EndX;iX++) { Tile* Tile = Area::AreaControl.GetTile(iX * TILE_SIZE, iY * TILE_SIZE); int atileY = iY * TILE_SIZE; int atileX = iX * TILE_SIZE; if(PosValidTile(Tile,atileX,atileY) == false) { Return = false; } } } } if(Flags &amp; ENTITY_FLAG_MAPONLY) { }else { for(int i = 0;i &lt; (int)EntityList.size();i++) { if(PosValidEntity(EntityList[i], NewX, NewY) == false) { Return = false; } } } return Return; } </code></pre> <p>The function that calls the previous one is my OnMove function.</p> <pre><code>void Entity::OnMove(float MoveX, float MoveY) { if(MoveX == 0 &amp;&amp; MoveY == 0) return; double NewX = 0; double NewY = 0; CanJump = false; MoveX *= Time::TimeControl.GetDeltaTime(); MoveY *= Time::TimeControl.GetDeltaTime(); if(MoveX != 0) { if(MoveX &gt;= 0) NewX = Time::TimeControl.GetDeltaTime(); else NewX = -Time::TimeControl.GetDeltaTime(); } if(MoveY != 0) { if(MoveY &gt;= 0) NewY = Time::TimeControl.GetDeltaTime(); else NewY = -Time::TimeControl.GetDeltaTime(); } while(true) { if(Flags &amp; ENTITY_FLAG_GHOST) { PosValid((float)(X + NewX), (float)(Y + NewY)); X += (float)NewX; Y += (float)NewY; }else { if(PosValid((float)(X + NewX), (int)(Y))) { X += (float)NewX; }else { SpeedX = 0; } if(PosValid((float)(X), (float)(Y + NewY))) { Y += (float)NewY; }else { if(MoveY &gt; 0) { CanJump = true; } SpeedY = 0; } } MoveX += (float)-NewX; MoveY += (float)-NewY; if(NewX &gt; 0 &amp;&amp; MoveX &lt;= 0) NewX = 0; if(NewX &lt; 0 &amp;&amp; MoveX &gt;= 0) NewX = 0; if(NewY &gt; 0 &amp;&amp; MoveY &lt;= 0) NewY = 0; if(NewY &lt; 0 &amp;&amp; MoveY &gt;= 0) NewY = 0; if(MoveX == 0) NewX = 0; if(MoveY == 0) NewY = 0; if(MoveX == 0 &amp;&amp; MoveY == 0) break; if(NewX == 0 &amp;&amp; NewY == 0) break; } } </code></pre> <p>This function is then called in the main Loop Like so OnMove(SpeedX,SpeedY); The speeds are calculated as fallows</p> <pre><code> SpeedX += AccelX * Time::TimeControl.GetDeltaTime(); SpeedY += AccelY * Time::TimeControl.GetDeltaTime(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload