Discuss Scratch

treelink
Scratcher
55 posts

Shark Game Help

So I am doing complex coding making the code work and prevent the lag that tampered with my game, the main issue is the fish, I keep giving them enough collision so they don't begin to go out water but they still go out the water and start flying in space, help out

SHORTCUT
https://scratch.mit.edu/projects/696671276/editor/

Shortcut is not advertising, only meant so you can already see the problem without having to enter my account and then go into it

pointtowardsfridgesayI need foodaddBurgertostomach

Last edited by treelink (May 26, 2022 02:45:06)

RT_Borg
Scratcher
1000+ posts

Shark Game Help

Hi treelink,

I see your fish (and shark) go to random positions, anywhere on the screen, and then you try to correct the the situation by checking whether they're “a fish out of water” and trying a new random position while they're moving. When things slowed down, it looks like you started building in extra broadcasts and checks.

You can simplify your problem by having a block that finds legal positions (and sets them in a pair of x/y variables) and use these to set an initial position and glide targets for the clones. If you only go to and glide to legal positions, all the other complication melts away.

I made a simplified remix with only the fish (and without costume changes) to show the technique.

In the “find legal fish position” block, I use your idea of trying random positions, but it checks repeatedly until if finds a good location, and then records that next legal position in to-position-x and to-position-y. (All the variables I defined are “For this sprite only”.)

I also used a common trick of hiding the original fish forever, and doing all the movement in “when I start as a clone”. So every fish you see is a clone.

HELP FOR: Shark!
https://scratch.mit.edu/projects/696777764

You can probably backpack the “find legal fish position” block if you like it.

In Shark sprite, I think all or most of the lag is coming from Reset When Collision hits. Right-click edit the definition and uncheck “Run without screen refresh”.

I don't think the point in direction blocks at the top of Reset When Collision hits do anything. That is, I don't think Scratch can tell what you want it to do there. There's also some things not quite right with the rest of this block.

But if you get the fish simplified with my suggestion and cut the lag by unchecking the box on Reset When Collision hits, it might make it easier to see what's happening and get the rest working.

If you work on the shark and can't get it to stay where it should, come say hello in Help again.

– RT_Borg

Powered by DjangoBB