how to randomly spawn actors inside a 6x7 grid?
FamTechAdmin
Member Posts: 47
hi.
I was just wondering how to randomly spawn actors inside a 6x7 grid?
I want to spawn actors onto 41 spots inside the grid and leave 1 spot empty (located at the bottom-right corner).
it should randomly choose between 4 types of actors and spawn only once, at the beginning of a level.
Im trying to create a game similar to candy crush and free fall...
...well, it only looks similar at the beginning of the game.
update: I watched this tutorial, How To Spawn Random, Non-Repeating Actors https://youtube.com/watch?v=J-60AF68Bxc and was wondering if it is possible to use this logic on a grid? if yes, then how?
Comments
Spawn the actors and assign a "type" to them at random afterwards. That way you're just spawning a simple grid and doing a change attribute in each actor.
Is there something more you'd be after?
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
@Armelline
Thanks for the tip but I´m not sure if I understood how to assign a "type" to them to be able to spawn a simple grid?
yes, once the grid is set and I have 41 actors on it and 1 empty square (the bottom-right corner), I will only be able to move the actors closest to the empty square. which means the actors that are next to it on either side or above or below it.
@FamTechAdmin - I think what he means is something I implemented in my game.
I spawn the actor. The first rule of the actor is to assign a random number between 1 and 3 to a self.myType integer attribute.
I then change the graphic of the actor, based on the value of self.myType using IF statements.
If you do this, you don't really need to randomly place them, you just fill all empty squares with an actor and as soon as it's placed, it becomes one of the 4 different types.
@ookami007
I tried accordingly to this tutorial, How To Spawn Random, Non-Repeating Actors https://youtube.com/watch?v=J-60AF68Bxc but only one out of 41 actors seem to work. changing to a different image I mean.
but I think that I´ll try your method instead... sounds less complicated than the one I just tried.
@FamTechAdmin - Here's a demo for you of two ways to do it. The first way (first scene... hit the START button) will generate a 6x7 grid with the same object. The object itself will make a random version of itself (change number and color).
The second version (2nd scene), hit the start button and it will generate a 6x7 grid with 4 different objects randomly placed.
I hope that helps you.
https://dropbox.com/s/6fjs6wcbmvxcnuw/Random%20Object%20Generation.zip?dl=0
@ookami007
thank you for the demo, it was exactly how I wanted the actors to be added to the grid. I´ll experiment a little to see if I can get it as I pictured it in my head
@ookami007 Thank you for this
@FamTechAdmin / @ant_lad - Glad to help.
@ookami007
I have a few questions regarding the grid, maybe you can help?
1) If you're using my template, when the objects are spawned they are spawned on specific x,y coordinates that are calculated based on what row/column is being drawn. The calculation is in the spawn actor behavior. You just have to tweak that until it's in the right place.
2) Yes, if you want to use images, you just change the image to whatever you want based on the number... or if you're using the separate object spawner, just set the image in each object.
3) That's a complex question and it really depends on what you want to happen. Are you thinking something along the lines of a match 3 game, where the gems, etc. fall down when there is space below them?
4) You'll most like have to generate it in a table, then loop through the table a few times to check and fix any issues.