Updated - gnuskii - GNUSki improved for ascii skiing experience.
(HTM) git clone git://bitreich.org/gnuskii git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/gnuskii
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
(DIR) LICENSE
---
(DIR) commit b964e57401e264dbf9a4804eb6d99714f7305a0e
(DIR) parent cab3875cb4121070254411cac19504fd56b94cea
(HTM) Author: Rudolf Olah <rudolf.olah.to@gmail.com>
Date: Tue, 28 Jun 2005 08:39:50 -0400
Updated
Diffstat:
M src/main.cpp | 82 +++++++++++++------------------
1 file changed, 35 insertions(+), 47 deletions(-)
---
(DIR) diff --git a/src/main.cpp b/src/main.cpp
@@ -20,8 +20,8 @@ void* collideY(void* temp);
//Global variables
bool collidex, collidey;
-int ski_x, ski_y, ski_next_y;
-int obj_x[OBJ_NUM], obj_y[OBJ_NUM];
+object *obstacles[OBJ_NUM];
+skiDude *zero;
int main(int argc, char** argv)
{
@@ -31,87 +31,75 @@ int main(int argc, char** argv)
pthread_t moveThread, collideYThread;
int moveTRet, collideYRet;
- //Set starting skiDude position and angle
- ski_x = 0; ski_y = 8; ski_next_y = 8;
- angle = 2;
collidex = false; collidey = false;
+
+ zero = new skiDude(0, 8, angle_c);
+
//Make object x and y random
- for (int i = 0; i < OBJ_NUM; i++)
+ for (int i = 0; i < OBJ_NUM/2; i++)
{
- obj_x[i] = rndInt(3,60);
- obj_y[i] = rndInt(0,20);
+ obstacles[i] = new tree(rndInt(3,60), rndInt(3,60));
+ };
+ for (int j = OBJ_NUM/2; j < OBJ_NUM; j++)
+ {
+ obstacles[j] = new rock(rndInt(3,60), rndInt(3,60));
};
clear();
//Draw the ski dude
- drawSkiDude(ski_y,ski_x,angle);
- //Draw the trees
- for (int i = 0; i < OBJ_NUM/2; i++)
- drawTree(obj_x[i], obj_y[i]);
- //Draw the rocks
- for (int i = OBJ_NUM/2; i < OBJ_NUM; i++)
- {
- drawRock(obj_x[i], obj_y[i]);
- };
+ zero->draw();
+ //Draw the obstacles
+ for (int i = 0; i < OBJ_NUM; i++)
+ obstacles[i]->draw();
refresh();
//Start the threads
- moveTRet = pthread_create(&moveThread,NULL,timer,NULL);
- collideYRet = pthread_create(&collideYThread,NULL,collideY,NULL);
+ moveTRet = pthread_create(&moveThread, NULL, timer, NULL);
+ collideYRet = pthread_create(&collideYThread, NULL, collideY, NULL);
while (!collidex && !collidey)
{
d = getch(); // input from keyboard
switch (d)
{
- case KEY_UP: case '8': angle+=1; break;
- case KEY_RIGHT: case '5': break;
- case KEY_DOWN: case '2': angle-=1; break;
+ case KEY_UP: case '8': zero->setAngle(zero->getAngle() + 1); break;
+ case KEY_DOWN: case '2': zero->setAngle(zero->getAngle() - 1); break;
+ case KEY_RIGHT: case '5': break;
case 'q': finish(0); break; // quit?
};
- //Check angle bounds
- if (angle > 4)
- angle = 4;
- if (angle < 0)
- angle = 0;
-
clear();
if (!collidex && !collidey)
- drawSkiDude(ski_y,ski_x,angle); //Draw the ski dude
+ zero->draw(); //Draw the ski dude
else
{
- add(ski_x,ski_y,'X');
+ zero->crash();
break;
};
- //Draw the trees
- for (int i = 0; i < OBJ_NUM/2; i++)
- drawTree(obj_x[i], obj_y[i]);
- //Draw the rocks
- for (int i = OBJ_NUM/2; i < OBJ_NUM; i++)
- {
- drawRock(obj_x[i], obj_y[i]);
- };
+ //Draw the obstacles
+ for (int i = 0; i < OBJ_NUM; i++)
+ obstacles[i]->draw();
//Make sure ski dude goes in the right direction
- switch (angle)
+ /*switch (angle)
{
case angle_l:
case angle_cl: ski_next_y = ski_y+1; break;
case angle_r:
case angle_cr: ski_next_y = ski_y-1; break;
- };
+ };*/
if (!collidex && !collidey)
- ski_y = ski_next_y;
+ zero->setY(zero->getNextY());
//If ski dude is not complete left or right, add to the position
if (angle > angle_l && angle < angle_r)
- ski_x++;
+ zero->setX(zero->getX() + 1);
refresh();
}
refresh();
+ pthread_exit(NULL);
finish(0);
return 0;
};
@@ -121,12 +109,12 @@ void* timer(void* temp)
//Check collisions with rocks
for (int i = OBJ_NUM/2; i < OBJ_NUM; i++)
{
- if (ski_x == obj_x[i])
+ if (zero->getX() == obstacles[i]->getX())
collidex = true;
};
- system("sleep 1");
- if (!collidex && !collidey)
- ski_x++;
+ system("sleep 2");
+ //if (!collidex && !collidey)
+ zero->setX(zero->getX() + 1);
};
void* collideY(void* temp)
@@ -134,7 +122,7 @@ void* collideY(void* temp)
//Check collisions with rocks
for (int i = OBJ_NUM/2; i < OBJ_NUM; i++)
{
- if (ski_next_y == obj_y[i])
+ if (zero->getNextY() == obstacles[i]->getY())
collidey = true;
};
};