Answer the question
In order to leave comments, you need to log in
How to arrange objects in canvas?
I'm recently learning javascript. And even less canvas. I want to complete my dialogue quest) The map is generated there randomly for now, please tell me what to change in the code so that you can edit the map manually, in a Java script. (placement of squares with given coordinates) Here is the code that is responsible for random generation:
//генерация ландшафта
function createWorld()
{
console.log('Creating world...');
//создание пустоши
for (var x=0; x < worldWidth; x++)
{
world[x] = [];
for (var y=0; y < worldHeight; y++)
{
world[x][y] = 0;
}
}
// раставляем скалы случайным образом
for (var x=1; x < worldWidth; x++)
{
for (var y=1; y < worldHeight; y++)
{
if (Math.random() > 0.75)
world[x][y] = 0;
}
}
Answer the question
In order to leave comments, you need to log in
Better this way:
class Arrays<T>
{
public T GetValue(int k)
{
if (k < 0 || k > array.Length)
throw new IndexOutOfRanfeException();
return (array[k]);
}
class Arrays<T> where T : class
{
public T GetValue(int k)
{
if (k < 0 || k > array.Length)
return null;
return (array[k]);
}
class Arrays<T>
{
public T GetValue(int k)
{
if (k < 0 || k > array.Length)
return default(T);
return (array[k]);
}
Why do you need to return -1 array cell? Do you know programming theory? Are you sure this is the approach you need? In my experience, I have never seen an array start with -1. To return array[-1] to you, you need exactly that. Perhaps I misunderstood the question, so we can wait for an answer from colleagues.
PS
If nevertheless to answer you without all these lectures, then, most likely, in any way. As I said, all arrays start either from 0 or from 1 (if I'm not confusing anything). Well, in general, the answer on the surface is no way. You can't bring back something that doesn't exist. If the index is outside, then this cell does not exist, therefore - no way.
My verdict is no.
javascript, render, objects
Almost all the code is already there. Now the world is randomly generated. The whole canvas is a space that you can walk on, then rocks (obstacles) randomly. The problem is to set the coordinates of the rocks with the script (no complicated map editor) just set the position of the rocks (the space that the Persian cannot walk on) I thought it would be enough to edit this part code : for (var x=1; x < worldWidth; x++) { for (var y=1; y < worldHeight; y++) { if (Math.random() > 0.75) world[x][y] = 0; } } and instead of Math.random set the coordinates
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question