ASCII 219 and moving

This is a discussion on ASCII 219 and moving within the Game Programming forums, part of the General Programming Boards category; Okay, I made a really bad program just to mess around with moving something on the screen, I have two ...

  1. #1
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262

    ASCII 219 and moving

    Okay, I made a really bad program just to mess around with moving something on the screen, I have two problems, first when I use the ASCII 219(That's the block on right?) it is some vowel with a tilde above it... also how can I have the user enter a key without having to have them push enter?

    Code:
    // Written by Phillip Hermans
    // Runnin' 'round!
    // Started Feburary 17, 2003
    
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    	{
    	int x = 5, y = 5,sent = 1;
    	char ent;
    
    	cout << "To stop playing hit 0 then enter, to move hit a direction(W,A,S,D) then enter!" << endl;
    
    	gotoxy(x,y);
    	cout << char(219);
    
    	while(ent != 0)
    		{
    		cin >> ent;
    		switch(ent)
    			{
    			case 'w':
    			case 'W': y--; break;
    
    			case 's':
    			case 'S': y++; break;
    
    			case 'd':
    			case 'D': x++;  break;
    
    			case 'a':
    			case 'A': x--;  break;
    
    			case '0': return 0;
    
    			default: cout << "YOU BROKE IT!";
    			}
    		clrscr();
    		gotoxy(1,1);
    		cout << "To stop enter 0";
    
    		gotoxy(x,y);
    		cout << char(219);
    		}
    
    		return 0;
    		}

  2. #2
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    also how can I have the user enter a key without having to have them push enter?
    is this pure DOS or just DOS console. If it was pure DOS I would do some interrupt calls. DOS console is a diff story. I don't know how to do it on DOS console (I jumped from pure DOS to windows, never did DOS console)

  3. #3
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ...

    getch();

    char choice;
    choice=getch();

    if(choice==Up)
    {
    x--;
    }

    edit: btw you need to include conio.h for this

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    And if you want a constant flow in the program without any halts to read a character:

    if(kbhit()) Key = getch();
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    I really don't know what platform I'm using...

    I can tell you the compiler Borland Turbo C++ 4.5.
    So does anyone know about that block character? Okay it doesn't work here either it displays: ...

    Also is there a way to move the object without clearing the screen and displaying it again? Is this the normal way to do it?
    Last edited by CheesyMoo; 02-18-2003 at 03:07 PM.

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by CheesyMoo
    Also is there a way to move the object without clearing the screen and displaying it again? Is this the normal way to do it?
    Print an 'empty' character (space or whatever) at the object's position, move the object then draw the object's character at the new position.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    I read that wrong, I thought he meant without pausing gameloop. Yeah you can just use getch(), but it pauses your program until somebody presses a key, which for games, sux0rs.

  8. #8
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Okay I wanna' kick it up a notch, how do I read input from the arrow keys?

  9. #9
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Okay here is my updated code, after you push the button once, you can't move it again...

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    	{
    	int x=5,y=5;
    	char Key;
    	gotoxy(x,y);
    
    
    	while(Key != 'x')
    		{
    		getch();
    		if(kbhit()) Key = getch();
    		gotoxy(x,y);
    		cout << " ";
    		if(Key == 'w')
    		 y--;
    		if(Key == 's')
    		 y++;
    		if(Key == 'a')
    		 x--;
    		if(Key == 'd')
    		 x++;
    		if(Key == 'x')
    		 break;
    		gotoxy(x,y);
    		cout << char(219);
    		}
    
    	return 0;
    	}

  10. #10
    I am he who is the man! Stan100's Avatar
    Join Date
    Sep 2002
    Posts
    361

    VK_

    I'm using the VK_ stuff now, and I can't get VK_H to work. SEE:
    Code:
    ReadConsoleInput(hInput, &InputRecord, 1, &Events);
    if(InputRecord.EventType == KEY_EVENT && InputRecord.Event.KeyEvent.bKeyDown)
    {
    if (InputRecord.Event.KeyEvent.wVirtualKeyCode==VK_H)
    {
    cout << "Controls: \n";
    cout << "Hit \"H\" at any time to display help, and controls \n";
    cout << "Hit Space to fire \n";
    }
    It gives me a error saying VK_H isn't defined
    Stan The Man. Beatles fan

    When I was a child,
    I spoke as a child,
    I thought as a child,
    I reasoned as a child.
    When I became a man,
    I put childish ways behind me"
    (the holy bible, Paul, in his first letter to the Cor. 13:11)

  11. #11
    ! |-| /-\ +3 1337 Yawgmoth's Avatar
    Join Date
    Dec 2002
    Posts
    187
    Char 219 shows up as a block to me.
    L33t sp3@k sux0rz (uZ it t@k3s 10 m1|\|ut3s 2 tr@nzl@te 1 \/\/0rd & th3n j00 h@\/3 2 g3t p@$t d@ m1zpelli|\|gz, @tr0(i0u$ gr@mm@r @|\|d 1n(0/\/\pr3#3|\|$1bl3 $l@|\|g. 1t p\/\/33nz j00!!

    Speling is my faverit sujekt

    I am a signature virus. Add me to your signature so that I may multiply.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21