View Single Post
  #9  
Old 01-22-2012, 09:37 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Separate your presentation code from the game logic and you will simplify things immensely. You'll have code that's easier to understand, easier to change later, and is less prone to errors.

For example, something like:
PHP Code:
if (RIGHT_WALL_X ball.pos.ball.radius) {
  
// we have a collision on the right wall!!

is much easier to manage and understand than your code (which I'm only assuming is doing something similar to what's above):
PHP Code:
if(findImg(1004).polygon[temp.iy] - cos(degtorad(temp.angle)) * BALL_SPEED findImg(1000).polygon[1] || 
      
findImg(1004).polygon[temp.iy] - cos(degtorad(temp.angle)) * BALL_SPEED findImg(1000).polygon[7]){ 
      
temp.angle 180 temp.angle
    } 
In your game loop, you would have something like:
PHP Code:
function gameLoop() {
  
updateGame(); // updates the model (check for collisions, move ball, etc)
  
renderGame(); // draws the model in its current state

  // .. loop endlessly

Use simple units for the model (for example, a ball with a width of 1 unit instead of 16 pixels) and then when you are drawing the game, just convert the units to pixels (or tiles, or whatever). This would also allow you to change the way you render the game without having to mess with the game logic at all.

Also, I would use vectors for something like this, too.
__________________
Reply With Quote