New account registration is temporarily disabled.

CRAZYL'S PROFILE

Search

Filter

Trigonometry script for rpg maker 2003

Small update to the demo in my last post:

  • Combined both versions (linear and binary search) into a single test project
  • Combined cos() and sin() into a single common event cosSin()
  • Turned binary search into inline code to remove the overhead of recursive event calls (according to Vanit's Performance Tutorial)
  • Removed typos in the lookup table generation script

Dice Gambling Game

Cool idea - I'd try to use arrays here. You will save yourself a lot of work and you really need only one common event ;)

This Rm2k-example implements the dice game for any number of dice. For each game of dice you call a small common event:

Explanation

  • The array 0302*0307 stores the numbers of dice showing 1 through 6, respectively
  • 0032:diceResultPtr = 301 is a pointer to the array above
  • 0062:nDice contains the number of dice in the game the player has chosen before
  • 0048:_throw contains an integer where each digit represents the number of one die

The loop cycles through all dice you throw - for each die, the array is updated (+1) and the biggest tuple you currently have is stored in _maxTuple.

After all dice are thrown, the player wins some gold, depending on the biggest tuple in the throw.

Trigonometry script for rpg maker 2003

Kazesui's trig scripts via lookup-table are great! I modified them a little to get a bit more flexibility.

Download Rm2k demo (number graphics originate from "Sternenkind Saga"):
testTrig.7z (v1.1)

Changes:

  • reduced lookup table size (only 91 cosine values, 90 tangent values and 2 pointers in range 0101:0283)
  • simplify GetAngleA,B() into atan2(y, x)
  • a simple version using linear search and another using recursive binary search (should be faster)

cosSin() and atan2() will overwrite the output variables retv(0), retv(1) and rev(0), respectively - save important values before you call them!

Screenshots:


Implementation details:

You'll find the main changes in the cosSin() and atan2() routine - using symmetries and the 360° period, you can get rid of all but the first 91 values of the cosine lookup table. With a 90° shift you can use cosine to implement sine.

All arrays have a pointer to the end of the array before the data - that's why we need to add _angle += 1 at the end. Check the common event initTrigPackage() to see how arrays are constructed.

With a second lookup table, you can get rid of the fork-trees in GetAngleA,B(). Using rotation symmetry, you only need to store 90 values as a tangent lookup table. This table is used by atan2(), the replacement for GetAngleA,B():


The lookup tables were generated by


We need the offset of 0.5 degrees for the tangent lookup table to get intervals centered around integer values:


The values of the lookup tables were generated by a maxima script.
Pages: 1