Help with coding sorry for spelling

can you help me with making it so than when the eneime over laps it takes a score away https://arcade.makecode.com/S82497-93162-33523-31779 and a menu, sorry i am new to coding and thanks for the enemiy ai and a attack

1 Like

First, your current code sets the life back up to 3 every time the “enemy overlapped player” code runs. To change that, I’ll move the set life block to the On Start:

Now, when we hit an enemy, our health goes down, but we instantly die. This is because every frame the you are touching the enemy, -1 health is applied, and at even 30 frames per second it takes just a 10th of a second to lose all 3 lives.
To fix this, most games either destroy the enemy when it touches you the first time (for example a bullet damages the player once and then gets destroyed) or you give the player a short time where they are invincible, called i-frames. To do this, we can create a variable that starts a countdown when the player gets hit, and then the player can’t get hit again until that countdown is over:

If it’s hard to understand what those variables are doing, here is a version that might be easier to understand:

Hope this helps! And welcome to the Makecode forums! If you have any more questions don’t hesitate to ask!

1 Like

Welcome to MakeCode! I think I see the problem with the attack.

Instead of setting your initial (starting) health to 3 at the beginning, you’re setting it to 3 every time you overlap with an enemy. Then you decrease the health by one, setting it to 2. This means that every time you overlap with an enemy, instead of decreasing your health, it will always set it to 2. I fixed the code so that it sets to 4 in the beginning (I always use 4 because it’s the biggest number it can display on the screen without shortening it).

This was the problem

Here’s the new game; enjoy!

Also, try making your own pixel art! Once you get good at it, it’s really fun and makes your games feel more yours. If you’re doing this for school, then perhaps consider staying at it for fun and making big games that are fun to do. I learned to use MakeCode by testing each block to see what it did and finding complicated solutions to the simple problems I had, but the Forum can also be helpful if you need advice. Although I’d recommend trying to figure it out on your own first, if you can’t then there are lots of people here who’d love to help.

With Regards,

MyCraft_Steve

every time it overlaps with an enemy, its sets the life to 3 then subtract one. fix: one set the life once, in the on start.

thanks

1 Like

also is there a way to make a attack and a menu

i am confulsed how to do this i can’t find any of this in the blockes\

1 Like

The True / False block is in the same tab where “If” blocks are, the Logic tab. If those are confusing, you can replace the “true” blocks with “1” and replace the “false” blocks with “0”. To get the variables to go into the if blocks, you can just drop them into there and they change to have angled sides automatically. If variables are 0 or undefined then they count as “false” and the If block doesn’t run. Any other number or value and they count as “true” and the If block runs.

ok thanks

1 Like

still a bit too confusing for me, sorry.

Here is yet another way you could code this feature, but idk how much more I can explain this, so here is this project for you to look at. This would be a lot easier to explain in person, so if you have more questions, consider asking someone irl.

This is a slightly simpler method.

The main thing to be aware of it that every time you overlap an enemy, this code runs again, even if the code from a different overlap event is still running. Using this variable to keep track of the player being invincible lets us ignore any overlap events that run while the player is invincible. Basically, while the player is invincible, we skip additional overlap events.

So you overlap an enemy, the code runs and sets “PlayerIsInvincible” to true, and so when you overlap the enemy again, the If block prevents the code inside from running. Then, after 1 second (1000 ms), the first overlap code finally gets to the code that turns “PlayerIsInvincible” to false (not true), and so the next time you overlap and enemy after that the code is not skipped.

  • First enemy overlap, If NOT “PlayerIsInvincible” (This means “if playerIsInvincible = false”, so the If block runs): -1 health, “PlayerIsInvincible” = true

  • Next enemy overlap, If NOT “PlayerIsInvincible” (Now the player is invincible, so the IF block does not run)…

  • After 1000 ms, the first enemy overlap code then sets “PlayerIsInvincible” to false, so next time the player overlaps an enemy, the IF block runs and the player gets another -1 health and the timer starts again.