Useful Formulas and Other Things

Tile index to Pics1 position ~Downsider

this.tile = tiles[mousex,mousey];
setimg pics1.png,256*int(this.tile/512)+16*(this.tile%16),int((this.tile%512)/16)*16,16,16;

Distance formula ~Christopher

dx = x1-x2;
dy = y1-y2;
dist = (dx^2+dy^2)^.5;

Pics1 to tile index ~Shiny

POSITION_X = x pixel position in pics1.png
POSITION_Y = y pixel position in pics1.png
this.tile=((int(POSITION_X/16)%16)+(int(POSITION_X/256)*512))+((int(POSITION_Y/16)*16)%512);

Set dir to face X/Y coords ~NPC Baddies

this.dx = mousex;
this.dy = mousey;
if (abs(this.dx)>abs(this.dy)) {
  if (this.dx>0) playerdir=3; else playerdir=1;
} else {
  if (this.dy>0) playerdir=2; else playerdir=0;
}

Feel free to add more, and if anybody posts more below, I’ll add them to this post :o

Pretty useful for people like me as I am no good with maths.

dist = (((y1-y2)^2)+((x1-x2)^2)^0.5;

distance formula

dx = x1-x2;
dy = y1-y2;
dist = (dx^2+dy^2)^.5;

I think is more informative, as it breaks it down for the user. Not to mention there are a lot of times you just need the delta’s and not the distance.

Oh, and here is my pics1 to tiles format formula:
[php]POSITION_X = x pixel position in pics1.png
POSITION_Y = y pixel position in pics1.png
this.tile=((int(POSITION_X/16)%16)+(int(POSITION_X/256)*512))+((int(POSITION_Y/16)*16)%512);[/php]

Thanks :slight_smile:

For calculating the size of a stat(like health…) bar(normally… there are times you would have to use a different formula, like a right-side bar):

barwidth = (value/maxvalue)*sizeofbargraphic;

So…

barwidth = (hearts/fullhearts)*100;

For a graphical bar of 100 pixels width.

That pretty much applies to all bar graphics linked to a stat (hp,mp,ap)

Ya, that’s why the first one I posted was very vague – to give the idea of what to replace them with.

Yea, but you said health bar and i didn’t want the noobs to get confused :stuck_out_tongue:

Oops :x I went through all that trouble to keep it as non specific as I could and I fucked up that bit :stuck_out_tongue:

For toggling weapons:

this.on = (this.on+1)%2; or this.on = abs(this.on-1); or this.on = (this.on == 0);

example:

if (weaponfired) { this.on = (this.on+1)%2; if (this.on == 1) {doStuff;} else {doOtherStuff;} } [COLOR=“Silver”]

---------- Post added at 04:59 AM ---------- Previous post was at 04:53 AM ----------

[/COLOR]

Time:

this.time = (timevar+5760)%17280;
this.hours = int((this.time/720)%12);
this.minutes = int((this.time/12)%60);

holy necro batman

I’ll contribute.

This is for plotting points on a circle using degrees from the standard position(north position? lol).

this.degrees = 30;//can be whatever
this.rad = (((this.degrees+30)%360)/360)*(pi*2);
this.position_x = cos(this.rad);
this.position_y = sin(this.rad);

Alternatively you could use radians and save yourself a line of code converting.

This could be useful in anything from moving in a circle to drawing one.

  setarray this.plot,720;
  for (this.i= 0;this.i<360;this.i++){
    this.degrees = this.i;
    this.rad = (((this.degrees+30)%360)/360)*(pi*2);
    this.position_x = cos(this.rad);
    this.position_y = sin(this.rad);
    this.plot[this.i*2] = x+this.position_x;
    this.plot[this.i*2+1] = y+this.position_y;
  }
  showpoly 300,this.plot;

Or moving in a circle

if (playerenters){
  showcharacter;
  setcharprop #3,head0.png;
  setcharprop #C0,orange;
  setcharprop #C1,white;
  setcharprop #C2,blue;
  setcharprop #C3,red;
  setcharprop #C4,black;
  setcharprop #2,shield1.gif;
  shieldpower = 1;
  dir = 2;
  timeout = 0.05;
}

if (timeout){
  this.degrees+=10;
  this.rad = (((this.degrees+30)%360)/360)*(pi*2);
  this.position_x = cos(this.rad);
  this.position_y = sin(this.rad);

  x+=this.position_x;
  y+=this.position_y;

  timeout = 0.05;
}

Circles are great.

I was going to post circle stuff, but eeeehh.

THAT CIRCLE FORMULA IS QUITE USEFUL

well actually I can already think of one way I would use it, but it would lag the hell out of Graal.
Anyway nice bump, I never even knew this thread existed.

edit: yeah I knew I wasn’t crazy, this isn’t even stickied. GIVE IT A STICKY FOR CRYIN OUT LOUD.

edit2: since this is in a sticky I might as well point out that that movement system in circles can be used for Bullet Hell simulation/cloning on Graal. If you rework the Graal logic you can even just use it in other programming situations too.