Arcade-Shooter game code design

Started by
1 comment, last by Nicholas Kong 10 years, 4 months ago

Hi Everyone. I have started to work on arcade-shooter game for android and i found that i have problem with code design. Take this example.There is 1 level with lot of different enemies. So i ve got interface, one general enemy and many enemies which extends general enemy. Should i define AI inside general enemy or make it as a new object? And what about level design how should i define when and how many enemies start to move or doing something... So my question is: is there any official design pattern, framework etc. for arcade games? Thanks.

Advertisement
Separating classes for AI (controllers that can "drive" any kind of enemy) and enemies (flying things that offer the AI a set of inputs and commands) should be the best choice in most cases: - Separation of concerns makes code easier to work with in general. - It allows you to consolidate enemy classes and adopt a data-driven design: defining an enemy type doesn't require a new class, you only need to specify a sprite and an AI module for use by a generic Enemy class. - In turn, using only one Enemy class avoids unnecessary polymorphism overhead. - It allows easy replacement of AI, even in live enemies, facilitating experiments, variations and complex behaviour without undue complication of the Enemy classes. - It helps with uniform treatment of player-controlled and AI-controlled ships, without unwanted duplications and asymmetries.

Omae Wa Mou Shindeiru

You should isolate Enemy and AI separably. There might be cases where you have some sprites that does not move and some that do.

You could make AI an interface. Instead of calling it AI, you could call it Movable.

In Java, it would be like this:

public class Enemy implements Movable

{

}

public interface Movable

{

public void move(int x, int y)

{

}

}

You could make AI a separate object too. See which one of the two design fits better.

This topic is closed to new replies.

Advertisement