C. Final Code

//Source code follows:
#include
#include
#include
#include
#include

class dinosaur{
public:
dinosaur();
int height,j,d;
void JumpDuck(int touchX);
void Draw();
int y;
private:

int maxy;
};

class cactus{//3 of these make up the cacti that the user sees.
public:
cactus(int=301, int=1);
int x;
int y;
void DrawCactus();
int CactusReady();//should check if time has elapsed enough for cactus to be dead, and randomly generate a new one
void Move();//slide cactus left, if it’s at zero, set it to inactive
void Reset();
int Test(int Tedy);
int ranNum;
int type;
int active;

private:

};

int main(void)
{
LCD.SetBackgroundColor(WHITE);
LCD.SetFontColor(BLACK);
LCD.Clear();
float touchX,touchY,scores[6];
LCD.WriteAt(“Welcome to DINOSAUR GAME”,10,50);
LCD.WriteAt(“Touch the screen anywhere”,10,90);
LCD.WriteAt(“To continue”,130, 150);

int y;
for(y=0;y<1;y++){ //Draw splash dino LCD.DrawHorizontalLine(180-y,20+14,20+17); LCD.DrawHorizontalLine(181-y,20+13,20+18); LCD.DrawHorizontalLine(182-y,20+12,20+14); LCD.DrawHorizontalLine(182-y,20+16,20+19);//red LCD.DrawHorizontalLine(183-y,20+12,20+19); LCD.DrawHorizontalLine(184-y,20+11,20+14); LCD.DrawHorizontalLine(185-y,20+11,20+18); LCD.DrawHorizontalLine(186-y,20+10,20+14); LCD.FillRectangle(20+9,180+7-y,5,4);//green LCD.FillRectangle(20+7,180+9-y,3,11);//yellow LCD.DrawHorizontalLine(190-y,20+15,20+16);//blue LCD.FillRectangle(20+10,180+11-y,2,6);//purple LCD.DrawVerticalLine(20+12,180+12-y,180+18-y); //orange LCD.DrawVerticalLine(20+13,180+14-y,180+19-y); LCD.DrawVerticalLine(20+14,180+16-y,180+19-y); LCD.DrawVerticalLine(20+15,180+18-y,180+19-y); LCD.DrawVerticalLine(20+6,180+11-y,180+15-y); LCD.DrawVerticalLine(20+5,180+12-y,180+16-y); LCD.DrawVerticalLine(20+4,180+13-y,180+17-y); LCD.DrawVerticalLine(20+3,180+15-y,180+18-y); LCD.DrawVerticalLine(20+2,180+16-y,180+18-y); LCD.DrawVerticalLine(20+1,180+17-y,180+19-y); LCD.DrawPixel(20+0,180+19-y); LCD.DrawPixel(20+8,180+8-y);//light green LCD.DrawPixel(20+10,180+18-y); LCD.DrawPixel(20+11,180+19-y); LCD.DrawPixel(20+16,180+19-y); LCD.DrawPixel(20+17,180+18-y); LCD.DrawPixel(20+18,180+19-y); } do{} while(!LCD.Touch(&touchX,&touchY)); int score = 0,cactusTimer=0,i,menuSum; for (i=0;i<=5;i++){ scores[i] = 0; } int temp,swaps=0; dinosaur Ted; while(1){ Ted.y = 0; Ted.j=0; Ted.height=20; cactus c1(375,0),c2(250,0),c3(125,0); //create 3 evenly spaced cacti, all inactive cactus pt(1000,0); pt.type = 4; int f=1;//while loop will run forever LCD.Clear(); int score = 0,cactusTimer=0; srand(TimeNow()); LCD.Clear();//start screen LCD.DrawHorizontalLine(120,0,319); LCD.DrawVerticalLine(160,0,239); LCD.WriteAt("PLAY",40,50);//11 LCD.WriteAt("RULES",210,50);//21 LCD.WriteAt("STATS",40,170);//12 LCD.WriteAt("CREDITS",210,170);//22 Sleep(150); int j; do{ j=LCD.Touch(&touchX,&touchY); } while(!j); menuSum= 0; if (touchX <=160){ menuSum+=10;} else if (touchX >160){
menuSum+=20;}
if (touchY <=120){ menuSum +=1;} else if (touchY >120){
menuSum+=2;}

switch (menuSum){
case 21:
LCD.Clear();
LCD.Write(“RULES:”);
LCD.WriteAt(“1.Don’t hit anything.”,2,20);
LCD.WriteAt(“(Except the ground)”,2,40);
LCD.WriteAt(“2.Touch the right side”,2,60);
LCD.WriteAt(“to jump”,2,80);
LCD.WriteAt(“3.Touch the left side”,2,100);
LCD.WriteAt(“(hard) to duck”,2,120);
LCD.WriteAt(“4.Go as far as you can.”,2,140);
Sleep(10000);
break;
case 12:
LCD.Clear();
LCD.Write(“HIGH SCORES:”);
for(i=0;i<=4;i++){ LCD.WriteAt(scores[i],2,20+20*i); } Sleep(10000); break; case 22: LCD.Clear(); LCD.Write("CREDITS:"); LCD.WriteAt("THIS WORK OF ART MADE BY",2,20); LCD.WriteAt("DREAM TEAM.",2,40); LCD.WriteAt("MEMBERS:",2,60); LCD.WriteAt("THE George Hinton and",2,80); LCD.WriteAt("THE Cameron Foster",2,100); //LCD.WriteAt("4. Go as far as you can. GL-HF",2,80); Sleep(10000); break; case 11: while (f==1){ LCD.Clear();//clear screen to white for redraw LCD.DrawHorizontalLine(201,0,319);//ground LCD.WriteAt("Score:",2,2); //scorekeeping LCD.WriteAt(score, 80, 2); LCD.Touch(&touchX, &touchY); Ted.JumpDuck(touchX); if(c1.Test(Ted.y)|| c2.Test(Ted.y)|| c3.Test(Ted.y)|| pt.Test(Ted.y)){ f = 0; break; } Ted.Draw(); c1.Move(); c2.Move();//move the cacti to the left c3.Move(); pt.Move(); c1.DrawCactus(); c2.DrawCactus(); c3.DrawCactus(); pt.DrawCactus(); //this block ensures cacti don't spawn too close together or spawn inside eachother if (cactusTimer>=50){
i = rand() %4;
switch (i){
case 0:
if (c1.CactusReady()){
c1.Reset();
cactusTimer = 0;
}
break;
case 1:
if (c2.CactusReady()){
c2.Reset();
cactusTimer = 0;
}
break;
case 2:
if (c3.CactusReady()){
c3.Reset();
cactusTimer = 0;
}
break;
case 3:
if (pt.CactusReady()){
pt.Reset();
cactusTimer = 0;
pt.type = 4;
pt.y = 165;
}
break;
}
}
cactusTimer++;

score++;
Sleep(5);

}//main game loop

LCD.Clear();
LCD.Write(“ouch.”);
Sleep(3000);

swaps = 0;
scores[5]=score;
do{ //sort scores
swaps = 0;
for (i=0;i<=4;i++){ if (scores[i]= 155 ){
j =1;
}
}
if (j == 1){ //on the way up
//y += 0.001 *maxy* ((2 * (sqrt(maxy-y)))); //just try this it may not work
y+=5;
if (y >= maxy){
y = maxy;
j = 2;
}
}
if (j == 2){ // on the way down
//y -= 0.001 *maxy* ((2 * (sqrt(maxy-y))));
y-=5;
if (y <= 0){ y = 0; j = 0; } } d=1; if (touchX <= 155 && touchX >1){
height = 7;
y -=13;
d=2;
}
}

void dinosaur::Draw(){ //draws the dinosaur. sets y back to what it was so it can duck again.
//LCD.FillRectangle(20,180-y,20,height);
if (height==20){
LCD.DrawHorizontalLine(180-y,20+14,20+17);
LCD.DrawHorizontalLine(181-y,20+13,20+18);
LCD.DrawHorizontalLine(182-y,20+12,20+14);
LCD.DrawHorizontalLine(182-y,20+16,20+19);//red
LCD.DrawHorizontalLine(183-y,20+12,20+19);
LCD.DrawHorizontalLine(184-y,20+11,20+14);
LCD.DrawHorizontalLine(185-y,20+11,20+18);
LCD.DrawHorizontalLine(186-y,20+10,20+14);
LCD.FillRectangle(20+9,180+7-y,5,4);//green
LCD.FillRectangle(20+7,180+9-y,3,11);//yellow
LCD.DrawHorizontalLine(190-y,20+15,20+16);//blue
LCD.FillRectangle(20+10,180+11-y,2,6);//purple
LCD.DrawVerticalLine(20+12,180+12-y,180+18-y); //orange
LCD.DrawVerticalLine(20+13,180+14-y,180+19-y);
LCD.DrawVerticalLine(20+14,180+16-y,180+19-y);
LCD.DrawVerticalLine(20+15,180+18-y,180+19-y);
LCD.DrawVerticalLine(20+6,180+11-y,180+15-y);
LCD.DrawVerticalLine(20+5,180+12-y,180+16-y);
LCD.DrawVerticalLine(20+4,180+13-y,180+17-y);
LCD.DrawVerticalLine(20+3,180+15-y,180+18-y);
LCD.DrawVerticalLine(20+2,180+16-y,180+18-y);
LCD.DrawVerticalLine(20+1,180+17-y,180+19-y);
LCD.DrawPixel(20+0,180+19-y);
LCD.DrawPixel(20+8,180+8-y);//light green
LCD.DrawPixel(20+10,180+18-y);
LCD.DrawPixel(20+11,180+19-y);
LCD.DrawPixel(20+16,180+19-y);
LCD.DrawPixel(20+17,180+18-y);
LCD.DrawPixel(20+18,180+19-y);
}
if (height==7){
LCD.DrawHorizontalLine(180-y+0,20+0,20+1);
LCD.DrawHorizontalLine(180-y+0,20+6,20+11);
LCD.DrawHorizontalLine(180-y+0,20+14,20+18);
LCD.DrawHorizontalLine(180-y+1,20+0,20+2);
LCD.DrawHorizontalLine(180-y+1,20+5,20+15);
LCD.DrawHorizontalLine(180-y+1,20+17,20+19);
LCD.DrawHorizontalLine(180-y+2,20+1,20+19);
LCD.DrawHorizontalLine(180-y+3,20+2,20+15);
LCD.DrawHorizontalLine(180-y+4,20+2,20+19);
LCD.DrawHorizontalLine(180-y+5,20+4,20+12);
LCD.DrawHorizontalLine(180-y+6,20+5,20+6);
LCD.DrawHorizontalLine(180-y+6,20+10,20+13);
LCD.DrawPixel(20+8,180-y+6);
LCD.DrawPixel(20+15,180-y+6);
LCD.DrawPixel(20+14,180-y+5);
}
height = 20;
if (d==2){
y +=13;
}
}

cactus::cactus(int X, int a){//default is 301, 1. Spawn a cactus at the right side of the screen, active.
x = X;
y = 180;
active = a;
type = rand() % 3;
ranNum = -1;
}

void cactus::Reset(){//move the cactus to the right side of the screen and reset it.
x = 301;
y = 180;
active = 1;
type = rand() % 3;
}

void cactus::DrawCactus(){//draws cacti and pteros
if (active == 1){
switch (type){
case 0:
LCD.DrawVerticalLine(x+0,180+2,180+19);
LCD.DrawVerticalLine(x+1,180+1,180+19);
LCD.DrawVerticalLine(x+2,180+2,180+19);
LCD.DrawVerticalLine(x+3,180+10,180+11);
LCD.DrawVerticalLine(x+4,180+7,180+11);
LCD.DrawVerticalLine(x+5,180+6,180+11);
LCD.DrawVerticalLine(x+5,180+15,180+16);
LCD.DrawVerticalLine(x+6,180+7,180+11);
LCD.DrawPixel(x+6,180+16);
LCD.DrawVerticalLine(x+7,180+13,180+19);
LCD.DrawPixel(x+8,180+17);
LCD.DrawVerticalLine(x+9,180+14,180+18);
break;
case 1:
LCD.DrawVerticalLine(x+0,180+8,180+13);
LCD.DrawVerticalLine(x+1,180+7,180+13);
LCD.DrawVerticalLine(x+2,180+12,180+13);
LCD.DrawVerticalLine(x+3,180+2,180+19);
LCD.DrawVerticalLine(x+4,180+1,180+19);
LCD.DrawVerticalLine(x+5,180+2,180+19);
LCD.DrawVerticalLine(x+6,180+12,180+13);
LCD.DrawVerticalLine(x+7,180+8,180+13);
LCD.DrawVerticalLine(x+8,180+7,180+13);
LCD.DrawVerticalLine(x+9,180+8,180+13);
break;
case 2:
LCD.DrawVerticalLine(x+9-+0,180+2,180+19);
LCD.DrawVerticalLine(x+9-1,180+1,180+19);
LCD.DrawVerticalLine(x+9-2,180+2,180+19);
LCD.DrawVerticalLine(x+9-3,180+10,180+11);
LCD.DrawVerticalLine(x+9-4,180+7,180+11);
LCD.DrawVerticalLine(x+9-5,180+6,180+11);
LCD.DrawVerticalLine(x+9-5,180+15,180+16);
LCD.DrawVerticalLine(x+9-6,180+7,180+11);
LCD.DrawPixel(x+9-6,180+16);
LCD.DrawVerticalLine(x+9-7,180+13,180+19);
LCD.DrawPixel(x+9-8,180+17);
LCD.DrawVerticalLine(x+9-9,180+14,180+18);
break;
case 4:
LCD.DrawPixel(x+10,165+0);
LCD.DrawPixel(x+10,165+1);
LCD.DrawHorizontalLine(165+2,x+9,x+10);
LCD.DrawHorizontalLine(165+3,x+9,x+10);
LCD.DrawHorizontalLine(165+4,x+8,x+10);
LCD.DrawHorizontalLine(165+5,x+7,x+10);
LCD.DrawHorizontalLine(165+6,x+6,x+10);
LCD.DrawHorizontalLine(165+7,x+4,x+6);
LCD.DrawHorizontalLine(165+7,x+8,x+10);
LCD.DrawHorizontalLine(165+8,x+2,x+19);
LCD.DrawHorizontalLine(165+9,x+0,x+17);
LCD.DrawHorizontalLine(165+10,x+9,x+19);
LCD.DrawHorizontalLine(165+11,x+9,x+16);
LCD.DrawHorizontalLine(165+12,x+10,x+16);
LCD.DrawHorizontalLine(165+13,x+10,x+16);
LCD.DrawHorizontalLine(165+14,x+11,x+15);
LCD.DrawHorizontalLine(165+15,x+11,x+15);
LCD.DrawHorizontalLine(165+16,x+12,x+14);
LCD.DrawHorizontalLine(165+17,x+13,x+14);
LCD.DrawPixel(x+13,165+18);
LCD.DrawPixel(x+13,165+19);
break;
}

//LCD.WriteAt(type, x,y);

}
}

void cactus::Move(){//slides the cactus to the right side of the screen. if it touches 0, the cactus dies
x-=5;
if (x <= 0){ active = 0; } } int cactus::CactusReady(){//checks if enough time has passed since cactus death, returns 0 or 1 if (active==0){//cactus must be inactive to reset if (x<=-50 && ranNum<0){//enough time has passed, ran generator hasn't started ranNum = rand() % 16;//rand between 0 and 15 theoretically return 0; } else if(ranNum==15){//tell main to generate a cactus (time&rand)=1 return 1; ranNum=-1;//will trip ranNum reset if cactus goes 50 past dino } else if(ranNum<15){//increases rand ranNum++; return 0; } } else if (active==1){ return 0; } } int cactus::Test(int tedy){//tests for collision between ptero/cactus and dino. returns 1 on collision. this function sucks if (active == 1){ if (type<=2){ if (x>=15 & x<=40 & tedy<=20){//cacti. ted.y just needs to be above cactus height return 1; } } else if (type ==4){//bird if (x>=15 & x<= 40 & tedy <= 15& tedy >=-5){//NEEDS DEBUGGING!!!!!!!! CANT DO AT HOME
return 1;
}
else {return 0;}
}
else{ return 0; }

}
else {return 0;}
}

//499 lines is a better number