home   |  video   |  gallery   |  circuitry   |  code   |  schematics   |  bom   |  gems of wisdom  


CODE

Signaling Module:
[Header File]  [Pseudocode]  [C Code]

Timing Module:
[Header File]  [Pseudocode]  [C Code]

Pinout:

[Pinout Diagram]
Game Play Module:
[Header File]  [Pseudocode]  [C Code]

Main Module:
[Header File]  [Pseudocode]  [C Code]

Game Play Pseudocode

/* G Play module for Railroad HandCar arcade game */

/* Get raw handcar velocity to sync w/puppet pump */

HandleDiff
  Accepts nothing, returns an unsigned char
  
  unsigned int NewVel, NewPos = HandlePosition();
  int RawVel = NewPos - OldPos;
 
  Set raw speed to old - new handpump positions
  Set current speed halfway between previous and abs(raw) speeds

  Set the previous speed to the current speed
  Set the previous position to the current position

  If raw speed is positive (less noise), pump puppets up
  If raw speed is negative (less noise), pump puppets down
 	
  Return the current speed


/* Calculate the handcar's velocity (range 0-100) */

CalculateVelocity
  Accepts nothing, returns an unsigned char

  If the player is not jumping
    Increment the average speed by the raw handle speed

  Decriment the average speed by 1% for friction
  If the average speed is over 100, set it to 100

/* Account for the servo's dead-band (hysteresis) */

CalculateChase
  Accepts and unsigned int, returns nothing

  If the current speed is faster than the villain's speed
    Decriment an accumulator to account for servo dead band

  If the current speed is slower than the villain's speed
    Increment an accumulator to account for servo dead band
 
  If the accumulator has reached its maximum value
    Advance the villain forward
    Re-set the accumulator value to 0
 
  If the accumulator has reached its minimum value
    Retreat the villain backward
    Re-set the accumulator value to 0

/* Step villain left or right relative to handcar */

AdvanceVillain
  Accepts a char, returns nothing

  If the villain is moving forward
    Increment his current position

    If he was just moving backward
      Add the servo hysteresis to his position

    Set the previous direction to forward
 
  Else (the villain is moving backward)
    Decriment his current position

    If he was just moving forward
      Add the servo hysteresis to his position
       
    Set the previous direction to backward
  Endif

  If the villain exceeded his maximum position
    Set his position to the maximum
  
  If the villain exceeded his minimum position
    Set his position to the minimum

  Place the villain based on the current position

/* Check that villain reached right-most position */

Caught
  Accepts nothing, returns a char (boolean)

  Return whether the villain is at his maximum position
}

/* Check if handcar is currently over an obstacle */
/* Index off RECOVER_TIME, which is greather than */
/* COLLIDE_TIME, because the player needs time to */
/* exit obstacle without starting a new collision */


Colliding
  Accepts nothing, returns a char (boolean)

  If player is at an obstacle but not jumping or recovering
    Start the collision and recovery timers
    Advance the villain forward

  If the collision timer is actively counting
    return TRUE
  Else
    return FALSE