summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-03-10 21:42:28 +0000
committerJoursoir <chat@joursoir.net>2021-03-10 21:42:28 +0000
commit5c236549c9abbbd99a42ebb3847711925a3588b1 (patch)
treeee7c38209560172c1c86ac81eaffeface6162e38
parentb87c20d9acd663b129a48f36ae411571cf19f7a7 (diff)
downloadascii-road-5c236549c9abbbd99a42ebb3847711925a3588b1.tar.gz
ascii-road-5c236549c9abbbd99a42ebb3847711925a3588b1.tar.bz2
ascii-road-5c236549c9abbbd99a42ebb3847711925a3588b1.zip
use GameWorld for draw background
-rw-r--r--main.cpp62
1 files 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 <stdlib.h>
#include <time.h>
+#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);
}