S
S
SpeNch2020-11-14 12:38:20
Mathematics
SpeNch, 2020-11-14 12:38:20

How to make a 2d world?

Explain how object readability works.

I googled, but didn't find anything.

It is necessary that the player moves around the map,
and objects that are stored in this form: derevo = {y: 100; x: 334}
SO that they draw dynamically depending on which movement key the player has pressed.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Askhat Bikmetov, 2020-11-14
@askhat

Something like this (wasd control)

D
dollar, 2020-11-14
@dollar

All objects that fall on the screen (and are not outside of it) are simply drawn on the screen. Each object has coordinates, so it's easy to programmatically check if an object is on screen or off screen.
Usually in games such a scheme is adopted that all objects are drawn anew every tick. And there can be a lot of ticks per second (this is what is called FPS - frames per second). So if something changes in the game world, then the picture immediately changes visually.
The movement buttons just change the coordinates. They are not directly related to display. But indirectly, they lead to the effect that the object (the main character) seems to be moving. Only the coordinates do not change smoothly, but discretely - each frame new coordinates. It's just that the "jumps" of 1-2 pixels are imperceptible to the eye, and it rounds it off and considers it a continuous movement.
It turns out that one program code is responsible for changing the coordinates, depending on the keystrokes. And other code reads those coordinates to draw the frame. What they have in common is only a memory area with coordinates, but one writes to it, and the other reads. Otherwise, they do not need to be mixed, and should be considered and coded separately from each other.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question