diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 0244949..cc54185 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/art/black.png b/art/black.png new file mode 100644 index 0000000..d575b65 Binary files /dev/null and b/art/black.png differ diff --git a/art/blue.png b/art/blue.png new file mode 100644 index 0000000..b112e38 Binary files /dev/null and b/art/blue.png differ diff --git a/art/car.png b/art/car.png index 5341b13..a9b6f27 100644 Binary files a/art/car.png and b/art/car.png differ diff --git a/art/cars.png b/art/cars.png new file mode 100644 index 0000000..9c51e3c Binary files /dev/null and b/art/cars.png differ diff --git a/art/grass.png b/art/grass.png index 3212025..e2f764c 100644 Binary files a/art/grass.png and b/art/grass.png differ diff --git a/art/green.png b/art/green.png new file mode 100644 index 0000000..39f76c4 Binary files /dev/null and b/art/green.png differ diff --git a/art/hills.png b/art/hills.png index 1101b9f..22199d9 100644 Binary files a/art/hills.png and b/art/hills.png differ diff --git a/art/old/car 2.png b/art/old/car 2.png new file mode 100644 index 0000000..d79ba9d Binary files /dev/null and b/art/old/car 2.png differ diff --git a/art/old/car0.png b/art/old/car0.png new file mode 100644 index 0000000..5d61c84 Binary files /dev/null and b/art/old/car0.png differ diff --git a/art/old/car1.png b/art/old/car1.png new file mode 100644 index 0000000..f2eae77 Binary files /dev/null and b/art/old/car1.png differ diff --git a/art/old/car2.png b/art/old/car2.png new file mode 100644 index 0000000..571835f Binary files /dev/null and b/art/old/car2.png differ diff --git a/art/old/checker0.png b/art/old/checker0.png new file mode 100644 index 0000000..162a76f Binary files /dev/null and b/art/old/checker0.png differ diff --git a/art/old/curb.png b/art/old/curb.png new file mode 100644 index 0000000..86b949f Binary files /dev/null and b/art/old/curb.png differ diff --git a/art/old/curb0.png b/art/old/curb0.png new file mode 100644 index 0000000..66ef097 Binary files /dev/null and b/art/old/curb0.png differ diff --git a/art/old/grass/grass0.png b/art/old/grass/grass0.png new file mode 100644 index 0000000..5213625 Binary files /dev/null and b/art/old/grass/grass0.png differ diff --git a/art/old/grass/grass1.png b/art/old/grass/grass1.png new file mode 100644 index 0000000..aa51df4 Binary files /dev/null and b/art/old/grass/grass1.png differ diff --git a/art/old/grass/grass2.png b/art/old/grass/grass2.png new file mode 100644 index 0000000..f2a50c0 Binary files /dev/null and b/art/old/grass/grass2.png differ diff --git a/art/old/grass/grass3.png b/art/old/grass/grass3.png new file mode 100644 index 0000000..5d1ddde Binary files /dev/null and b/art/old/grass/grass3.png differ diff --git a/art/old/grass/grass4.png b/art/old/grass/grass4.png new file mode 100644 index 0000000..79cd8c0 Binary files /dev/null and b/art/old/grass/grass4.png differ diff --git a/art/old/grass/grass5.png b/art/old/grass/grass5.png new file mode 100644 index 0000000..1d28751 Binary files /dev/null and b/art/old/grass/grass5.png differ diff --git a/art/old/road0.png b/art/old/road0.png new file mode 100644 index 0000000..dce172e Binary files /dev/null and b/art/old/road0.png differ diff --git a/art/old/road1.png b/art/old/road1.png new file mode 100644 index 0000000..8069780 Binary files /dev/null and b/art/old/road1.png differ diff --git a/art/old/title/title 0.png b/art/old/title/title 0.png new file mode 100644 index 0000000..32f4ad9 Binary files /dev/null and b/art/old/title/title 0.png differ diff --git a/art/old/title/title 1.png b/art/old/title/title 1.png new file mode 100644 index 0000000..be0c6b5 Binary files /dev/null and b/art/old/title/title 1.png differ diff --git a/art/old/title/title 2.png b/art/old/title/title 2.png new file mode 100644 index 0000000..227a866 Binary files /dev/null and b/art/old/title/title 2.png differ diff --git a/art/old/title/title 2b.png b/art/old/title/title 2b.png new file mode 100644 index 0000000..fd05407 Binary files /dev/null and b/art/old/title/title 2b.png differ diff --git a/art/old/title/title 3.png b/art/old/title/title 3.png new file mode 100644 index 0000000..e12f161 Binary files /dev/null and b/art/old/title/title 3.png differ diff --git a/art/old/title/title 3a.png b/art/old/title/title 3a.png new file mode 100644 index 0000000..d58505d Binary files /dev/null and b/art/old/title/title 3a.png differ diff --git a/art/old/title/title 3b.png b/art/old/title/title 3b.png new file mode 100644 index 0000000..bdfb612 Binary files /dev/null and b/art/old/title/title 3b.png differ diff --git a/art/old/title/title 4.png b/art/old/title/title 4.png new file mode 100644 index 0000000..d99ba93 Binary files /dev/null and b/art/old/title/title 4.png differ diff --git a/art/old/title/title 40%.png b/art/old/title/title 40%.png new file mode 100644 index 0000000..ec3f0f3 Binary files /dev/null and b/art/old/title/title 40%.png differ diff --git a/art/old/title/title 4b.png b/art/old/title/title 4b.png new file mode 100644 index 0000000..380d3bf Binary files /dev/null and b/art/old/title/title 4b.png differ diff --git a/art/old/title/title 5.png b/art/old/title/title 5.png new file mode 100644 index 0000000..6d31824 Binary files /dev/null and b/art/old/title/title 5.png differ diff --git a/art/old/title/title 50%.png b/art/old/title/title 50%.png new file mode 100644 index 0000000..6670f50 Binary files /dev/null and b/art/old/title/title 50%.png differ diff --git a/art/old/title/title 5b.png b/art/old/title/title 5b.png new file mode 100644 index 0000000..e9498e7 Binary files /dev/null and b/art/old/title/title 5b.png differ diff --git a/art/old/title/title 6.png b/art/old/title/title 6.png new file mode 100644 index 0000000..598cbe0 Binary files /dev/null and b/art/old/title/title 6.png differ diff --git a/art/old/title/title 7.png b/art/old/title/title 7.png new file mode 100644 index 0000000..47cbfff Binary files /dev/null and b/art/old/title/title 7.png differ diff --git a/art/old/title/title 7b.png b/art/old/title/title 7b.png new file mode 100644 index 0000000..a1cb3ec Binary files /dev/null and b/art/old/title/title 7b.png differ diff --git a/art/orange.png b/art/orange.png new file mode 100644 index 0000000..9c22389 Binary files /dev/null and b/art/orange.png differ diff --git a/art/purple.png b/art/purple.png new file mode 100644 index 0000000..aa5a6bc Binary files /dev/null and b/art/purple.png differ diff --git a/art/red.png b/art/red.png new file mode 100644 index 0000000..a9b6f27 Binary files /dev/null and b/art/red.png differ diff --git a/art/road.png b/art/road.png index d188bd3..92171f4 100644 Binary files a/art/road.png and b/art/road.png differ diff --git a/art/title.png b/art/title.png new file mode 100644 index 0000000..de40d12 Binary files /dev/null and b/art/title.png differ diff --git a/art/title.psd b/art/title.psd new file mode 100644 index 0000000..5510105 Binary files /dev/null and b/art/title.psd differ diff --git a/art/white.png b/art/white.png new file mode 100644 index 0000000..9701357 Binary files /dev/null and b/art/white.png differ diff --git a/car.png b/car.png new file mode 100644 index 0000000..5341b13 Binary files /dev/null and b/car.png differ diff --git a/grass.png b/grass.png new file mode 100644 index 0000000..3212025 Binary files /dev/null and b/grass.png differ diff --git a/hills.png b/hills.png new file mode 100644 index 0000000..1101b9f Binary files /dev/null and b/hills.png differ diff --git a/main.cpp b/main.cpp index 6ec6d15..ce43259 100644 --- a/main.cpp +++ b/main.cpp @@ -1,1135 +1,70 @@ -//-------------------------------------------------------------------------------------------------- -// F4 Racing -//-------------------------------------------------------------------------------------------------- -// This is an advancement in my game making skills, building off the back of my work on the "Collect the Balls" game. -//-------------------------------------------------------------------------------------------------- -// created by Rune -// black box code by Sigonasr2 from the OLC (one lone coder) Discord server -//-------------------------------------------------------------------------------------------------- #define OLC_PGE_APPLICATION -#include "pixelGameEngine.h" // used for drawing the game +#include "pixelGameEngine.h" -//-------------------------------------------------------------------------------------------------- -// class -//-------------------------------------------------------------------------------------------------- -class Racer : public olc::PixelGameEngine +using namespace olc; + +class Circles : public olc::PixelGameEngine { public: - Racer() + Circles() { - sAppName = "F4 Racing"; + sAppName = "Circles"; } -private: - float car_pos = 0.0f; - float distance = 0.0f; - float speed = 0.0f; - - float curvature = 0.0f; - float track_curve = 0.0f; - float car_curve = 0.0f; - float track_dist = 0.0f; - - float cur_lap_time = 0.0f; - - std::vector> vecTrack; - std::list list_times; - - bool bothKeysPressed = false; // checking for dual key press; could probably work with more than 2 keys - - // custom control template - olc::Key Move_Up = olc::W; - olc::Key Move_Down = olc::S; - olc::Key Move_Left = olc::A; - olc::Key Move_Right = olc::D; - - std::array keyslist = { "UP", "DOWN", "LEFT", "RIGHT" }; - int configKeyIndex = -1; - char pressedKey; - - int cup = -1; // for cup selection screen - int track = -1; // for track selection screen - - int player = 0; // for car selection screen - - bool start = false; - public: - - // Menu Setup - //---------------------------------------- - bool activeOption = true; // highlighting current option - int highlighted=0; - - struct MenuItem - { - std::string label; // label - olc::vi2d pos; // label's position - std::string label2; // another label to right of label - }; - - struct Object - { - olc::vf2d pos{ 0, 0 }; // the x position represents how far to the left/right it is from the center. -1 ~ 1: road's range; the y position is how far along the track it is - olc::vf2d size{ 1, 1 }; - olc::Decal* decal = nullptr; - olc::vf2d offset{ 0, 0 }; // how far off the image will be - bool rendered = false; - olc::vf2d drawPos; - olc::vf2d drawSize; - olc::vf2d drawOffsetPos; - }; - - std::vector mainMenu; - std::vector playGame; - std::vector pickTrack; - std::vector grandPrix; - std::vector selectCar; - std::vector controls; - std::vector gameOver; - - std::vector gameObjects; - enum class state - { - MAIN_MENU, - PLAY_GAME, - CAR_SELECT, - CONTROLS, - RUN_GAME, - // game - TRACK_SELECT, - CUP_SELECT, - // tracks - CIRCUIT, - FIG_EIGHT, - ARROW_HEAD, - track_4, - OVERPASS, - PEANUT, - track_6, - track_7, - track_8, - track_9, - JX9, // special track ;) - // cups - INDIE, - STREET, - PRO, - GRAND_PRIX - }; - - state gameState = state::MAIN_MENU; - - // Variables - //---------------------------------------- - - // lap times - - // player - int score; // score at end of track; based on final place - int lap; // current lap player is on - int place; // current place player is in - - olc::Decal* car; // initialize car - olc::Decal* hill; // initialize hill - olc::Decal* grass; // initialize grass - olc::Decal* road; // initialize road, curbs, and finish line - olc::Decal* banner; // initialize banner - olc::Decal* title; // initialize title banner - - std::string KeyToString(olc::Key key) - { - const std::array keyStrings = - { - "NONE","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9", - "F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12","UP","DOWN","LEFT","RIGHT","SPACE","TAB","SHIFT","CTRL","INS","DEL","HOME","END","PGUP","PGDN","BACK","ESCAPE","ENTER","ENTER", - "PAUSE","SCROLL LK","Kp-0","Kp-1","Kp-2","Kp-3","Kp-4","Kp-5","Kp-6","Kp-7","Kp-8","Kp-9","Kp-*","Kp-/","Kp-+","Kp--","Kp-.",".","=",",","-","OEM_1", - "OEM_2","OEM_3","OEM_4","OEM_5","OEM_6","OEM_7","OEM_8","CAPS LOCK","END" - }; - return keyStrings[key]; + int CIRCLE_PRECISION=32; + + void DrawCircleDecal(vf2d pos,float radius,Pixel col=WHITE) { + std::vector poly; + std::vector uvs; + for (int i=0;i poly; + std::vector uvs; + poly.push_back(pos); + uvs.push_back({0,0}); + for (int i=0;i list) - { - // drawing and coloring menu selections - for (int i = 0; i < list.size(); i++) - { - olc::vi2d textSize = GetTextSize(list[i].label) / 2 * 4; - olc::Pixel textCol = olc::GREY; // greys out unselected options - if (highlighted == i) - { - textCol = olc::Pixel(255, 201, 14); // gold - } - DrawStringDecal(list[i].pos - textSize, list[i].label, textCol, { 4.0f, 4.0f }); - if (list[i].label2.size() > 0) - { - olc::vi2d offset = { ScreenWidth() / 3, -textSize.y / 2 }; - DrawStringDecal(list[i].pos + offset, list[i].label2, textCol, { 4.0f, 4.0f }); - } - } - - // selecting options - highlighted = std::clamp(highlighted, 0, (int)list.size() - 1); // loop if out of range - - int shortestDist=9999999; - int largestDist=-9999999; - int targetItem=highlighted; - - if (GetKey(olc::Key::DOWN).bPressed) { - for (int i=0;ilist[i].pos.y) { //It's above us. - int dist = abs(list[highlighted].pos.y-list[i].pos.y); - if (distlist[i].pos.y) { //It's above us. - int dist = abs(list[highlighted].pos.y-list[i].pos.y); - if (distlist[i].pos.x) { //It's to the left of us. - int dist = abs(list[highlighted].pos.x-list[i].pos.x); - if (dist>largestDist) { - targetItem=i; - largestDist=dist; - } - } - } - } - } - } - highlighted=targetItem; - } - - if (GetKey(olc::Key::LEFT).bPressed) { - for (int i=0;ilist[i].pos.x) { //It's to the left of us. - int dist = abs(list[highlighted].pos.x-list[i].pos.x); - if (distlargestDist) { - targetItem=i; - largestDist=dist; - } - } - } - } - } - } - highlighted=targetItem; - } - - if (highlighted >= (int)list.size()) - { - highlighted = 0; // wrap around when above max - } - if (highlighted < 0) - { - highlighted = list.size() - 1; // wrap around when below zero - } - } - -//-------------------------------------------------------------------------------------------------- -// controls -//-------------------------------------------------------------------------------------------------- - void GetAnyKeyPress(olc::Key keypress) override - { - if (configKeyIndex != -1) - { - switch (configKeyIndex) - { - case 0: - { - Move_Up = keypress; - }break; - case 1: - { - Move_Right = keypress; - }break; - case 2: - { - Move_Left = keypress; - }break; - case 3: - { - Move_Down = keypress; - }break; - } - controls[configKeyIndex].label2 = KeyToString(keypress); - configKeyIndex = -1; - } - } - -//-------------------------------------------------------------------------------------------------- -// Main Game Function -//-------------------------------------------------------------------------------------------------- bool OnUserUpdate(float fElapsedTime) override { - if (GetKey(olc::Key::CTRL).bHeld && GetKey(olc::Key::F12).bHeld && !bothKeysPressed) - { - return false; - } - - // dry skybox - GradientFillRectDecal({ 0.0f, 0.0f }, { ScreenWidth() + 0.0f, ScreenHeight() / 2 + 0.0f }, olc::DARK_BLUE, olc::BLUE, olc::BLUE, olc::DARK_BLUE); - - // the hills have eyes; y'know, like in Super Mario Bros. What reference did you think was going to be here? - DrawPartialDecal({ 0.0f, ScreenHeight() / 2 - 100.0f }, hill, { 0.0f + track_curve * 200, 0.0f }, { ScreenWidth() + 0.0f, (float)hill->sprite->height }, { 1.5f, 1.0f }); - //DrawPartialDecal({ 180.0f, ScreenHeight() / 2 - 100.0f }, hill, { 0.0f + track_curve * 200, 0.0f }, { ScreenWidth() + 0.0f, (float)hill->sprite->height }); - - // draw grass - DrawPartialWarpedDecal(grass, { { 0.0f, ScreenHeight() / 2 + 0.0f }, { -ScreenWidth() * 2 + 0.0f, ScreenHeight() + 0.0f}, { ScreenWidth() * 2 + ScreenWidth() + 0.0f, ScreenHeight() + 0.0f }, { ScreenWidth() + 0.0f, ScreenHeight() / 2 + 0.0f } }, { 0.0f, -distance }, { 1 * 32, 4 * 64 }); - -//-------------------------------------------------------------------------------------------------- - if (gameState == state::MAIN_MENU) - { - // display title - DrawDecal({ 95.5f, 95.5f }, title/*, {0.4f, 0.4f}*/); - DisplayMenu(mainMenu); - //DrawStringDecal({ ScreenWidth() / 2 + 0.0f, ScreenHeight() / 2 + 0.0f }, "START GAME", olc::WHITE, { 4.0f, 4.0f }); - - if (GetKey(olc::Key::ENTER).bPressed || GetKey(olc::Key::SPACE).bPressed) - { - // vertical menu - if (highlighted == 0) - { - gameState = state::PLAY_GAME; - highlighted = 0; - } - else if (highlighted == 1) - { - gameState = state::CONTROLS; - highlighted = 0; - } - else - { - return false; // quit game - } - } - if (GetKey(olc::Key::ESCAPE).bPressed) - { - return false; // exit via Escape key - } - } - -//-------------------------------------------------------------------------------------------------- - else if (gameState == state::PLAY_GAME) - { - DisplayMenu(playGame); - if (GetKey(olc::Key::ENTER).bPressed || GetKey(olc::Key::SPACE).bPressed) - { - // vertical menu - if (highlighted == 0) - { - gameState = state::TRACK_SELECT; - highlighted = 0; - } - else if (highlighted == 1) - { - gameState = state::CUP_SELECT; - highlighted = 0; - } - else - { - gameState = state::MAIN_MENU; // return to menu - highlighted = 0; - } - } - if (GetKey(olc::Key::ESCAPE).bPressed || GetKey(olc::Key::BACK).bPressed) - { - gameState = state::MAIN_MENU; - highlighted = 0; - } - } - -//-------------------------------------------------------------------------------------------------- - else if (gameState == state::TRACK_SELECT) - { - DisplayMenu(pickTrack); - if (GetKey(olc::Key::ENTER).bPressed || GetKey(olc::Key::SPACE).bPressed) - { - if (highlighted == 0) - { - gameState = state::CIRCUIT; - track = 1; - gameState = state::CAR_SELECT; - } - else if (highlighted == 1) - { - gameState = state::FIG_EIGHT; - track = 2; - gameState = state::CAR_SELECT; - } - else if (highlighted == 2) - { - gameState = state::ARROW_HEAD; - track = 3; - gameState = state::CAR_SELECT; - } - else if (highlighted == 3) - { - gameState = state::track_4; - track = 4; - gameState = state::CAR_SELECT; - } - else if (highlighted == 4) - { - gameState = state::OVERPASS; - track = 5; - gameState = state::CAR_SELECT; - } - else if (highlighted == 5) - { - gameState = state::PEANUT; - track = 6; - gameState = state::CAR_SELECT; - } - else if (highlighted == 6) - { - gameState = state::track_6; - track = 7; - gameState = state::CAR_SELECT; - } - else if (highlighted == 7) - { - gameState = state::track_7; - track = 8; - gameState = state::CAR_SELECT; - } - else if (highlighted == 8) - { - gameState = state::track_8; - track = 9; - gameState = state::CAR_SELECT; - } - else - { - gameState = state::PLAY_GAME; - highlighted = 0; - } - } - if (GetKey(olc::Key::CTRL).bHeld && GetKey(olc::Key::F9).bHeld) - { - // okay, so, gotta work out how to do cheat codes it seems xD - gameState = state::JX9; - track = 0; - gameState = state::CAR_SELECT; - } - if (GetKey(olc::Key::ESCAPE).bPressed || GetKey(olc::Key::BACK).bPressed) - { - gameState = state::PLAY_GAME; - highlighted = 0; - } - } - -//-------------------------------------------------------------------------------------------------- - else if (gameState == state::CUP_SELECT) - { - DisplayMenu(grandPrix); - if (GetKey(olc::Key::ENTER).bPressed || GetKey(olc::Key::SPACE).bPressed) - { - // 2 x 2 menu - if (highlighted == 0) - { - gameState = state::INDIE; - cup = 0; - gameState = state::CAR_SELECT; - } - else if (highlighted == 1) - { - gameState = state::STREET; - cup = 1; - gameState = state::CAR_SELECT; - } - else if (highlighted == 2) - { - gameState = state::PRO; - cup = 2; - gameState = state::CAR_SELECT; - } - else if (highlighted == 3) - { - gameState = state::GRAND_PRIX; - cup = 3; - gameState = state::CAR_SELECT; - } - else - { - gameState = state::PLAY_GAME; // return to menu - cup = -1; - highlighted = 0; - } - } - if (GetKey(olc::Key::ESCAPE).bPressed || GetKey(olc::Key::BACK).bPressed) - { - gameState = state::PLAY_GAME; - highlighted = 0; - } - } - -//-------------------------------------------------------------------------------------------------- - else if (gameState == state::CAR_SELECT) - { - DisplayMenu(selectCar); - if (GetKey(olc::Key::ENTER).bPressed || GetKey(olc::Key::SPACE).bPressed) - { - if (highlighted == 0) - { - // red car - player = 0; - gameState=state::RUN_GAME; - } - else if (highlighted == 1) - { - // blue car - player = 1; - } - else if (highlighted == 2) - { - // green car - player = 2; - } - else if (highlighted == 3) - { - // gold car - player = 3; - } - else if (highlighted == 4) - { - // purple car - player = 4; - } - else if (highlighted == 5) - { - // white car - player = 5; - } - else if (highlighted == 6) - { - // orange car - player = 6; - } - else if (highlighted == 7) - { - // black car - player = 7; - } - else - { - if (cup != -1) - { - // return to cup select - gameState = state::CUP_SELECT; - } - if (track != -1) - { - // return to track select - gameState = state::TRACK_SELECT; - } - highlighted = 0; - } - } - if (GetKey(olc::Key::ESCAPE).bPressed || GetKey(olc::Key::BACK).bPressed) - { - if (cup != -1) - { - // return to cup select - gameState = state::CUP_SELECT; - } - if (track != -1) - { - // return to track select - gameState = state::TRACK_SELECT; - } - highlighted = 0; - } - } - -//-------------------------------------------------------------------------------------------------- - else if (gameState == state::CONTROLS) - { - DisplayMenu(controls); - if (GetKey(olc::Key::ENTER).bPressed) - { - if (highlighted == 0) - { - configKeyIndex = highlighted; - } - else if (highlighted == 1) - { - configKeyIndex = highlighted; - } - else if (highlighted == 2) - { - configKeyIndex = highlighted; - } - else if (highlighted == 3) - { - configKeyIndex = highlighted; - } - else if (highlighted == 4) - { - // reset default controls - DisplayMenu(controls); - Move_Up = olc::W; - Move_Down = olc::S; - Move_Left = olc::A; - Move_Right = olc::D; - - } - else - { - gameState = state::MAIN_MENU; - highlighted = 0; - } - } - if (GetKey(olc::Key::ESCAPE).bPressed || GetKey(olc::Key::BACK).bPressed) - { - gameState = state::MAIN_MENU; - } - } - -//-------------------------------------------------------------------------------------------------- - if (gameState == state::RUN_GAME) // run main game loop - { - Clear(olc::BLACK); // this still needed? we've since replaced it with the gradient sky box - - // get a point on the track - float offset = 0; - int TrackSection = 0; - - cur_lap_time += fElapsedTime; - - // record lap time - if (distance >= track_dist) - { - distance -= track_dist; - list_times.push_front(cur_lap_time); // push time to front - list_times.pop_back(); // pop time to back - cur_lap_time = 0.0f; - } - - // find position on track (could optimize) << should probably optimize given the complexity of this game - while (TrackSection < vecTrack.size() && offset <= distance) - { - offset += vecTrack[TrackSection].second; - TrackSection++; - } - - float TargetCurvature = vecTrack[TrackSection - 1].first; // drawing curves to screen - - float TrackCurveDiff = (TargetCurvature - curvature) * fElapsedTime * speed; // correcting the drawing of curves to the screen - curvature += TrackCurveDiff; // update track curve difference - - track_curve += (curvature)*fElapsedTime * speed; - - - - // draw racetrack canvas - - std::vector pos; - std::vector uvs; - for (int y = 0; y < ScreenHeight() / 2; y++) - { - // racetrack canvas variables - float perspective = (float)y / (ScreenHeight() / 2.0f); - - float mid_point = 0.5f + curvature * powf((1.0f - perspective), 3); - float road_width = 0.1f + perspective * 0.8f; - float curb_width = road_width * 0.15f; - - road_width *= 0.5f; - - int lf_curb = (mid_point - road_width) * ScreenWidth(); - int rt_curb = (mid_point + road_width) * ScreenWidth(); - - int row = ScreenHeight() / 2 + y; - - float horizon = powf(1.0f - perspective, 2) * 80; - - // check for finish line - if (distance + horizon > track_dist - 20 && distance + horizon < track_dist) - { - // draw checkerboard pattern - uvs.push_back({ 0, fmod(((distance + horizon) - (track_dist - 20)) / 20.0f, 0.5f) + 0.5f }); - uvs.push_back({ 1, fmod(((distance + horizon) - (track_dist - 20)) / 20.0f, 0.5f) + 0.5f }); - } - else - { - // draw standard track piece - uvs.push_back({ 0, sinf(80.0f * powf(1.0f - perspective, 2) + distance) / 4 + 0.25f }); - uvs.push_back({ 1, sinf(80.0f * powf(1.0f - perspective, 2) + distance) / 4 + 0.25f }); - } - - // drawing grass and curb - pos.push_back({ lf_curb + 0.0f, row + 0.0f }); - pos.push_back({ rt_curb + 0.0f, row + 0.0f }); - - // black box rendering shenanigans; if I ever understand programming enough at a later date, I can figure out wtf is going on here - int i = 0; - for (Object& obj : gameObjects) - { - float horizonRange = powf(1.0f - perspective, 2) * ((distance + horizon) - obj.pos.y) / horizon; - if (!obj.rendered && (distance + horizon) > obj.pos.y && (distance + horizon) < obj.pos.y + 80 && row >= ScreenHeight() / 2 + ScreenHeight() / 2 * horizonRange) - { - obj.drawPos = { (mid_point + road_width * obj.pos.x) * ScreenWidth(), horizonRange * (ScreenHeight() / 2) + ScreenHeight() / 2 }; - obj.drawOffsetPos = { obj.offset.x, obj.size.y * road_width * -obj.offset.y }; - obj.drawSize = { obj.size.x * road_width, obj.size.y * road_width }; - obj.rendered = true; - - // yeah.... so, even after copying it manually, i still have no clue what this thing is doing, lol - } - } - } - - // on the road again; drawing the track - SetDecalStructure(olc::DecalStructure::STRIP); - DrawPolygonDecal(road, pos, uvs); - SetDecalStructure(olc::DecalStructure::FAN); - - // draw trackside props - for (Object& obj : gameObjects) - { - if (obj.rendered) - { - if (obj.decal != nullptr) - { - DrawDecal(obj.drawPos + obj.drawOffsetPos, obj.decal, obj.drawSize); - } - else - { - FillRectDecal(obj.drawPos, obj.drawSize, olc::BLUE); - } - } - } - - //---------------------------------------- - // debug quick-reset - if (GetKey(olc::Key::F4).bPressed) - { - Reset(); - } - // move forward - if (GetKey(olc::Key::W).bHeld || GetKey(olc::Key::UP).bHeld) - { - speed += 2.0f * fElapsedTime; - } - else // might remove this in a later stage of development - { - speed -= 1.0f * fElapsedTime; - } - // move back ? - if (GetKey(olc::Key::S).bHeld || GetKey(olc::Key::DOWN).bHeld) - { - distance -= 20.0f * fElapsedTime; - } - - int car_dir = 0; // default car facing - - // move left - if (GetKey(olc::Key::A).bHeld || GetKey(olc::Key::LEFT).bHeld) - { - car_curve -= 0.7f * fElapsedTime; - car_dir = -1; - } - // move right - if (GetKey(olc::Key::D).bHeld || GetKey(olc::Key::RIGHT).bHeld) - { - car_curve += 0.7f * fElapsedTime; - car_dir = +1; - } - - // slow car if on grass - if (fabs(car_curve - track_curve) >= 0.8f) - { - speed -= 5.0f * fElapsedTime; - } - - // clamp speed - if (speed < 0.0f) speed = 0.0f; - if (speed > 1.0f) speed = 1.0f; - - // move car along track according to car speed - distance += (70.0f * speed) * fElapsedTime; - - // draw car - car_pos = car_curve - track_curve; - DrawDecal({ ScreenWidth() / 2 - 128 + car_pos * ScreenWidth() / 2, ScreenHeight() / 4 * 3.0f - 128 }, car); - SetPixelMode(olc::Pixel::ALPHA); - - // spedometer - std::string mph = std::to_string(speed); - DrawString(4, 4, mph); - - // show time - auto disp_time = [](float t) - { - int min = t / 60.0f; - int sec = t - (min * 60.0f); - int milli = (t - (float)sec) * 1000.0f; - - // need to change this out to a 'DrawString()' function instead - return std::to_string(min) + "." + std::to_string(sec) + ":" + std::to_string(milli); - }; - - // correct for the first '0' in the seconds timer - //if () - //{ - // // draw min + '0' + sec + milli - // DrawString(4, 16, disp_time(cur_lap_time)); - //} - //else - //{ - DrawString(4, 16, disp_time(cur_lap_time)); - //} - - // display last 5 lap times - int j = 30; - for (auto l : list_times) - { - DrawString(10, j, disp_time(l)); - j += 10; - } - - // debug code - //std::string numb1 = std::to_string(car_pos); - //DrawString(4, 26, numb1); - //std::string numb2 = std::to_string(track_dist); - //DrawString(4, 38, numb2); - } - + // called once per frame + DrawCircleDecal({50,50},10,BLUE); + FillCircleDecal({100,100},20,GREEN); return true; } }; -//-------------------------------------------------------------------------------------------------- int main() { - Racer game; - if (game.Construct(1280, 720, 1, 1)) - game.Start(); + Circles demo; + if (demo.Construct(256, 240, 4, 4)) + demo.Start(); return 0; } - -//-------------------------------------------------------------------------------------------------- -// END OF FILE -//-------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/road.png b/road.png new file mode 100644 index 0000000..d188bd3 Binary files /dev/null and b/road.png differ diff --git a/start.png b/start.png new file mode 100644 index 0000000..20dccae Binary files /dev/null and b/start.png differ