//Player COLL
getKeys
getDir
if(MAP>0 && SHOP==0)
{
switch(dir)
{
case 0:
if(spd<0)
{
spd+=.5;
if(spd>-.5)
{
spd=0;
}
}
if(spd>0)
{
spd-=.5;
if(spd<.5)
{
spd=0;
}
}
COLL.x+=spd;
switch(pSpin)
{
case 0:
if(pJump)
{
switch(cDir)
{
case 0:
SetPlayerAnim("FallLeft");
break;
case 1:
SetPlayerAnim("FallRight");
break;
}
}
if (!pJump)
{
if(animindex==0)
{
SetPlayerAnim("StandLeft");
}
if(animindex==1)
{
SetPlayerAnim("StandRight");
}
}
break;
case 1:
switch(cDir)
{
case 0:
SetPlayerAnim("SpinLeft");
break;
case 1:
SetPlayerAnim("SpinRight");
break;
}
break;
}
break;
case 1:
cDir=1;
if(pJump==1 && pSpin==0)
{
SetPlayerAnim("FallRight");
}
if(pSpin==1 && pJump==1)
{
SetPlayerAnim("SpinRight");
}
if(!pJump && !pSpin)
{
if(cmr==0)
{
SetPlayerAnim("WalkRight");
}
else if(cmr==1)
{
SetPlayerAnim("StandRight");
}
}
cml=0;
if(cmr==0){
switch(RunKey)
{
case 0:
SetMove(3+sextra, .5);
break;
case 1:
SetMove(5+sextra, .5);
break;
}
}
break;
case -1:
cDir=0;
if(pJump==1 && pSpin==0)
{
SetPlayerAnim("FallLeft");
}
if(pSpin==1 && pJump==1)
{
SetPlayerAnim("SpinLeft");
}
if(!pJump && !pSpin)
{
if(cml==0)
{
SetPlayerAnim("WalkLeft");
}
else if(cml==1)
{
SetPlayerAnim("StandLeft");
}
}
cmr=0;
if(cml==0){
switch(RunKey)
{
case 0:
SetMove(-3-sextra, .5);
break;
case 1:
SetMove(-5-sextra, .5);
break;
}
}
break;
}
pAnimNum=animindex;
if(hp<=0)
{
transp=.99;
gameoverx=1;
}
if(KeyAttack)
{
at++;
if(at==1)
{
PlaySound2("data/shot.wav", 1, 1, 0.000000);
switch(cDir)
{
case 0:
CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
break;
case 1:
CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
break;
}
}
if(at>=5)
{
at=0;
}
}
if(!KeyAttack)
{
at=-0;
}
}
if(pSpin) {
soundtimer++;
if(soundtimer>=6)
{
soundtimer=0;
}
PlaySound2("data/spin3.wav", .2, 1, 0.000000);
}
if(pSpin==0)
{
soundtimer=0;
}
if(pJump)
{
cmr=0; cml=0;
}
if(frameflash)
{
temp++;
if(temp==10||temp==20||temp==30||temp==40||temp==50)
{
transp=.99;
}
if(temp==5||temp==15||temp==25||temp==35||temp==45||temp==55)
{
transp=0;
}
if(temp>=60)
{
frameflash=0;
temp=0;
}
}
//Player COLL
getKeys
getDir
if(MAP>0 && SHOP==0)
{
switch(dir)
{
case 0:
spd = spd<0 ? min(spd+0.5, 0) : max(spd-0.5, 0);
COLL.x+=spd;
switch(pSpin)
{
case 0:
if(pJump)
{
switch(cDir)
{
case 0:
SetPlayerAnim("FallLeft");
break;
case 1:
SetPlayerAnim("FallRight");
break;
}
}
else // (!pJump)
{
switch(animindex)
{
case 0:
SetPlayerAnim("StandLeft");
break;
case 1:
SetPlayerAnim("StandRight");
break;
}
}
break;
case 1:
switch(cDir)
{
case 0:
SetPlayerAnim("SpinLeft");
break;
case 1:
SetPlayerAnim("SpinRight");
break;
}
break;
}
break;
case 1:
cDir=1;
switch(pJump+pSpin*2)
{
case 0: // pJump==0 && pSpin==0
if(cmr==0)
{
SetPlayerAnim("WalkRight");
}
else if(cmr==1)
{
SetPlayerAnim("StandRight");
}
break;
case 1: // pJump==1 && pSpin==0
SetPlayerAnim("FallRight");
break;
case 2: // pJump==0 && pSpin==1
break;
case 3: // pJump==1 && pSpin==1
SetPlayerAnim("SpinRight");
break;
}
cml=0;
if(cmr==0)
{
switch(RunKey)
{
case 0:
SetMove(3+sextra, .5);
break;
case 1:
SetMove(5+sextra, .5);
break;
}
}
break;
case -1:
cDir=0;
switch(pJump+pSpin*2)
{
case 0: // pJump==0 && pSpin==0
if(cml==0)
{
SetPlayerAnim("WalkLeft");
}
else if(cml==1)
{
SetPlayerAnim("StandLeft");
}
break;
case 1: // pJump==1 && pSpin==0
SetPlayerAnim("FallLeft");
break;
case 2: // pJump==0 && pSpin==1
break;
case 3: // pJump==1 && pSpin==1
SetPlayerAnim("SpinLeft");
break;
}
cmr=0;
if(cml==0)
{
switch(RunKey)
{
case 0:
SetMove(-3-sextra, .5);
break;
case 1:
SetMove(-5-sextra, .5);
break;
}
}
break;
}
pAnimNum=animindex;
if(hp<=0)
{
transp=.99;
gameoverx=1;
}
if(KeyAttack)
{
at++;
if(at==1)
{
PlaySound2("data/shot.wav", 1, 1, 0.000000);
switch(cDir)
{
case 0:
CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
break;
case 1:
CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
break;
}
}
else if(at>=5)
{
at=0;
}
}
else if(!KeyAttack)
{
at=0;
}
}
if(pSpin)
{
soundtimer++;
if(soundtimer>=6)
{
soundtimer=0;
}
PlaySound2("data/spin3.wav", .2, 1, 0.000000);
}
else if(pSpin==0)
{
soundtimer=0;
}
if(pJump)
{
cmr=0; cml=0;
}
if(frameflash)
{
temp++;
if(temp%10==0)
{
transp=.99;
}
else if((temp+5)%10==0)
{
transp=0;
}
if(temp>=60)
{
frameflash=0;
temp=0;
}
}
skydereign wrote:Well by the looks of it, none of this would cause the lag. But while going through it I did clean it up a bit. I could have condensed it more with the ternary operator, but I wasn't sure how comfortable with it you are, so I just most of those as they were. A couple of things though...
You like to not specify comparisons in if statements, which I personally don't like, but the real problem is that you aren't really uniform in doing it. You had a couple of if(var) and if(var==0). While other times you had if(var) and if(!var). Most of the cases I don't think you really meant if(var) but rather if(var==1). Sometimes it is better to be explicit, as it explains what type of values the variable has (and I didn't fix these as I still wasn't completely sure if they were just boolean valued variable). Namely since I was looking at it, I couldn't directly tell what values the variable had. Along those lines, you should use else if more often. You had in many places if statements followed by another if statement that couldn't possibly trigger if the one above it did. That's the time you want to use an else if, that way you aren't making redundant checks with if. The last thing, as always, I'd recommend using a more standard spacing scheme. Even if you personally don't find the default spacing scheme any easier to read, it does make looking through your code a whole lot easier. Uniform spacing can tell you were in the code you are.
- Code: Select all
//Player COLL
getKeys
getDir
if(MAP>0 && SHOP==0)
{
switch(dir)
{
case 0:
spd = spd<0 ? min(spd+0.5, 0) : max(spd-0.5, 0);
COLL.x+=spd;
switch(pSpin)
{
case 0:
if(pJump)
{
switch(cDir)
{
case 0:
SetPlayerAnim("FallLeft");
break;
case 1:
SetPlayerAnim("FallRight");
break;
}
}
else // (!pJump)
{
switch(animindex)
{
case 0:
SetPlayerAnim("StandLeft");
break;
case 1:
SetPlayerAnim("StandRight");
break;
}
}
break;
case 1:
switch(cDir)
{
case 0:
SetPlayerAnim("SpinLeft");
break;
case 1:
SetPlayerAnim("SpinRight");
break;
}
break;
}
break;
case 1:
cDir=1;
switch(pJump+pSpin*2)
{
case 0: // pJump==0 && pSpin==0
if(cmr==0)
{
SetPlayerAnim("WalkRight");
}
else if(cmr==1)
{
SetPlayerAnim("StandRight");
}
break;
case 1: // pJump==1 && pSpin==0
SetPlayerAnim("FallRight");
break;
case 2: // pJump==0 && pSpin==1
break;
case 3: // pJump==1 && pSpin==1
SetPlayerAnim("SpinRight");
break;
}
cml=0;
if(cmr==0)
{
switch(RunKey)
{
case 0:
SetMove(3+sextra, .5);
break;
case 1:
SetMove(5+sextra, .5);
break;
}
}
break;
case -1:
cDir=0;
switch(pJump+pSpin*2)
{
case 0: // pJump==0 && pSpin==0
if(cml==0)
{
SetPlayerAnim("WalkLeft");
}
else if(cml==1)
{
SetPlayerAnim("StandLeft");
}
break;
case 1: // pJump==1 && pSpin==0
SetPlayerAnim("FallLeft");
break;
case 2: // pJump==0 && pSpin==1
break;
case 3: // pJump==1 && pSpin==1
SetPlayerAnim("SpinLeft");
break;
}
cmr=0;
if(cml==0)
{
switch(RunKey)
{
case 0:
SetMove(-3-sextra, .5);
break;
case 1:
SetMove(-5-sextra, .5);
break;
}
}
break;
}
pAnimNum=animindex;
if(hp<=0)
{
transp=.99;
gameoverx=1;
}
if(KeyAttack)
{
at++;
if(at==1)
{
PlaySound2("data/shot.wav", 1, 1, 0.000000);
switch(cDir)
{
case 0:
CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
break;
case 1:
CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
break;
}
}
else if(at>=5)
{
at=0;
}
}
else if(!KeyAttack)
{
at=0;
}
}
if(pSpin)
{
soundtimer++;
if(soundtimer>=6)
{
soundtimer=0;
}
PlaySound2("data/spin3.wav", .2, 1, 0.000000);
}
else if(pSpin==0)
{
soundtimer=0;
}
if(pJump)
{
cmr=0; cml=0;
}
if(frameflash)
{
temp++;
if(temp%10==0)
{
transp=.99;
}
else if((temp+5)%10==0)
{
transp=0;
}
if(temp>=60)
{
frameflash=0;
temp=0;
}
}
Lastly, seeing that code it's no wonder you don't like debugging. Your habits make your code rather hard to look through. Did you have anything else that would cause the lag? It would be easier to see the ged though.
Users browsing this forum: No registered users and 1 guest