I’m in the process of creating a top down space shooter. I have an array set to throw asteroids at he player. However, once they get through that part I want to have them fight a boss. Once defeated, they progress to the next level.
Is this possible? So far I can’t quite figure out how to set up levels. I’ve seen an array of levels for a side platformer, but not something like a space shooter. Any tips would be grateful!
There isn’t a “built-in” way to do multiple levels, it really depends on the game. A good place to start though is to break your program into functions. For example, have a function for creating the player, have a function for adding enemies to the game, etc.
Then, create a function that “cleans up” in between levels. That usually means deleting all of the sprites in the game, and there is a very useful block for doing that in the “Arrays” category that gives you a list of all of the sprites of a certain kind. For example, if I wanted to delete all of the enemies I might do this:
Once you have that, you can call your create functions to start a level and your cleanup functions to end it. You could have one function per level, or do what the platformer does and have a function that takes an image and places enemies on the map where certain colors are.
For the boss part, I think you should have a variable, that increases by 1 each level they beat. This counter can be used to dictate things that happen, like a boss, or harder levels. It’ll be 0 at the start, and go up from there.
Brilliant idea! This is why the community here is so helpful. It makes complete sense. Use functions to clear the screen and change up the enemies with the illusion of levels. My next hurdle will be, the best way to ‘trigger’ the function - at the moment, I’m thinking of using an ‘On Game Update 40000ms’ to have the next function triggered after 40secs for example, but then it will do that ever 40 secs which I don’t particular want - any other creative ways of doing this? Is there a way to trigger an event other than after a time period?
You could trigger the new level function off of any event; one that might be helpful would be based off when a certain number of enemies are destroyed. For example, you could say ‘when a certain number of enemies have been destroyed, create a boss and stop spawning enemies; then move onto the next level when the boss is destroyed.’ This can get a bit complicated, but here’s a snippet of one approach to creating that sort of behavior:
This will create a boss after 5 enemies have been destroyed on the first level, then 15 for the next level, and so on. (I also added a lifespan to the example below so that it will destroy the boss and continue after a short time)
Hey Jwunderl! Thanks for the snippet of code! I had a helped! I’ve been able to set it so after 15 asteroids are destroyed, it spawns the boss. I’m going to pick your brain so see how deep it can make this little side project to go.
I’m thinking about allowing the user to select 3 different ships at the beginning of the game, essentially 3 different sprites. Is this possible? Are their any project like that at the moment where a sprite is an some form of array, the user selects that sprite that would be utilised throughout the code?
Secondly - Is there a way to put pictures or colour behind a splash screen? Normally it’s all black but I’m trying to think of a creative way to do pixel art cut scenes to see if some kind of storyline is possible. Again, thanks for the visual help with the code! Appreciate all the effort. I’ve attach my code thus for people to look at. Eventually I’ll change the sprite of the ship to an original with animation of flames coming out the back but just trying to get the mechanics working. So far it goes as far as spawning the cake (boss) but that’s it for now.
For selecting your ship, take a look at the Memory game in MakeCode Arcade. You can find it in the Blocks Games section.
Because it’s a rather common construction (John Park uses something similar in his racing game, too), I created an extension to simplify this. If you’re interested, then take a look at this thread for more information:
I am also still looking for a tutorial on how to use the “storyboard” extension. I have scrubbed the internet and can find no reference anywhere to it. With no instructions it is hard to know were even to start.
I am looking to have a “splash” screen at the beginning of the game and then a menu system. Also when the game ends to have an end game scene.
The icon of storyboard seems to suggest you could do it, but as I said there is literally no documentation on how to use it. I have also never seen any code examples.
Thanks for getting back to me.
Is there some technical reason there cannot be a block to make scenes?
If there cannot be a block to make scenes, maybe there should not be any blocks at all.
The not being able to make the scene in blocks really confused me when I was trying to understand the extension.
I agree, we should change the description on that extension or remove the blocks. @peli thoughts on that?
For example, if you have a variable named mySprite and you use it in two different scenes you could run into situations where one scene overwrites the sprite of the other while the scene is paused. Debugging that kind of code would be pretty difficult.