diff --git a/CMakeLists.txt b/CMakeLists.txt index bf4215f..e192ff6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ set(ASSETS_cg assets-cg/backgrnd/canyon.png assets-cg/backgrnd/rockline.png assets-cg/backgrnd/snowmount.png + assets-cg/backgrnd/treelinesnow.png assets-cg/backgrnd/kilimandjaro.png assets-cg/billboard/leftturn.png diff --git a/CppOutRun.layout b/CppOutRun.layout index 86e163c..f1f0f35 100644 --- a/CppOutRun.layout +++ b/CppOutRun.layout @@ -2,40 +2,23 @@ - + - - - - - - - - - - - - - - - - + - + + + + - - - - - - + - + @@ -45,44 +28,60 @@ - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + - + + + + + + - + - - - - - - - - - - - + @@ -90,36 +89,44 @@ - + - + - - - - + - + - + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/assets-cg/backgrnd/treelinesnow.png b/assets-cg/backgrnd/treelinesnow.png new file mode 100644 index 0000000..de9151c Binary files /dev/null and b/assets-cg/backgrnd/treelinesnow.png differ diff --git a/assets-cg/decos/africa/af_bigleaf.png b/assets-cg/decos/africa/af_bigleaf.png index b5419c9..20e4d82 100755 Binary files a/assets-cg/decos/africa/af_bigleaf.png and b/assets-cg/decos/africa/af_bigleaf.png differ diff --git a/assets-cg/fonts/speedfont.png b/assets-cg/fonts/speedfont.png index 85032dd..ba55baa 100644 Binary files a/assets-cg/fonts/speedfont.png and b/assets-cg/fonts/speedfont.png differ diff --git a/assets-cg/hud/speedhud.png b/assets-cg/hud/speedhud.png index a997b2e..9572aad 100644 Binary files a/assets-cg/hud/speedhud.png and b/assets-cg/hud/speedhud.png differ diff --git a/src/include/circuit.h b/src/include/circuit.h index cbba898..6678cb8 100644 --- a/src/include/circuit.h +++ b/src/include/circuit.h @@ -63,7 +63,7 @@ void initData( void ); void createCircuit( int circuitNumber ); void putBillBoards( void ); void createClouds( void ); -void createTraffic( void ); +void createTraffic( uint16_t maxSegment ); void projectCircuitFP( void ); void projectCircuitFP( uint16_t index ); @@ -76,7 +76,7 @@ void printCircuit( int i ); void drawCircuitSegment( uint16_t index ); void drawDecoration( uint16_t index ); void drawTraffic( uint16_t index ); -void drawClouds( int offset ); +void drawClouds( void ); void drawFarBackground( int offset, int currentbiome ); void drawNearBackground( int offset, int currentbiome ); diff --git a/src/include/segment.h b/src/include/segment.h index e2da4ce..fc4bd6f 100644 --- a/src/include/segment.h +++ b/src/include/segment.h @@ -38,6 +38,7 @@ class Segment int8_t Environment = PLAINS; int8_t Special = 0; + bool CheckValidated = false; int8_t Curve=0; int8_t Slope=0; diff --git a/src/main.cc b/src/main.cc index 9f22349..801d0c0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -25,21 +26,12 @@ #include "include/menus.h" -//extern bopti_image_t car1, car2, car3, car4, car5, car6, car7, car8; -//extern bopti_image_t tree1, tree2, tree3, tree4, tree5, tree6; -//extern bopti_image_t leftturn, rightturn, uphill, downhill; -//extern bopti_image_t checkpoint, startlights, stoplights, waitlights; extern bopti_image_t player; -//extern bopti_image_t sky1, sky2, sky3; -//extern bopti_image_t mountain, treeline; -//extern bopti_image_t mainscreen; extern font_t speedfont; extern bopti_image_t speedhud; - int CurrentCircuitBiome = PLAINS; - std::vector circuit; std::vector nuages; std::vector traffic; @@ -64,6 +56,7 @@ bool BDrawRoad = true; uint16_t currentcurve=0; uint8_t shiftcolor=0; + float speed = 0.0; float maxspeedforward = 5.0; float maxspeedbackward = 2.0; @@ -98,17 +91,29 @@ static void get_inputs( float dt, int index ) if (CC<0) { viewside=-1; - cam->decX( CC*dt*speed/100 ); + + //cam->decX( CC*dt*speed/100 ); + + if (CurrentCircuitBiome==FINLAND) cam->decX( CC*dt*speed/50 ); // very hard to turn in Finland with snow + else if (CurrentCircuitBiome==AFRICA) cam->decX( CC*dt*speed/75 ); // hard in Africa with dirt + else cam->decX( CC*dt*speed/100 ); // more easy on normal roads } else if (CC>0) { viewside=+1; - cam->decX( CC*dt*speed/100 ); + + //cam->decX( CC*dt*speed/100 ); + + if (CurrentCircuitBiome==FINLAND) cam->decX( CC*dt*speed/50 ); // very hard to turn in Finland with snow + else if (CurrentCircuitBiome==AFRICA) cam->decX( CC*dt*speed/75 ); // hard in Africa with dirt + else cam->decX( CC*dt*speed/100 ); // more easy on normal roads } if(keydown(KEY_LEFT)) { - cam->decX(25.0); + //cam->decX(25.0); + cam->decX(5.0*speed*direction); + viewside=-1; if (CC<0) viewside=-2; // We are in a curve and turning if (CC>0) viewside=0; @@ -116,13 +121,15 @@ static void get_inputs( float dt, int index ) if(keydown(KEY_RIGHT)) { - cam->incX(25.0); + //cam->incX(25.0); + cam->incX(5.0*speed*direction); + viewside=1; if (CC>0) viewside=+2; if (CC<0) viewside=0; } - if(keydown(KEY_SHIFT)) + if(keydown(KEY_SHIFT)) // Accelerates { if (direction==-1 && speed > 0) { @@ -142,7 +149,7 @@ static void get_inputs( float dt, int index ) speedcontrol = true; } - if(keydown(KEY_ALPHA)) + if(keydown(KEY_ALPHA)) // breaks or rear if speed <0 { if (direction==1 && speed > 0) { @@ -202,7 +209,7 @@ static void get_inputs( float dt, int index ) if (speedcontrol==false) { - speed-=0.3; + speed-=0.1; if (speed<0) speed=0; if (direction==1) @@ -227,12 +234,12 @@ static void get_inputs( float dt, int index ) if (fround(cam->cX)<-1.35*ROAD_WIDTH && speed>0.0) { speed=0.0; - cam->cX=fix(-0.75*ROAD_WIDTH); + cam->cX=fix(-0.0*ROAD_WIDTH); //set the car in the center of the road (was formerly -0.75) } if (fround(cam->cX)>1.35*ROAD_WIDTH && speed>0.0) { speed=0.0; - cam->cX=fix(0.75*ROAD_WIDTH); + cam->cX=fix(0.0*ROAD_WIDTH); //set the car in the center of the road (was formerly 0.75) } } @@ -248,7 +255,7 @@ int main(void) #endif - + srand( rtc_ticks() ); prof_init(); @@ -264,7 +271,7 @@ int main(void) int32_t start_time = 99000000; uint32_t score=99999; uint8_t stage=0; - uint8_t selectedCircuit=0; + int8_t selectedCircuit=0; uint32_t time_update=0, time_create=0, time_project=0, time_render=0; @@ -327,10 +334,14 @@ int main(void) initData( ); // Positioning of the Camera createCircuit( selectedCircuit ); // Creates the circuit + MAX_SEGMENT = circuit.size(); + uint32_t maxDistance = (MAX_SEGMENT-nbInterestingSegments-5)*SEGMENT_LENGTH; + putBillBoards(); createClouds(); // Creates the Sky and Clouds - createTraffic(); // Creates the cars + createTraffic( MAX_SEGMENT ); // Creates the cars + prepareDecoration( CurrentCircuitBiome ); // Prepares the multiple variations of Decoration (image scaling) prepareTraffic(); // Prepares the multiple variations of Cars (image scaling) @@ -338,14 +349,14 @@ int main(void) time_create = prof_time(perf_create); //-------------- - MAX_SEGMENT = circuit.size(); + int indexstart = 0; int indexend = 0; - uint32_t maxDistance = (MAX_SEGMENT-nbInterestingSegments-5)*SEGMENT_LENGTH; - uint32_t dt=0; + + float dt=0; uint16_t l=0; uint32_t remaining_time; @@ -387,7 +398,7 @@ int main(void) { updateTraffic( dt, maxDistance ); - for (int k=0; kwZ / SEGMENT_LENGTH; if (CarSegment>=indexstart && CarSegmentCarList.size(); l++ ) // For all cars inside that road segment + for(unsigned int l=0; lCarList.size(); l++ ) // For all cars inside that road segment { uint8_t indexCar = circuit[indexstart]->CarList[l]; @@ -419,11 +430,11 @@ int main(void) if (BDrawCars) - for( int l=0; lCarList.size(); l++ ) // For all cars inside that road segment + for( unsigned int l=0; lCarList.size(); l++ ) // For all cars inside that road segment { uint8_t indexCar = circuit[indexstart+1]->CarList[l]; - if (traffic[indexCar]->wX>(roadpart-0.15f) && traffic[indexCar]->wX<(roadpart+0.15f) && traffic[indexCar]->SpeedwX>(roadpart-0.20f) && traffic[indexCar]->wX<(roadpart+0.20f) && traffic[indexCar]->SpeedCurve; if (BDrawCars) - for( int l=0; lCarList.size(); l++ ) // For all cars inside that road segment + for( unsigned int l=0; lCarList.size(); l++ ) // For all cars inside that road segment { uint8_t indexCar = circuit[k]->CarList[l]; traffic[indexCar]->Project3DFP( cam, k ); @@ -462,7 +473,7 @@ int main(void) drawSky( DAY_BLUE_SKY ); if (BDrawClds) - drawClouds( l % 396 ); + drawClouds( ); drawFarBackground( deltaFarbackground, CurrentCircuitBiome ); drawNearBackground( deltaNearbackground, CurrentCircuitBiome ); @@ -480,7 +491,7 @@ int main(void) drawDecoration( k ); if (BDrawCars) - for( int l=0; lCarList.size(); l++ ) // For all cars inside that road segment + for( unsigned int l=0; lCarList.size(); l++ ) // For all cars inside that road segment { uint8_t indexCar = circuit[k]->CarList[l]; drawTraffic( indexCar ); @@ -489,6 +500,11 @@ int main(void) circuit[k]->CarList.clear(); } + if (circuit[indexstart]->Special == CHECKPOINT && circuit[indexstart]->CheckValidated == false) + { + start_time+=60000000; + circuit[indexstart]->CheckValidated = true; + } int mod_base=20; int mod_comp=10; @@ -532,6 +548,7 @@ int main(void) dsubimage( 245, 5, &speedhud, 37, 117, 38, 13, DIMAGE_NONE); // speed logo dsubimage( 245, 25, &speedhud, 37, 130, 38, 13, DIMAGE_NONE); // timer logo + dsubimage( 5, 205, &speedhud, 0, 143, 27, 13, DIMAGE_NONE); // fps logo dfont(&speedfont); if (drawspeed==0.0) @@ -567,6 +584,13 @@ int main(void) //dupdate(); + + //dprint( 3, 202, C_BLACK, "%.0f", dt ); + //dprint( 1, 200, C_WHITE, "%.0f", dt ); + + dprint_opt(42,202, C_RGB(0,0,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "%.0f <", (float) (1000.0f/dt) ); // the '>' symbol corresponds to "fps" + dprint_opt(40,200, C_RGB(255,255,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "%.0f <", (float) (1000.0f/dt) ); + r61524_display(gint_vram, 0, DHEIGHT, R61524_DMA_WAIT); diff --git a/src/parameters.h b/src/parameters.h index 83c2cf2..d8852dc 100644 --- a/src/parameters.h +++ b/src/parameters.h @@ -19,7 +19,7 @@ #define NB_CLOUDS_SKY 10 -#define NB_CARS_TRAFFIC 100 +#define NB_CARS_TRAFFIC 200 #define MAX_SUBIMAGES_TREES 12 #define NB_TREES_TYPES 15 diff --git a/src/src/circuit.cc b/src/src/circuit.cc index 37b6e6a..fb4e142 100644 --- a/src/src/circuit.cc +++ b/src/src/circuit.cc @@ -32,7 +32,7 @@ extern bopti_image_t cc_void, us_bigleaf, us_smallleaf, cc_bigleaf, cc_smallleaf extern bopti_image_t sky1, sky2, sky3; extern bopti_image_t mountain, canyon, snowmount, kilimandjaro; -extern bopti_image_t treeline, rockline; +extern bopti_image_t treeline, rockline, treelinesnow; extern bopti_image_t leftturn, rightturn, uphill, downhill; extern bopti_image_t checkpoint, startlights, stoplights, waitlights; @@ -514,17 +514,15 @@ void createClouds( void ) } -void createTraffic( void ) +void createTraffic( uint16_t maxSegment ) { - srand( rtc_ticks() ); - for( int k = 0; k < NB_CARS_TRAFFIC; k++) { int8_t X = rand() % 4; - //double Z = (double) (rand() % 4000); + double Z = (double) (SEGMENT_LENGTH * (rand() % (maxSegment-5)) + 10.0); //int8_t X = 0; - double Z = (k+1)*SEGMENT_LENGTH; - uint8_t S = 4 + (rand() % 2); + //double Z = (k+1)*SEGMENT_LENGTH; + uint8_t S = 2 + (rand() % 3); uint8_t T = rand() % 8; Cars* car; @@ -540,6 +538,17 @@ void createTraffic( void ) } } + +inline int getRandom( int8_t biome ) +{ + //Needed to generate integer between -1 and +6; + int a = (rand() % 15)-8; + if (a<0) a=-1; // we clamp a to above -1; + + return a; +} + + void addCheckPoint( int8_t biome ) { double lastZ=0; @@ -690,22 +699,20 @@ void addStraightLine( Length l, int8_t biome ) lastZ=circuit[lastIndex-1]->wZ+SEGMENT_LENGTH; } - srand( rtc_ticks() ); - for( int i=0; iwZ+SEGMENT_LENGTH; } - srand( rtc_ticks() ); - for( int i=0; iwZ+SEGMENT_LENGTH; } - srand( rtc_ticks() ); - for( int i=0; iwZ+SEGMENT_LENGTH; } - srand( rtc_ticks() ); - for( int i=0; iX - image->width/2; int Y = traffic[index]->Y - image->height; - dimage( X, Y, image ); + + //dimage( X, Y, image ); + if (distance!=0) dimage( X, Y, image ); } -void drawClouds( int offset ) +void drawClouds( void ) { bopti_image_t *cloud; - for( int k =0; kType==0) cloud=&sky1; else if (nuages[k]->Type==1) cloud=&sky2; @@ -1302,6 +1308,7 @@ void drawFarBackground( int offset, int currentbiome ) else if (currentbiome==USA) image=&canyon; else if (currentbiome==FINLAND) image=&snowmount; else if (currentbiome==AFRICA) image=&kilimandjaro; + else image=&mountain; int X = offset; int DX = image->width; @@ -1327,9 +1334,9 @@ void drawNearBackground( int offset, int currentbiome ) if (currentbiome==PLAINS) image=&treeline; else if (currentbiome==DESERT) image=&rockline; else if (currentbiome==USA) image=&rockline; - else if (currentbiome==FINLAND) image=&cc_void; + else if (currentbiome==FINLAND) image=&treelinesnow; else if (currentbiome==AFRICA) image=&cc_void; - + else image=&treeline; int X = offset; int DX = image->width; diff --git a/src/src/menus.cc b/src/src/menus.cc index b04a567..5903e7a 100644 --- a/src/src/menus.cc +++ b/src/src/menus.cc @@ -1,6 +1,10 @@ #include "../include/menus.h" #include #include +#include "../parameters.h" + +#include +#include extern bopti_image_t mainscreen; @@ -8,6 +12,9 @@ extern bopti_image_t africa1, desert1, finland1, plains1, usa1; extern bopti_image_t flag, linear, circular; extern font_t autofont, autofontsmall; +extern bool record; +extern bool screenshot; + bool doneTitle = false; @@ -15,7 +22,7 @@ bool doneMainMenu = false; uint8_t MainMenuSelection=0; bool doneMenuCircuit = false; -uint8_t CircuitSelection=0; +int8_t CircuitSelection=0; bool doneMenuCredit = false; @@ -44,6 +51,19 @@ void drawStartTitle( void ) pulse++; getInputStartTitle(); + +#if IS_FXLIB==1 + if (screenshot && usb_is_open()) + { + usb_fxlink_screenshot(false); + screenshot = false; + } + + if(record && usb_is_open()) + { + usb_fxlink_videocapture(false); + } +#endif } } @@ -55,12 +75,18 @@ void getInputStartTitle( void ) while(1) { key_event_t ev = getkey_opt(opt, &timeout); - if(ev.type == KEYEV_NONE) return -1; + if(ev.type == KEYEV_NONE) return; int key = ev.key; if (key==KEY_EXE) doneTitle = true; + +#if IS_FXLIB==1 + if(keydown(KEY_F5)) screenshot = true; + if(keydown(KEY_F6)) record = !record; +#endif // IS_FXLIB + } } @@ -110,6 +136,19 @@ int drawMainMenu( void ) pulse++; getInputMainMenu(); + +#if IS_FXLIB==1 + if (screenshot && usb_is_open()) + { + usb_fxlink_screenshot(false); + screenshot = false; + } + + if(record && usb_is_open()) + { + usb_fxlink_videocapture(false); + } +#endif } return MainMenuSelection; @@ -123,7 +162,7 @@ void getInputMainMenu( void ) while(1) { key_event_t ev = getkey_opt(opt, &timeout); - if(ev.type == KEYEV_NONE) return -1; + if(ev.type == KEYEV_NONE) return; int key = ev.key; @@ -141,6 +180,10 @@ void getInputMainMenu( void ) if (MainMenuSelection==4) MainMenuSelection=0; else MainMenuSelection++; } +#if IS_FXLIB==1 + if(keydown(KEY_F5)) screenshot = true; + if(keydown(KEY_F6)) record = !record; +#endif // IS_FXLIB } } @@ -277,6 +320,19 @@ int drawMenuCircuitSelect( void ) pulse++; getInputCircuitSelect(); +#if IS_FXLIB==1 + if (screenshot && usb_is_open()) + { + usb_fxlink_screenshot(false); + screenshot = false; + } + + if(record && usb_is_open()) + { + usb_fxlink_videocapture(false); + } +#endif + if (CircuitSelection==-1) return -1; } @@ -291,7 +347,7 @@ void getInputCircuitSelect( void ) while(1) { key_event_t ev = getkey_opt(opt, &timeout); - if(ev.type == KEYEV_NONE) return -1; + if(ev.type == KEYEV_NONE) return; int key = ev.key; @@ -313,6 +369,11 @@ void getInputCircuitSelect( void ) if (CircuitSelection==9) CircuitSelection=0; else CircuitSelection++; } + +#if IS_FXLIB==1 + if(keydown(KEY_F5)) screenshot = true; + if(keydown(KEY_F6)) record = !record; +#endif // IS_FXLIB } } @@ -370,6 +431,19 @@ void drawCredit( void ) dupdate(); +#if IS_FXLIB==1 + if (screenshot && usb_is_open()) + { + usb_fxlink_screenshot(false); + screenshot = false; + } + + if(record && usb_is_open()) + { + usb_fxlink_videocapture(false); + } +#endif + pulse++; offset--; getInputCredit(); @@ -386,12 +460,17 @@ void getInputCredit( void ) while(1) { key_event_t ev = getkey_opt(opt, &timeout); - if(ev.type == KEYEV_NONE) return -1; + if(ev.type == KEYEV_NONE) return; int key = ev.key; if (key==KEY_EXE) doneMenuCredit = true; + +#if IS_FXLIB==1 + if(keydown(KEY_F5)) screenshot = true; + if(keydown(KEY_F6)) record = !record; +#endif // IS_FXLIB } }