• entries
    743
  • comments
    1924
  • views
    579572

Moving platforms

Sign in to follow this  
Aardvajk

112 views

Got horizontal and vertical moving platforms that Udo can ride on working.



As usual, nothing is ever as simple as one might hope. Verticals were okay, but the problem with the horizontals is if you are standing sort of half on a ledge and the platform slides under you, it shouldn't push you really, but if you land sort of half on the platform it should, if you see what I mean.

Anyway, the whole code for the platforms is here.


#include "platform.h"

CPlatform::CPlatform()
{
Layer=ltMid;
}

void CPlatform::Call()
{
CBasicItem::Call();
}

CVertPlatform::CVertPlatform(CInputStream &Is)
{
Is >> ID >> Bank >> Frame >> W >> H >> X >> Y >> Dir >> Min >> Max;
}

void CVertPlatform::Call()
{
bool IsPCOn=PC->IsStandingOn(this);
float V=Dir*2.0f,Ny=Y+V,Vy=V; if(VertCollide(Ny,Vy)) Dir=-Dir; Y=Ny;

if(Min>=0 && Yfloat(Min); Dir=-Dir; }
if(Max>=0 && Y>Max){ Y=float(Max); Dir=-Dir; }

if(IsPCOn) PC->MoveY(Y-PC->GetRect().H,V);

CPlatform::Call();
}

CHorzPlatform::CHorzPlatform(CInputStream &Is)
{
Is >> ID >> Bank >> Frame >> W >> H >> X >> Y >> Dir >> Min >> Max;
}

void CHorzPlatform::Call()
{
bool IsPCOn=PC->IsStandingOn(this);
int No=1; float Anc=PC->GetX()-X;
if(IsPCOn)
{
if(PC->GetStandingOn()!=this) No=PC->CountStandingOn();
}

float AX=PC->GetX()-X;

float V=Dir*2.0f,Nx=X+V,Vx=V; if(HorzCollide(Nx,Vx)) Dir=-Dir; X=Nx;

if(Min>=0 && Xfloat(Min); Dir=-Dir; }
if(Max>=0 && X>Max){ X=float(Max); Dir=-Dir; }

if(IsPCOn && No==1)
{
PC->MoveX(X+Anc,V);
PC->SetStandingOn(this);
}
else if(PC->GetStandingOn()==this) PC->SetStandingOn(0);

CPlatform::Call();
}



I guess it isn't that bad really. I'm not over keen on having to have added all this GetStandingOn() and SetStandingOn() stuff, but the player character storing the current block it is riding on was the only way around the problem above.

Works rock-solid now and moving platforms were one of the tricky bits I was worried about so that's a significant milestone tonight.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now