Sobes.tech
Intern — Middle

Updating object coordinates along the X axis

livecode

Task condition

It is necessary to create a simple engine that will update the state of three entities. Each entity is represented by a point with coordinates (x, y). When the update() function is called, all entities shift one unit to the right along the X-axis. The initial coordinates are set when creating the objects.

data class Point(var x: Int, var y: Int)

class Entity(var position: Point) {
    fun update() {
        position.x += 1
    }
}

fun updateScreen(entities: List<Entity>) {
    for (entity in entities) {
        entity.update()
    }
}