I?ll create the sprite and put it around the game area to restrict it.
Yeah you still have to place the ship somewhat correctly when you create it.
So System->create Ship_mid_1 on X=int(Random(500)) and Y = int(Random(500))
This would create that ship somewhere on 0-500x, 0-500y.
So you have specify the range, like so:
System->create Ship_mid_1 on X=int(Random(200,500)) and Y = int(Random(200,500))
Then the ships will be placed between 200,500x and 200,500y
I just don't understand very well the identification of the ships. I beleive that I need to spread 100 sprites on the game area for when the player clicks on one of them, check if there's a part of the ship below.
You don't need to add 100 sprites. What you can do is to simply add two variable to the ship.family for instant (BE ADVISED YOU ONLY NEED TO ADD THESE VARIABLES IF YOU WANT TO DO SOMETHING SPECIAL FOR EACH PART OF THE SHIP, OTHERWISE YOU DONT NEED THEM):
Ship_number = 1
Ship_part = "Mid"
Then when you create the ships and lets say you know that you need 5 ships.
The middle part of the ship is what we use to control a ship. As its the part that hold the "Front" and "End" image points.
So it would look like this:
1. First check if Number_of_ship_placed < than 5
if that's the case, we need to create a ship:
2. System->create Ship_mid_1 on X=int(Random(200,500)) and Y = int(Random(200,500))
- Ship_mid_1.Ship_number = Number_of_ships_placed
- Ship_mid_1.Ship_part = "Mid"
So now you would have a ship like this:
-o- <- middle part of the ship :)
(Then you know that this ship is number 1 ship, and its the middle part of it)
3. Then you spawn the rest of the ship parts.
So first we add the front part:
- On event Ship_mid_1 created
Ship_mid_1 spawn new object "Ship_front_1" at imagepoint "Front"
Ship_front_1.Ship_number = ship_mid_1.Ship_number (Now it have the same ship number as the middle part)
Ship_front_1.ship_part = "Front" (And now you know its the front part)
So now the ship looks like this:
Then we spawn the last part exactly the same way:
Ship_mid_1 spawn new object "Ship_end_1" at imagepoint "End"
Ship_end_1.Ship_number = ship_mid_1.Ship_number (Now it have the same ship number as the middle part)
Ship_end_1.ship_part = "End" (And now you know its the end part)
And finally the ship looks like this:
Then we pin these parts to the middle part, so we only have to work with that piece when we have to manipulate it.
Ship_front.pin to object -> Ship_mid_1
Ship_end.pin to object -> Ship_mid_1
And finally you change the rotation of the middle part, to add the random rotation.
Ship_mid_1.angle = random(360)
If you in the pin behaviour have put it to "Position and angle" the other parts will follow the middle part correctly.
To check for hit
1. If Crosshair is overlapping Ship.family
Since it can overlap more than one part, you just use pick nearest as well, so it only picks 1.
And then you can now just check for ship number and ship part if you want to do something special to these parts. Or if you just want to destroy them you can just add:
- On event Mouse.left click object -> ship_family
Pick nearest ship to crosshair.
Show equation somewhere on the screen.
Here is an example of the crosshair and overlapping functionality.
Just spawn a ship with Q again and left click on a ship.
Battleship crosshair test