Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 22nd, 2006, 3:57 PM   #1
jeremy04
Newbie
 
Join Date: May 2006
Location: near Philly
Posts: 4
Rep Power: 0 jeremy04 is on a distinguished road
Send a message via AIM to jeremy04
Space invaders "concept"

Hey guys..

I have to make a final project (sure you've heard alot of "requests")
I have a simple question..

Very simular to this guys:
http://www.programmingforums.org/for...space+invaders


how would I go about making the aliens in "Space Invaders" ALL move to the right, then down, then left, etc..

Heres my code so far:

#include <iostream.h>
#include <conio.h>
#include <time.h>
#include <lvp/string.h>

void sleep(double delay) {

 time_t start_time, cur_time;

			time(&start_time);
			do
			{
					  time(&cur_time);
			}
			while((cur_time - start_time) < delay);
}

int main() {

		  const int rows = 12;
		  const int cols = 6;
		  int g=0;


String Aliens[rows][cols];
int temp[rows][cols];


for(int x=1; x<rows; x++) {
	for(int y=0; y<cols; y++) {

		Aliens[x][y]="~";

		}
	}


for( x=1; x<rows; x+=2) {
	for(int y=0; y<cols; y++) {
		 g++;
		temp[x][y]= g;
		Aliens[x][y]="(^_^)";

		}
	}

		 for(int f=1; f<5; f++) {


				for(x=1; x<rows; x+=6)
					{
						for(int y=0; y<cols; y++) {


							gotoxy(f+1,y);

							cout << Aliens[x][y];


					}

		}

	  sleep(0.5);
	  clrscr();


	}




}

Its only makes the first column move not the 2nd...

I'm kindof stuck @ this code.. I heard you have to like make the aliens "move" to the next array?

if thats so, does simply adding +1 to x and storing a new "alien" in that spot, and make x = nothing. (to give the impression that it moved instead of clearing the screen) the way to go?

any insight would be much appreciated.
jeremy04 is offline   Reply With Quote
Old May 22nd, 2006, 6:21 PM   #2
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Why are you using deprecated headers? And what is lvp/string.h? Is that something from turbo C++ or am I missing something? You might also want to change your indenting, cause this reads very annoyingly.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old May 22nd, 2006, 6:53 PM   #3
jeremy04
Newbie
 
Join Date: May 2006
Location: near Philly
Posts: 4
Rep Power: 0 jeremy04 is on a distinguished road
Send a message via AIM to jeremy04
Yes it is Turbo C++, yeah my identing is bad too ..

lvp/string.h is from my book, no worries bout that.

from what i described above post, does it make sense at all to anybody?
jeremy04 is offline   Reply With Quote
Old May 22nd, 2006, 7:09 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
First of all, use a less dead compiler. Use the correct headers, and indent your code properly.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 22nd, 2006, 7:37 PM   #5
jeremy04
Newbie
 
Join Date: May 2006
Location: near Philly
Posts: 4
Rep Power: 0 jeremy04 is on a distinguished road
Send a message via AIM to jeremy04
Ok I will do that. Like I said, I'm not too sure about the concept of programming this game.. you know like the strategy part. what would I be better off using ,arrays or structures? or both perhaps.
jeremy04 is offline   Reply With Quote
Old May 22nd, 2006, 7:46 PM   #6
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 422
Rep Power: 4 Wizard1988 is on a distinguished road
If all of your aliens are kept in an array, simply loop through the whole array and change the variable(s) that is responsible for the x,y position.
Wizard1988 is offline   Reply With Quote
Old May 23rd, 2006, 5:34 AM   #7
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Use std::vector and iterate (std::iterator) through it.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC