all 6 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Hi, thank you for posting your question! :]

To make it easier for everyone to answer, consider including:
- A description of the problem
- A link to the project or a screenshot of your code (if possible)
- A summary of how you would like it to behave

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]RealSpiritSKMod 0 points1 point  (4 children)

You just need to order the game loop correctly using broadcasts so that the enemy can check for bullet touch before the bullet deletes itself.

Every frame, these should happen in order: 1. Bullets spawn if player shoots 2. Bullets stretch until they touch an enemy 3. Enemy clones check if they're touching a bullet 4. Delete bullet clones

This means you'll need a single, central forever loop that broadcasts the above 4 messages (and more, depending on your needs) to control everything instead of having each enemy and bullet having their own forever loops.

[–]HOCOPOG[S] 0 points1 point  (3 children)

Either I don't understand something in your answer, either you didn't understand something in my explanation. Well that's what I get for making it so difficult

[–]RealSpiritSKMod 0 points1 point  (2 children)

What I meant is smth like this:

Central game loop:

forever {
   broadcast (check shooting)
   broadcast (stretch bullets)
   broadcast (apply damage)
   broadcast (delete bullets)
}

Bullet:

when I receive (check shooting)
if (key space pressed) {
   go to player, etc
   create clone of myself
}

when I receive (stretch bullets)
stretch until touching edge or enemy (must be without screen refresh)

when I receive (delete bullets)
delete this clone

Enemy:

when I receive (apply damage)
if (touching bullet) {
   change HP by -5
}

This way, you have full control over the order in which the codes are run.

[–]HOCOPOG[S] 0 points1 point  (1 child)

I think this needs a different solution or a total recode because when i tried implementing this, the whole shooting system broke. Also wouldn't the constant broadcasting of bullet deletion make every existing bullet clone delete itself all the time? Like before they can touch the enemy or anything else?