I made this a while back.
The Green Monster always move towards the nearest blue pellet.
A circle sprite is always at the Monsters position.
The circle grows in size continously.
When the circle touches a pellet, the Monster sets its angle towards that pellet.
The circle sets size to small when it touches a pellet.
Since there’s no way to use maths to measure the distance of each pellet to the monster, i used this technique to detect the closest pellet.
When a pellet touches the Monster or players sprite, that pellet instantly sets position to a random location that can be anywhere onscreen.
For any interested, they can check the code to see how this was done
I made this a while back.
This really cool game and logic, thanks @Suzzy-Grey
@Suzzy-Grey very interestingly, how did you implement the random generation of objects?
If you make the “Heart” sprite visible, you’ll see that it uses the “Wrap around” behaviour.
The heart moves super fast from the screens top to the screens bottom and left to right.
So the Heart’s moving in a diagonal motion. The Heart pretty much has occupied every space on the screen in a few seconds as it quickly moves. A Pellet sets position to the Hearts position when its touched by the player or NPC. So no clones are being created or destroyed. Only the position of the existing pellets change during the game.
Thanks @Suzzy-Grey, i think this is an excellent option for randomly generating objects. I also want to share one more way, which significantly offloads the project when the scene loading.
- Create Border in the your scene.
2)Add the Spawn Controller.
3)Add the “Bullet” behavior for the “Spawn Controller” object, adjust the speed, turn on “Bounce” parameter and adjust the “Flow Direction” parameter.
4)Add the “Point” object, which we will clone.
5)Create the new class “Points” for the “Point” object.
Disable the visibility of the “Spawn Controller” object when the scene starts:
Сloning the new objects with the necessary periodicity (Due to the fact that our object “Spawn Controller” randomly moves around the scene, we get the generation of the object in a random place.)
Improve performance - remove objects that are long on the scene:
Creative way of detecting closest pellet. I got beat by 30 points.
The game runs 4 times faster on the PC than on the Ipad.
As a result, the NPC moves a bit too fast on the PC and runs off screen a bit and isn’t as accurate as it is on the Ipad.
Thanks for playing
I love this game. I think you should publish it out to the App Store- do you know about the unity exporter that’s now built in? Separately- on the web version I find that I cannot eat pellets that are at the far top or far bottom of the screen. Like an invisible wall stops me from moving further. do you experience the same thing?
Thanks, but i purchased Construct 2 a while back and find it easy to use for making 2D games.
I’ll try remixing that game and remove the '“Padding” i added to the players sprite to stop it running off screen and add “Wrap around” so the players sprite can move to a screens edge and appear on the opposite side of the screen.
Also, when i first used “Padding”, i noticed it’s only accurate as long as the screen isn’t zoomed in or out in the editor. The “Padding” seems like a wire frame rectangle that gets bigger/smaller when zooming in/out with the editor.
You can try the “Padding” for yourself and zoom in/out in the editor and see problem.
This could be fixed by having the “Padding” wrap around the screens edges regardless if the scene is zoomed in or out.
Ok great! Btw- have you published out any games from Construct 2 to mobile?
I haven’t published a mobile game.
I can publish a PC game to the Scirra Arcade and a game will be playable on modern mobile HTML5 supported browsers.( as long as there’s just taps/clicks of sprites)
The Safari browser on Ipad doesn’t support HTML5 as good as Chrome
I have no experience publishing a mobile game (ios/apk) though it’s possible with Construct 2