Discuss Scratch

DJExplozo
Scratcher
33 posts

How do I make a game over and restart feature?

I am working on a banana catcher game where you are a monkey trying to catch bananas. A prototype has been released and you play it here https://scratch.mit.edu/projects/710351172/ . Most of the coding process so far has been rather nice. However, I cannot for the life of me figure out how to do game over and restart. Here is how I want it to work.

In my game, there are points, and when you collect bananas, the points goes up. There is also HP in my game, where you start at 3 HP, but you get hit by obstacles like coconuts, the HP goes down. I have already figured out that when either the points go below zero or the HP goes to zero, that is when I want the game over to happen, where the score is calculated. I also want the current game to temporarily stop. This I cannot figure out. I tried using variables and broadcasts for this, but it did not work. An idea would be to delete all the clones until the game is restarted, but I am not sure about that, and even then, I can't get it to work.

I also can't get the restart feature to work. I want it that when any key is pressed after the game over, a new game (NOT THE ORIGINAL GAME CONTINUING) starts, and everything is basically restarted. I don't know how to code this at all, so please help. If you have any ideas, visit the prototype, make your changes there, and tell me so I can add it to the finished game.

Last edited by DJExplozo (July 2, 2022 16:02:43)

abcde1234qwe
Scratcher
500+ posts

How do I make a game over and restart feature?

DJExplozo wrote:

I am working on a banana catcher game where you are a monkey trying to catch bananas. A prototype has been released and you play it here https://scratch.mit.edu/projects/710351172/ . Most of the coding process so far has been rather nice. However, I cannot for the life of me figure out how to do game over and restart. Here is how I want it to work.

In my game, there are points, and when you collect bananas, the points goes up. There is also HP in my game, where you start at 3 HP, but you get hit by obstacles like coconuts, the HP goes down. I have already figured out that when either the points go below zero or the HP goes to zero, that is when I want the game over to happen, where the score is calculated. I also want the current game to temporarily stop. This I cannot figure out. I tried using variables and broadcasts for this, but it did not work. An idea would be to delete all the clones until the game is restarted, but I am not sure about that, and even then, I can't get it to work.

I also can't get the restart feature to work. I want it that when any key is pressed after the game over, a new game (NOT THE ORIGINAL GAME CONTINUING) starts, and everything is basically restarted. I don't know how to code this at all, so please help. If you have any ideas, visit the prototype, make your changes there, and tell me so I can add it to the finished game.
Instead of a stop this script block under the broadcast, use a stop other scripts in sprite.
when I receive [Game Over v]//This should be in the other sprites.
stop [other scripts in sprite v]

To add the restart feature, you could add a restart button.
when I receive [Game Over v]//This should be in the restart button sprite.
wait (0) secs
wait until <not <mouse down?>>
wait until <<mouse down?> and <touching [mouse-pointer v] ?>>
broadcast [Game v]

when I receive [Game v]
reset timer
. . .//Set variables back to normal here.
. . .//Other code if needed.

Last edited by abcde1234qwe (July 2, 2022 16:13:49)

Muyaolu123
Scratcher
100+ posts

How do I make a game over and restart feature?

Try this:

when green flag clicked
forever
if <<(points) < [0]> or <(health) = [0]>> then
calculate score
else
do whatever the sprite is intended to do in the game

end
end

——————————
A scratcher

cat:: [events] [hat]

Last edited by Muyaolu123 (July 2, 2022 21:26:26)

DJExplozo
Scratcher
33 posts

How do I make a game over and restart feature?

@abcde1234qwe So my game is completely corrupted, I dunno why, I dunno how, but the bananas are not acting well. The game over screen does work, so thanks for that. Could you look into the code of the corrupted copy and fix it cause I dunno what I'm doing wrong.

Corrupt : https://scratch.mit.edu/projects/711154153/
Non-Corrupt without Game Over: https://scratch.mit.edu/projects/710351172/

Please help, I want o release the game by mid-july.
DJExplozo
Scratcher
33 posts

How do I make a game over and restart feature?

abcde1234qwe wrote:

DJExplozo wrote:

I am working on a banana catcher game where you are a monkey trying to catch bananas. A prototype has been released and you play it here https://scratch.mit.edu/projects/710351172/ . Most of the coding process so far has been rather nice. However, I cannot for the life of me figure out how to do game over and restart. Here is how I want it to work.

In my game, there are points, and when you collect bananas, the points goes up. There is also HP in my game, where you start at 3 HP, but you get hit by obstacles like coconuts, the HP goes down. I have already figured out that when either the points go below zero or the HP goes to zero, that is when I want the game over to happen, where the score is calculated. I also want the current game to temporarily stop. This I cannot figure out. I tried using variables and broadcasts for this, but it did not work. An idea would be to delete all the clones until the game is restarted, but I am not sure about that, and even then, I can't get it to work.

I also can't get the restart feature to work. I want it that when any key is pressed after the game over, a new game (NOT THE ORIGINAL GAME CONTINUING) starts, and everything is basically restarted. I don't know how to code this at all, so please help. If you have any ideas, visit the prototype, make your changes there, and tell me so I can add it to the finished game.
Instead of a stop this script block under the broadcast, use a stop other scripts in sprite.
when I receive [Game Over v]//This should be in the other sprites.
stop [other scripts in sprite v]

To add the restart feature, you could add a restart button.
when I receive [Game Over v]//This should be in the restart button sprite.
wait (0) secs
wait until <not <mouse down?>>
wait until <<mouse down?> and <touching [mouse-pointer v] ?>>
broadcast [Game v]

when I receive [Game v]
reset timer
. . .//Set variables back to normal here.
. . .//Other code if needed.

So my game is completely corrupted, I dunno why, I dunno how, but the bananas are not acting well. The game over screen does work, so thanks for that. Could you look into the code of the corrupted copy and fix it cause I dunno what I'm doing wrong.

Corrupt : https://scratch.mit.edu/projects/711154153/
Non-Corrupt without Game Over: https://scratch.mit.edu/projects/710351172/

Please help, I want o release the game by mid-july.
abcde1234qwe
Scratcher
500+ posts

How do I make a game over and restart feature?

DJExplozo wrote:

So my game is completely corrupted, I dunno why, I dunno how, but the bananas are not acting well. The game over screen does work, so thanks for that. Could you look into the code of the corrupted copy and fix it cause I dunno what I'm doing wrong.

Corrupt : https://scratch.mit.edu/projects/711154153/
Non-Corrupt without Game Over: https://scratch.mit.edu/projects/710351172/

Please help, I want o release the game by mid-july.
I see the problem now. In the game over sprite, whenever you press a key, it broadcasts Game.
when [Any v] key pressed//This is your current code.
broadcast [Game v]

To fix this, replace this with a when I receive block.
when I receive [Game Over v]//This should only be in the Game Over sprite.
wait until <not <key [Any v] pressed?>>
wait until <key [Any v] pressed?>
broadcast [Game v]

I also noticed some other problems. Instead of running a when flag pressed block to run your scripts, use the broadcast Game block.
when green flag clicked//Only 1 sprite or the backdrop should have this code.
broadcast [Game v]

Lastly, place this script in all the sprites except the Game Over sprite.
when I receive [Game Over v]
stop [other scripts in sprite v]

Also, the broadcast, Game, should include these blocks.
when I receive [Game v]
reset timer
set [example variable v] to []//Whatever this variable needs to be.
. . .//Run your code here.

Everything should be fixed. Hopefully this works and you understood it.

Edit: If a sprite contains clones, add this code.
when I receive [Game Over v]
stop [other scripts in sprite v]
delete this clone

Last edited by abcde1234qwe (July 2, 2022 21:06:21)

Welmerer
Scratcher
26 posts

How do I make a game over and restart feature?

DJExplozo wrote:

@abcde1234qwe So my game is completely corrupted, I dunno why, I dunno how, but the bananas are not acting well. The game over screen does work, so thanks for that. Could you look into the code of the corrupted copy and fix it cause I dunno what I'm doing wrong.

Corrupt : https://scratch.mit.edu/projects/711154153/
Non-Corrupt without Game Over: https://scratch.mit.edu/projects/710351172/

Please help, I want o release the game by mid-july.
I don't understand what's wrong with the “corrupt” version. Can you be more specific with what's wrong?

Last edited by Welmerer (July 2, 2022 21:05:38)

DJExplozo
Scratcher
33 posts

How do I make a game over and restart feature?

abcde1234qwe wrote:

DJExplozo wrote:

So my game is completely corrupted, I dunno why, I dunno how, but the bananas are not acting well. The game over screen does work, so thanks for that. Could you look into the code of the corrupted copy and fix it cause I dunno what I'm doing wrong.

Corrupt : https://scratch.mit.edu/projects/711154153/
Non-Corrupt without Game Over: https://scratch.mit.edu/projects/710351172/

Please help, I want o release the game by mid-july.
I see the problem now. In the game over sprite, whenever you press a key, it broadcasts Game.
when [Any v] key pressed//This is your current code.
broadcast [Game v]

To fix this, replace this with a when I receive block.
when I receive [Game Over v]//This should only be in the Game Over sprite.
wait until <not <key [Any v] pressed?>>
wait until <key [Any v] pressed?>
broadcast [Game v]

I also noticed some other problems. Instead of running a when flag pressed block to run your scripts, use the broadcast Game block.
when green flag clicked//Only 1 sprite or the backdrop should have this code.
broadcast [Game v]

Lastly, place this script in all the sprites except the Game Over sprite.
when I receive [Game Over v]
stop [other scripts in sprite v]

Also, the broadcast, Game, should include these blocks.
when I receive [Game v]
reset timer
set [example variable v] to []//Whatever this variable needs to be.
. . .//Run your code here.

Everything should be fixed. Hopefully this works and you understood it.

Edit: If a sprite contains clones, add this code.
when I receive [Game Over v]
stop [other scripts in sprite v]
delete this clone
Thanks dude, you helped a lot. I will credit you in the final release. It is now non corrupted with a game over.

Last edited by DJExplozo (July 3, 2022 00:26:28)

CJSkitss
Scratcher
67 posts

How do I make a game over and restart feature?

DJExplozo wrote:

I am working on a banana catcher game where you are a monkey trying to catch bananas. A prototype has been released and you play it here https://scratch.mit.edu/projects/710351172/ . Most of the coding process so far has been rather nice. However, I cannot for the life of me figure out how to do game over and restart. Here is how I want it to work.

In my game, there are points, and when you collect bananas, the points goes up. There is also HP in my game, where you start at 3 HP, but you get hit by obstacles like coconuts, the HP goes down. I have already figured out that when either the points go below zero or the HP goes to zero, that is when I want the game over to happen, where the score is calculated. I also want the current game to temporarily stop. This I cannot figure out. I tried using variables and broadcasts for this, but it did not work. An idea would be to delete all the clones until the game is restarted, but I am not sure about that, and even then, I can't get it to work.

I also can't get the restart feature to work. I want it that when any key is pressed after the game over, a new game (NOT THE ORIGINAL GAME CONTINUING) starts, and everything is basically restarted. I don't know how to code this at all, so please help. If you have any ideas, visit the prototype, make your changes there, and tell me so I can add it to the finished game.
when green flag clicked
forever
if <touching [Death Object] ?> then broadcast [Restart]
end
when I receive [Restart]
say [Game Code Here]
end

Last edited by CJSkitss (July 3, 2022 03:42:22)

iLikeBoba3
New Scratcher
1 post

How do I make a game over and restart feature?

so confusing.could you make it easier???

Powered by DjangoBB