Sunday, January 22, 2012
gameduino specific stuff
static uint16_t atxy(byte x, byte y)
{
return RAM_PIC + 64 * y + x;
}
static void draw_red_time(uint16_t dst, long n)
{
GD.wr(dst + 0, BG_RZERO + (n / 10000) % 10);
GD.wr(dst + 1, BG_RZERO + (n / 1000) % 10);
GD.wr(dst + 3, BG_RZERO + (n / 100) % 10);
GD.wr(dst + 4, BG_RZERO + (n / 10) % 10);
GD.wr(dst + 5, BG_RZERO + n % 10);
}
static void draw_red_speed(uint16_t dst, long n)
{
GD.wr(dst + 0, BG_RZERO + (n / 100) % 10);
GD.wr(dst + 1, BG_RZERO + (n / 10) % 10);
GD.wr(dst + 2, BG_RZERO + n % 10);
}
static void draw_cyan_time(uint16_t dst, long n)
{
GD.wr(dst + 0, BG_CZERO + (n / 10000) % 10);
GD.wr(dst + 1, BG_CZERO + (n / 1000) % 10);
GD.wr(dst + 3, BG_CZERO + (n / 100) % 10);
GD.wr(dst + 4, BG_CZERO + (n / 10) % 10);
GD.wr(dst + 5, BG_CZERO + n % 10);
}
static void draw_cyan_speed(uint16_t dst, long n)
{
GD.wr(dst + 0, BG_CZERO + (n / 100) % 10);
GD.wr(dst + 1, BG_CZERO + (n / 10) % 10);
GD.wr(dst + 2, BG_CZERO + n % 10);
}
finish
void finish() {
if(finish0 != 0 && finish1 != 0){
if(raceStarted) {
raceStarted = false;
winner();
}
}
}
countdown code
void countdown() {
if (raceStarting) {
if((millis() - lastCountDownMillis) > 1000){
lastCountDown -= 1;
lastCountDownMillis = millis();
}
if(lastCountDown == 3) {
count3();
}
if(lastCountDown == 2) {
count2();
}
if(lastCountDown == 1) {
count1();
}
if(lastCountDown == 0) {
start();
raceStarting = false;
raceStarted = true;
green0();
green1();
digitalWrite(goLed0,HIGH);
digitalWrite(goLed1,HIGH);
}
}
}
button code, this isn't quite right
void button(){
buttonState0 = digitalRead(button0);
if (raceStarted == false){
if(buttonState0 == HIGH) {
ticks0 = 0;
ticks1 = 0;
finish0 = 256*0;
finish1 = 256*0;
raceStarting = true;
raceStarted = false;
lastCountDown = 4;
lastCountDownMillis = millis();
win = 16;
}
}
if (raceStarted == true){
if(buttonState0 == HIGH) {
raceStarted = false;
digitalWrite(goLed0,LOW);
digitalWrite(goLed1,LOW);
}
}
}
main code
/*
pixel_sprints ver 0.1a
goldsprints bike racing software for arduino
using modified opensprints hardware for input
and gameduino vga control shield for output
pin 2 - io interupt
pin 3 - start stop button
pin 4 - player 1 sensor
pin 5 - player 2 sensor
pin 6 - player 1 led
pin 7 - player 2 led
pin 8
pin 9 - SPI select
pin 10
pin 11 - SPI MOSI
pin 12 - SPI MISO
pin 13 - SPI SCK
jan, 11, 2012
jevon elliott carlson
*/
#include <SPI.h>
#include <GD.h>
#include "pixelSprintsBg.h"
#include "pixelSprintsSprites.h"
//define background calls
#define BG_YELLOW 68
#define BG_GREEN 69
#define BG_RED 70
#define BG_CYAN 10
#define BG_RZERO 48
#define BG_CZERO 58
#define BG_BLACK 0
//define sprite calls
//define pins
int button0 = 3; // start stop button
int sensor0 = 4; // player 1
int sensor1 = 5; // player 2
int goLed0 = 6; // player 1 start stop light
int goLed1 = 7; // player 2 start stop light
//-----variables
// booleans, bytes
boolean raceStarted = false;
boolean raceStarting = false;
boolean buttonState0 = false;
boolean previousValue0 = HIGH;
boolean previousValue1 = HIGH;
boolean value0 = 0;
boolean value1 = 0;
// chars, bytes
// integers, 2 bytes
int velo0 = 0;
int velo1 = 0;
int lastCountDown;
int raceLengthTicks = 1904;
int updateInterval = 250;
int win = 16;
int pos0 = 24;
int pos1 = 24;
// longs, 4 bytes
unsigned long raceStartMillis;
unsigned long currentTimeMillis;
unsigned long ticks0;
unsigned long ticks1;
unsigned long finish0;
unsigned long finish1;
unsigned long lastCountDownMillis;
unsigned long lastUpdateMillis = 0;
unsigned long lastMphMillis = 0;
unsigned long tickSample0;
unsigned long mph0;
unsigned long lastTickSample0;
unsigned long tickSample1;
unsigned long mph1;
unsigned long lastTickSample1;
// start function__________________
void start() {
raceStartMillis = millis();
}
// setup
void setup() {
//game setup ___________________
pinMode(goLed0, OUTPUT);
pinMode(goLed1, OUTPUT);
digitalWrite(goLed0, LOW);
digitalWrite(goLed1, LOW);
pinMode(sensor0, INPUT);
pinMode(sensor1, INPUT);
digitalWrite(sensor0, HIGH);
digitalWrite(sensor1, HIGH);
pinMode(button0, INPUT);
//video setup ___________________
GD.begin();
for (byte y = 0; y < 39; y++)
GD.copy(RAM_PIC + y * 64, pixelSprintsBg_pic + y * 50, 50);
GD.copy(RAM_CHR, pixelSprintsBg_chr, sizeof(pixelSprintsBg_chr));
GD.copy(RAM_PAL, pixelSprintsBg_pal, sizeof(pixelSprintsBg_pal));
GD.copy(PALETTE16A, pixelSprintsSprites_sprpal, sizeof(pixelSprintsSprites_sprpal));
GD.copy(RAM_SPRIMG, pixelSprintsSprites_sprimg, sizeof(pixelSprintsSprites_sprimg));
}
// loop________________________________________________
void loop()
{
button();
if (raceStarting) {
countdown();
}
if (raceStarted)
{
race();
finish();
winner();
mph();
}
// GD.waitvblank();
draw_red_time(atxy(5,12), finish0 );
draw_red_speed(atxy(41,12), mph0);
draw_cyan_time(atxy(5,25), finish1 );
draw_cyan_speed(atxy(41,25), mph1);
GD.__wstartspr(0);
draw_pixelSprintsSprites(((ticks0 / 5.95) + 24), 130, 0, 0);
draw_pixelSprintsSprites(((ticks1 / 5.95) + 24), 170, 1, 0);
draw_pixelSprintsSprites(380, win, 2, 0);
GD.__end();
}
Subscribe to:
Posts (Atom)