-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (56 loc) · 2.1 KB
/
main.cpp
File metadata and controls
74 lines (56 loc) · 2.1 KB
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
#include <iostream>
#include "raylib.h"
#include "rlgl.h"
#include "constants.h"
#include "car.h"
#include "track.h"
#include <vector>
using namespace std;
int main() {
InitWindow(screenW, screenH, "fuck you");
SetTargetFPS(60);
std::cout << screenW/2 << screenH/2 << endl;
Car player(screenW / 2, screenH / 2);
std::cout << player.xPos << " " << player.yPos << std::endl << player.vSize;
Track f1Track = CreateOvalTrack();
while(!WindowShouldClose()) {
player.updatePos();
BeginDrawing();
f1Track.DrawTrack();
DrawText(TextFormat("RPM: %d", player.rpm), 50, 50, 20, WHITE);
DrawText(TextFormat("Gear: %d", player.gear), 50, 75, 20, WHITE);
rlDisableBackfaceCulling();
ClearBackground(BLACK);
// leftmost
Vector2 v1 = {(player.xPos) + player.vSize * cos(player.theta + 3*PI/4 ), (player.yPos) + player.vSize * sin(player.theta + 3*PI/4)};
Vector2 v2 = {(player.xPos) + player.vSize * cos(player.theta + 5*PI/4), (player.yPos) + player.vSize * sin(player.theta + 5*PI/4)};
// rightmost
Vector2 v3 = {(player.xPos) + player.vSize * cos(player.theta ), (player.yPos) + player.vSize * sin(player.theta)};
DrawTriangle(v1, v2, v3, player.vColor);
EndDrawing();
}
return 0;
}
void Track::DrawTrack() {
DrawSplineCatmullRom(trackPoints.data(), trackPoints.size(), width, color);
}
Track CreateOvalTrack() {
vector<Vector2> trackShape = {
{320, 180},
{960, 180},
{1120, 360},
{960, 540},
{320, 540},
{160, 360}
};
// Wrap points for closed loop: add last two points at start, first two points at end
vector<Vector2> f1TrackPoints;
f1TrackPoints.push_back(trackShape[trackShape.size() - 2]); // Second to last
f1TrackPoints.push_back(trackShape[trackShape.size() - 1]); // Last
for (const auto& point : trackShape) {
f1TrackPoints.push_back(point);
}
f1TrackPoints.push_back(trackShape[0]); // First
f1TrackPoints.push_back(trackShape[1]); // Second
return Track(f1TrackPoints, 60, GRAY);
}