Hello! In the game I'm making, I have a room where the character has to shoot (click) the center of a moving target that looks like this:
(https://i.imgur.com/FKuIycT.png)
The thing is, I want it to only be a valid shot when they click the center (the yellow circle). So I figured I'd use 2 objects, like this:
(https://i.imgur.com/SypXSVI.jpg)
(Blanco1)
(https://i.imgur.com/4Ode8o4.png)
(Blanco2)
It looks like this in the room:
(https://i.imgur.com/2QkrAZ7.jpg)
The 2nd object is set as unclickable in the room script. Then I plan to make them move randomly in a walkable area.
function room_RepExec()
{
if (!oBlanco.Moving) {
int walkx = Random (401);
int walky = Random (641);
if (GetWalkableAreaAt (walkx, walky) == 1)
oBlanco.Move (walkx, walky, 1);
oBlanco2.Move (walkx, walky, 1);
}
}
It works. But the smaller target (Blanco1) moves elsewhere for some reason, before coordinating its movement with Blanco2.
HERE'S A VIDEO OF IT (https://www.youtube.com/watch?v=2V1whwW5dQM)Spoiler
(https://i.imgur.com/4VnJhIG.jpg)
I've read the whole Object section in the manual, I've tried to adjust the first object by adding and substracting the difference in pixels with the 2nd object... All to no avail. Thanks in advance for any help provided.
Just move one of them, then make the second object "follow exactly" in late-rep-exe.
Objects are positioned using their bottom left corner, not their center.
Which means you'll need
function room_RepExec()
{
if (!oBlanco.Moving) {
int walkx = Random(System.ViewportWidth - Game.SpriteWidth[oBlanco2.Graphic]);
int h = Game.SpriteHeight[oBlanco2.Graphic];
int walky = Random(System.ViewportHeight - h) + h;
if (GetWalkableAreaAt (walkx, walky) == 1) {
oBlanco.Move (walkx + 73, walky - 73, 1);
oBlanco2.Move (walkx, walky, 1);
}
}
}
(I also wrapped both Move.Commands in your GetWalkableAreaAt check, you only moved oBlanco conditionally)
Finally: using Pythagorean math, you can easily calculate the distance of the click from the bull's eye, determining the exact ring they hit while using a single sprite.
float dx = IntToFloat(oBlanco.X + 89 - mouse.x);
float dy = IntToFloat(oBlanco.Y - 89 - mouse.y);
int dist = FloatToInt(Maths.Sqrt(dx*dx + dy*dy), eRoundNearest);
if (dist < 17) Display("yellow");
Edit: fixed Math/s typo.
Thanks a lot, Khris! But I've encountered a problem. When I try to run it, it says "undefined symbol: Math". Maybe I pasted that last bit on the wrong function? I pasted it on the room's "on_mouse_click".
I believe it is actually Maths.
Yes it is. It's also something you can easily look up by pressing F1 while using AGS (roll)
Also, if you type "Math" it should bring up an autocomplete dropdown list with "Maths" highlighted.