Wednesday, October 20, 2010

Success with Scratch 1.4- created a random enemy creation mechanic

It's not finished yet to the level I'd hoped to reach, but I managed to create a scratch program that can randomly generate enemies! Executing the program always generates one out of ten random enemies. Based on random variables between -10 and 10, it determines whether a second enemy will spawn. If the variable is greater than 0, it spawns a second one of ten enemies and generates a third variable between -10 and 10. If this third variable is greater than 0, it creates a third enemy. The enemy's health only displays if one has spawned, hides it otherwise.

I'm pleased with how this is turning out. I haven't worked out a way to battle these enemies yet, but the logic behind using variables to create more complex programs is starting to make more sense to me. Originally I had only planned to have two enemies to demo this program, and they would not change; this function adds a good deal of random chance to the game, with relatively simple code. when I seek to improve on it, I may add enemy HP variables, values that change depending on which enemy spawns. I might also add a boss spawn mechanic, which could simply be an additional random value in the code used to determine the first enemy's sprite.




An example in which only one enemy has spawned. Note that Randommobspawn 1 and 2 are both < 1. These variables are related, and a third enemy will only spawn if a second spawns- a second will spawn only if a random variable between -10 and 10 is greater than 0.


No comments:

Post a Comment