The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.39 / 5.00 38,635 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.09 / 5.00 15,161 ViewsI'm making a simple tile-based engine, with 50x50 tiles, and I've come across a problem.
You see, I'm using the code below, and the player's moving perfectly. Apart from zooming off of the stage. It comes back if you press the opposite key, but then zooms off of the other side.
//BASIC
onClipEvent(load){
_root.ymove=0;
_root.xmove=0;
}
onClipEvent(enterFrame){
this._y+=_root.ymove;
this._x+=_root.xmove;
//WALL
while(_root.wall.hitTest(_x+10,_y,true)&&_root.xmove>0){
_root.xmove--;
}
while(_root.wall.hitTest(_x-10,_y,true)&&_root.xmove<0){
_root.xmove++;
}
while(_root.wall.hitTest(_x,_y+10,true)&&_root.ymove>0){
_root.ymove--;
}
while(_root.wall.hitTest(_x,_y-10,true)&&_root.ymove<0){
_root.ymove++;
}
//_X MOVEMENT
if(Key.isDown(Key.LEFT)){
_root.ymove==0
_root.xmove-=50;
_xscale=-100;
}
if(Key.isDown(Key.RIGHT)){
_root.ymove==0
_root.xmove+=50;
_xscale=100;
}
if(_root.xmove<=-50){
_root.xmove=-50
}
if(_root.xmove>=50){
_root.xmove=50
}
//_Y MOVEMENT
if(Key.isDown(Key.UP)){
_root.xmove==0
_root.ymove-=50;
}
if(Key.isDown(Key.DOWN)){
_root.xmove==0
_root.ymove+=50;
}
if(_root.ymove<=-50){
_root.ymove=-50
}
if(_root.ymove>=50){
_root.ymove=50
}
//DISPLAY
if(!Key.isDown(Key.LEFT)&&!Key.isDown(Key.RIGHT)&&!Key.isDown(Key.UP)&&!Key.isDown(Key.DOWN)){
this.gotoAndStop(1)
}
if(Key.isDown(Key.LEFT)){
this.gotoAndStop(2)
}
if(Key.isDown(Key.RIGHT)){
this.gotoAndStop(2)
}
if(Key.isDown(Key.UP)){
this.gotoAndStop(3)
}
if(Key.isDown(Key.DOWN)){
this.gotoAndStop(4)
}
}
I know the problem is somewhere in the "_x movement" and "_y movement" sections, but I can't find a solution. Any help is appreciated.
Signature? What signature?
Also, any games I plan to make may or may not become vaporware. I'm not good with organizing my life...
I would suggest, in the WALL section, that you use "if" instead of "while" as I assume (because you didn't say so specifically) that he zooms off stage when you hit a wall.
At 1/3/11 03:17 PM, Tygerman wrote: I would suggest, in the WALL section, that you use "if" instead of "while" as I assume (because you didn't say so specifically) that he zooms off stage when you hit a wall.
I'll change that, but, no. He zooms off when you move him in any direction.
Signature? What signature?
Also, any games I plan to make may or may not become vaporware. I'm not good with organizing my life...
Why are you making his speed exponential?
_root.ymove+=50;
That means that every frame you hold the button down his speed increases by 50... change anywhere you are doing that to this...
_root.ymove=50;
and you should fix the issue.
At 1/4/11 02:25 AM, JackSmack wrote: Why are you making his speed exponential?
Actually, the change in speed is linear, and the position changes parabolically. Nothing exponential.
sorry... math nazi here
#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}
At 1/4/11 02:48 AM, Redshift wrote:At 1/4/11 02:25 AM, JackSmack wrote: Why are you making his speed exponential?Actually, the change in speed is linear, and the position changes parabolically. Nothing exponential.sorry... math nazi here
Easy for you to say... I thought you guys only spoke in binary. :P Whatever the hell you call it I'm thinking that is the issue.
I'm not sure what the solution to your problem is, but I've got another tip for ya :)
You don't need to use CPU intense hitTests for collision in tile-based games. Your tiles are probably stored in an array, right? You just need multiply order of your tile with tile size, and you know exactly where the unpathable area is!
You also don't need to use While, since you can just simply move your hero to the side of the tile.
At 1/4/11 02:25 AM, JackSmack wrote: Why are you making his speed exponential?
_root.ymove+=50;
That means that every frame you hold the button down his speed increases by 50... change anywhere you are doing that to this...
_root.ymove=50;
and you should fix the issue.
D'oh! That would explain it. Thanks.
At 1/4/11 05:37 AM, Mufanza wrote: I'm not sure what the solution to your problem is, but I've got another tip for ya :)
You don't need to use CPU intense hitTests for collision in tile-based games. Your tiles are probably stored in an array, right? You just need multiply order of your tile with tile size, and you know exactly where the unpathable area is!
You also don't need to use While, since you can just simply move your hero to the side of the tile.
I don't use arrays. At all. I just put everything in one movieclip, that solves all of my problems. This is going to be one of the last things I do with as2, so I'm not going to learn either. I might look them up in as3, but it depends, on how bothered I am.
Signature? What signature?
Also, any games I plan to make may or may not become vaporware. I'm not good with organizing my life...
At 1/4/11 04:23 PM, Niallmcfc wrote: I don't use arrays. At all. I just put everything in one movieclip, that solves all of my problems. This is going to be one of the last things I do with as2, so I'm not going to learn either. I might look them up in as3, but it depends, on how bothered I am.
please stick to as2 then.
They are the same in AS2 as they are in AS3
Anyway, you use only square or rectangle based tiles, right? You can at least turn the shapeflag of your hitTest off
At 1/4/11 04:47 PM, milchreis wrote:At 1/4/11 04:23 PM, Niallmcfc wrote: I don't use arrays. At all. I just put everything in one movieclip, that solves all of my problems. This is going to be one of the last things I do with as2, so I'm not going to learn either. I might look them up in as3, but it depends, on how bothered I am.please stick to as2 then.
Sorry? AS3 is much better, and much more updated. Why would I want to stick to as2, when it's worse?
Signature? What signature?
Also, any games I plan to make may or may not become vaporware. I'm not good with organizing my life...