AI of opponents - First tests

This commit is contained in:
Sylvain PILLOT 2022-03-26 23:32:26 +01:00
parent d73a41fa99
commit 3b91065004
20 changed files with 560 additions and 214 deletions

View File

@ -18,6 +18,7 @@ set(SOURCES
src/src/clouds.cc
src/src/cars.cc
src/src/menus.cc
src/src/utils.cc
)
set(ASSETS_cg
@ -90,7 +91,7 @@ set(ASSETS_cg
assets-cg/fonts/auto20.png
assets-cg/fonts/startseq.png
assets-cg/fonts/plate5.png
assets-cg/menus/flag.png
assets-cg/menus/bigflag.png

View File

@ -38,6 +38,7 @@
<Unit filename="src/include/drawstuff.h" />
<Unit filename="src/include/menus.h" />
<Unit filename="src/include/segment.h" />
<Unit filename="src/include/utils.h" />
<Unit filename="src/main.cc" />
<Unit filename="src/parameters.h" />
<Unit filename="src/src/camera.cc" />
@ -47,6 +48,7 @@
<Unit filename="src/src/drawstuff.cc" />
<Unit filename="src/src/menus.cc" />
<Unit filename="src/src/segment.cc" />
<Unit filename="src/src/utils.cc" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>

View File

@ -2,109 +2,36 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="src/include/camera.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src/main.cc" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="221" topLine="0" />
</Cursor>
</File>
<File name="src/colors.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="35" topLine="0" />
</Cursor>
</File>
<File name="src/include/clouds.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="306" topLine="0" />
</Cursor>
</File>
<File name="src/src/menus.cc" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="20917" topLine="638" />
</Cursor>
</File>
<File name="src/src/cars.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1019" topLine="8" />
</Cursor>
</File>
<File name="src/src/clouds.cc" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="203" topLine="0" />
</Cursor>
</File>
<File name="src/src/segment.cc" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
<Cursor>
<Cursor1 position="230" topLine="30" />
</Cursor>
</File>
<File name="src/parameters.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="559" topLine="0" />
</Cursor>
</File>
<File name="src/include/drawstuff.h" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="637" topLine="0" />
</Cursor>
</File>
<File name="src/include/circuit.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1291" topLine="0" />
</Cursor>
</File>
<File name="src/src/drawstuff.cc" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2603" topLine="18" />
</Cursor>
<Folding>
<Collapse line="9" />
<Collapse line="33" />
<Collapse line="40" />
<Collapse line="46" />
<Collapse line="76" />
<Collapse line="126" />
</Folding>
</File>
<File name="src/main.cc" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="24886" topLine="745" />
</Cursor>
</File>
<File name="src/include/menus.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="390" topLine="0" />
<Cursor1 position="8620" topLine="378" />
</Cursor>
</File>
<File name="src/src/circuit.cc" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="10565" topLine="282" />
<Cursor1 position="210" topLine="0" />
</Cursor>
<Folding>
<Collapse line="588" />
<Collapse line="604" />
<Collapse line="629" />
<Collapse line="639" />
<Collapse line="684" />
<Collapse line="720" />
<Collapse line="730" />
<Collapse line="777" />
<Collapse line="812" />
<Collapse line="850" />
<Collapse line="887" />
<Collapse line="1179" />
<Collapse line="1186" />
<Collapse line="1196" />
<Collapse line="1206" />
<Collapse line="498" />
<Collapse line="514" />
<Collapse line="539" />
<Collapse line="549" />
<Collapse line="594" />
<Collapse line="630" />
<Collapse line="640" />
<Collapse line="687" />
<Collapse line="722" />
<Collapse line="760" />
<Collapse line="797" />
<Collapse line="1089" />
<Collapse line="1096" />
<Collapse line="1106" />
<Collapse line="1116" />
</Folding>
</File>
<File name="TODO.txt" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src/include/clouds.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="251" topLine="0" />
</Cursor>
</File>
<File name="CMakeLists.txt" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2421" topLine="36" />
<Cursor1 position="306" topLine="0" />
</Cursor>
</File>
<File name="src/fixed.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -112,9 +39,27 @@
<Cursor1 position="5" topLine="0" />
</Cursor>
</File>
<File name="src/include/segment.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src/src/cars.cc" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="252" topLine="9" />
<Cursor1 position="1019" topLine="8" />
</Cursor>
</File>
<File name="src/src/drawstuff.cc" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2807" topLine="14" />
</Cursor>
<Folding>
<Collapse line="9" />
<Collapse line="33" />
<Collapse line="40" />
<Collapse line="46" />
<Collapse line="76" />
<Collapse line="131" />
</Folding>
</File>
<File name="src/include/utils.h" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="107" topLine="0" />
</Cursor>
</File>
<File name="src/include/cars.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -122,9 +67,91 @@
<Cursor1 position="332" topLine="0" />
</Cursor>
</File>
<File name="src/src/utils.cc" open="1" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="30" topLine="0" />
</Cursor>
</File>
<File name="src/src/clouds.cc" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="203" topLine="0" />
</Cursor>
</File>
<File name="src/parameters.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="559" topLine="0" />
</Cursor>
</File>
<File name="src/include/segment.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="252" topLine="9" />
</Cursor>
</File>
<File name="TODO.txt" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="251" topLine="0" />
</Cursor>
</File>
<File name="src/src/menus.cc" open="1" top="1" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="33866" topLine="179" />
</Cursor>
<Folding>
<Collapse line="61" />
<Collapse line="99" />
<Collapse line="125" />
<Collapse line="190" />
<Collapse line="226" />
<Collapse line="238" />
<Collapse line="375" />
<Collapse line="417" />
<Collapse line="488" />
<Collapse line="511" />
<Collapse line="626" />
<Collapse line="669" />
<Collapse line="781" />
<Collapse line="873" />
<Collapse line="935" />
</Folding>
</File>
<File name="src/include/drawstuff.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="655" topLine="0" />
</Cursor>
</File>
<File name="src/include/menus.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="510" topLine="0" />
</Cursor>
</File>
<File name="src/include/camera.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="221" topLine="0" />
</Cursor>
</File>
<File name="src/src/camera.cc" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="370" topLine="0" />
</Cursor>
</File>
<File name="src/colors.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="35" topLine="0" />
</Cursor>
</File>
<File name="src/src/segment.cc" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
<Cursor>
<Cursor1 position="230" topLine="30" />
</Cursor>
</File>
<File name="src/include/circuit.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1291" topLine="0" />
</Cursor>
</File>
<File name="CMakeLists.txt" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="448" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@ -25,6 +25,8 @@ class Cars
uint8_t Speed;
uint8_t Type;
int8_t Turn=0;
//uint8_t DScale;
// for debugging only

View File

@ -24,4 +24,7 @@ void drawPauseQuit( void );
void getInputPauseQuit( void );
int drawMenuCircuitDetails( int circuit, int mode );
void getInputCircuitDetails( void );
#endif // MENUS_H

20
src/include/utils.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef UTILS_H
#define UTILS_H
#include <gint/display.h>
#include <gint/std/stdlib.h>
#include <string.h>
size_t image_size_profile(int profile, int width, int height);
size_t image_size(bopti_image_t const *img);
int get_pixel(bopti_image_t const *img, int x, int y);
void set_pixel(bopti_image_t *img, int x, int y, int color);
bopti_image_t *resize(bopti_image_t const *src, int w, int h);
#endif // UTILS_H

View File

@ -57,6 +57,7 @@ struct DataPerf
DataPerf GraphPerf[ MAXDATA ];
unsigned int DataIndex=0;
uint8_t NB_CARS_TRAFFIC=200;
bool stop = false;
bool exitToOS = false;
@ -106,7 +107,6 @@ int CS=0;
void initEverything( void )
{
CurrentCircuitBiome = PLAINS;
@ -371,7 +371,7 @@ int main(void)
int32_t start_time = 100000000;
uint32_t score=0;
uint8_t stage=0;
int8_t selectedCircuit=0;
int8_t selectedCircuit=0, secondvalidation=0;
uint32_t time_update=0, time_create=0, time_project=0, time_render=0;
@ -386,10 +386,19 @@ int main(void)
exitflag = false;
stage = drawMainMenu();
if (stage==0 || stage==1)
if (stage==0)
{
selectedCircuit = drawMenuCircuitSelect();
if (selectedCircuit != -1) exitflag=true;
if (selectedCircuit != -1) secondvalidation = drawMenuCircuitDetails( selectedCircuit, 0 );
if (selectedCircuit != -1 && secondvalidation != -1) exitflag=true;
}
else if (stage==1)
{
selectedCircuit = drawMenuCircuitSelect();
if (selectedCircuit != -1) secondvalidation = drawMenuCircuitDetails( selectedCircuit, 1 );
if (selectedCircuit != -1 && secondvalidation != -1) exitflag=true;
}
else if (stage==2)
{
@ -562,8 +571,8 @@ int main(void)
if (traffic[indexCar]->wX>(roadpart-0.25f) && traffic[indexCar]->wX<(roadpart+0.25f) && traffic[indexCar]->Speed>speed)
{
if (traffic[indexCar]->wX>-0.25) traffic[indexCar]->wX-=0.5; // if we are on one of the most right lanes, we overtake by the left
else traffic[indexCar]->wX=-0.25; // else we change to the lane on the right
if (traffic[indexCar]->wX>=-0.25) traffic[indexCar]->wX-=0.5; // if we are on one of the most right lanes, we overtake by the left
else traffic[indexCar]->wX<-0.25; // else we change to the lane on the right
}
}
@ -571,11 +580,97 @@ int main(void)
{
uint8_t indexCar = circuit[indexstart+1]->CarList[l];
if (traffic[indexCar]->wX>(roadpart-0.20f) && traffic[indexCar]->wX<(roadpart+0.20f) && traffic[indexCar]->Speed<speed)
if (traffic[indexCar]->wX>(roadpart-0.22f) && traffic[indexCar]->wX<(roadpart+0.22f) && traffic[indexCar]->Speed<speed)
{
speed = 2.0;
speed = traffic[indexCar]->Speed - 0.5;
}
}
if (DiffLevel>=1) // Normal or Hard : cars can overtake the other opponents
{
for( unsigned int k=indexstart; k<indexend; k++)
{
for( unsigned int l=0; l<circuit[k]->CarList.size(); l++ ) // For all cars inside that road segment
{
uint8_t indexCar = circuit[k]->CarList[l];
for( unsigned int m=0; m<circuit[k+1]->CarList.size(); m++ )
{
uint8_t indexCar2 = circuit[k+1]->CarList[m];
if (traffic[indexCar]->wX==traffic[indexCar2]->wX && traffic[indexCar]->Speed>=traffic[indexCar2]->Speed) // a car is following and other one just in front of ehr, at the same speed or quicker
{
//if (traffic[indexCar]->wX>=-0.25) traffic[indexCar]->wX-=0.5;
//else traffic[indexCar]->wX=-0.25;
if (traffic[indexCar]->wX>=-0.25) traffic[indexCar]->Turn = -1;
else traffic[indexCar]->Turn = +1;
}
}
}
}
if (DiffLevel==2) // if difficulty set to hard, we allo changing lane (random based if not currently overtaking an other car)
{
for (unsigned int u=indexstart; u<indexend; u++)
{
for (unsigned int v=0; v<circuit[u]->CarList.size(); v++)
{
unsigned int k = circuit[u]->CarList[v];
if (traffic[k]->Turn == 0)
{
int mov = rand() % 100;
if (mov>=95) // we let the car change its lane in 5% of cases
{
if (traffic[k]->wX==-0.75) traffic[k]->Turn = +1;
else if (traffic[k]->wX==0.75) traffic[k]->Turn = -1;
else
{
int side = -1 + (rand()%3);
traffic[k]->Turn = side;
}
}
}
}
}
}
for (unsigned int u=indexstart; u<indexend; u++)
{
for (unsigned int v=0; v<circuit[u]->CarList.size(); v++)
{
unsigned int k = circuit[u]->CarList[v];
/*
if (traffic[k]->Turn == -1)
{
traffic[k]->wX -= 0.10;
if (traffic[k]->wX==-0.75 || traffic[k]->wX==-0.25 || traffic[k]->wX==0.25) traffic[k]->Turn = 0;
}
else if (traffic[k]->Turn == 1)
{
traffic[k]->wX += 0.10;
if (traffic[k]->wX==-0.25 || traffic[k]->wX==0.25 || traffic[k]->wX==0.75) traffic[k]->Turn = 0;
}
*/
traffic[k]->wX += (float) traffic[k]->Turn * 0.10f;
if (traffic[k]->wX>=-0.80 && traffic[k]->wX<=-0.70) traffic[k]->wX = -0.75, traffic[k]->Turn = 0;
else if (traffic[k]->wX>=-0.30 && traffic[k]->wX<=-0.20) traffic[k]->wX = -0.25, traffic[k]->Turn = 0;
else if (traffic[k]->wX>=0.20 && traffic[k]->wX<=0.30) traffic[k]->wX = 0.25, traffic[k]->Turn = 0;
else if (traffic[k]->wX>=0.70 && traffic[k]->wX<=0.80) traffic[k]->wX = 0.75, traffic[k]->Turn = 0;
}
}
}
}
uint16_t cumulCurve=0;
@ -627,7 +722,7 @@ int main(void)
}
cam->cY = fix( 300+2*CS ) + interpolatePositionY(fround(cam->cZ) );
cam->cY = fix( 350+2*CS ) + interpolatePositionY(fround(cam->cZ) );
for( int k=indexend-1; k>=indexstart; k--)
{

View File

@ -19,7 +19,6 @@
#define NB_CLOUDS_SKY 10
#define NB_CARS_TRAFFIC 200
#define MAX_SUBIMAGES_TREES 12
#define NB_TREES_TYPES 15

View File

@ -12,7 +12,9 @@
#include "../include/drawstuff.h"
#include "../colors.h"
#include "../include/utils.h"
extern uint8_t NB_CARS_TRAFFIC;
extern std::vector<Segment*> circuit;
extern std::vector<Clouds*> nuages;
@ -43,105 +45,14 @@ bopti_image_t *scaledCars[NB_CARS_TYPES][MAX_SUBIMAGES_CARS] = { 0 };
extern int CurrentCircuitBiome;
size_t image_size_profile(int profile, int width, int height)
{
size_t size = sizeof(bopti_image_t);
if(profile == 0 || profile == 1) // PX_RGB565, PX_RGB565A
size += width * height * 2;
else if(profile == 2) // PX_P8
size += 512 + width * height;
else if(profile == 3) // PX_P4
size += 32 + ((width + 1) / 2) * height;
return size;
}
size_t image_size(bopti_image_t const *img)
{
return image_size_profile(img->profile, img->width, img->height);
}
int get_pixel(bopti_image_t const *img, int x, int y)
{
if((unsigned)x >= img->width || (unsigned)y >= img->height)
return 0;
uint8_t *bytes = (void *)img->data;
if(img->profile <= 1)
return img->data[y * img->width + x];
if(img->profile == 2)
return bytes[y * img->width + x + 512];
if(img->profile == 3)
{
int s = (img->width + 1) >> 1;
int i = y * s + (x >> 1) + 32;
if(x & 1)
return bytes[i] & 0x0f;
else
return bytes[i] >> 4;
}
return 0;
}
void set_pixel(bopti_image_t *img, int x, int y, int color)
{
if((unsigned)x >= img->width || (unsigned)y >= img->height)
return;
uint8_t *bytes = (void *)img->data;
if(img->profile <= 1)
img->data[y * img->width + x] = color;
else if(img->profile == 2)
bytes[y * img->width + x + 512] = color;
else if(img->profile == 3)
{
int s = (img->width + 1) >> 1;
int i = y * s + (x >> 1) + 32;
if(x & 1)
bytes[i] = (bytes[i] & 0xf0) | (color & 0x0f);
else
bytes[i] = (bytes[i] & 0x0f) | ((color & 0x0f) << 4);
}
}
bopti_image_t *resize(bopti_image_t const *src, int w, int h)
{
size_t size = image_size_profile(src->profile, w, h);
bopti_image_t *img = malloc(size);
if(!img) return NULL;
size_t palette_size = 0;
if(src->profile == 2) // PX_P8
palette_size = 512;
else if(src->profile == 3) // PX_P4
palette_size = 32;
img->profile = src->profile;
img->alpha = src->alpha;
img->width = w;
img->height = h;
memcpy(img->data, src->data, palette_size);
for(int y = 0; y < h; y++)
for(int x = 0; x < w; x++)
{
int color = get_pixel(src, x * src->width / w, y * src->height / h);
set_pixel(img, x, y, color);
}
return img;
}
extern int DiffLevel;
void initData( void )
{
cam = new camera();
cam->cX = fixdouble(0.0f);
cam->cY = fixdouble(300.0f);
cam->cY = fixdouble(350.0f);
cam->cZ = fixdouble(100.0f);
}
@ -609,7 +520,14 @@ void createTraffic( uint16_t maxSegment )
double Z = (double) (SEGMENT_LENGTH * (rand() % (maxSegment-5)) + 10.0);
//int8_t X = 0;
//double Z = (k+1)*SEGMENT_LENGTH;
uint8_t S = 2 + (rand() % 3);
uint8_t S;
// if Difficulty = easy, all cars are at the same speed 175km/h)
if (DiffLevel==0) S=3.5;
else S = 2 + (rand() % 3); // else speed is random and then overtaking can happen
uint8_t T = rand() % 8;
Cars* car;

View File

@ -5,6 +5,12 @@
#include <gint/usb.h>
#include <gint/usb-ff-bulk.h>
#include <gint/std/stdlib.h>
#include "../include/utils.h"
extern uint8_t NB_CARS_TRAFFIC;
extern bopti_image_t mainscreen;
@ -24,6 +30,9 @@ uint8_t MainMenuSelection=0;
bool doneMenuCircuit = false;
int8_t CircuitSelection=0;
bool doneMenuDetailsCircuit = false;
int8_t CircuitDetailsSelection=0;
bool doneMenuCredit = false;
bool doneOptions = false;
@ -106,8 +115,8 @@ void getInputStartTitle( void )
doneTitle = true;
#if IS_FXLIB==1
if(keydown(KEY_F5)) screenshot = true;
if(keydown(KEY_F6)) record = !record;
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif // IS_FXLIB
}
@ -208,8 +217,8 @@ void getInputMainMenu( void )
else MainMenuSelection++;
}
#if IS_FXLIB==1
if(keydown(KEY_F5)) screenshot = true;
if(keydown(KEY_F6)) record = !record;
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif // IS_FXLIB
}
}
@ -398,8 +407,8 @@ void getInputCircuitSelect( void )
}
#if IS_FXLIB==1
if(keydown(KEY_F5)) screenshot = true;
if(keydown(KEY_F6)) record = !record;
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif // IS_FXLIB
}
}
@ -495,8 +504,8 @@ void getInputCredit( void )
doneMenuCredit = true;
#if IS_FXLIB==1
if(keydown(KEY_F5)) screenshot = true;
if(keydown(KEY_F6)) record = !record;
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif // IS_FXLIB
}
}
@ -651,8 +660,8 @@ void getInputOptions( void )
}
#if IS_FXLIB==1
if(keydown(KEY_F5)) screenshot = true;
if(keydown(KEY_F6)) record = !record;
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif // IS_FXLIB
}
}
@ -767,6 +776,13 @@ void drawGameOptions( void )
#endif
}
if (CarsNumb==0) NB_CARS_TRAFFIC=50;
else if (CarsNumb==1) NB_CARS_TRAFFIC=100;
else if (CarsNumb==2) NB_CARS_TRAFFIC=200;
else NB_CARS_TRAFFIC=150;
SkipTime = true; // To avoid counting or de-counting time during menu
return;
@ -854,8 +870,8 @@ void getInputGameOptions( void )
}
#if IS_FXLIB==1
if(keydown(KEY_F5)) screenshot = true;
if(keydown(KEY_F6)) record = !record;
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif // IS_FXLIB
}
}
@ -969,8 +985,175 @@ void getInputPauseQuit( void )
}
#if IS_FXLIB==1
if(keydown(KEY_F5)) screenshot = true;
if(keydown(KEY_F6)) record = !record;
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif // IS_FXLIB
}
}
int drawMenuCircuitDetails( int circuit, int mode )
{
uint16_t pulse=0;
doneMenuDetailsCircuit = false;
CircuitDetailsSelection=0;
bopti_image_t *preview1=nullptr, *preview2=nullptr, *src1=nullptr, *src2=nullptr;
if (circuit==0) src1=&plains1, src2=&linear;
else if (circuit==1) src1=&desert1, src2=&linear;
else if (circuit==2) src1=&usa1, src2=&linear;
else if (circuit==3) src1=&finland1, src2=&linear;
else if (circuit==4) src1=&usa1, src2=&linear;
else if (circuit==5) src1=&plains1, src2=&circular;
else if (circuit==6) src1=&desert1, src2=&circular;
else if (circuit==7) src1=&usa1, src2=&circular;
else if (circuit==8) src1=&finland1, src2=&circular;
else if (circuit==9) src1=&usa1, src2=&circular;
preview1 = resize( src1, src1->width*1.5, src1->height*1.5 );
preview2 = resize( src2, src2->width*1.5, src2->height*1.5 );
while (!doneMenuDetailsCircuit)
{
dclear( C_BLACK );
dsubimage( 0, 32, &mainscreen, 0, 32, 396, 140, DIMAGE_NONE);
dfont(&autofont);
dimage( 16, 45, preview1 );
dimage( 16, 45, preview2 );
drawRectangle( 16, 45, 90, 90, C_RGB(255,255,255), 3 );
if (circuit==0 || circuit==5) dprint_opt(198, 2, C_RGB(255,255,255), C_NONE, DTEXT_CENTER, DTEXT_TOP, "EUROPEAN PLAINS" );
else if (circuit==1 || circuit==6) dprint_opt(198, 2, C_RGB(255,255,255), C_NONE, DTEXT_CENTER, DTEXT_TOP, "ATACAMA DESERT" );
else if (circuit==2 || circuit==7) dprint_opt(198, 2, C_RGB(255,255,255), C_NONE, DTEXT_CENTER, DTEXT_TOP, "US ROAD 66" );
else if (circuit==3 || circuit==8) dprint_opt(198, 2, C_RGB(255,255,255), C_NONE, DTEXT_CENTER, DTEXT_TOP, "SNOW IN FINLAND" );
else if (circuit==4 || circuit==9) dprint_opt(198, 2, C_RGB(255,255,255), C_NONE, DTEXT_CENTER, DTEXT_TOP, "KENYAN SAVANAH" );
if (circuit==0 || circuit==1 || circuit==2 || circuit==5 || circuit==6 || circuit==7)
{
dprint_opt(122, 42, C_RGB(0,0,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "GRIP - GOOD" );
dprint_opt(120, 40, C_RGB(255,255,255), C_NONE, DTEXT_LEFT, DTEXT_TOP, "GRIP - GOOD" );
}
else if (circuit==3 || circuit==8)
{
dprint_opt(122, 42, C_RGB(0,0,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "GRIP - LOW" );
dprint_opt(120, 40, C_RGB(255,255,255), C_NONE, DTEXT_LEFT, DTEXT_TOP, "GRIP - LOW" );
}
else if (circuit==4 || circuit==9)
{
dprint_opt(122, 42, C_RGB(0,0,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "GRIP - SLIDE" );
dprint_opt(120, 40, C_RGB(255,255,255), C_NONE, DTEXT_LEFT, DTEXT_TOP, "GRIP - SLIDE" );
}
if (circuit==0 || circuit==1 || circuit==2 || circuit==5 || circuit==6 || circuit==7)
{
dprint_opt(122, 82, C_RGB(0,0,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "ASPHALT" );
dprint_opt(120, 80, C_RGB(255,255,255), C_NONE, DTEXT_LEFT, DTEXT_TOP, "ASPHALT" );
}
else if (circuit==3 || circuit==8)
{
dprint_opt(122, 82, C_RGB(0,0,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "ICE AND SNOW" );
dprint_opt(120, 80, C_RGB(255,255,255), C_NONE, DTEXT_LEFT, DTEXT_TOP, "ICE AND SNOW" );
}
else if (circuit==4 || circuit==9)
{
dprint_opt(122, 82, C_RGB(0,0,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "DIRT AND DUST" );
dprint_opt(120, 80, C_RGB(255,255,255), C_NONE, DTEXT_LEFT, DTEXT_TOP, "DIRT AND DUST" );
}
if (circuit==0 || circuit==1 || circuit==2 || circuit==3 || circuit==4)
{
dprint_opt(122, 122, C_RGB(0,0,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "ONE LAP" );
dprint_opt(120, 120, C_RGB(255,255,255), C_NONE, DTEXT_LEFT, DTEXT_TOP, "ONE LAP" );
}
else
{
dprint_opt(122, 122, C_RGB(0,0,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "THREE LAPS" );
dprint_opt(120, 120, C_RGB(255,255,255), C_NONE, DTEXT_LEFT, DTEXT_TOP, "THREE LAPS" );
}
dprint_opt(198, 197, C_RGB(pulse%256,0,pulse%256), C_NONE, DTEXT_CENTER, DTEXT_BOTTOM, ">> HANG ON TO <<" );
dprint_opt(198, 222, C_RGB(pulse%256,0,pulse%256), C_NONE, DTEXT_CENTER, DTEXT_BOTTOM, ">> YOUR HELMET <<" );
dupdate();
pulse++;
getInputCircuitDetails();
#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
}
free(preview1);
free(preview2);
return CircuitDetailsSelection;
}
void getInputCircuitDetails( void )
{
int opt = GETKEY_DEFAULT & ~GETKEY_REP_ARROWS;
int timeout = 1;
while(1)
{
key_event_t ev = getkey_opt(opt, &timeout);
if(ev.type == KEYEV_NONE) return;
int key = ev.key;
if (key==KEY_EXE)
{
doneMenuDetailsCircuit = true;
CircuitDetailsSelection = 1;
}
if (key==KEY_EXIT)
{
CircuitDetailsSelection = -1;
doneMenuDetailsCircuit = true;
}
/*
if (key==KEY_UP || key==KEY_LEFT)
{
if (CircuitSelection==0) CircuitSelection=9;
else CircuitSelection--;
}
if (key==KEY_DOWN || key==KEY_RIGHT)
{
if (CircuitSelection==9) CircuitSelection=0;
else CircuitSelection++;
}
*/
#if IS_FXLIB==1
if(keydown(KEY_7)) screenshot = true;
if(keydown(KEY_8)) record = !record;
#endif // IS_FXLIB
}
}

96
src/src/utils.cc Normal file
View File

@ -0,0 +1,96 @@
#include "../include/utils.h"
size_t image_size_profile(int profile, int width, int height)
{
size_t size = sizeof(bopti_image_t);
if(profile == 0 || profile == 1) // PX_RGB565, PX_RGB565A
size += width * height * 2;
else if(profile == 2) // PX_P8
size += 512 + width * height;
else if(profile == 3) // PX_P4
size += 32 + ((width + 1) / 2) * height;
return size;
}
size_t image_size(bopti_image_t const *img)
{
return image_size_profile(img->profile, img->width, img->height);
}
int get_pixel(bopti_image_t const *img, int x, int y)
{
if((unsigned)x >= img->width || (unsigned)y >= img->height)
return 0;
uint8_t *bytes = (void *)img->data;
if(img->profile <= 1)
return img->data[y * img->width + x];
if(img->profile == 2)
return bytes[y * img->width + x + 512];
if(img->profile == 3)
{
int s = (img->width + 1) >> 1;
int i = y * s + (x >> 1) + 32;
if(x & 1)
return bytes[i] & 0x0f;
else
return bytes[i] >> 4;
}
return 0;
}
void set_pixel(bopti_image_t *img, int x, int y, int color)
{
if((unsigned)x >= img->width || (unsigned)y >= img->height)
return;
uint8_t *bytes = (void *)img->data;
if(img->profile <= 1)
img->data[y * img->width + x] = color;
else if(img->profile == 2)
bytes[y * img->width + x + 512] = color;
else if(img->profile == 3)
{
int s = (img->width + 1) >> 1;
int i = y * s + (x >> 1) + 32;
if(x & 1)
bytes[i] = (bytes[i] & 0xf0) | (color & 0x0f);
else
bytes[i] = (bytes[i] & 0x0f) | ((color & 0x0f) << 4);
}
}
bopti_image_t *resize(bopti_image_t const *src, int w, int h)
{
size_t size = image_size_profile(src->profile, w, h);
bopti_image_t *img = malloc(size);
if(!img) return NULL;
size_t palette_size = 0;
if(src->profile == 2) // PX_P8
palette_size = 512;
else if(src->profile == 3) // PX_P4
palette_size = 32;
img->profile = src->profile;
img->alpha = src->alpha;
img->width = w;
img->height = h;
memcpy(img->data, src->data, palette_size);
for(int y = 0; y < h; y++)
for(int x = 0; x < w; x++)
{
int color = get_pixel(src, x * src->width / w, y * src->height / h);
set_pixel(img, x, y, color);
}
return img;
}