From 5c236549c9abbbd99a42ebb3847711925a3588b1 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Wed, 10 Mar 2021 21:42:28 +0000 Subject: use GameWorld for draw background --- main.cpp | 62 ++++++++++++-------------------------------------------------- 1 file changed, 12 insertions(+), 50 deletions(-) diff --git a/main.cpp b/main.cpp index e5a781e..e013252 100644 --- a/main.cpp +++ b/main.cpp @@ -2,65 +2,30 @@ #include #include +#include "GameWorld.hpp" #include "Vehicle.hpp" +#include "models.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, "______// \\\\"); -} - int main(int argc, char *argv[]) { + int total_rows, total_cols; initscr(); noecho(); curs_set(0); srand(time(0)); + getmaxyx(stdscr, total_rows, total_cols); struct timespec my_timer; my_timer.tv_sec = 0; my_timer.tv_nsec = 50000000; // 100000000 - getmaxyx(stdscr, total_rows, total_cols); + GameWorld *world = new GameWorld(total_rows, total_cols); Vehicle *car = 0; struct ll_vehicle *ptr_first = new struct ll_vehicle(0, 0); struct ll_vehicle *ptr; int wait_move = 0; - for(;;) - { - clear(); - draw_background(); + for(;;) { ptr = ptr_first; while(ptr) @@ -70,16 +35,15 @@ int main(int argc, char *argv[]) if(wait_move > 0) break; - ptr->data = new Vehicle( - rand() % veh_types_max, total_rows, -1); + int type = rand() % veh_types_max; + ptr->data = new Vehicle(type, total_rows-1, -veh_store[type].length); car = ptr->data; - wait_move = car->GetLength() + 3 + rand() % 10; + wait_move = veh_store[type].length + 3 + rand() % 10; ptr->next = new struct ll_vehicle(0, 0); } - car->MoveRight(); - if(!car->Draw(total_cols)) { + if(!car->MoveRight(world)) { ptr = ptr->next; delete car; delete ptr_first; @@ -90,10 +54,8 @@ int main(int argc, char *argv[]) ptr = ptr->next; } - if(wait_move > 0) - wait_move--; - - refresh(); + wait_move--; + world->Update(); nanosleep(&my_timer, NULL); } -- cgit v1.2.3-18-g5258