This repository has been archived by the owner on Sep 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrive.c
131 lines (91 loc) · 2.21 KB
/
drive.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <stdio.h>
#include "GL/glut.h"
#include "drive.h"
#include "ImageUtil.h"
#include "TextUtil.h"
int notch = 0;
double accel[] = {
-0.03, // EB
-0.025, // B7
-0.02,
-0.015,
-0.01,
-0.005,
-0.003,
-0.002,
-0.001, // N
0.005, // M1
0.01,
0.015,
0.02 // M4
};
Texture lvTex[13];
void tickDrive( double time, double *speed, double *position ){
double a;
if( notch <= 9 ){
a = *speed * accel[ notch ] * 10;
if( a > -0.5 ) a = -0.5;
}else{
a = ( MAX_SPEED - *speed ) * accel[ notch ];
if( a < 0.2 ) a = 0.2;
}
*speed += a * ( time / 1000 );
if( *speed < 0.5 && notch <= 9 ) *speed = 0;
*position += *speed * 1000 * ( time / 60 / 60 / 1000 );
}
void stepDrive( int w, int locked ){
notch += w;
if( notch >= 13 ) notch = 12;
else if( notch < 0 ) notch = 0;
if( locked != 0 && notch > 8 ) notch = 8;
}
void resetDrive( void ){
notch = 0;
}
void loadControlsAssets( void ){
GetTextureByPNGImage( &lvTex[0], CTRL_LV_TEXTURE_EB );
for( int i = 0; i < 7; i++ ){
char x[30];
sprintf( x, CTRL_LV_TEXTURE_B_FORMAT, 7 - i );
GetTextureByPNGImage( &lvTex[ i + 1 ], x );
}
GetTextureByPNGImage( &lvTex[ 1 + 7 ], CTRL_LV_TEXTURE_N );
for( int i = 0; i < 4; i++ ){
char x[30];
sprintf( x, CTRL_LV_TEXTURE_M_FORMAT, i + 1 );
GetTextureByPNGImage( &lvTex[ i + 1 + 7 + 1 ], x );
}
}
void renderControls( void ){
DrawTexture( &lvTex[ notch ],
CTRL_LV_TEXTURE_LEFT,
CTRL_LV_TEXTURE_TOP,
CTRL_LV_TEXTURE_WIDTH,
CTRL_LV_TEXTURE_HEIGHT
);
}
void renderMeters( double speed, double position ){
char speedChar[20];
sprintf( speedChar, "%3.0lf km/h", speed );
RenderText(
speedChar,
CTRL_LV_TEXTURE_LEFT - CTRL_LV_TEXTURE_WIDTH - 70,
CTRL_LV_TEXTURE_TOP + 50
);
char positionChar[20];
sprintf( positionChar, "%4.0lf m", position );
RenderText(
positionChar,
CTRL_LV_TEXTURE_LEFT - CTRL_LV_TEXTURE_WIDTH - 70 ,
CTRL_LV_TEXTURE_TOP + 75
);
}
void renderTime( int timeSec ){
char timeChar[20];
sprintf( timeChar, "%2d:%02d", timeSec / 60, timeSec % 60 );
RenderText(
timeChar,
CTRL_LV_TEXTURE_LEFT - CTRL_LV_TEXTURE_WIDTH - 70 ,
CTRL_LV_TEXTURE_TOP + 100
);
}