Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Apr 25th, 2006, 9:53 PM   #1
lilmul123
Newbie
 
Join Date: Mar 2006
Posts: 22
Rep Power: 0 lilmul123 is on a distinguished road
still working on my game... (for-loop)

the problem I'm having now is trying to show the output of the "ray gun"

#include <conio.h>
#include <stdio.h>
#include <dos.h>
#include <iostream.h>


int main()
{
	char firstchoice,a,dir,length;
	int locationx,locationy,same,timer,locationxbullet,locationybullet;
	timer=50;
	_setcursortype(_NOCURSOR);
	textcolor(YELLOW);
	textbackground(BLUE);
	locationx=40;
	locationy=24;
	locationxbullet=40;
	locationybullet=23;
	clrscr();
	gotoxy(19,12);
	cout << "Welcome to Steve's Awesome Computer Game!";
	gotoxy(19,13);
	cout << "Press H for help.";
	gotoxy(19,14);
	cout << "Otherwise, Press any other key to continue.";
	firstchoice=getch();

if(firstchoice == 'h')
	{
		clrscr();
		cout << "You're a rogue space pilot on a mission to destroy other ASCII characters.\nUse A to move left and D to move right.\nUse the spacebar to shoot.\nYou win when all the other ASCII characters are dead.\nGOOD LUCK!";
	}
	else
	{
	timer=timer-1;
	clrscr();
	for(a=1;a<=79;a++)
	    {
		gotoxy(a,1);printf("X");
		gotoxy(a,25);printf("X");
	    }
	    for(a=2;a<=24;a++)
	    {
		gotoxy(1,a);printf("X");
		gotoxy(79,a);printf("X");
	    }
				// insert the code from other program here for the aliens
	  do
	{

		if(kbhit() !=0)
		{
		dir=getch();

		if(dir=='a')
		{
		   gotoxy(locationx,locationy);
		   printf("   ^_^   ");
		   locationx--;
		   locationxbullet--;
		}
		if(dir=='d')
		{
		gotoxy(locationx,locationy);
		  printf("   ^_^   ");
		  locationx++;
		  locationxbullet++;
		  }
		if(dir=='m')
		{
		gotoxy(locationxbullet,locationybullet);
		for(locationybullet=23;locationybullet>=2;locationybullet--)
		printf("   I   ");
		}
		
	     }
	     }while(dir!='x');
	}

		

	}

near the end, I have a for loop. what I'm trying to get the loop to do is have the "I" start right in front of the ship (the ^_^), and then shoot upwards. the problem is, with this for-loop, the I's just output in a strange horizontal pattern and don't go upwards in a straight line at all. what is the proper loop I should be using? any help is appreciated.


edit: BTW, I'm working on a space invaders clone
lilmul123 is offline   Reply With Quote
Old Apr 25th, 2006, 10:10 PM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 893
Rep Power: 4 The Dark is on a distinguished road
You need to put the gotoxy call inside the for loop, so that you position the cursor just before you call printf.
The Dark is offline   Reply With Quote
Old Apr 25th, 2006, 10:15 PM   #3
lilmul123
Newbie
 
Join Date: Mar 2006
Posts: 22
Rep Power: 0 lilmul123 is on a distinguished road
thanks! it worked. but...it goes directly to the top without any kind of trail. is there an easy fix for this?
lilmul123 is offline   Reply With Quote
Old Apr 25th, 2006, 10:29 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Show your modified loop?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 25th, 2006, 10:36 PM   #5
lilmul123
Newbie
 
Join Date: Mar 2006
Posts: 22
Rep Power: 0 lilmul123 is on a distinguished road
		if(dir=='m')
		{
		for(locationybullet=23;locationybullet>=2;locationybullet--)
		gotoxy(locationxbullet,locationybullet);
		printf("   I   ");
		}
lilmul123 is offline   Reply With Quote
Old Apr 25th, 2006, 10:39 PM   #6
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 893
Rep Power: 4 The Dark is on a distinguished road
You need braces around the statements in the for loop - at the moment it is just running through the gotoxy's
The Dark is offline   Reply With Quote
Old Apr 25th, 2006, 10:42 PM   #7
lilmul123
Newbie
 
Join Date: Mar 2006
Posts: 22
Rep Power: 0 lilmul123 is on a distinguished road
Quote:
Originally Posted by The Dark
You need braces around the statements in the for loop - at the moment it is just running through the gotoxy's

can you give an example please?
lilmul123 is offline   Reply With Quote
Old Apr 25th, 2006, 11:17 PM   #8
rollin92
Newbie
 
Join Date: Apr 2006
Posts: 2
Rep Power: 0 rollin92 is on a distinguished road
		if(dir=='m')
		{
		   for(locationybullet=23;locationybullet>=2;locationybullet--)
		   {
                         gotoxy(locationxbullet,locationybullet);
		         printf("   I   ");
                   }
		}
rollin92 is offline   Reply With Quote
Old Apr 25th, 2006, 11:31 PM   #9
lilmul123
Newbie
 
Join Date: Mar 2006
Posts: 22
Rep Power: 0 lilmul123 is on a distinguished road
thank you, kind sir. my gun is complete. now to work on those aliens.
lilmul123 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 2:39 AM.

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