The structure of the game world in the classes

I am developing a 2D game in Java, and I need some basic game scenarios (enemy spawn, spawn element, changing the properties of enemies).

I don’t know how to divide the game world so that I can easily work with it.

I need enemies (with health and basic AI) of different types, classes of objects (can be selected by the player), a tile map with different blocks.

How can I organize my gaming peaceful architecture? And which core classes should I use to easily extend and support Game World?

+4
source share
2 answers

The basics of the game world for me are the search for common grounds.

the world goes forward in time. so that all active elements (player, discarded items, enemies, npc), but all passive elements are not (block of stone, wood, home), so I would use 2 interfaces ActiveElement and PassiveElement. the active element may have a stepintime () function, which is called by the game world every time in itself in time. both elements can have a render () function that draws an element whenever the game world is drawn on canvas.

then all enemies should call them ai in order to determine their next time step, as well as to check for collisions with any other objects, and whatever that means (player bullet trees, etc.) is the same basically for every other element.

this is for me the most basic architecture in the game worlds.

then there is a performance problem when it would be better to put certain things in your own threads and let them work (enemy ai, who checks the position and status of his avatar in each cycle and makes an input that is read with each step on time), but I don’t have enough experience to develop. then you should go to the gamedev website (for example, as karim79 said).

implemented elements can have their own attributes, and then easily expand (health, statistics) and write to an interpreter who reads simpel scripts that communicate with the game world, adding opponents, etc.

ciao

+3
source

Usually I have a layout similar to this one .

GameObject has features such as Draw() and Move() . Enemy then sets up a few more functions and variables for implementing artificial intelligence in Goblin and Unicorn . Player contains everything you need to move the player in Move() .

This is just a general idea of ​​what I will do. Its different for each game, depending on what type of game it is and how you play it.

0
source

All Articles