Thread: moving objects

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    Question moving objects

    hi

    i wanna write a code that permits the user to shift the object to all sides.

    for instance the keys are "a "for lest "s" for down "d" for right and finaly "w"w for up.i developed a solution for this but it doesnt run correctly;

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

    int i,x,y;
    char key;
    void main() {
    .
    .
    .
    key = getch();
    if (key=' w ') {
    movey++
    }
    .
    .
    .
    and goes on like that
    is that correct?or what should i do?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    48
    (key=' w ')

    should be (key == 'w')

    but that could be a typo. i'm not sure about the 'w' either. it might be "w" but i can't remember if thats java or C++
    astride a storied past, thats everywhere you are

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    43
    Yeah I did the same thing on a program of mine only i used the keys E=left, D=down, E=up, and F=right. In my program I put it in it's own function so I only had to type PLAYER(); in the main() function. The code is this.

    Code:
    void player()
    {
    
    /* int X and Y tell where the player is
       int oldX and oldY tell where the player moved from (to clear that spot)
    
       int X=1, Y=1, oldX, oldY;
       char move;
    
       while(1)
       {
    
    /* This is where the computer knows where to put
    the player and set it up to clear the last place
    the player was so you don't see a trail of O's. */
    
    		gotoxy(X,Y);
    		oldX=X;
    	        oldY=Y;
    		printf("O");
    
    
    /* This is the part where it gets the input
    and sees if they moved left, right, up, or down. */
    
               move=toupper(getch());
    	   switch(move)
    	   {
    
    		   case 'S':
    				X--;
    			   points--;
    			      break;
    
    		   case 'D':
    				Y++;
    			   points--;
    			      break;
    
    		   case 'F':
    			   points--;
    				X++;
    			      break;
    
    		   case 'E':
    				Y--;
    			   points--;
    			      break;
    
    		   default:  //if they hit keys other then EDSF print this
    			gotoxy(1,24);
    			printf("Move with E, D, S, F\n");
    			printf("Make your next move.");
    			move=toupper(getch());
    	   }//end switch
    
    // puts a space where the player was after they moved	
          gotoxy(oldX, oldY);
          printf(" ");
    
       }//end while loop
    
    }//end player
    ()(ôô)()© MonKey ware
    Kyle J. R.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving objects with mouse in 3D.
    By psychopath in forum Game Programming
    Replies: 15
    Last Post: 07-10-2011, 04:20 PM
  2. Moving Objects in D3D?
    By VertexBuffer in forum Game Programming
    Replies: 3
    Last Post: 01-18-2007, 04:21 AM
  3. moving objects in a window
    By axr0284 in forum Windows Programming
    Replies: 1
    Last Post: 02-26-2006, 07:23 PM
  4. moving objects in d3d...
    By Unregistered in forum Game Programming
    Replies: 1
    Last Post: 01-09-2002, 04:07 PM
  5. Moving Objects on the Screen
    By BigSter in forum C++ Programming
    Replies: 6
    Last Post: 12-02-2001, 10:37 PM