Randomize two tiles and fill the screen

0 favourites
  • 4 posts
From the Asset Store
An educational game for Fill in the Blanks. An easy to use template for developers to build larger games
  • Hi, I'm making a 1942 clone and I need to randomize two tiles, fill the whole screen with them, and then make a vertical scrolling.

    Shouldn't be too hard, right?

    I could use the Vertical Shooter example but it only uses one "tile" and placement is random.

    --- Specific data ---

    Let's assume each tile is 32 x 32 pixels and I need to fill a 480 x 640 screen size.

    Honestly I can't imagine how to make them spawn both randomly across the screen.

    Maybe I can fill the screen with one, then randomly place the other on top? That would be more resource intensive, I think.

    And then the scrolling, which I have also no idea how to make it work, since the example is a bit different from what I want to make.

  • pimbadumba bump

    This is the finished version =P

    youtube.com/watch

  • This is one way you could do it. In case anyone else has this question. And keep in mind that my way isn't usually the best way to do it. :-D

    First you create your Sprite object. Give it (x) animations. 2 in your case. One for each of the ground tiles you want to move. Make sure to set their hot spot to 0,0 and set the animation speed to 0.

    Then you can either create the initial screen full of tiles manually, or run two loops at startup that create tiles on the X and Y axis and then randomize the animation frame. That will fill your screen with tiles. The example I included does this.

    Next, you make the tiles move. I use Every 0.05 ms move Tiles 1 pixel at 90 degrees. You can manipulate that later.

    Next, in your case, your window height is 640. So... make an event that checks the tile Y position. That same event will need another event called "For Each Object" to make sure every tile creates this action, not just the first one. If the Y position is below 640, delete the tile, and create a new tile at X coordinate(tile.x), Y coordinate(-32), then set that tile's animation frame to random(2)

    That should do it. And since I suck Raptor-turds at explaining, I included a capx. You'll need C2 version 146 or higher. (I think)

    Capx: db.tt/N7S3i683

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks!

    I worked a bit more on this and could make it work with the Wrap behaviour. It's not 100% random but it really does the job for this game.

    If someone wants to replicate it:

    • Enable Wrap Behavior on the "Stars" sprite.
    • Disable or Delete the whole "Destroying Bottom Stars..." Group Event.
    • Change the Repeat of the first loop to one more (22 + 1)
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)