My Asteroids Program

So I made a little game in the console using the console game library
(here's the link http://www.johnromero.com/developer.html)

My problem is, the program doesn't work.
It compiles just fine but when it runs nothing happens.
Absolutely nothing

Here's the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//Asteroids
#include "console.h"
#include <conio.h>		// for _getch()
#include <stdlib.h>		// for printf()
#include <time.h>		// for srand(), rand()

using namespace std;

void drawPlayer(int x,int y,int ox,int oy,char sprite)
{
	GotoXY(x,y);
	cout<<sprite;

	if (x!=ox || y!=oy){
		GotoXY(ox,oy);
		cout<<" ";}
}

void gameLoop()
{

	 //Setting player 1's coordinates
     int p1x=5;
     int p1y=25;

	 //The way the player is facing
	 //1=Up 2=Up+Right 3=Right 4=Down+Right 
	 //5=Down 6=Down+Left 7=Left 8=Up+Left
	 int pdirection=7; //The player starts off facing left

	 int key=0;
	 int p1key=0;

	 bool gameExit=false;

	 char p1char='-';

	 for(;;);
	 {

		int p1oldx=p1x;
		int p1oldy=p1y;
		
		if (_kbhit())
			key = _getch();
		
		if (key==KEY_ARROWUP || key==KEY_ARROWLEFT || key==KEY_ARROWRIGHT || key==KEY_S)
			p1key = key;
		 
		if (p1key==KEY_ARROWRIGHT)
			++pdirection;

		if (p1key==KEY_ARROWLEFT)
			--pdirection;

		if (pdirection < 1)
			pdirection = 8;

		if (pdirection > 8)
			pdirection = 1;

		switch (pdirection){
			case 1:
			{
				p1char='|';
				break;
			}
			case 2:
			{
				p1char='/';
				break;
			}
			case 3:
			{
				p1char='-';
				break;
			}
			case 4:
			{
				p1char='\\';
				break;
			}
			case 5:
			{
				p1char='|';
				break;
			}
			case 6:
			{
				p1char='/';
				break;
			}
			case 7:
			{
				p1char='-';
				break;
			}
			case 8:
			{
				p1char='\\';
				break;
			}
		}

		if (p1key==KEY_ARROWUP){
			switch (pdirection){
				case 1:
				{
					--p1y;
					break;			
				}
				case 2:
				{
					--p1y;
					++p1x;
					break;
				}
				case 3:
				{
					++p1x;
					break;
				}
				case 4:		
				{
					++p1y;
					++p1x;
					break;
				}
				case 5:  //5=Down 6=Down+Left 7=Left 8=Up+Left
				{
					++p1y;
					break;
				}
				case 6:
				{
					++p1y;
					--p1x;
					break;
				}
				case 7:
				{
					--p1x;
					break;
				}
				case 8:
				{
					--p1y;
					--p1x;
					break;
				}
			}
		}
		
		Sleep(100);

		drawPlayer(p1x,p1y,p1oldx,p1oldy,p1char);
	}
}

int main()
{
	ClrScr();

	gameLoop();

	return 0;
}


This is just a rough program I made today so please just focus on why it isn't functioning instead of any other errors it (probably) has.
1
2
for(;;);
{


Loops stop at the next semicolon or brace set.

That is an empty loop. You're deadlocking the program.

Get rid of that semicolon:

1
2
for(;;)  // no semicolon after the for loop
{
Thank you very much!
It's disheartening to think that just 1 semicolon can screw over my program because switching back to C++ after a while with Pascal is a little difficult.
I look forward to using this forum in the future!
So I made a little game in the console using the console game library
(here's the link http://www.johnromero.com/developer.html)


you feel like john romero?... you got to be very old :D...

hes a legend in game programming... on the level of sid meier and peter molineux:P...
Last edited on
Topic archived. No new replies allowed.