Be a Supporter!

Tile based problem

  • 280 Views
  • 10 Replies
New Topic Respond to this Topic
Niallmcfc
Niallmcfc
  • Member since: Aug. 16, 2009
  • Offline.
Forum Stats
Member
Level 09
Gamer
Tile based problem 2011-01-03 10:21:54 Reply

I'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...

Tygerman
Tygerman
  • Member since: Aug. 16, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Tile based problem 2011-01-03 15:17:33 Reply

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.


BBS Signature
Niallmcfc
Niallmcfc
  • Member since: Aug. 16, 2009
  • Offline.
Forum Stats
Member
Level 09
Gamer
Response to Tile based problem 2011-01-04 02:13:54 Reply

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...

JackSmack
JackSmack
  • Member since: Nov. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Game Developer
Response to Tile based problem 2011-01-04 02:25:55 Reply

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.


Visit JackSmack.com and submit your Flash Games!

BBS Signature
Redshift
Redshift
  • Member since: Feb. 12, 2005
  • Offline.
Forum Stats
Member
Level 15
Programmer
Response to Tile based problem 2011-01-04 02:48:09 Reply

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);}

BBS Signature
JackSmack
JackSmack
  • Member since: Nov. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Game Developer
Response to Tile based problem 2011-01-04 04:30:07 Reply

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.


Visit JackSmack.com and submit your Flash Games!

BBS Signature
Mufanza
Mufanza
  • Member since: Aug. 22, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Tile based problem 2011-01-04 05:37:56 Reply

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.

Niallmcfc
Niallmcfc
  • Member since: Aug. 16, 2009
  • Offline.
Forum Stats
Member
Level 09
Gamer
Response to Tile based problem 2011-01-04 16:23:52 Reply

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...

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Tile based problem 2011-01-04 16:47:06 Reply

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.

Mufanza
Mufanza
  • Member since: Aug. 22, 2009
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Tile based problem 2011-01-05 11:29:48 Reply

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

Niallmcfc
Niallmcfc
  • Member since: Aug. 16, 2009
  • Offline.
Forum Stats
Member
Level 09
Gamer
Response to Tile based problem 2011-01-05 11:38:12 Reply

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...