GLuint MyCar::generateCar() { GLuint car = glGenLists(1); glNewList(car, GL_COMPILE); drawCar(); glEndList(); return car; }
// Draw all opponents of the current car. void cGrTrackMap::drawCars(tCarElt *currentCar, tSituation *s, int x, int y) { int i; for (i = 0; i < s->_ncars; i++) { if ((s->cars[i] != currentCar) && !(s->cars[i]->_state & (RM_CAR_STATE_DNF | RM_CAR_STATE_PULLUP | RM_CAR_STATE_PULLSIDE | RM_CAR_STATE_PULLDN))) { if (s->cars[i]->race.pos > currentCar->race.pos) { drawCar(s->cars[i], behindCarColor, x, y); } else { drawCar(s->cars[i], aheadCarColor, x, y); } } } }
void Render::paintGL() { glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); move(); drawGrid(); drawCar(); drawSparks(); drawBody(world->getTrack()->getBody()); drawText(); drawParents(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glOrtho(0, width(), height(), 0, 1.0, -1.0); drawTable(); drawGraph(); glPopMatrix(); //GL_MODELVIEW glMatrixMode(GL_PROJECTION); glPopMatrix(); }
void display(void) { glClearColor (0.0,0.0,0.0,1.0); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); drawCar(); glutSwapBuffers(); //swap the buffers }
int main() { Car Jori; Car Opel; Car Mersedec; drawCar(Mersedec, "grey"); std::cout << "There are " << Car::getCarCount() << "cars created" << std::endl; return 0; }
void cars::drawCars(){ render r; glColor3f(1.0,0.0,0.0); drawCar(); for(int j = 0; j < 4; j++){ for(float i = 1.0; i >= -1.0; i--){ glRectf(x[j] - (2 * x[j]), 0.5 + ydist[j] - 0.1, x[j] - (2 * x[j]) + 0.05, 0.5 + ydist[j]); } } }
void Render::createCarCallList() { GeneticAlgorithm *algorithm = world->getAlgorithm(); unsigned int oldCallListNubmer = algorithm->getCarCallListNuber(); if (oldCallListNubmer) glDeleteLists(oldCallListNubmer, 1); unsigned int listNubmer = glGenLists(1); algorithm->setCarCallList(listNubmer); glNewList(listNubmer, GL_COMPILE); drawCar(); glEndList(); }
void display(void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity (); /* clear the matrix */ /* viewing transformation */ gluLookAt (0.0, 0.0, 0.0, 0.0, theta-2.2, -5.0, 0.0, 1.0, 0.0); drawGround(); drawCar(); draw_remote_car(); glFlush (); glutSwapBuffers(); }
// DRAW SCREEN OBJECTS HERE void polygon(void) { glClear(GL_COLOR_BUFFER_BIT); drawPoint(startPosX, startPosY); for (int i = 0; i < cars.size(); i++ ) { drawCar(cars[i]); } glutSwapBuffers(); }
// Draw the track map according to the display mode void cGrTrackMap::display( tCarElt *currentCar, tSituation *situation, int Winx, int Winy, int Winw, int Winh ) { if (viewmode == TRACK_MAP_NONE) { return; } // Compute track map position. int x = Winx + Winw + map_x - (int) (map_size*track_x_ratio); int y = Winy + Winh + map_y - (int) (map_size*track_y_ratio); // Setup and display track map. glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBindTexture(GL_TEXTURE_2D, mapTexture); // Draw track. if (viewmode & (TRACK_MAP_NORMAL | TRACK_MAP_NORMAL_WITH_OPPONENTS)) { drawTrackNormal(x, y); } else if (viewmode & (TRACK_MAP_PAN | TRACK_MAP_PAN_WITH_OPPONENTS)) { drawTrackPanning(Winx, Winy, Winw, Winh, currentCar, situation); } else if (viewmode & (TRACK_MAP_PAN_ALIGNED | TRACK_MAP_PAN_ALIGNED_WITH_OPPONENTS)) { drawTrackPanningAligned(Winx, Winy, Winw, Winh, currentCar, situation); } // Draw cars in normal map mode. if (viewmode & TRACK_MAP_NORMAL_WITH_OPPONENTS) { drawCars(currentCar, situation, x, y); } if (viewmode & (TRACK_MAP_NORMAL | TRACK_MAP_NORMAL_WITH_OPPONENTS)) { drawCar(currentCar, currentCarColor, x, y); } }
// G³ówna funkcja rysowania. Tutaj wywo³ujemy wszystkie obiekty do narysowania. void display() { currentTime = glutGet(GLUT_ELAPSED_TIME); CalcCarPosition(); glm::vec4 &worldLightPos = carPosition; glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); { glutil::MatrixStack modelMatrix; modelMatrix.SetMatrix(g_viewPole.CalcMatrix()); lightPosCameraSpace = modelMatrix.Top() * worldLightPos; setDefaultLightParams(&adsShader, worldLightPos, direction, nextLight); { glutil::PushStack push(modelMatrix); // Pod³oga { glutil::PushStack push(modelMatrix); glm::mat4 invTransform = glm::inverse(modelMatrix.Top()); glUseProgram(adsShader.theProgram); glUniformMatrix4fv(adsShader.modelToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top())); glUniform3f(adsShader.Ks, 0.0f, 0.0f, 0.0f); // niech pod³oga nie ma odbicia g_pPlaneMesh->Render("lit-color"); glUseProgram(0); } drawCylinder(modelMatrix, worldLightPos); drawCar(modelMatrix, worldLightPos); drawSphere1(modelMatrix, worldLightPos); drawSphere2(modelMatrix, worldLightPos); drawTetrahedron1(modelMatrix, worldLightPos); } } glutPostRedisplay(); glutSwapBuffers(); oldTime = currentTime; }
static int getCar(lua_State *L) { // get car from Lua state float track = lua_tonumber(L, 1); float lenght = lua_tonumber(L, 2); float position = lua_tonumber(L, 3); float maxspeed = lua_tonumber(L, 4); float speed = lua_tonumber(L, 5); lua_pop(L, 5); // add lua to bar int n = ((BAR_W)*(position+lenght))/(TRACKS_FINISH-TRACKS_BEGIN); cars_num[n] += 1; cars_col[n] += speed/maxspeed; cars_col[n] /= 2; // draw car to screen drawCar(position, ((float)SCREEN_H - (CAR_WIDTH*1.3)*TRACKS_NUM)/2 + 0.15*CAR_WIDTH + (CAR_WIDTH*1.3)*(track - 1), lenght, speed/maxspeed); return 0; }
/* Redraws window contents */ void glutWidget::render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clears color and depth bits of framebuffer //Convenience variables float t = (float) ((int) (((float) clock()) * 50.0 / CLOCKS_PER_SEC) % 30) / 30.0; int t2 = ((int) (((float) clock()) * 50.0 / CLOCKS_PER_SEC) % 240) / 30; float t3 = (float) clock() * 5.0 / CLOCKS_PER_SEC; //These are the control points for the bezier curves GLfloat curves[8][4][3] = { { {-8, 0, -8.5}, {-7, 0, -8.5}, {-5, 0, -8.5}, {-4, 0, -8.5} }, { {-4, 0, -8.5}, {-3.5, 0, -8.5}, {-3.5, 0, -8.5}, {-3.5, 0, -8} }, { {-3.5, 0, -8}, {-3.5, 0, -7}, {-3.5, 0, -5}, {-3.5, 0, -4} }, { {-3.5, 0, -4}, {-3.5, 0, -3.5}, {-3.5, 0, -3.5}, {-4, 0, -3.5} }, { {-4, 0, -3.5}, {-5, 0, -3.5}, {-7, 0, -3.5}, {-8, 0, -3.5} }, { {-8, 0, -3.5}, {-8.5, 0, -3.5}, {-8.5, 0, -3.5}, {-8.5, 0, -4} }, { {-8.5, 0, -4}, {-8.5, 0, -5}, {-8.5, 0, -7}, {-8.5, 0, -8} }, { {-8.5, 0, -8}, {-8.5, 0, -8.5}, {-8.5, 0, -8.5}, {-8, 0, -8.5} } }; //Manually evaluate the bezier curves float s = 1 - t; float AB[2] = {curves[t2][0][0]*s + curves[t2][1][0]*t, curves[t2][0][2]*s + curves[t2][1][2]*t}; float BC[2] = {curves[t2][1][0]*s + curves[t2][2][0]*t, curves[t2][1][2]*s + curves[t2][2][2]*t}; float CD[2] = {curves[t2][2][0]*s + curves[t2][3][0]*t, curves[t2][2][2]*s + curves[t2][3][2]*t}; float ABC[2] = {AB[0]*s + BC[0]*t, AB[1]*s + BC[1]*t}; float BCD[2] = {BC[0]*s + CD[0]*t, BC[1]*s + CD[1]*t}; float pos[2] = {ABC[0]*s + BCD[0]*t, ABC[1]*s + BCD[1]*t}; float slope = (ABC[1] - BCD[1]) / (ABC[0] - BCD[0]); float theta = atan(slope); //Rotation/translation matrix float matrix[4][4] = { {cos(theta), 0, -sin(theta), 0}, {0, 1, 0, 0}, {sin(theta), 0, cos(theta), 0}, {pos[0], 0.01, pos[1], 1} }; //Keep the texture pointing in the right direction throughout the loop if((ABC[0] - BCD[0]) < 0) { matrix[0][2] = -(matrix[0][2]); matrix[2][0] = -(matrix[2][0]); } else if((ABC[0] - BCD[0]) > 0) { matrix[0][0] = -(matrix[0][0]); matrix[2][2] = -(matrix[2][2]); } //Draw streets glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, street_texture); glUseProgram(m_program); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0,1); glNormal3f(0,1,0); glVertex3f(-10,0,-10); glTexCoord2f(0,0); glNormal3f(0,1,0); glVertex3f(-10,0,10); glTexCoord2f(1,1); glNormal3f(0,1,0); glVertex3f(10,0,-10); glTexCoord2f(1,0); glNormal3f(0,1,0); glVertex3f(10,0,10); glEnd(); glUseProgram(0); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); // //Draw cars for (int i = 0; i < 9; i++) { matrix[3][0] = pos[0] + ((i % 3) * 6); matrix[3][2] = pos[1] + ((i / 3) * 6); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf(matrix[0]); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, car_texture); glUseProgram(m_program); drawCar(); glUseProgram(0); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glPopMatrix(); if (i+1 == camera) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(matrix[3][0],0.5,matrix[3][2],sin(roty)+matrix[3][0],sin(rotx)+0.2,-cos(roty)+matrix[3][2],0,1,0); //Camera rotation/translation is done here } } // //Draw structures for (int i = 0; i < 9; i++) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef((i % 3) * 6, 0, (i / 3) * 6); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, structure_texture); glUseProgram(m_program); drawStructure(); glUseProgram(0); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glPopMatrix(); } // //Draw skybox glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, skybox_texture); glUseProgram(m_program); drawSkybox(); glUseProgram(0); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); // //Draw walls glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, wall_texture); glUseProgram(m_program); drawWalls(); glUseProgram(0); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); // if (!camera) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(cposx,0.25,cposz,sin(roty)+cposx,sin(rotx)+cposy,-cos(roty)+cposz,0,1,0); //Camera rotation/translation is done here } glutSwapBuffers(); //swaps front and back buffer for double buffering }
void display(void) { /* clear the window color before drawing is performed */ glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glPushMatrix(); static float upx; static float upy; static int upz; switch(viewstate) { case NORMALVIEW: upx=0; upy=1; upz=0; break; case NORMALVIEW+1: upx=1; upy=0; upz=0; break; case NORMALVIEW+2: upx=0; //printf("%d\n",upx); //printf("%d\n",upy); upy=0; upz=1; break; } //printf("%f\n",velocity_angle); gluLookAt(cam_X,cam_Y,cam_Z, cam_ViewX, cam_ViewY, cam_ViewZ, upx, upy, upz); /* Add code here to transform the car and the ground & draw them * use glTranslate, glRotate, glLoadIdentity, glPushMatrix, glPopMatrix, glMaterial, * glBegin, gluSphere...etc * * Add code for Texture Mapping for the car and the ground * use glTexImage2D.. */ //update car light static GLfloat light1pos[4]; light1pos[0]= position_X+0.66*sin(velocity_angle*PI/180); light1pos[1]= position_Y+0.66*cos(velocity_angle*PI/180); light1pos[2]= position_Z-0.3; light1pos[3]= 1.f; static GLfloat light1direction[3]; light1direction[0] = sin(velocity_angle*PI/180); light1direction[1] = cos(velocity_angle*PI/180); light1direction[2] = 0; //printf("light1position[0]:%f,light1position[1]:%f\n",light1pos[0],light1pos[1]); /*light1direction[0] = 0; light1direction[1] = 0; light1direction[2] = 0.5;*/ //light1direction[3] = 1; //printf("light1direction[0]:%f,light1direction[1]:%f\n",light1direction[0],light1direction[1]); glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,light1direction); glLightfv(GL_LIGHT1, GL_POSITION, light1pos); drawGround(); drawCar(); glPopMatrix(); glFlush(); glutSwapBuffers(); }
//TODO: function that draw the train void TrainView::drawTrain(bool doingShadows) { float step = 50.0f; float size = 15.0; int carCount = 4; //draw track glLineWidth(size); int drawCount = 0; double accumulatedDistance = -1; bool skippedShift = false; size_t i = 0; while (true) { if (drawCount >= carCount) { break; } if (curveMode == CurveModeLinear) { ControlPoint thisPoint = world->points[i % world->points.size()]; ControlPoint nextPoint = world->points[(i+1) % world->points.size()]; for (int j = 0; j < step; j++) { float from = j*(1.0f/step); float to = (j+1)*(1.0f/step); Pnt3f *fromPoint = new Pnt3f( thisPoint.pos.x + (nextPoint.pos.x - thisPoint.pos.x) * from, thisPoint.pos.y + (nextPoint.pos.y - thisPoint.pos.y) * from, thisPoint.pos.z + (nextPoint.pos.z - thisPoint.pos.z) * from); Pnt3f *toPoint = new Pnt3f( thisPoint.pos.x + (nextPoint.pos.x - thisPoint.pos.x) * to, thisPoint.pos.y + (nextPoint.pos.y - thisPoint.pos.y) * to, thisPoint.pos.z + (nextPoint.pos.z - thisPoint.pos.z) * to); double thisDistance = pow( pow((*fromPoint).x - (*toPoint).x, 2) + pow((*fromPoint).y - (*toPoint).y, 2) + pow((*fromPoint).z - (*toPoint).z, 2), 0.5); if (skippedShift && drawCount < carCount && (accumulatedDistance == -1 /* first time*/ || accumulatedDistance > size)) { // can draw float x = (*toPoint).x - (*fromPoint).x; float y = (*toPoint).y - (*fromPoint).y; float z = (*toPoint).z - (*fromPoint).z; float xAngle = atanf(y/z); float yAngle = atanf(-z/x); float zAngle = atanf(y/x); float pi = atan(1)*4; glPushMatrix(); glTranslated((*fromPoint).x,(*fromPoint).y,(*fromPoint).z); glRotated(xAngle/pi*180, 1, 0, 0); glRotated(yAngle/pi*180, 0, 1, 0); glRotated(zAngle/pi*180, 0, 0, 1); glScaled(size, size, size); drawCar(carCount - drawCount, doingShadows); glPopMatrix(); accumulatedDistance = 0; drawCount++; } else { accumulatedDistance += thisDistance; if (!skippedShift && accumulatedDistance >= world->trainU) { skippedShift = true; accumulatedDistance = -1; } } } } else if (curveMode == CurveModeCatmull) { ControlPoint point1 = world->points[i % world->points.size()]; ControlPoint point2 = world->points[(i+1) % world->points.size()]; ControlPoint point3 = world->points[(i+2) % world->points.size()]; ControlPoint point4 = world->points[(i+3) % world->points.size()]; for (int j = 0; j < step; j++) { float from = j*(1.0f/step); float to = (j+1)*(1.0f/step); Pnt3f *fromPoint = catmullPoint(from, point1.pos, point2.pos, point3.pos, point4.pos); Pnt3f *toPoint = catmullPoint(to, point1.pos, point2.pos, point3.pos, point4.pos); double thisDistance = pow( pow((*fromPoint).x - (*toPoint).x, 2) + pow((*fromPoint).y - (*toPoint).y, 2) + pow((*fromPoint).z - (*toPoint).z, 2), 0.5); if (skippedShift && drawCount < carCount && (accumulatedDistance == -1 /* first time*/ || accumulatedDistance > size)) { // can draw float x = (*toPoint).x - (*fromPoint).x; float y = (*toPoint).y - (*fromPoint).y; float z = (*toPoint).z - (*fromPoint).z; float xAngle = atanf(y/z); float yAngle = atanf(-z/x); float zAngle = atanf(y/x); float pi = atan(1)*4; glPushMatrix(); glTranslated((*fromPoint).x,(*fromPoint).y,(*fromPoint).z); glRotated(xAngle/pi*180, 1, 0, 0); glRotated(yAngle/pi*180, 0, 1, 0); glRotated(zAngle/pi*180, 0, 0, 1); glScaled(size, size, size); drawCar(carCount - drawCount, doingShadows); glPopMatrix(); accumulatedDistance = 0; drawCount++; } else { accumulatedDistance += thisDistance; if (!skippedShift && accumulatedDistance >= world->trainU) { skippedShift = true; accumulatedDistance = -1; } } } } i++; } }
//main game loop extern void showGame(MI0283QT9 lcd){ //setup seed uint16_t seed = (rand() % 65534) + 1; srand(seed); //setup car uint8_t x = 2; uint8_t movCounter = 0; uint8_t colored[] = {red,green,blue}; uint16_t score = 0; uint8_t pSensitivity = 0; initGenObjects(); //objects preGenObjects[128]; if (sLow == 1) { pSensitivity = 5; } else if (sMedium == 1) { pSensitivity = 4; } else if (sHigh == 1){ pSensitivity = 3; } //Draw game road showDefaultLayout(lcd); nun.nunchuck_init(); posYobj1 = 0; posYobj2 = 0; posYobj3 = 0; prevposXobj1 = 0; prevposXobj2 = 0; prevposXobj3 = 0; keepObj2Alive = 0; keepObj3Alive = 0; uint8_t carHitMax = 15; uint8_t truckHitmax = 18; uint8_t countDown = 3; //start game loop while(1){ if(returnToMain){ returnToMain = 0; lcd.fillScreen(BACKGROUND); break; } if(restartGame){ posYobj1 = 0; posYobj2 = 0; posYobj3 = 0; prevposXobj1 = 0; prevposXobj2 = 0; prevposXobj3 = 0; keepObj2Alive = 0; keepObj3Alive = 0; //Draw game road initGenObjects(); x = 2; movCounter = 0; colored[0] = red; colored[1] = green; colored[2] = blue; score = 0; pSensitivity = 0; if (sLow == 1) { pSensitivity = 5; } else if (sMedium == 1) { pSensitivity = 4; } else if (sHigh == 1) { pSensitivity = 3; } showDefaultLayout(lcd); onBeginB = 0; restartGame = 0; countDown = 3; } //countdown before game start while(countDown != 0){ lcd.drawInteger(centerText(" ", 3), 150, countDown, DEC, OBJECTCOLOR, BACKGROUND, 3); _delay_ms(1000); lcd.drawInteger(centerText(" ", 3), 150, countDown, DEC, BACKGROUND, BACKGROUND, 3); if(countDown == 1){ lcd.drawText(centerText("START" , 3), 150, "START", OBJECTCOLOR, BACKGROUND, 3); _delay_ms(1000); lcd.drawText(centerText("START" , 3), 150, "START", BACKGROUND, BACKGROUND, 3); } countDown--; } //shows the enemy cars showGenObjects(lcd); //Draw player car at start location drawCar(lcd, x, 12,colored); //If obj1 is at you y location, check if objectx = playerx if((object[0].type == 1 && object[0].posY >= 12 && object[0].posY <= carHitMax ) || (object[0].type == 2 && object[0].posY >= 12 && object[0].posY <= truckHitmax)){ if (object[0].posX == x ) { showGameOverMenu(lcd, score); }else{ if(object[0].posY == carHitMax || object[0].posY == truckHitmax){ score = object[0].type + score; } } }else if((object[1].type == 1 && object[1].posY >= 12 && object[1].posY <= carHitMax ) || (object[1].type == 2 && object[1].posY >= 12 && object[1].posY <= truckHitmax)){ //If obj2 is at player y location, check if objectx = playerx if (object[1].posX == x) { showGameOverMenu(lcd,score); }else{ if(object[1].posY == carHitMax || object[1].posY == truckHitmax){ score = object[1].type + score; } } } else if((object[2].type == 1 && object[2].posY >= 12 && object[2].posY <= carHitMax ) || (object[2].type == 2 && object[2].posY >= 12 && object[2].posY <= truckHitmax)){ //If obj3 is at player y location, check if objectx = playerx if (object[2].posX == x) { showGameOverMenu(lcd,score); }else{ if(object[2].posY == carHitMax || object[2].posY == truckHitmax){ score = object[2].type + score; } } } //draws car at x depending on tilt, and y = 12 (front of car), y = 15 end of car if(nun.retreive_data()){ if (nun.getC() ==1) { showPauseMenu(lcd); } //if nunchuck is tilted right, increment x if(nun.getAccX() > 148 || nun.getJoyX() > 150){ if(movCounter == 0){ removeCar(lcd, x, 12); if(x<4){ x++; } movCounter++; }else{ movCounter++; if(movCounter>=pSensitivity){ movCounter = 0; } } drawCar(lcd, x, 12, colored); } //draw car at x location //if nunchuck is tilted left, substract 1 from x else if((nun.getAccX() > 70 && nun.getAccX() < 108) || nun.getJoyX() < 90){ if(movCounter==0){ removeCar(lcd, x, 12); if(x>0){ x--; } movCounter++; }else{ movCounter++; if(movCounter>=pSensitivity){ movCounter = 0; } } //draw car at x location drawCar(lcd, x, 12, colored); //if nunchuck is in middle, movCounter = 0 }else if(nun.getAccX() > 120 && nun.getAccX() < 136){ movCounter = 0; } lcd.drawInteger(22, 2, score, DEC, GRASSCOLOR, BACKGROUND, 1); } } }
//shows the objects on screen - this loop is a example loop on how to print the objects! void showGenObjects(MI0283QT9 lcd){ if(!onBeginB){ initGenObjects(); onBeginB = 1; } //_delay_ms(150); /* If you select hard mode the cars/trucks you have to dodge move on the x position. If the car/truck is on position 4 the car/truck will go left. If the car/truck is on position 0 the cars/trucks will go right. Otherwise the will go to a random direction. */ if(hard == 1 && (posYobj1 % 12) == 0){ uint8_t operatordefine; if(object[0].posX == 4){ object[0].posX--; }else if(object[0].posX == 0){ object[0].posX++; }else if(object[0].posX != 0 && object[0].posX != 4){ operatordefine = rand() % 2 + 1; if(operatordefine == 1){ object[0].posX++; }else{ object[0].posX--; } } if(object[1].posX == 4){ object[1].posX--; }else if(object[1].posX == 0){ object[1].posX++; }else if(object[1].posX != 0 && object[1].posX != 4){ operatordefine = rand() % 2 + 1; if(operatordefine == 1){ object[1].posX++; }else{ object[1].posX--; } } if(object[2].posX == 4){ object[2].posX--; }else if(object[2].posX == 0){ object[2].posX++; }else if(object[2].posX != 0 && object[1].posX != 4){ operatordefine = rand() % 2 + 1; if(operatordefine == 1){ object[2].posX++; }else{ object[2].posX--; } } } uint8_t yCompare = GRIDYLENGTH + 9; uint8_t rgbcolor[] = {255,255,255}; if(posYobj1 == yCompare){ posYobj1 = 0; removeTruck(lcd, prevposXobj1, object[0].posY); genNewObjects(0); } else if(posYobj2 == yCompare){ posYobj2 = 0; keepObj2Alive = 0; removeTruck(lcd, prevposXobj2, object[1].posY); genNewObjects(1); } else if(posYobj3 == yCompare){ posYobj3 = 0; keepObj3Alive = 0; removeTruck(lcd, prevposXobj3, object[2].posY); genNewObjects(2); } if(object[0].type == 1){ removeCar(lcd, prevposXobj1, object[0].posY); drawCar(lcd, object[0].posX, posYobj1, object[0].rgb); object[0].posY = posYobj1; } else { removeTruck(lcd, prevposXobj1, object[0].posY); drawTruck(lcd, object[0].posX, posYobj1, object[0].rgb); object[0].posY = posYobj1; } posYobj1++; if(posYobj1 > 6 || keepObj2Alive){ posYobj2++; keepObj2Alive = 1; if(object[1].type == 1){ if(posYobj2 < 128){ removeCar(lcd, prevposXobj2, object[1].posY); drawCar(lcd, object[1].posX, posYobj2, object[1].rgb); object[1].posY = posYobj2; } } else { if(posYobj2 < 128){ removeTruck(lcd, prevposXobj2, object[1].posY); drawTruck(lcd, object[1].posX, posYobj2, rgbcolor); object[1].posY = posYobj2; } } } if(posYobj1 > 12 || keepObj3Alive){ posYobj3++; keepObj3Alive = 1; if(object[2].type == 1){ if(posYobj3 < 128){ removeCar(lcd, prevposXobj3, object[2].posY); drawCar(lcd, object[2].posX, posYobj3, object[2].rgb); object[2].posY = posYobj3; } } else { if(posYobj3 < 128){ removeTruck(lcd, prevposXobj3, object[2].posY); drawTruck(lcd, object[2].posX, posYobj3, object[2].rgb); object[2].posY = posYobj3; } } } prevposXobj1 = object[0].posX; prevposXobj2 = object[1].posX; prevposXobj3 = object[2].posX; }