Author Topic: Custom tileshape  (Read 10706 times)

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Custom tileshape
« on: 2008-01-16, 03:52:44 PM »
i am so sorry! there was once a thread but i don't find it anymore. there is a tut but i ask you because time is running out for me....
how to define this tileshape??
(lower half solid, upper half not)
« Last Edit: 2008-01-16, 03:56:10 PM by Morgengrauen »

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Custom tileshape
« Reply #1 on: 2008-01-16, 05:02:53 PM »
oh, and this.
please don't say: split your tileset into smaller tiles. this tileset has actually 35 tiles. at the moment i use it in four different versions. makes 140 tiles. soon it will be some more versions.
i really don't want them to quadruple.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Custom tileshape
« Reply #2 on: 2008-01-16, 09:30:27 PM »
Either create a new code object under TileShapes.cs called BottomHalf.cs (and delete the default code it puts in) or edit TileShapes.cs itself.
In it (at the bottom, if you edit TileShapes.cs), put this code:

Code: [Select]
public class BottomHalf : TileShape
{
   private static BottomHalf m_Value = new BottomHalf();

   public static BottomHalf Value
   {
      get
      {
         return m_Value;
      }
   }

   public BottomHalf()
   {
   }

   public override short GetTopSolidPixel(short width, short height, short min, short max)
   {
      return (short)(height / 2);
   }

   public override short GetBottomSolidPixel(short width, short height, short min, short max)
   {
      return (short)(height-1);
   }

   public override short GetLeftSolidPixel(short width, short height, short min, short max)
   {
      return (max > height / 2 ? 0 : short.MaxValue);
   }

   public override short GetRightSolidPixel(short width, short height, short min, short max)
   {
      return (max > height / 2 ? (short)(width-1) : short.MaxValue);
   }
}

The advantage of editing TileShapes.cs is you don't have extra files.  However, if you ever needed to reset the code in the project, this would disappear unless it were in a separate file.
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Custom tileshape
« Reply #3 on: 2008-01-17, 06:07:54 AM »
I think the "max > height / 2" should be "max >= height / 2" in both cases.

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Re: Custom tileshape
« Reply #4 on: 2008-01-17, 06:33:57 AM »
IDEA!

A little editor thing, where you have a brush, and you colour an invisible mask over tiles, (u can see them in the editor but not in game) with the painted pixels being solid and the pixels u didnt paint normal, non solid pixels. this would allow some awesome tile shapes...

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Custom tileshape
« Reply #5 on: 2008-01-17, 06:37:01 AM »
yeah, as i said in the other thread about importing these custom tileshapes.
but i guess this function would use much more computer power than defining the shape through script.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Custom tileshape
« Reply #6 on: 2008-01-17, 07:00:35 AM »
IDEA!

A little editor thing, where you have a brush, and you colour an invisible mask over tiles, (u can see them in the editor but not in game) with the painted pixels being solid and the pixels u didnt paint normal, non solid pixels. this would allow some awesome tile shapes...

Tile shapes are supposed to be simple and quick, not awesome ;).  It seems a shame to put so much work into a shape, which the player usually doesn't notice anyway.  Usually an approximate shape is good enough, don't you think?  I have to laugh thinking about it... can you imagine someone saying, "Woah! did you see that!?  My player moved up 4 pixels instead of 2 when I moved to the right 5 pixels on this tile... awesome shape!" :D  (I don't mean to make fun, but I think you could see the humor in that, and humor is a good thing.)  Anyway, I can see the value in it, but there's a significant cost to implement such an idea, so there would have to be some really important benefits to do something like this.  (As I said in the other thread, I had this for a while and I took it out.)

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Re: Custom tileshape
« Reply #7 on: 2008-01-17, 07:43:15 AM »
Quote
Tile shapes are supposed to be simple and quick, not awesome Wink.  It seems a shame to put so much work into a shape, which the player usually doesn't notice anyway.  Usually an approximate shape is good enough, don't you think?  I have to laugh thinking about it... can you imagine someone saying, "Woah! did you see that!?  My player moved up 4 pixels instead of 2 when I moved to the right 5 pixels on this tile... awesome shape!" Cheesy  (I don't mean to make fun, but I think you could see the humor in that, and humor is a good thing.)  Anyway, I can see the value in it, but there's a significant cost to implement such an idea, so there would have to be some really important benefits to do something like this.  (As I said in the other thread, I had this for a while and I took it out.)
roflmao yeh that's pretty funny. :p

Was playing the game "N" when I thought of it, and it has like quarter-pipe tiles, and all different angles of slopes and stuff, and it has some cool maneuvers that I wanna try and put into a game... for example you can jump from walls, the longer you hold the jump button the higher you jump... (there is eventually a limit, its not like flying lol, but it allows for more control over the sprite in-game) when you jump, you don't jump up, you jump perpendicular to the ground, so you can be running up a quarter pipe and jump when it's almost vertical and you can reach places you can't normally get to... it's actually a really cool game. :D

Quote
yeah, as i said in the other thread about importing these custom tileshapes.
lmao, sorry I didn't read that thread yet. :p

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Custom tileshape
« Reply #8 on: 2008-01-17, 12:22:45 PM »
You can write functions that create solidity as angles and curves etc. using SIN and COS functions, etc.  All the other things you talked about are also easy (relatively) with so many possible rules and coding available.  Jumping higher with longer button presses is something I implemented in a test program when I was ripping Mario graphics awhile ago (Mario has that same effect).
Edward Dassmesser

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Custom tileshape
« Reply #9 on: 2008-01-17, 12:59:21 PM »
You can write functions that create solidity as angles and curves etc. using SIN and COS functions, etc.

cool, i need to remember that. i might have guessed.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Custom tileshape
« Reply #10 on: 2008-01-24, 03:37:30 PM »
when i insert the code from durnurd, this error message occurs:
Type of conditional expression can't be determined because 'int' and 'short' both implicitly convert to each other

Code: [Select]
public class BottomHalf : TileShape
{
   private static BottomHalf m_Value = new BottomHalf();

   public static BottomHalf Value
   {
      get
      {
         return m_Value;
      }
   }

   public BottomHalf()
   {
   }

   public override short GetTopSolidPixel(short width, short height, short min, short max)
   {
      return (short)(height / 2);
   }

   public override short GetBottomSolidPixel(short width, short height, short min, short max)
   {
      return (short)(height-1);
   }

   public override short GetLeftSolidPixel(short width, short height, short min, short max)
   {
      return (max > height / 2 ? 0 : short.MaxValue);
   }

   public override short GetRightSolidPixel(short width, short height, short min, short max)
   {
      return (max > height / 2 ? (short)(width-1) : short.MaxValue);
   }
}

Richard Kain

  • Regular
  • **
  • Posts: 23
    • View Profile
Re: Custom tileshape
« Reply #11 on: 2008-01-24, 04:56:25 PM »
I'm actually interested in creating tile shapes that have the corners clipped off. That is to say, they would have diagonal values where the corners would be. This is so that there could be a bit of easing whenever the player runs into a corner. Right now, when the player attempts to go through a passage that is the same size as them, they have to hit it dead on. (or they bump into the edges around it) If I was able to bevel the corners near passages like this, it would be possible for me to "ease" or "guide" the player into these tight spaces.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Custom tileshape
« Reply #12 on: 2008-01-25, 08:48:36 AM »
I'm actually interested in creating tile shapes that have the corners clipped off. That is to say, they would have diagonal values where the corners would be. This is so that there could be a bit of easing whenever the player runs into a corner. Right now, when the player attempts to go through a passage that is the same size as them, they have to hit it dead on. (or they bump into the edges around it) If I was able to bevel the corners near passages like this, it would be possible for me to "ease" or "guide" the player into these tight spaces.
I imagine it might also be easier to get into a passage if the tiles are slightly larger than the player, which would make the gap also slightly larger.
when i insert the code from durnurd, this error message occurs:
Type of conditional expression can't be determined because 'int' and 'short' both implicitly convert to each other
Alright, time to actually test...
Change this line:
      return (max >= height / 2 ? 0 : short.MaxValue);
to this:
      return (max >= height / 2 ? (short)0 : short.MaxValue);
It apparently has to know what type of value '0' is and it can't tell between an int or a short, and implicit conversions confuse it because they both mean the same thing.
Edward Dassmesser

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Custom tileshape
« Reply #13 on: 2008-01-25, 09:25:00 AM »
after changing this line the game compiles. but when i use this definition, the game crashes either when i hit the tile (first try), or a while after i've hit it (second try).

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Custom tileshape
« Reply #14 on: 2008-01-25, 12:38:25 PM »
after changing this line the game compiles. but when i use this definition, the game crashes either when i hit the tile (first try), or a while after i've hit it (second try).
I tried it on the sample project and for awhile it worked fine, then it randomly shot off to the opposite side of the screen.  I'm not sure why you got the error, though.  I am not sure if the sample was just lucky for it to work properly such that it didn't shoot off the end of the screen or what, but the problem is that GetRightSolidPixel expects short.MinValue instead of short.MaxValue if there is no right solid pixel.  So change this:
      return (max >= height / 2 ? (short)(width-1) : short.MaxValue);
to this
      return (max >= height / 2 ? (short)(width-1) : short.MinValue);
(in GetRightSolidPixel)
Edward Dassmesser