Click to See Complete Forum and Search --> : C++ Trouble


Stradman
03-28-2001, 08:26 PM
I have this Computer Science assignment where I have to do a game and I want to do Space Invaders. however I do not know how I would make everything move according to keyboard response. I also need to know anything else that might be of importance....

Zoma
03-29-2001, 01:02 PM
Well, there's a lot to be said. I'm not sure how much you know, because your post is very vague.

Basically, games are structured with everything inside one big loop (I think this is sometimes called, "the game cycle"). Every iteration of the loop corresponds to everything in the game being done once. By this I mean that during each iteration, hit detection is checked, input is checked, graphics are draw, etc. There's been a decided order for all of this, but I forget what it is. Probably something like game logic, then graphics, then user input. Although user input could be the first thing checked, I'm not sure.

I have no idea what you're doing, though. The question seems simple enough that this probably isn't for an advanced class (eg, a graduate level CS class on game programming).

Basically, you'll want to check to see if the user has entered anything once per game cylce. If he has, then you'll want to buffer his input, and then run some tests on it. The first check will obviously be to see if his input is valid. If the "p" key doesn't correspond to valid user input, then the input is just discarded, and the game continues. The valid keys are then checked to see what they entered, with the corresponding logica for each key taking place. Actually, checking for a valid key really isn't necessary if you just used a case statement with the default action being "break."

Anyways, I hope this answers your question. Please give some more specific details, if it does not.

richardginn
03-29-2001, 01:46 PM
To make this game you will have to decide on many things.

1. What the good guy is going to look and how he will move.

2. What the bad guy is going to look and how it will move.

3. What will the fire look like for both good guy and bad guy.

You will need one gigantic loop with a bunch of function calls to it.

Some of the functions used:

proper input from user.

If the Good guy is at the edge of the screen.

If the Bad guys is at the edge of the screen.

Movement of the character.

Function to update score if you want it.

Function for the ammo used in the game.

Collison detection function.

You may need more than just these.

------------------
www.geocities.com/richardginn/templatehtml (http://www.geocities.com/richardginn/templatehtml) -Come visit the Template HTML homepage

SBC member

Stradman
03-29-2001, 08:27 PM
well since its like a space invaders game, I figure the guy(which will be one ship) will be at the bottom. it will not move up or down, just left and right to be able to avoid the shots from the aliens. The alien ships will be at the top and there will be 4 rows of them. The bottom row will only shoot and at random times as well. They will progress towards the player(which is at the bottom) a row at a time. Space bar will shoot a bullet at the enemy ships. Left and right arrow keys will move the ship left and right. I need help on all that and also a function that will take care of the shooting.
Thanks.

richardginn
03-30-2001, 10:45 AM
well when you press the spacebar the program will first check to see if that is a valid character, then it will go to a function that will move a shot straight up the screen.
If the shot is a direct hit on the bad guy it will then goto another function that will destroy the bad and remove him off the screen.

------------------
www.geocities.com/richardginn/templatehtml (http://www.geocities.com/richardginn/templatehtml) -Come visit the Template HTML homepage

SBC member

Zoma
03-30-2001, 11:26 PM
Basically what you'll want to do is this:

In your main loop, you will have something like this:


char ch;
ch = GetInput();
CheckInput(ch);


The CheckInput function looks like:


switch(ch)
{
case 'a':
MoveLeft();
break;

case 'd':
MoveRight();
break;

case ' ':
Shoot();
break;

...

default:
break;
}


Then the function MoveLeft would look like:


{
if ( player.x_coord >= LEFT_SIDE_OF_SCREEN + SHIP_MOVEMENT_RATE + (int)(SHIP_SIZE/2) )
player.x_coord -= SHIP_MOVEMENT_RATE;
}


Hope this looks good on the page http://www.sharkyforums.com/ubb/smile.gif