game basics

Started by
3 comments, last by evilclown 22 years, 2 months ago
I''m trying to figure out the best way to organize objects in my game. It will be a top down view, and the arrow keys move you. Zombies will chase and attack you. Before if I ever had to do collision detection I would have to loop through each type of object and check. Is there some way I can inheriet a class so they all have similar types? If I layed it out on a tree it would look like this

baseclass
  creature
    player
    zombie
      regular
      boss
  object
    box
    wall
  projectile
   bullet
   flame		
 
Then I''m not sure what to do. Maybe make a vector of creatures, objects and projectiles. And for each creature see if it runs into another creature or object. Then if a projectile hits a object, damage it, if it hits a creature, hurt it. Another problem is how should I make movement? I was using

float move_x(float x, float distance, double dir) {
  return (distance * cos(dir)) + x;
}
float move_y(float y, float distance, double dir) {
  return (distance * sin(dir)) + y;
}
 
I thought I could just have coordinates that the zombie wants to reach, and each update it moves a little farther. Is it much harder to use vectors? (I think then they head to where you are going, not just your current position.)
Advertisement
Try this instead, I''m pretty sure it will work.



float move_x(float x, float distance, double dir) { return distance * (cos(dir)+sin(dir)) + x;}

float move_y(float y, float distance, double dir) { return distance * (sin(dir)-cos(dir)) + y;}


my movement code worked, but I don''t know how to do the other part. Should I be using OOP?
i like to design my agents so that they are black boxes.

in other words, your game should not be able to mess up you agents, other than initialization and delete.

i do this like:

for all_objects
object.act();

so the ai is ran from inside your class, and the player getinput is inside the class.
so player is derived from monster, where player.act overides monser.act, that normally does ai.

entity agent -default agent is monsters  player -overrides ai routines with getinputs staticStuff  dynamicStuff 


you are apparently using static polymorphism, where you have a different class for each thing type. instead, think about having a general class that can be loaded with properties.
for instance, zombie would have hp = 50, while mummy would have hp = 80...there is no need for a mummy class.

also, think about ai scripts vs hard-coded ai. this way, you can load a mummy script or a zombie script.


Edited by - evilcrap on February 20, 2002 3:34:06 PM
I understand what you are saying, but I don''t know how to actually use it in code. Do you have some sample or any links I should read?

This topic is closed to new replies.

Advertisement