So, I made a game on Makecode. It’s called Philip the flathead, and everything seems to be going smoothly, all except for the enemies. I tried making something simple in creating them, but it doesn’t seem to spawn where I need them to. In fact they don’t spawn whatsoever. Can somebody please look it over and tell me what I did wrong?
Now, I have a new problem. I made some code for the enemies to change direction when a wall is in front of them, but all they do is continue to go left.
Oh, I see. Thanks, man. Also, the grey tiles you keep falling through are meant for you to fall through. I did that on purpose as a kind trick for the player. You can tell the difference between these tiles and the other brick tiles based off the bottom.
Ahhhh. That makes sense. The game is really cool. I like the animations and stuff. Too cool. Your farmer guy is cool. I forgot his name though… Nevermind found it. His name is philip. Well I’m here if you need any help soooooo. COOL
Nice raining tacos enemy. I gotta eat some dinner but the enemies might need to do some more work. Make it follow and maybe use projectiles or overlaps to destroy your tacos too.
Since you referred to the speed of the enemies multiple times (-30), I also just created a variable called ‘enemySpeed’. You’ll notice that when an enemy hits a wall on the left, the vx is set to ‘absolute of’ (which just takes the negative speed (-30) and makes it positive).
I changed your code so that the enemies move in the other direction when hitting a well. You had written a for each loop that changed the direction, but that was only occurring within the ‘StartLevel’ method (which is called once). So I removed that code and placed in within the ‘on sprite of kind ‘Enemy’ hits wall at location’ event (you can find it under ‘Scene’ menu).
I copied what you did onto my original game, and made sure that I understood it of course, but when I tested it, it did the same thing as before. What did I do wrong?
You need to use the variables ‘sprite’ and ‘otherSprite’ that are given at the top of the event. To use those variables, click and drag the variable to other sprite placeholders (i.e. sprite to Philip and otherSprite to small_blob). Although you are correct to assume that the only player is ‘Philip’ (which is the variable sprite), and the enemies you create are assigned to ‘small_blob’; the problem occurs when you create multiple enemies. The last enemy created may be further to the right of the game, but it does not refer to the first one you created. Long story, I know.
This is what I changed in the event block
Philip => sprite
small_blob => otherSprite
Also, you were checking if the bottom of Philip was less than the y of small_blob (well ‘otherSprite’, an enemy); which suggests you are checking if the player jumps on top of the enemy. It would be better to specify ‘player bottom’ is less than or equal to the ‘enemy top’. However, your enemies were 16 pixels in height, but only 7 pixels tall. The top measurement takes into account the transparent pixels (i.e the pixels not having any color) that are above the enemy. I changed the height of the enemies to 7 pixels.
Even when I changed that, I noticed that the overlap event was not working as expected, so I changed the condition to be:
if (sprite.vy > 0) (the player sprite is falling down), then the player landed on top of the enemy. I also placed the destroy at the bottom of the if statement.
I was expecting to do it myself, but I never even considered any of this. Thank you so much @cosmoscowboy. You must be from Microsoft cause you seem to know every problem and how to fix it.