   Noob windows game problem
  I'm writing code for my game dev class and I'm having trouble making 3 of my game objects (tanks) move to one side of the screen, hit it, move to the other wall hit it and repeat. Similar to how space invaders work but without the movement downwards towards to character.I'm using visual studio 2010 for C++right now im having it hit the left side of the screen and stop before leaving frame. Using this.if(gameObject4Position.x > enemyTankHalfWidth) // gameObject4Position tracks the nearest tank to the left wall   {  gameObject2Position.x -= enemySpeed; // these decrements move the three separate tanks to the left and the control if statement stops them all when the first one reaches the side.  gameObject3Position.x -= enemySpeed;  gameObject4Position.x -= enemySpeed;  } I'm a noob here and im not sure what else is required for someone to help me. Please mention if I'm missing any pertinent information. also, i would like this to loop repeatedly. Thanks in advance 
I'm writing code for my game dev class and I'm having trouble making 3 of my game objects (tanks) move to one side of the screen, hit it, move to the other wall hit it and repeat. Similar to how space invaders work but without the movement downwards towards to character.I'm using visual studio 2010 for C++right now im having it hit the left side of the screen and stop before leaving frame. Using this.if(gameObject4Position.x > enemyTankHalfWidth) // gameObject4Position tracks the nearest tank to the left wall  {gameObject2Position.x -= enemySpeed; // these decrements move the three separate tanks to the left and the control if statement stops them all when the first one reaches the side.gameObject3Position.x -= enemySpeed;gameObject4Position.x -= enemySpeed; } I'm a noob here and im not sure what else is required for someone to help me. Please mention if I'm missing any pertinent information. also, i would like this to loop repeatedly. Thanks in advance Simple. Represent your movement on the x axis by a "velocity vector". In this case we only need the x component of the velocity vector (the y component would be zero) and so I will denote that by vx. Now:Start of game:vx = -enemySpeed;while(gameIsLooping){gameObject2Position.x += vx; // these  decrements move the three separate tanks to the left and the control if  statement stops them all when the first one reaches the side.    if(gameObject2Position.x < leftBoundryX)    {vx = enemySpeed;  //or vx = abs(vx); where abs stands for absolute value.    }}Basically when we set vx negative the object moves left. When we set vx positive then the object moves right.P.S.: Word of advice... From the looks of your code, you really need to look into an object management system. Try storing your objects in an array and then iterating through the objects to update the positions. That way you can add objects without exponentially increasing your code.   ;[quote name='MCPengelly' timestamp='1303682499' post='4802428']I'm writing code for my game dev class and I'm having trouble making 3 of my game objects (tanks) move to one side of the screen, hit it, move to the other wall hit it and repeat. Similar to how space invaders work but without the movement downwards towards to character.I'm using visual studio 2010 for C++right now im having it hit the left side of the screen and stop before leaving frame. Using this.if(gameObject4Position.x > enemyTankHalfWidth) // gameObject4Position tracks the nearest tank to the left wall  {gameObject2Position.x -= enemySpeed; // these decrements move the three separate tanks to the left and the control if statement stops them all when the first one reaches the side.gameObject3Position.x -= enemySpeed;gameObject4Position.x -= enemySpeed; } I'm a noob here and im not sure what else is required for someone to help me. Please mention if I'm missing any pertinent information. also, i would like this to loop repeatedly. Thanks in advance Simple. Represent your movement on the x axis by a "velocity vector". In this case we only need the x component of the velocity vector (the y component would be zero) and so I will denote that by vx. Now:Start of game:vx = -enemySpeed;while(gameIsLooping){gameObject2Position.x += vx; // these  decrements move the three separate tanks to the left and the control if  statement stops them all when the first one reaches the side.    if(gameObject2Position.x < leftBoundryX)    {vx = enemySpeed;  //or vx = abs(vx); where abs stands for absolute value.    }}Basically when we set vx negative the object moves left. When we set vx positive then the object moves right.P.S.: Word of advice... From the looks of your code, you really need to look into an object management system. Try storing your objects in an array and then iterating through the objects to update the positions. That way you can add objects without exponentially increasing your code.[/quote]How would i make the variable leftBoundryX though?Make a completely new variable?also, lines -while(gameIsLooping){are they required if i already have a game loop? Because my game loop is above where i actually create my tank objects. also a word on your advice. I'm pretty new/not great at this stuff so all advice is welcome. My first year is almost complete and i'm working out best i can with limited knowledge so I'm not sure how i would do specifically what you're referring to. A link or something might help though? I know of arrays but haven't really used them for practical use. Thanks in advance, Sorry again for being inexperienced  I'm doing what i can to improve my knowledge base.   ;[quote name='shadowisadog' timestamp='1303688108' post='4802463'][quote name='MCPengelly' timestamp='1303682499' post='4802428']I'm writing code for my game dev class and I'm having trouble making 3 of my game objects (tanks) move to one side of the screen, hit it, move to the other wall hit it and repeat. Similar to how space invaders work but without the movement downwards towards to character.I'm using visual studio 2010 for C++right now im having it hit the left side of the screen and stop before leaving frame. Using this.if(gameObject4Position.x > enemyTankHalfWidth) // gameObject4Position tracks the nearest tank to the left wall  {gameObject2Position.x -= enemySpeed; // these decrements move the three separate tanks to the left and the control if statement stops them all when the first one reaches the side.gameObject3Position.x -= enemySpeed;gameObject4Position.x -= enemySpeed; } I'm a noob here and im not sure what else is required for someone to help me. Please mention if I'm missing any pertinent information. also, i would like this to loop repeatedly. Thanks in advance Simple. Represent your movement on the x axis by a "velocity vector". In this case we only need the x component of the velocity vector (the y component would be zero) and so I will denote that by vx. Now:Start of game:vx = -enemySpeed;while(gameIsLooping){gameObject2Position.x += vx; // these  decrements move the three separate tanks to the left and the control if  statement stops them all when the first one reaches the side.    if(gameObject2Position.x < leftBoundryX)    {vx = enemySpeed;  //or vx = abs(vx); where abs stands for absolute value.    }}Basically when we set vx negative the object moves left. When we set vx positive then the object moves right.P.S.: Word of advice... From the looks of your code, you really need to look into an object management system. Try storing your objects in an array and then iterating through the objects to update the positions. That way you can add objects without exponentially increasing your code.[/quote]How would i make the variable leftBoundryX though?Make a completely new variable?also, lines -while(gameIsLooping){are they required if i already have a game loop? Because my game loop is above where i actually create my tank objects. also a word on your advice. I'm pretty new/not great at this stuff so all advice is welcome. My first year is almost complete and i'm working out best i can with limited knowledge so I'm not sure how i would do specifically what you're referring to. A link or something might help though? I know of arrays but haven't really used them for practical use. Thanks in advance, Sorry again for being inexperienced  I'm doing what i can to improve my knowledge base.[/quote]If you already have a game loop then you would instead use your own game loop. I just posted that so you knew that the code should be looped. Also leftBoundryX is just a variable representing the left coordinate of your screen (the minimum value the tank can take). You would simply use your own value/variables here but since I wasn't clear on what those were I left it up to you.Try looking for information on data structures and oop programming techniques. Specifically polymorphism...   ;[quote name='MCPengelly' timestamp='1303689768' post='4802473'][quote name='shadowisadog' timestamp='1303688108' post='4802463'][quote name='MCPengelly' timestamp='1303682499' post='4802428']I'm writing code for my game dev class and I'm having trouble making 3 of my game objects (tanks) move to one side of the screen, hit it, move to the other wall hit it and repeat. Similar to how space invaders work but without the movement downwards towards to character.I'm using visual studio 2010 for C++right now im having it hit the left side of the screen and stop before leaving frame. Using this.if(gameObject4Position.x > enemyTankHalfWidth) // gameObject4Position tracks the nearest tank to the left wall  {gameObject2Position.x -= enemySpeed; // these decrements move the three separate tanks to the left and the control if statement stops them all when the first one reaches the side.gameObject3Position.x -= enemySpeed;gameObject4Position.x -= enemySpeed; } I'm a noob here and im not sure what else is required for someone to help me. Please mention if I'm missing any pertinent information. also, i would like this to loop repeatedly. Thanks in advance Simple. Represent your movement on the x axis by a "velocity vector". In this case we only need the x component of the velocity vector (the y component would be zero) and so I will denote that by vx. Now:Start of game:vx = -enemySpeed;while(gameIsLooping){gameObject2Position.x += vx; // these  decrements move the three separate tanks to the left and the control if  statement stops them all when the first one reaches the side.    if(gameObject2Position.x < leftBoundryX)    {vx = enemySpeed;  //or vx = abs(vx); where abs stands for absolute value.    }}Basically when we set vx negative the object moves left. When we set vx positive then the object moves right.P.S.: Word of advice... From the looks of your code, you really need to look into an object management system. Try storing your objects in an array and then iterating through the objects to update the positions. That way you can add objects without exponentially increasing your code.[/quote]How would i make the variable leftBoundryX though?Make a completely new variable?also, lines -while(gameIsLooping){are they required if i already have a game loop? Because my game loop is above where i actually create my tank objects. also a word on your advice. I'm pretty new/not great at this stuff so all advice is welcome. My first year is almost complete and i'm working out best i can with limited knowledge so I'm not sure how i would do specifically what you're referring to. A link or something might help though? I know of arrays but haven't really used them for practical use. Thanks in advance, Sorry again for being inexperienced  I'm doing what i can to improve my knowledge base.[/quote]If you already have a game loop then you would instead use your own game loop. I just posted that so you knew that the code should be looped. Also leftBoundryX is just a variable representing the left coordinate of your screen (the minimum value the tank can take). You would simply use your own value/variables here but since I wasn't clear on what those were I left it up to you.Try looking for information on data structures and oop programming techniques. Specifically polymorphism...[/quote]I'm now having issues with the object actually detecting the edge of the window and coming back. not sure exactly why. But i'll continue to try and get it working.   