Closed ddubbert closed 4 years ago
Topics:
{
value: {
type: String, // NodeGroup-Type
nodes: [
{
id: String,
type: String, // NodeGroup-Type
title: Sting, // Name or Title of node
position: {
x: Number,
y: Number,
},
radius: Number,
sprite: String?, // If an image instead of color should be used to display this node (e.g. food, obstacles etc.)
color: String?, // Background color of node if no sprite was provided
}
]
}
}
{
value: {
cellSize: Number,
rows: [
{
cells: [
{
nodes: [
{
id: String,
type: String, // NodeGroup-Type
title: String, // Name or Title of node
position: {
x: Number,
y: Number,
},
radius: Number,
sprite: String?, // If an image instead of color should be used to display this node (e.g. food, obstacles etc.)
color: String?, // Background color of node if no sprite was provided
}
]
}
]
}
]
}
}
{
value: {
nodes: [ {
id: String,
type: String, // NodeGroup-Type
title: String, // Name or Title of node
position: {
x: Number,
y: Number,
},
radius: Number,
sprite: String?, // If an image instead of color should be used to display this node (e.g. food, obstacles etc.)
color: String?, // Background color of node if no sprite was provided
},
{
id: String,
type: String, // NodeGroup-Type
title: String, // Name or Title of node
position: {
x: Number,
y: Number,
},
radius: Number,
sprite: String?, // If an image instead of color should be used to display this node (e.g. food, obstacles etc.)
color: String?, // Background color of node if no sprite was provided
}],
}
}
{
value: {
user: {
id: String,
type: String, // NodeGroup-Type
title: String, // Name or Title of node
position: {
x: Number,
y: Number,
},
radius: Number,
sprite: String?, // If an image instead of color should be used to display this node (e.g. food, obstacles etc.)
color: String?, // Background color of node if no sprite was provided
},
event: String, // Something like 'grow' or 'die'
value: Number?, // If event needs a second value parameter
}
}
Services:
User: Provides a way to create a Player-object or to change the direction a player is moving and therefore needs to be connected to the Gateway. It also stores each active player, their size and current position. Periodically it processes player movements and publishes them as a group to the NodePositions-Topic. It needs to know, when players are colliding, to remove the smaller player and add size to the bigger one. It only handles Player collisions. Other collisions are handled by the corresponding services. If those events have an impact on a player, the User service will get notified through the UserEvents topic.
Food: The Food service is responsible for generating the food nodes players can consume to grow. It needs to be aware of all currently active food nodes, so that there isn't an endless amount of those active at the same time. Therefore it needs to know when a player consumed food to reproduce the same amount. It only handles Food collisions. When a user consumed food, this service als notifies the User service about how much a user should grow (through the UserEvents-Topic). Every time the Food-Nodes change, it publishes all active Food-Positions as a group to the NodePositions-Topic.
Obstacle: The Obstacle service is responsible for generating all obstacles on the game board. First, this will be boundaries and safe zones but any other obstacle that might be of interest can be added later. It publishes the obstacle positions as a group to the NodePositions-Topic and handles collisions with those obstacles. If those collisions have an impact on a player, this service will notify the User service through the UserEvents-Topic (e.g. if a player collided with the boundaries and has to be destroyed or if a player is inside of a safe zone and therefore indestructible).
NodeCollector: This service is supposed to collect all game nodes published by other services to the NodePositions-Topic. Periodically it merges their current state to a unified data structure, that is optimized for collision detection or rendering and publishes these structures to the GridObjects-Topic.
Collision: This service is responsible for detecting collisions between nodes, which it gets through the GridObjects-Topic. Because every game object is a node, this service does not need to know if it is a user, food or an obstacle and can handle all of them at once. If it detects a collision it publishes an event containing the colliding nodes to the Collisions-Topic.
Rendering: This service is responsible for building the game board and publishing its current state to all active clients. Therefore it needs to know all nodes positions (player-, food, obstacle- nodes), which it gets through the GridObjects-Topic. It also needs to be connected to the Gateway to be reachable by clients.
(Bonus) Statistics: This service is responsible for collecting all the game data and providing statistics for different aspects (like biggest player, longest living player, overall consumed food etc.). First of all it should provide a leaderboard and can be enhanced later. Therefore it might need to read all of the Events other services provide. It also needs to be connected to the Gateway.
Which of those services need to provide an API and which wont ? In other words: Which are only workers and which need to directly be addressed by a client?
In addition, how many different Events and Topics are needed for connecting the Services? What are their names, how should the corresponding events data structure be, are those events grouped or is each event send as a standalone and what Services are posting to and reading from these Topics?