Jump to content
  • Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

200 Neutral

About adrian17

  • Rank

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1.   Actually, I have implemented something similar - for bullets with complex movements. Every complex bullet has its own vector of instructions which are executed at specified time frames. It's not perfect, since I would also love to make a bullet spawn other bullets with an instruction. Aside from that, I'm very happy with this.   That's how it looks like: //BasicEnemy::Logic() for(int i=0;i<360;i+=15) { bulletManager->AddEnemyComplexBullet(B_BULLET1, x, y, basev, i-a, 0, 0); bulletManager->AddEnemyBulletData(45, BULLET_ANGULAR_VELOCITY, SET, 5); bulletManager->AddEnemyBulletData(45, BULLET_ACCEL, SET, -0.7); bulletManager->AddEnemyBulletData(55, BULLET_ANGULAR_VELOCITY, SET, 0); bulletManager->AddEnemyBulletData(55, BULLET_ACCEL, SET, 0); } Anyway, that was the first thing I thought about when thinking about enemy behaviors, but unfortunately it won't work. That's simply because, no matter how complex the instruction is, it won't allow looping (...but I hope I'm wrong about that). If I want to shoot 100 bullets in a circle, writing 100 instructions for each shot makes no sense. That's exactly why I couldn't make the bullet spawn other bullets.   I don't really need to use states and respond to any behavior, because I don't need the enemies to respond to anything whatsoever. I just need a clean way to set a behavior once, when creating the enemy or declare it when the program begins and then assign it to enemy during its creation. (and as "behavior" I just mean either "at a given frame since creation, set/change velocity and direction" or "shoot a bullet/a lot of bullets in a given direction" OR "...with a random offset" OR "...in the player's direction" OR "in the player's direction with a random offset" OR ... )
  2. I'm creating a simple shmup from scratch. This is how my base Enemy class looks like: class Enemy { public: Enemy(int ntype, double nx, double ny, double nvx, double nvy): type(ntype), x(nx), y(ny), vx(nvx), vy(nvy) {}; virtual ~Enemy() {}; void Move(){x+=vx;y+=vy;}; virtual void Logic()=0; virtual void Draw(); bool IsDead(){return health<0;} void ReduceHealth(int damage){health-=damage;} SDL_Rect GetLoc(){return loc;} protected: int type; int health; double x, y; double vx, vy; SDL_Rect loc, source; void GetVectorToPlayer(double &x, double &y); double GetAngleToPlayer(); }; The Logic() function is the main function that defines the enemies' behaviours. It can influence both its movements and shooting patterns. For example, it may look like this:   double angle=GetAngleToPlayer(); if(globalFrameCounter%120==0) //will shoot every two seconds for(int i=-3;i<=3;i+=1) //will shoot seven bullets in the player's direction bulletManager->AddEnemyBullet(B_BULLET1, x, y, 5, angle+i); //bullet sprite, location, velocity and direction Finally, all the enemies are created on the vector via the manager, like this (I have only one BasicEnemy subclass for now, so the function will be expanded int the future): void EnemyManager::AddEnemy(int type, double x, double y, double vx, double vy) { enemies.push_back(std::unique_ptr<BasicEnemy>(new BasicEnemy(type, x, y, vx, vy))); } Now, my problem is, what if I want to have a lot of different types of enemy behaviours. In the current state, it would force me to write a separate subclass with a new Logic() function for every possible behaviour. That's obviously the wrong approach, since it would force me to create tens and tens of subclasses. I also don't want to use any scripting language like Lua, because I have no knowledge of them and it feels like using a sledgehammer to crack a nut. So... is there an easier way that I'm not seeing?
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!