Author Topic: Sloped Tiles - FlxTilemapExt  (Read 9862 times)

The Turnip Master

  • Member
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
    • Nerdspiel
Sloped Tiles - FlxTilemapExt
« on: Tue, Nov 8, 2011 »
So, for my current project, I thought I'd try implementing sloped tiles.  I've attempted before in past projects, but it's always been more trouble than it's worth.  This time, however, I seem to have it working, thanks to all the work that people have already done here on the forums.

Here's my extended Tilemap class, based mostly off the one made by krix.  It functions very similarly, but has the ability to customize your tile set to set any number of sloped tiles, which is a good thing for me because my tile sets tend to get huge.  Also, I added the ability to set tile as being one way "cloud" type tiles that can be jumped through from below.

FlxTilemapExt
Demo Project
Demo SWF

There's also a quick demo project that I made to test it, based on the EZPlatformer demo.  I finally got it running smoothly on my machine, but I'd be interested to see if anyone else can find any problems.  You still seem to stick a bit to the ceiling on the downward slopes, but other than that, it seems to function correctly.

Enjoy.

« Last Edit: Mon, Nov 21, 2011 by The Turnip Master »

Chelnok

  • Contributor
  • ****
  • Posts: 257
  • Karma: +0/-0
    • View Profile
Re: Sloped Tiles - FlxTilemapExt
« Reply #1 on: Tue, Nov 8, 2011 »
Looks good. Thanks!

camasthecat

  • Contributor
  • ****
  • Posts: 461
  • Karma: +0/-0
  • WOW! 400+ Posts!? Jeez! Do I have a life!?!?
    • View Profile
    • My site for thermalJS, an HTML5/Javascript engine kinda-like flixel:
Re: Sloped Tiles - FlxTilemapExt
« Reply #2 on: Tue, Nov 8, 2011 »
Cool, Thanks a bunch!

yadurajiv

  • Member
  • **
  • Posts: 35
  • Karma: +1/-0
  • ~.^ wut you say?
    • View Profile
    • the rant
Re: Sloped Tiles - FlxTilemapExt
« Reply #3 on: Fri, Nov 11, 2011 »
Very nice and useful! ^_^
^___________^

marsoll

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Sloped Tiles - FlxTilemapExt
« Reply #4 on: Sun, Nov 13, 2011 »
Looks really good. When going up the slope, movement "feels" a little bit fast, in my opinion.
Other than that... great stuff!

Cheers, Marcus

KWarp

  • Active Member
  • ***
  • Posts: 105
  • Karma: +0/-0
  • Game Programmer
    • View Profile
    • kwarp.com
Re: Sloped Tiles - FlxTilemapExt
« Reply #5 on: Wed, Nov 16, 2011 »
This is pretty good.

Nitpick:
I notice that the box character moves into the slope a little more at the cracks between two slope blocks, making the hills "bumpy". This is probably because one of the other solid blocks is being used for collision resolution instead of one of the slope blocks.
To understand recursion, you must first understand recursion.

krix

  • Member
  • **
  • Posts: 61
  • Karma: +0/-0
    • View Profile
Re: Sloped Tiles - FlxTilemapExt
« Reply #6 on: Mon, Nov 21, 2011 »
So, for my current project, I thought I'd try implementing sloped tiles.  I've attempted before in past projects, but it's always been more trouble than it's worth.  This time, however, I seem to have it working, thanks to all the work that people have already done here on the forums.

Here's my extended Tilemap class, based mostly off the one made by krix.  It functions very similarly, but has the ability to customize your tile set to set any number of sloped tiles, which is a good thing for me because my tile sets tend to get huge.  Also, I added the ability to set tile as being one way "cloud" type tiles that can be jumped through from below.

FlxTilemapExt
Demo Project
Demo SWF

There's also a quick demo project that I made to test it, based on the EZPlatformer demo.  I finally got it running smoothly on my machine, but I'd be interested to see if anyone else can find any problems.  You still seem to stick a bit to the ceiling on the downward slopes, but other than that, it seems to function correctly.

Enjoy.

Glad to see you referencing me for the basic slope class. Just wondering why my name is linked to nerdspiel.com !?

Cheers,
Dirk

The Turnip Master

  • Member
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
    • Nerdspiel
Re: Sloped Tiles - FlxTilemapExt
« Reply #7 on: Mon, Nov 21, 2011 »
Glad to see you referencing me for the basic slope class. Just wondering why my name is linked to nerdspiel.com !?

Oops, my bad.  I was trying to link to your original post.  I must not have noticed the wrong link in my clipboard.  It should be fixed, now.

Also, nice work on the slope class.  Like I said, I've seen dozens of different takes on sloped tiles in Flash and I've never found one that actually worked well enough to try and use in a project.  Thanks for all the work!
« Last Edit: Mon, Nov 21, 2011 by The Turnip Master »

Dmeville

  • Member
  • **
  • Posts: 67
  • Karma: +0/-0
    • View Profile
Re: Sloped Tiles - FlxTilemapExt
« Reply #8 on: Fri, Dec 2, 2011 »
I found a FlxTilemapExt file around these forums about a month ago with all the same core code, just without the array of slopes.  Nice addition!  Looks nicer than the way I handled multiple slope tiles!

It works great for the player, however colliding the slopes against bullets seems to have strange results.  I've been trying to fix this here and there but to no avail.  All the bullets I'm using are just small moving FlxSprites, so why this wouldn't work with the same success of the player is weird.  (Unless I'm missing something!)

Here's an image to see what's happening exactly.  Maybe someone here could help me figure this out?
It's particularly frustrating when you're firing UP a slope at an enemy, it "hits" something invisible, and gets destroyed while it's moving BY the slope.

I'll upload a playable demo so anyone can test it out and see whats happening in real time.
[Click here to play the demo]
(WASD to move, mouse to aim, click to shoot)
« Last Edit: Fri, Dec 2, 2011 by Dmeville »

The Turnip Master

  • Member
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
    • Nerdspiel
Re: Sloped Tiles - FlxTilemapExt
« Reply #9 on: Mon, Dec 5, 2011 »
I think I know what your problem is.

If your bullet code is based off of the bullets in Mode or another demo, you probably have something like this in your PlayState class:

Code: [Select]
protected function overlapped(Sprite1:FlxSprite,Sprite2:FlxSprite):void
{
if((Sprite1 is EnemyBullet) || (Sprite1 is Bullet))
Sprite1.kill();
Sprite2.hurt(1);
}


This means that while most sprites can walk up a slope and overlap with the tile, bullets are specifically designed to die as soon as they come into contact with any other physical object.  Since all the slope logic is calculated in response to an overlap, most of the code in FlxTilemapExt doesn't even get a chance to run.

In a game that only shoots at right angles, it shouldn't really make much of a difference to gameplay, it just looks funny to see the bullet impact before it hits the slope.  The problem for you is that it can get in the way for diagonal shots that would miss the slope, but hit the corner of the tile.  The easiest thing to do would probably be to just modify the part of code above so that it responds differently to slopes.  If you design your levels so that sloped tiles are never floating out in space (like that one tile just to the right of your starting screen), then you could just have bullets ignore sloped tiles, letting the bullets hit the normal blocks behind them.  You could also try modifying the code to only kill in case of a collision, rather than an overlap, but that might cause problems with bullets colliding with enemies (unless your enemies are solid).

Alternatively, I know that Flixel Power Tools has a FlxWeapon class that supports angled bullets.  That might work better with sloped tiles.  I don't suppose anyone knows if FlxWeapon removes bullets on overlap?

camasthecat

  • Contributor
  • ****
  • Posts: 461
  • Karma: +0/-0
  • WOW! 400+ Posts!? Jeez! Do I have a life!?!?
    • View Profile
    • My site for thermalJS, an HTML5/Javascript engine kinda-like flixel:
Re: Sloped Tiles - FlxTilemapExt
« Reply #10 on: Mon, Dec 5, 2011 »
I can't get the ceiling slopes working! But the floor slopes are working... I looked at the example code, and I just copied and pasted, and now, all the tiles in the tilemap are glitched. :S Any solutions? I don't think my code is the problem...

The Turnip Master

  • Member
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
    • Nerdspiel
Re: Sloped Tiles - FlxTilemapExt
« Reply #11 on: Tue, Dec 6, 2011 »
I can't get the ceiling slopes working! But the floor slopes are working... I looked at the example code, and I just copied and pasted, and now, all the tiles in the tilemap are glitched. :S Any solutions? I don't think my code is the problem...

Well, I would probably start by taking a look at the code I used in the Demo SWF I posted above.  I haven't run into any bugs in the demo, so hopefully you should be able to compile a SWF and have it function correctly.  It's pretty much just a version of the EZ Platformer demo with a different tileset and using the FlxTilemapExt class instead of the normal FlxTilemap class.  If you can get the demo to work properly but not your program, then you might just be able to compare and see what the differences in your code are.

Just out of curiosity, what problem are you having with the ceiling?  Is it colliding like a full, solid block?  Is it not colliding at all?

Dmeville

  • Member
  • **
  • Posts: 67
  • Karma: +0/-0
    • View Profile
Re: Sloped Tiles - FlxTilemapExt
« Reply #12 on: Wed, Dec 7, 2011 »
Thanks for the insight!

It makes sense that since the bullets are clipping the edge of the tile they're getting destroyed, so I think the easiest thing to do would just make the bullets ignore the slopes. 

I'll post if if get any results.

EDIT:  In the SolveCollisionSlopeetcetc functions, I'm throwing all that code into the else block of an if(obj is Bullet) conditional.  If the obj is a bullet, I set a property on the bullet, CollidingWithSlope to true.

Then, in my FlxG.collide between bullets and tilemap, I have if(!bullet.CollidingWithSlope){ bullet.Explode()}

The problem I'm having is once the bullet hits the slope, it's CollidingWithSlope is set to true, but it is never set back to false, and get's stuck in the corner behind the slope, never exploding and being destroyed.  How would I go about fixing this?  What I guess I mean to ask is where can I add one line of code that will get executed whenever I collide with any tile that ISN'T a slope?

.. I'll continue looking into it/testing about.


On a slightly different note, It still baffles me why things like this (see attached image) happen :s
« Last Edit: Wed, Dec 7, 2011 by Dmeville »

camasthecat

  • Contributor
  • ****
  • Posts: 461
  • Karma: +0/-0
  • WOW! 400+ Posts!? Jeez! Do I have a life!?!?
    • View Profile
    • My site for thermalJS, an HTML5/Javascript engine kinda-like flixel:
Re: Sloped Tiles - FlxTilemapExt
« Reply #13 on: Wed, Dec 7, 2011 »
Yay! I got the ceiling tiles working! The problem was that I had only one variable in the array I was sending to the tiles-There has to be more than one! Way is that anyway??

The Turnip Master

  • Member
  • **
  • Posts: 26
  • Karma: +0/-0
    • View Profile
    • Nerdspiel
Re: Sloped Tiles - FlxTilemapExt
« Reply #14 on: Fri, Dec 9, 2011 »
Yay! I got the ceiling tiles working! The problem was that I had only one variable in the array I was sending to the tiles-There has to be more than one! Way is that anyway??

It's not that you need more than one variable in the array, it's just a quirk of how arrays work in Actionscript.  For example, let's say you have something like this:

Code: [Select]
var tempCL:Array = new Array(3, 4);
var tempCR:Array = new Array(5);

The first line says "Create an array of length two with '3' and '4' as values."  The second line says "Create an empty array of length five."  My bet is that when you just had one value, Flash was creating an empty array to pass to FlxTilemapExt.  There are a few different ways you can get around that problem.  The best would probably be to create your array of the proper length first, then populate it.  However, I've found that simply writing the line with quotation marks around the value works as well, so:

Code: [Select]
var tempCR:Array = new Array("5");

Technically, this method should be placing a String consisting of a number 5, rather than the number itself, but the slope function seems to understand it just as well.


camasthecat

  • Contributor
  • ****
  • Posts: 461
  • Karma: +0/-0
  • WOW! 400+ Posts!? Jeez! Do I have a life!?!?
    • View Profile
    • My site for thermalJS, an HTML5/Javascript engine kinda-like flixel:
Re: Sloped Tiles - FlxTilemapExt
« Reply #15 on: Fri, Dec 9, 2011 »
Oh, OK. Thanks! :D