Thread: Help with logic..

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    6

    Help with logic..

    So basically im trying to work on a single player pong game ...

    What im struggling with the logic behind the movement of the paddle..

    If i just keep pressing the one direction, say a ... that moves fine, though the issue arises when i than press z, rather than moving down just one space, it moves far more than that...

    Code:
    	
    
    /* a = up, z = down */
    
    
    	int	c, temp, moveA, moveZ;
    	temp = 1; 
    	moveA, moveZ = 5; 
    	
    	set_up();
    
    	while ( ( c = getchar()) != 'q' ){
    		if ( c == 'a' ){
    		clear();
    		attron(A_REVERSE);
    	
    		move(0,LEFT_EDGE+20);
    		addstr(" Single Player Pong ");	
    	
    		move(2,LEFT_EDGE+2);
    		addstr(" INSTRUCTIONS: (move paddle) A - up, Z - down (quit) - q ");
    	
    	
    		move(TOP_ROW-1,LEFT_EDGE-1);           	
    		hline(' ', LEFT_EDGE + 53);		/* Top Border */
    		vline(' ', TOP_ROW + 13);		/*  Left Side  */
    	
    		move(BOT_ROW+1,LEFT_EDGE); 	  	/* Bottom Border */
    		hline(' ', LEFT_EDGE + 52);
    		
    		moveA = (TOP_ROW + 5)-temp;
    		move(moveA,RIGHT_EDGE+1);		  
    		vline(' ', (BOT_ROW-TOP_ROW)/3);
    		attroff(A_REVERSE);
    		getch();	
    		if ( c == 'a' )	{
    			temp++;
    			}
    		else {
    			moveA = moveA +1;
    			}
    		}
    		else if ( c == 'z' ){
    		clear();
    		attron(A_REVERSE);
    	
    		move(0,LEFT_EDGE+20);
    		addstr(" Single Player Pong ");	
    	
    		move(2,LEFT_EDGE+2);
    		addstr(" INSTRUCTIONS: (move paddle) A - up, Z - down (quit) - q ");
    	
    	
    		move(TOP_ROW-1,LEFT_EDGE-1);           	
    		hline(' ', LEFT_EDGE + 53);		/* Top Border */
    		vline(' ', TOP_ROW + 13);		/*  Left Side  */
    	
    		move(BOT_ROW+1,LEFT_EDGE); 	  	/* Bottom Border */
    		hline(' ', LEFT_EDGE + 52);
    		
    		moveZ = (TOP_ROW + 5)+ temp;
    		move(moveZ,RIGHT_EDGE+1);	  
    		vline(' ', (BOT_ROW-TOP_ROW)/3);
    		attroff(A_REVERSE);
    		getch();
    		if ( c == 'z' ){
    			temp++;
    			}
    		else{
    			moveZ = moveZ -1;
    			}
    		}

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Make a function to handle movement. Pass it a value that indicates up or down. If up, use + 1, if down, use -1 (or whatever your movement increment is).


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Digital Logic
    By strokebow in forum Tech Board
    Replies: 3
    Last Post: 12-09-2006, 01:05 PM
  2. Logic
    By LordBronz in forum C++ Programming
    Replies: 6
    Last Post: 05-23-2006, 05:41 PM
  3. Actors, cues, event based logic.
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 04-27-2006, 10:58 PM
  4. Circular Logic
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-15-2001, 08:10 PM