Wsg yall, hope you have a good day. I made a ripoff mario game, but had a problem with enemy coding

Hi there, I really appreciate if you helped me. I made a dumb mario game for school project, I only had a problem with enemy’s coding that i couldn’t figure it out what was happening. Only i had a problem is spawning an enemy in specific location such as everytime enemy spawns it literally spawned from the sky. I placed a invisible red square (you can see in tilemap), which indicates a spawner, but it didnt spawned on the red square, it instead spawn from the sky.

Also, there’s another problem with another enemy coding, it literally floated in the air instead of falling into a lava pit or standing onto a platform, which is literally annoying.

LASTLY (sorry), How do i make my enemies follow the player while moving right and to bounce on a invisible wall without falling and how do I spawn enemies that wouldn’t cause my game to lag very hard. Also, how do I spawn enemies when I over lapped the “GO!” block on tilemap.

Apologies of I yapped alot, but I would appreciate if yall helped me out figuring out the code and help me places them.

3 Likes

I needed someone to help figure out whats wrong with my code before next Monday.
Ty!

2 Likes

Ok, this is a lot so I might do this in multiple posts so that the first ones get approved and sent faster (hopefully). The first problem is that there is an On Game Update Every (5000) Ms block that constantly spawns new enemies. I… don’t know why this exists. In the “Enemies Bounce on a invisible wall” function, you are already spawning all the enemies and you are replacing all the Red tiles with empty ones, so the “place (da enemy) on top of (value)” block in the On Game Update code literally does nothing because there are no Red tiles in the level anymore. Then, after that bit of code that does nothing, you call the Enemy Spawner function, which also has the same code that does nothing. The “place (da enemy) on top of random (Red tile)” block also does nothing for the same reason. (I will note that your variable names are hilarious! :rofl:) Moving right along, the next bit in the “on game update” code spawns a new enemy. For a different reason this time, that being that the “place (da enemy) on top of random (Red tile)” code runs before you create the new enemy, this enemy is never re-located from the default spawning position, only being slightly moved by the “X pick random” bit, so this is why an enemy randomly spawns in the sky every once in a while. Once again, if you moved the “place sprite on tile” bit to after you create said sprite, it would still do nothing because there still aren’t any Red tiles left in the level. Basically, what I’m saying, is that you don’t need that bit of code at all, unless you are trying to get enemies to respawn every once in a while, which you would have to do some other way. You should also remove the “For” loop at the top of “Enemy Spawner” as well as the “place (da enemy) on random (Red tile)” code at the top of the “for element” block in the same function.
Uhh… yeah… so, doing all that in a copy of your project seems to fix a lot, but now enemies don’t move because the “Enemy Spawner” function is never called. Moving all that into a Forever loop fixes that. The whole thing with Enemies floating over the big holes to get to you is because you never gave them gravity when they were created, only in the On Game Update code. Moving the “Gravityexists lol” code to directly after the “Set (da enemy) to (Sprite { } of kind (Enemy))” in the “Enemies bounce…” function fixes that, but now it’s incredibly laggy?!?

Uhhhh ok, I found it: there is a block detecting if an enemy overlaps the “lava” tile and it runs the same “place (da enemy) on top of random (Red tile)” code that, once again, still does nothing because there aren’t any red tiles in the level, but what it does instead is create a lot of lag because it is trying to find a red tile, probably by looping through the whole tilemap, and it’s doing that every single frame because the enemies are never moved out of the lava. So I removed that of course and everything works again!

One more thing is that “Play Sound” blocks, when you leave them on “play (sound) [until done]”, pause everything until they are done playing, so changing that to “[in background]” will fix that future issue. You did that in the “B button” code but not in the “projectile hits enemy sprite” code.
Umm… there’s some other stuff with, like, the player constantly bouncing up and down, which is just a slight problem with character images being offset weird so when the character hits the ground and their image changes, they aren’t touching the ground anymore or they are clipped into it or something so they change to the falling image and then back again when they hit the ground, creating an odd looking loop.
Uhh… there is the issue of the enemies bouncing on the ground, which can be fixed by making your own code to detect only when they are hitting walls and not the ground, because the “Sprite bounce on walls” code also checks for ground collisions. I removed that block, but didn’t write the extra code because I don’t want to do any code writing for you because that wouldn’t let you learn anything and what’s the fun in that??

Sorry for the massive paragraph! So much for making it short to get it approved quickly. Because this was a lot, I’ll post the link to my “corrected” copy somewhere soon in this post.
You might notice that I changed the name of the project. That’s because it’s not dumb, it’s really cool, and it’s only kinda jank because you’re still learning and don’t know everything yet (no one does!). Feel free to copy what I did in there, or just use that project (depends on what the rules are for what you’re doing, but it’s all still your code, I just moved some stuff around, so it should be fine).

Here’s the link to my copy of your project!

You should be able to click it, go to “show code” at the top right, and then click the little button with the export (square-with-an-arrow-pointing-to-the-top-right) logo on it to make your own copy and take a closer look. Good luck with the rest of your project! I don’t think I will help you with the enemy edge-bounce stuff because i’ve already written a lot, but I will note that there is a way to check what tile is below a sprite and make two new tiles that go on the corners of platforms so that when a sprite walks on top of them you can code them to turn around or something. Idk though, what you have so far is probably a perfectly fine way of doing it :blush:, Once again, good luck and happy coding!!! :grin: :+1:

5 Likes

HOLY SMOKES.

2 Likes

Got very bored in Earth Science, ok?? I’m just here to help :sob: :rofl: :grin:

3 Likes

Hey @WoofWoof,
Thanks for your response, doesn’t matter if you typed a whole paragraph, I have read all of it. The game actually worked after you fixed it, I really appreciate it!!!
This was actually my first time using make code, apologies when I add too many code, I’m just trying to get used to it lol

1 Like

Oh yeah, just incase you’re free, I noticed that the enemies were bouncing on a lava instead of being on a platform.
Is there another code for the enemy to spawn on random platforms when it’s touching a lava pit and the enemy being killed by player (average plumber dude :p)?
Apologies, I’m just braindead figuring it out

1 Like


At your doorstep :slight_smile:

6 Likes

I’d like to have a word with you…

5 Likes

Who me

1 Like

Uhhh, yeah, that shouldn’t be a problem once you get the enemy-bounce-on-wall code or whatever it was working. As I said before, one way to keep enemies on platforms would be to make them turn around if they walk to the edge of a platform. It seems you have started making something like this with those edge sprites, but another way to do it would be to make two new blocks that go on the edges of platforms so that when sprites walk over them you can detect this and make the sprite turn around. Idk, there are so many ways you could do this, and you just have to find one of them. Good luck! :+1: :smile:

Ahem

2 Likes

Do I have to repeat myself?

image

image

image

6 Likes

you win

2 Likes