nimos100's Forum Posts

  • Can you elaborate a bit more on how I would use nodes?

    When path finding create a path it create nodes along those path, kinda like waypoints. You can get the position of these, which you can then use to do your tests.

    As I said, I haven't tried something like what you are trying to do, so whether it works or not I don't know.

    But here is a simple test of what it looks like. The green squares are nodes.

    Just so you know sometimes the nodes aint showing, think that is because its probably trying to reach a point under a solid or because I made it really fast and there are a bug in it <img src="smileys/smiley36.gif" border="0" align="middle">

    But you should still be able to see what I mean....I hope :D

    Path finding node test

  • I haven't tried it so this is just a thought, but maybe you can use the nodes in the path finding, have you tried that?

  • I don't really have any experience in what you are doing, so cant really give you any feedback.

    but I really like the idea, you can make games like the old RPG, cant remember what they were called. Might try that at some point :D

  • Here is an example of how to do it.

    There are still overlapping, as this example only checks whether the mid part of the ship overlaps with the boundaries, and so you can see how its done.

    So to check for overlapping you still have to check for the other things, such as if front or end part is overlapping etc.

    Anyway I made some changes so i removed the While loop.

    And instead use a Ship_placed boolean which can be 0 for false and 1 for true. This is because there can be some problems with newly created objects. So doing it this way will remove that.

    So now it simply uses

    Number_of_ships < 3

    Then I have added a Overlap checker which will run as long as:

    Number_of_ships < 3

    Ship_placed = 0

    So when all ships have been placed Ship_placed = 1 and the overlapping checker stops.

    Secondly I have added a Identifier to the ships, based on the UID of the mid part. So each part ("Front", "End") can be selected through this and destroyed as well when an overlap is detected.

    Battleship Ship placement overlapping test

  • Try to link the capx file

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Nimos thanks but it seems that im making some mistake. Can you please give me more detailed instructions on how to do this:

    when i first finish a level i need to set this as a score and highscore aswell - i need to save the highscore. When the level is replayed, i need to load the highscore and compare it with current score. The higher will be set as text.

    thank you!

    Here is how you can do it, I just made it with some buttons to simulate how it should work, you just have to put them into the correct places ofc.

    However I would strongly suggest that you use functions to do it, as it would be a lot better. This example is just to show how to do it and to keep it as simple as possible, but if you know how to use functions I would strongly recommend doing that.

    Highscore test

  • I haven't actually used webstorage that much, but as I remember there is something about if you clear the cache you might loose it, but you can check that in the manual, as im not sure :D

    But yes you could do that.

    Just add this to the event where you want to save the score.

    To save:

    Webstorage -> set local key "Highscore" to Highscore

    To load:

    System -> on start of layout -> set Highscore = Webstorage.localvalue("Highscore")

  • Just do like this.

    Add a global variable called "Top score"

    Then compare that against local score when the game ends.

    if "Top score" < "local score" Set "Top score" = "local score"

  • Sure no problem :) hope it works out for you

  • But when the ship has 2, 4 or 5 pieces? In these cases, I can have 3, 2 or no piece in the middle of the ship. When you have 3 or 2 middle parts, all have the points of origin "front" and "end"? And the ship with two parts?

    You just modify each ship part so they fit. And you can freely decide which part of the ship you want to manipulate to control the ship. The size of the ship doesn't matter.

    Some examples.

    <) 2 part ship.

    (Just add an image point to the "End" part called "front" and spawn the front part to that one or the other way around, doesn't really matter)

    <--) 4 part ship.

    (You could choose the 2 part, and there you add a "Front" and a "Mid_part_2", and you spawn the second mid part to that. And in the second mid part you just add one called "End" and spawn the end to that one. Then you pin all of them to your control part, which in this case is "Mid_part_1")

    <---) 5 part ship

    (Exactly the same as a 4 part ship, you just add a "Mid_part_3" to second mid part. And in the third mid part you add the "End" part)

    Then in your code you can just make a "Ship creator" as I did in the example for each ship. And depending on which ship you want to create you use the correct "Ship creator".

    As you create the different ships in design mode, you just make sure that the image points fits what you need.

    So the "End" part used for a 2 part ship is not necessarily the same used for a 5 part ship. You could do it like that, but that's up to you to decide. You just have to modify the code accordingly, and not use the image points for some sizes ships that you would use for others.

    To explain it a bit more clear:

    If you only have 3 ship parts ("Front", "Mid", "End") you can make any size ship with these if you want. Doesn't matter whether its 4 or 100 long. The only thing is that if you want to use a 2 part ship, you have to add a front image point to the "End" part as well, which you only use for 2 part ships.

    And to the mid part you have added "Front" and "End" image points.

    Then you can in principal add whatever sprite you want to these image points. The names "Front" and "End" could just as well have been called "Snow" and "Rain" it wouldn't make any different, they are just names of the image points, that you have told construct 2 that you want them to be.

    (Just some information about why to use names: The reason its always good to name things like "image points" and "layers" for instant, is if you don't and just refer to them with there index number. Like if you look at your layers, they have an index number starting at 0, and if you add another layer it will be 1. You can add objects such as your ships to a certain layer if you want, by saying "Spawn ship on layer 0" however if you instead of using the index number use the name of the layer. like "Spawn ship on layer "Playing area". You can move these layers around as you please, and then you don't screw up things. Imagine that you use the index number 0, and suddenly figure out that it would be pretty nice if the "Water" was on its own layer below where the "Ships" are. If you do that and you don't use the name of the layer. You have to go through all your code an correct all the index numbers, because now the "Water" is actually on the layer with index 0 and the "Ships" should be on layer 1, but if you use names you can just drag the layers as you please, because the name of the layer doesn't change.....anyway just a short explanation :))

    So back on track.

    Since "Front" and "End" are just names, you can just spawn another mid part on "End" and then get the new "Mid" part to spawn the "End" part of the ship instead.

  • 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:

    <-o-

    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:

    <-o-)

    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.

    • Ship -> destroy

    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

  • If I understand you correct you want something like this:

    X------O----Y------------Z

    And before you can get to Z you have to complete Y, and you want the character to follow the line from X to Y, indicated by O in above illustration?

    If that's the case you can just predefine each path the character can take, and you could probably just use path finding behaviour.

    For instant:

    If

       Player is on X

       Right key is pressed

    Then

       Player find path to Y

    On path found

       Player move along path

    And if you need more ways for the player to travel from X you just add them, and check if down arrow is pressed instead of the right one for instant.

    You can then just add the lines as graphics, as the path finding behaviour, will always move straight from A->B, if you use standard settings.

    If you don't want straight lines, you can just add "Waypoints" along the lines, and then path find to them first until to can reach the next map.

    Since I cant draw it exact here, just imagine that at x1, x2, y1 the path is actually making a turn :)

    So it would look like this:

    X----x1--O--x2----Y----y1-----Z

    If that was what you meant ofc. :D

  • I think with the PIN behavior is more practical, but I don't understand why you changed the point of origin. Now the sprite appears on the line rather than within the squares. It's necessary because you are using PIN?

    Because you don't need the grid anymore. But you can keep the Origin at 0,0 you just have to adjust the "Front" and "End" image points.

    Two other important issues that it's very difficult for me: the problem of overlap and the fact that the ship is out of the playing area (sea sprite).

    You have to add "rules" for where to place the ship. A way you can do it is by adding some check sprites around the game area, if the ships are overlapping those then try a new location. For the overlap you just make a Sprite and tell it to follow your mouse cursor, and then when the player press the left button you check to see if that sprite is overlapping a ship part.

    I tried to create a loop with Repeat event and not work 100%. Sometimes the ship appears overlapping other.

    You cant really use repeat, as you don't know how many times you have to repeat it. So either you have to use a ship counter, or a while loop.

    If you want to place 5 ships you make a counter like "Ship_placed = 0" and every time you successfully place a ship you add 1 to this, and every time you detect an overlap you subtract one. And then you let the event run as long "Ship_placed < 5".

    I also need to restrict the area to ensure that ships always appear on the sea sprite. Do you know how can I solve this?

    You can do that with if you place those sprites around the play area and check if the ship overlap one of those.

  • I have modified your CAPX.

    This is how you could do it.

    Just press Q to spawn a ship.

    Battleship test

    To explain it:

    I have added 2 image points to the middle part of the ship. One is called "Front" and other "End".

    You can use these to place the rest of the parts correctly. Then you just pin these part to the middle part.

  • "I still do not understand how I can do to determine the position of the playing area ."

    Well basically you decide that for yourself, and can place it where ever you want as long as the math you use to place the ships are correct. Its up to you to decide it, I just used 0,0 as a starting point because its easier to explain then.

    But whether you add 40*1 to 0,0 or to 280,280 doesn't make any difference. The ratio of 40 is the same no matter what, because that's what you decided before hand.

    And as long as you go from 0-9 (10 spaces).

    But if you start at 0,0 you gaming area will be from 0-400 pixels. And if you started at 280,280 it will go from 280-680 pixels.

    So if o are the playing area. And you want it to start at 0,0 your screen would look something like that.

    oooooo------

    oooooo------

    oooooo------

    oooooo------

    ------------

    ------------

    ------------

    If you wanted it to start at 280,280, it would look something like this.

    ------------

    ---oooooo---

    ---oooooo---

    ---oooooo---

    ---oooooo---

    ------------

    ------------

    (This is no where accurate :D)

    But the factor are the same, no matter what starting point you choose.

    for 0,0

    (400 - 0) / 10 = 40px

    for 280,280

    (680 - 280) / 10 = 40px

    I also do not understand how to create random orientation to the ship (X / Y or left / right).

    Another possibility to distribute the ships : if I create the sprites in the overall size of the ship ( eg 40px / 120 px) and then control it through overlapp event to know which object it is overlapping and how many pieces are still missing from this object through the local variables? This would be more complicated to do? And if I separate the parts of the ship, but use a container to place it in the game and then go checking and destroying the parts separately? Which do you think would be the best (easy, quick, codeless) solution?

    Dropping the grid all together is the easiest I think.

    ////// OK THIS ISNT CORRECTLY DESCRIBED //////////////

    If you make the ships as separate objects, and in design mode you align them as you would like them to be in the game and add a pin behaviour to them, and then in "Start of layout" you pin all the ships correctly. And then you make a container for each ship that you need.

    Then you just create one part of the ship, place it at a random point and give it a random angle, and if set up correctly the rest of the ship will appear as it should. And then you can just use overlapping on each part to see if they are hit. That I would think is the easiest way to do it.   

    //////////////////////////////////////////////////////

    Should have tested it first :D