Introduction
Introduction Statistics Contact Development Disclaimer Help
Updated - gnuskii - GNUSki improved for ascii skiing experience.
git clone git://bitreich.org/gnuskii git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws…
Log
Files
Refs
Tags
README
LICENSE
---
commit b964e57401e264dbf9a4804eb6d99714f7305a0e
parent cab3875cb4121070254411cac19504fd56b94cea
Author: Rudolf Olah <[email protected]>
Date: Tue, 28 Jun 2005 08:39:50 -0400
Updated
Diffstat:
M src/main.cpp | 82 +++++++++++++----------------…
1 file changed, 35 insertions(+), 47 deletions(-)
---
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; …
- case KEY_RIGHT: case '5': …
- case KEY_DOWN: case '2': angle-=1; …
+ case KEY_UP: case '8': zero->setAngle(ze…
+ case KEY_DOWN: case '2': zero->setAngle(…
+ 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; bre…
case angle_r:
case angle_cr: ski_next_y = ski_y-1; bre…
- };
+ };*/
if (!collidex && !collidey)
- ski_y = ski_next_y;
+ zero->setY(zero->getNextY());
//If ski dude is not complete left or right, add to the positi…
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;
};
};
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.