![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
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. ![]() |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#3 |
|
Newbie
|
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? |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
|
|
|
|
|
|
#5 |
|
Newbie
|
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.
|
|
|
|
|
|
#6 |
|
Professional Programmer
Join Date: Oct 2005
Location: Chitown
Posts: 422
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|