summaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-03-08 20:36:26 +0000
committerJoursoir <chat@joursoir.net>2021-03-08 20:36:26 +0000
commitac3ab1206a7bddec5312bf974479853429426dfa (patch)
tree26c0aacd3c78b8c2bd2d9db8c21af530d68459e6 /main.cpp
downloadascii-road-ac3ab1206a7bddec5312bf974479853429426dfa.tar.gz
ascii-road-ac3ab1206a7bddec5312bf974479853429426dfa.tar.bz2
ascii-road-ac3ab1206a7bddec5312bf974479853429426dfa.zip
init project
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..ca406f4
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,86 @@
+#include <ncurses.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "Vehicle.hpp"
+#include "veh_models.hpp"
+
+int total_rows, total_cols;
+
+void draw_line(int y, char ch)
+{
+ int i;
+ move(y, 0);
+ for(i = 0; i < total_cols; i++)
+ addch(ch);
+}
+
+/* This version is a dummy */
+void draw_background()
+{
+ draw_line(total_rows-1, '_'); // road
+
+ mvprintw(total_rows-9, 10, " _-_");
+ mvprintw(total_rows-8, 10, " /~~ ~~\\");
+ mvprintw(total_rows-7, 10, " /~~ ~~\\");
+ mvprintw(total_rows-6, 10, "{ }");
+ mvprintw(total_rows-5, 10, " \\ _- -_ /");
+ mvprintw(total_rows-4, 10, " ~ \\\\ // ~");
+ mvprintw(total_rows-3, 10, " | |");
+ mvprintw(total_rows-2, 10, " | |");
+ mvprintw(total_rows-1, 10, "______// \\\\");
+
+ mvprintw(total_rows-9, 40, " _-_");
+ mvprintw(total_rows-8, 40, " /~~ ~~\\");
+ mvprintw(total_rows-7, 40, " /~~ ~~\\");
+ mvprintw(total_rows-6, 40, "{ }");
+ mvprintw(total_rows-5, 40, " \\ _- -_ /");
+ mvprintw(total_rows-4, 40, " ~ \\\\ // ~");
+ mvprintw(total_rows-3, 40, " | |");
+ mvprintw(total_rows-2, 40, " | |");
+ mvprintw(total_rows-1, 40, "______// \\\\");
+
+ refresh();
+}
+
+Vehicle *get_random_vehicle(int y, int x)
+{
+ Vehicle *car;
+ car = new Vehicle(rand() % veh_types_max, y, x);
+ return car;
+}
+
+int main(int argc, char *argv[])
+{
+ initscr();
+ noecho();
+ curs_set(0);
+ srand(time(0));
+
+ struct timespec my_timer;
+ my_timer.tv_sec = 0;
+ my_timer.tv_nsec = 50000000; // 100000000
+ getmaxyx(stdscr, total_rows, total_cols);
+
+ Vehicle *car = 0;
+ for(;;)
+ {
+ clear();
+ draw_background();
+
+ if(!car)
+ car = get_random_vehicle(total_rows, -1);
+
+ car->MoveRight();
+ if(!(car->Draw(total_cols))) {
+ delete car;
+ car = 0;
+ }
+
+ refresh();
+ nanosleep(&my_timer, NULL);
+ }
+
+ endwin();
+ return 0;
+}