Thread: virtual keys, while loop, movement

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    41

    virtual keys, while loop, movement

    ok, i have the player move with the virtual keys, and i want it to keep their location, it would be in an (x, y) grid, so i would have the x and y variable. My question is, while in the loop of the game, i would have it call a function to add one to x if they go up and minus one if they go down, and add one to y if they go right and minus one if they go left. I know int handles both possative and negative numbers so im not worried about that but im wondering, when the game loops would it read the new values of x and y or how would i get it to keep itself updated?
    In order of learned:
    HTML - Mastered
    CSS - Enough to use
    SSI - Mastered
    PHP - Advanced
    C/C++ - Current Project

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    pass variables by reference ( thats by pointers in c) then the variables will be updated properly.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    41
    ok, heres the basic of what i have so far:
    Code:
    int right(int& x) {return x++;}
    thats a refrence to x, and if they move right add one to x, but now how do i get it to restate that x is now the new number for good, unless they move again?
    In order of learned:
    HTML - Mastered
    CSS - Enough to use
    SSI - Mastered
    PHP - Advanced
    C/C++ - Current Project

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    because you are using a reference then that variable x will be updated by the function. So after calling right() x will be x+1. try it. call the function and cout initial value of x and value after func call.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Partners (D&D fan preferably)
    By C_ntua in forum Game Programming
    Replies: 44
    Last Post: 11-22-2008, 09:21 AM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. A somewhat bizzare problem!!! - WHILE LOOP
    By bobthebullet990 in forum C Programming
    Replies: 3
    Last Post: 03-31-2006, 07:19 AM
  4. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-31-2006, 12:59 AM
  5. Program with Shapes using Virtual Functions
    By goron350 in forum C++ Programming
    Replies: 12
    Last Post: 07-17-2005, 01:42 PM