AllanR's Recent Forum Activity

  • ok, just did a major update on the traintracks.capx

    I removed the code that was trying to manually space the wagons using an array of positions from the train head, and gave the wagons the bullet behavior instead. This works MUCH better - creating the train, starting, stopping are all greatly improved. And the CPU utilization is a lot lower as well - and simplified the code (they are all in the same family now).

    next thing I want to add is switches - so you can click to make the train change tracks! Another thing I would like to add is a control panel - click a train to bring up controls to start/stop/accelerate/slow down, zoom in/out to follow a train.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Gellowg

    you can also use remote preview if you just want to test it out for free.

    And you can export for HTML, upload it to a website, open it in Safari and save to Home screen. This works really well - and the price is right (free if you already have a web site).

  • Tenos

    I made a quick sample of how I would do it... put all the objects to find in a family to simplify the code.

    I made the spawn points big enough so that they can also be used when seeking. I have them at 20% opacity, but in the actual game you would want them to be invisible.

    each point has an instance variable to tell us if the location is occupied (which gets set when an object is put there.

    click the "Hide" button, and go find them!

    https://www.rieperts.com/games/forum/hidenseek.capx

  • nez05

    ok, since none of the instances actually move, and the routine recreates all segments row by row starting from the top left, you can't assume that the first instance is the head and the last instance is the tail.

    what it does is store the number of segments where the head just moved to, and then decreases every place in the array by one where there is a segment.

    so, the place in the array with the highest value (which is = Segments) is the head, and the place with a value of 1 is the tail.

    to get the direction for any segment, we would either have to look in the array all around that spot for a value that is one higher, in order to determine where the snake came from to get there. I thought an easier way was to create a second array and store the direction in a corresponding cell for that segment. So, the main array stores the segment number of the snake at that spot, and the direction array at that same spot holds the direction the snake was moving.

    The only irregular case is when the snake eats the food - all the segment values are bumped up by one, so when the snake is next created, there is no tail (segment with a value of 1). So, in that case we need to look for a value of 2 and we need to know the snake just ate food. Otherwise there would be no tail until the next time the snake gets recreated.

    https://www.rieperts.com/games/forum/snakearray.capx

    oh, there was a bug - food could get created at the top of the screen where the snake could not get it. I fixed that by add 2 instead of 1 to the random number. I got a snake up to 171 segments! :)

  • Reneczech

    well, I had a lot of fun playing with that, and have a good start... I borrowed ideas from a bunch of places - a line following example ROJOhound made a couple years ago, smooth curves for trucks, a wiggly worm demo, etc.

    I made two track segments (straight, and a 90 degree curve) that can snap together to make the layout you wanted. It would be easy to make other types of track segments - just have the end line up, and create image points.

    if you turn on snap to grid with a grid size of 44x44 pixels it is real easy to place the tracks. You have to make sure to get the arrows on the segments all pointing the same direction - otherwise the waypoints wont get created in the proper order at runtime... the waypoints are created based on image points on the track segments. You also have to assign a sequence number to each section of track so the program knows what order to process them in, when the waypoints are created. (There is a family instance number called SegmentNumber for this).

    I changed the layout a little to make a loop so the trains can keep going around and around. Then I thought it should be possible to have multiple tracks... it uses the track name to know which track a waypoint belongs to.

    I also made it so that trains can accelerate and slow down and stop - but there are still problems with spacing the wagons. I used a method I helped someone else with (who was making a worm), it keeps a history of where the head has been to position the parts behind it. this works well for keeping the wagons on the tracks around corners. But, I am not sure it is the best way to do this... I might try some other options later this week.

    going around curves is not as smooth as I would like either... adding more image points to the tracks might help, but that might add other problems too.

    So, hopefully this will give you something to work with.

    https://www.rieperts.com/games/forum/traintracks.capx

  • mumu64

    put the sprites in a family, and give the family the physics behavior. then, you can make the joint to the instance the player chooses.

  • well, just transpose as an intermediate step in the import process, so it ends up the right way in Construct.

    I wouldn't want to keep the data that way either!

    yeah, it is an extra step, but it would make life easier in C3.

  • Reneczech

    are you doing a top view or side view? and how long is the train? it would get a little tricky making all the cars getting pulled stay on the track, but I am sure it could be done.

    it would help if you posted a sample that had some track and parts of the train for us to experiment with.

  • I completely forgot about that check box - and I have used it to...

    I am also a database guy. I haven't used the C3 array editor, so I don't know how that works. I use PHP/MySQL and AJAX to load data from a database, and put the rows in X, and fields in Y, so a For Each X gives me rows.

    if the only option is to load in backwards in C3, you could transpose the data in Excel just before you load it, then it should look right...

  • jobel

    I have programmed for decades too, and use arrays in Construct all the time. I guess I have trained myself to not look at the X and Y labels, and just think Row and Column. When I make loops to go through an array I use tags of "Row" and "Column" so I see:

    Array - set value at (loopindex("Row"), loopindex("Column")) = value

    and to get the number of rows, it is array.width

    we don't get constants, but I do sometimes make variables for field name like in your example to make code easier to read when I come back to it. then code looks like:

    Array - set value at (loopindex("Row"), Player_Name) = value

    Array - set value at (loopindex("Row"), Games_Played) = value

    so, just because it says "Set at XY" doesn't mean you have to switch the rows and columns around.

  • OK! that makes it all clear now!

    I have run into that many times. The issue is you can't assume that the top left corner of the screen is 0,0. Normally I use scan outer to use the whole available screen, so I didn't consider that you would be masking off area outside the layout.

    if all your layers have parallax set to 0,0 then the layout will be centered on the screen. If any layers have the default 100,100 then they will be shifted over to the left...

    so since I don't know how your layers and masking sprites are set up, I adjusted my sample to use all parallax settings of 0,0. You can re-download my sample and now I think it does what you want.

    https://www.rieperts.com/games/forum/timetext.capx

  • You do not have permission to view this post

AllanR's avatar

AllanR

Member since 21 Nov, 2013

Twitter
AllanR has 23 followers

Trophy Case

  • 11-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Forum Patron Made 500 posts in the forums
  • Forum Hero Made 1,000 posts in the forums
  • Popular Game One of your games has over 1,000 players
  • x2
    Coach One of your tutorials has over 1,000 readers
  • Regular Visitor Visited Construct.net 7 days in a row
  • Steady Visitor Visited Construct.net 30 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

20/44
How to earn trophies