Turret AI sensing for games like Boom Beach


This might interest you

If you've played Boom Beach or Clash of Clans and wanted to make a cannon that senses when an enemy is near and aims and shoots at them, this is a way to do it on Hopscotch

Place a circle on the screen that will act as a sensor
Place something like a cannon in the circles centre
Place a cannon ball at the circles centre

Code for cannon:

When (enemy) bumps circle (point towards+code) to the enemy

Code for cannonball:

When (enemy) bumps circle (point towards+code) to the enemy
Move forward "X"
Set position to the circle "X" and "Y" position, set invisibility to 0%

When cannonball bumps enemy, set invisibility to 100%

Only when an enemy is touching the circle will the cannon ball be fired at it.


Heres a like.
I'm going to try this out.
If I publish something with it you will get credit.



I quickly made this after you said you were going to make this on Hopscotch.


I made this one.
You aren't on the side of the turret, you are the anteater trying not to get hit by it.
You have to collect Red Heart jewels (idk lol)
It's called Cops and Robbers
Drag the anteater to control it.


That's a great idea.

For a challenge do you think you could use cos/sine
to have a yellow circle orbit a character-tower
Make the screen black like night.
Only when the yellow circle bumps the player have the player shot at.
This would be like sneaking into a building at night with someone checking the premises with a spot light.
You could make a game like this with your idea of a jewel thief
And have your cos/sine code for making the yellow circle move closer/further from the tower


I could start on something like that for the second version.
It will take some time though.


Does your published game lag when u play?
My ipad is the ipad 3 and it"s pretty worn out and weakening in performance.
Even the project i published had a little lag and wasn't running smoothly for me


No, I have an iPad Air 2 so it runs pretty smooth.


I made The Jewel Thief
Same control method.
When the spotlight hits you, it permanently stays on you and two turrets start firing.
One fires the opposite direction to you, the other fires at you.
So it is pretty hard once you get detected.
In the future I might make a really hard version with a four way shooter.


That runs smoother on my ipad than your last effort.
I like the light staying on the players character when it touches it
One thing i noticed is after the lights focusing on the players sprite, if i take my finger off the sprite and press it again, the sprite won't move when pressing.sliding my finger around the screen.
Maybe send the light to the back of the sprite will fix this


@Stradyvarious that is a very cool design! I might use this in something :D

@GoatLord Yeah! That is hard, my score is 110 and I didn't get detected lol. Like Strady said, if you take you finger off the player once you are detected you can't move. Maybe a hitbox would help!


I fixed it and released a new version.


Here is the link: https://c.gethopscotch.com/p/y1rm4rqyy

Oh and @AHappyCoder
I will make the spotlight harder to dodge as your score gets higher in the next version


Yeah i just searched and played it.
The game runs very well.
If you add more to the game, post a link here or make a new topic showing your game.
I'd be very interested to see your results


Ok sure.
I will definitely be updating it over time.


Also, an idea would be have the player instantly die if they touch the centre triangle.
This would make the game more challenging, so the player can't take a shortcut through the centre


The next version is here!
The player dies if they touch the turret, and the spotlight gets faster as the score gets bigger.
@AHappyCoder i have a feeling you will find it much harder to get to 100 undetected now!
The Jewel Thief v2


It's more challenging now with you extra additions.


Version 4 is out now!
With a Modulus clock to increase the speed of the spotlight by 0.25 every 5 points you get!


It works great.
Good job
I still can't really think of how i would use modular when i think of my previous projects.