Random Actor Generation

It appears there's a few of us trying to get this working :P

I am now confused though, you see for this game to work, we had to add an invisible SCORE box to fit in the gap of the Obstacles, but because each obstacle's gap is located in a different place, surely this method wont work? because all of an "Actors" appearances or frames have the same collision box?
I really want to find a way to get this working too :( I have 5 different obstacles.

« Last Edit: February 16, 2014, 02:17:24 pm by TropicanaEnterprises »

Ceric

  • *
  • Posts: 610
You guys are going to have to explain more about how your game works for me to help you modify the Behaviors any more. It sounds like you're trying to create a puzzle game of some kind (ala Tetris), but I'll need more info to help.

That said, you can change the collision box size for each animation. Each frame has the same collision box, but each animation can be different. In this case the Behavior I made switches which animation is showing, not the frame.


Well im fairly certain that both myself and the creator of this thread have followed the same video tutorial on youtube, a fantastic tutorial, by Scott Wilson (http://www.youtube.com/watch?v=l6GYqy8kyr4) on how to clone Flappy Bird effectively, iv done this as my first attempt at a stencyl, with no coding or game dev knowledge whatsoever, and i think that Scott Wilson has taught me loads in a video only an hour and a half long, and this is in no way meant to be a dig at him, but just a few things were left for another video, and i myself for one am left dying to know how you do these last few things.
They are:
Add a HighScore
Spawn DIFFERENT obstacles each time (in the video we are taught how to spawn one every 3 seconds, but its the same one each time)

Iv already added and changed from the tutorial a fair bit, you can play the game in progress on my profile to see what iv done, but these final 2 feautres would complete my first, and first if many hopefully :P, Stencyl Project 8)

Ceric

  • *
  • Posts: 610
I checked out the video. For spawning different obstacles, the method I used here works fine. Just change the position where each obstacle spawns and set up the obstacles the same way Scott did in the video.

Like I said, each animation can have different collision box sizes, so you just change the collision boxes for the graphic associated with each animation. See the pics attached. Note that there are 4 different animations for the block. The blue animation has a hitbox of 32 x 32. The green block has a hitbox of 16 x 32.

As for the high score, that's more complex - you need to save the score achieved from the level only if it's a larger number than the one you most recently achieved, which involves comparing the two attributes every time your player actor dies.

I'll post something more on this tomorrow (though someone else may chime in before I get a chance, of course).

But the thing to trigger the score increment by 1 is a seperate actor, just placed in the gap between the 2 parts of the obstacle, how do we make the SCORETRIGGER spawn in the correct place each time?

Ceric

  • *
  • Posts: 610
You can use a region instead of an Actor to determine whether your bird has passed through the obstacle or not. In the video, he put the region in the "always" event. You don't need to do that. Just use the basic "when this actor collides with  something else" Event.

To create differently sized regions, you could detect which animation your parent obstacle is using and then spawn a new region, depending on which random animation was determined, that is attached to the actor. You would set the size of the region based on the obstacle's dimensions. It would basically use a series of "if" and "otherwise if" blocks for each obstacle variant.

I haven't tested this Behavior yet, so it may need adjusting. The region sizes, for example, are just placeholders - you would adjust them based on the sizes of the obstacles in your game.

Ceric

  • *
  • Posts: 610
I should add, though, that if you really want to use an invisible Actor, you just use the Create Actor block (instead of Create Region) and spawn it at the exact spot in the gap between the top and bottom parts of each obstacle. (Make sure you destroy it when it goes off screen.)

You would follow the same logic as in the Behavior above - just detect which animation you're using and then make sure you set the Y position of your invisible Actor so it fits between the gap.

Edit:

The downside to using an Actor rather than a Region in this case is that you're using your invisible Actor just like a Region - and a Region is basically just an invisible Actor. When you make a region using the Create Region block, you're setting the Region's dimensions and its collision (hitbox) size all at once. If you use an invisible Actor instead, you have to load a placeholder graphic, make it a sensor, then set its collision box, etc. You would also need to make a separate invisible Actor that fits in the gap between each obstacle (and go through all the steps required to set it up), which gets tedious when you could just calculate the gap opening and make a Region that fits each obstacle gap instead.

« Last Edit: February 17, 2014, 10:55:18 am by Ceric »

Thanks for all the help guys, iv got it working now, spawning different actor animation each time, using your screenshots as bible :) All i need now is high score functionality  8) 8)

Ceric

  • *
  • Posts: 610
Cool. Good to hear. When you say "high score," what exactly do you want it to do? Do you want it to just show the highest score that the player has achieved or something more like a leaderboard?

Yeah i just want it to show the highest score YOU have achieved, and to save it so that you can come back to the game and be at the same level.

I have added "worlds" which are going to unlock when the player hits 50 pts on the previous world, which means il also need to make some kind of behaviour that checks if the highscore on the previous level is over 50 i think?

Ceric

  • *
  • Posts: 610
Oh, to do that, you just save the player's score to a Game Attribute only if the current score is larger than the previously saved score. It would look something like this...

if [current score] is > [saved score]
set [saved score] to [current score]
otherwise if [current score] is <= [saved score]
do nothing

From there, you can just display the Game Attribute called saved score to show the highest score achieved.

Also, to check whether a level is unlocked or not, just have a level selection screen where it checks the value of the saved score Game Attribute and if it's high enough, the level selectors become clickable (or can be accessed via touch if this is a mobile game).