A
A
Alexey Maltsev2015-01-02 01:13:58
JavaScript
Alexey Maltsev, 2015-01-02 01:13:58

How to link the model and type of character in the game?

The project is not quite a game, but the visual part is very similar to an RPG game. In general, the essence is: there is a process, the process has resources and threads, threads have a list of commands. As soon as a request to execute a command arrives, the stream sprite must pass to the resource sprite. As soon as it is in place, the "mining" of the resource begins. After the end of "mining", the thread proceeds to the execution of the following commands, or cuts itself out. This is in general terms the work of the model. There are also controllers that should move the sprites on the canvas depending on what the thread is doing.
How can I organize the connection between the model and the view through the controller in this case? With events? For example, an event will be called when a thread has approached a resource, an event when the thread has finished "mining", attach the appropriate controller functions to this (for example, moving from resource to resource). It seems to me that I'm doing something wrong, can someone tell me which way to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Lerg, 2015-01-02
@Axel_User

Each character is a class / object, and self-sufficient, no external controllers should directly change its internal state.
Every object has an anchored sprite or set of sprites behind it.
Also, all objects have an update() method, according to which the sprite is drawn / updated on the canvas.
Objects interact with the environment and with each other through events.
Each object can feel the environment - collision detection in the immediate vicinity for touching and at some radius for vision.
The external controller only gives commands to your characters, sets goals that they must fulfill.
Can immediately set a list of goals that are executed in turn.
I didn’t make games in JavaScript, but the principles are the same everywhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question