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.
This is the finished version =P
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)
Develop games in your browser. Powerful, performant & highly capable.
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: