Chris Dick / Mbed 2 deprecated Gameduino_Manic_Miner_game

Dependencies:   Gameduino mbed

Committer:
TheChrisyd
Date:
Sun Aug 05 12:47:00 2012 +0000
Revision:
0:a2d36977aec3
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TheChrisyd 0:a2d36977aec3 1 #include "arduino.h"
TheChrisyd 0:a2d36977aec3 2
TheChrisyd 0:a2d36977aec3 3 long time_counter;
TheChrisyd 0:a2d36977aec3 4 Ticker ticker;
TheChrisyd 0:a2d36977aec3 5
TheChrisyd 0:a2d36977aec3 6 long millis(void) {
TheChrisyd 0:a2d36977aec3 7 return time_counter/1000;
TheChrisyd 0:a2d36977aec3 8 }
TheChrisyd 0:a2d36977aec3 9 long micros(void) {
TheChrisyd 0:a2d36977aec3 10 return time_counter;
TheChrisyd 0:a2d36977aec3 11 }
TheChrisyd 0:a2d36977aec3 12
TheChrisyd 0:a2d36977aec3 13 void one_micro(void) {
TheChrisyd 0:a2d36977aec3 14 time_counter += 10;
TheChrisyd 0:a2d36977aec3 15 }
TheChrisyd 0:a2d36977aec3 16
TheChrisyd 0:a2d36977aec3 17 void arduino_setup(void) {
TheChrisyd 0:a2d36977aec3 18 ticker.attach_us( &one_micro, 10 );
TheChrisyd 0:a2d36977aec3 19 }
TheChrisyd 0:a2d36977aec3 20
TheChrisyd 0:a2d36977aec3 21 byte lowByte(short int low) {
TheChrisyd 0:a2d36977aec3 22 byte bytelow = 0;
TheChrisyd 0:a2d36977aec3 23 bytelow = (low & 0xFF);
TheChrisyd 0:a2d36977aec3 24 return bytelow;
TheChrisyd 0:a2d36977aec3 25 }
TheChrisyd 0:a2d36977aec3 26
TheChrisyd 0:a2d36977aec3 27 byte highByte(short int high) {
TheChrisyd 0:a2d36977aec3 28 byte bytehigh = 0;
TheChrisyd 0:a2d36977aec3 29 bytehigh = ((high >> 8) & 0xFF);
TheChrisyd 0:a2d36977aec3 30 return bytehigh;
TheChrisyd 0:a2d36977aec3 31 }
TheChrisyd 0:a2d36977aec3 32
TheChrisyd 0:a2d36977aec3 33 long random(int number) {
TheChrisyd 0:a2d36977aec3 34 return (rand()%number);
TheChrisyd 0:a2d36977aec3 35 }
TheChrisyd 0:a2d36977aec3 36
TheChrisyd 0:a2d36977aec3 37 int random(int numberone, int numbertwo) {
TheChrisyd 0:a2d36977aec3 38 int random = 0;
TheChrisyd 0:a2d36977aec3 39 if ((numberone < 0) && (numbertwo < 0)) {
TheChrisyd 0:a2d36977aec3 40 numberone = numberone * -1;
TheChrisyd 0:a2d36977aec3 41 numbertwo = numbertwo * -1;
TheChrisyd 0:a2d36977aec3 42 random = -1 * (rand()%(numberone + numbertwo));
TheChrisyd 0:a2d36977aec3 43 }
TheChrisyd 0:a2d36977aec3 44 if ((numbertwo < 0) && (numberone >= 0)) {
TheChrisyd 0:a2d36977aec3 45 numbertwo = numbertwo * -1;
TheChrisyd 0:a2d36977aec3 46 random = (rand()%(numberone + numbertwo)) - numbertwo;
TheChrisyd 0:a2d36977aec3 47 }
TheChrisyd 0:a2d36977aec3 48 if ((numberone < 0) && (numbertwo >= 0)) {
TheChrisyd 0:a2d36977aec3 49 numberone = numberone * -1;
TheChrisyd 0:a2d36977aec3 50 random = (rand()%(numberone + numbertwo)) - numberone;
TheChrisyd 0:a2d36977aec3 51 } else {
TheChrisyd 0:a2d36977aec3 52 random = (rand()%(numberone + numbertwo)) - min(numberone, numbertwo);
TheChrisyd 0:a2d36977aec3 53 }
TheChrisyd 0:a2d36977aec3 54 return random;
TheChrisyd 0:a2d36977aec3 55 }