Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
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
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:17 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.