Terraria, Blocks That Matter, Battle Block theater, and junk jack can all do this...

Discussion in 'iOS Programming' started by AnonymousPoster, Dec 30, 2011.

  1. AnonymousPoster macrumors newbie

    Dec 30, 2011
    So I'm building a very basic platformer right now its a green square moving around in a world of orange square. Every time I make a new square I have to manually code so it works with the rest of the world. In all the games in the title they somehow wrote a way to say when you hit this type of block it stops you from falling, or it kills you, or it sets you on fire... I don't even know how this is done, is it a subview class? or something like that...
  2. ArtOfWarfare macrumors G3


    Nov 26, 2007
    I did some work on a platformer on the iMac I left at school... I don't have it with me right now and won't have it for two more weeks or so... But as I recall, my solution involved having an array of CGRects for each type of tile. 50 times a second it would check if the player had touched any of each type of tile, and it would respond accordingly based off of that info.

    I'm not sure if that's the best way of doing it, though.
  3. AnonymousPoster thread starter macrumors newbie

    Dec 30, 2011
    Thanks! your the first person to respond and I've been posting on different forums and sending emails to game studios for like 3 hours!

    Yeah I'm using a game loop and if statements to check if each specific block had intersected with it but there gotta be a better way because I have to code every square and not every type of square, I'm not sure how to even make check for a type of square and not for the individual square.
  4. ArtOfWarfare macrumors G3


    Nov 26, 2007
    My solution allowed for different types of squares, though?

    I had something like this:
    CGRect		wall[500];
    int		wallCount;
    CGRect		floor[500];
    int		floorCount;
    CGRect		messageTrigger[500];
    NSString	*message[500];
    int		messageCount;
    That's really rough, I just typed it straight into the forums because my actual work is on another machine...

    anyways, I would loop through the arrays to see if the player was intersecting with any of the rects at any given moment. If they were intersecting a wall, I would move them left or right to get them out of it, if they were intersecting a floor, I would move them up or down to get them out of it, and if they were intersecting a message trigger, it would display the corresponding message.

    (The count variables were used so that I could have any number up to 500 of a given element in a level...)

    Although I'm thinking I may take a different approach when I revisit this project as I'd rather be able to have non-rectangular structures... I'd like to have hills and stuff and so I figure I'll look into paths instead of rects...

Share This Page