Home Indie Game Spooky Revelations – An grownup sport about self-discovery

Spooky Revelations – An grownup sport about self-discovery

0
Spooky Revelations – An grownup sport about self-discovery

[ad_1]

So, first publish of the primary sport.
Meh. I’m purported to be fascinating.

So!

I’ll write a tad about my downside with setting the drawing order of pictures.
My sport is meant to have a number of pictures on prime of one another, and at first they had been simply drawn so as of sort (objects can be drawn first, then folks) after which by creation order (so folks created final would get drawn on prime of each different individual). This was clearly lower than perfect.

This is a picture of the issue (left), subsequent to the answer (proper)

So I regarded for sorting algorithms, and with me being a n00b, a easy algorithm can be appropriate. So I checked Wikipedia’s Sorting algorithm web page. A usually quick algorithm is good however:

  • Algorithms will be easier or extra difficult, with difficult algorithms taking extra time to implement
  • Different algorithms are sooner in several circumstances
  • Some algorithms are secure which means that issues with the identical place will not be moved; I’m utilizing floating level for X and Y positions in order that’s unlikely, however I’d wish to keep away from flickering resulting from two pictures being moved in the direction of the entrance after which in the direction of the again by way of the frames
  • Some algorithms are adaptive which means that if they’re near be so as, it’s sooner. Important as a result of between frames more often than not the sorting order will stay the identical

So I simply determined to choose the insertion type algorithm.

Thanks to Wikipedia’s web page including insertion type was solely translating pseudocode to Lua code, and switching from zero-based arrays (in Lua, arrays begin at 1).

I did hit a small snag after implementing it… wanting on the output numbers all the things regarded high quality, however now a number of the drawables weren’t being drawn. Turns out that I’m sorting by place within the X axis (Y-axis comes later), however I’m sorting by properties of objects, however what I’m sorting are the objects themselves. So I simply made a small modification to the algorithm to separate the sorting standards from what’s being sorted:

This is Wikipedia’s pseudocode (for zero-based arrays)

i ← 1
whereas i < size(A)
    x ← A[i]
    j ← i – 1
    whereas j >= 0 and A[j] > x
        A[j+1] ← A[j]
        j ← j – 1
    finish whereas
    A[j+1] ← x
    i ← i + 1
finish whereas

So at this level mine, as a result of my arrays begin at 1 and since I’m sorting objects by their property, is that this:

i ← 2
whereas i < size(A)
    obj_ref ← A[i]
    j ← i – 1
    whereas j > 0 and A[j].property > obj_ref.property
        A[j+1] ← A[j]
        j ← j – 1
    finish whereas
    A[j+1] ← obj_ref
    i ← i + 1
finish whereas

After that I added the flexibility to go an offset operate for the sorting standards, provided that I do not really wish to type by the X and Y axis of the photographs, as a result of these are on the prime left nook; the offset operate simply provides half width and half top to allow them to be sorted by their heart, not their origin.

That labored properly, and after sorting by the X axis, I simply repeated the sorting for the Y axis. So sure! Finally nobody’s ft are on nobody’s face!

I do not anticipate a number of (any?) folks to learn this, however in the event you do, know I’ll proceed posting however will probably be erratically at first till I get into an schedule.

Finally, as a result of I copy-pasted the pseudocode from Wikipedia I’m required to speak legalese and say this devlog entry is licensed to the general public beneath the CC-BY-SA 4.0 License.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here