Показать сообщение отдельно
Старый 17.07.2013, 15:43
ZackMercury вне форума Посмотреть профиль Отправить личное сообщение для ZackMercury Найти все сообщения от ZackMercury
  № 7  
Ответить с цитированием
ZackMercury
 
Аватар для ZackMercury

блогер
Регистрация: Jul 2013
Адрес: Север
Сообщений: 1,918
Записей в блоге: 23
Отправить сообщение для ZackMercury с помощью ICQ Отправить сообщение для ZackMercury с помощью Skype™
Цитата:
Сообщение от expl Посмотреть сообщение
Давайте по порядку.
- Если уровень бесконечный - то массив из различных цифр будет бесконечным, а значит невозможным. Как вы его создали...
Я про обучалки по созданию игр. Я долго пытался понять принцип превращения массив в сетку мклипов, но так и не понял.

Например, у одного из туториалов по платформеру такой код:
Код AS3:
//this guy will hold all of the blocks
var blockHolder:Sprite = new Sprite();
//then we add him to stage
addChild(blockHolder);
 
function createLvl():void
{
      //getting the current level we are on
      var lvlArray:Array = MovieClip(root)['lvlArray'+lvlCurrent);
      var lvlColumns:int = Math.ceil(lvlArray.length/16);
      //now we must create the level
      for(var i:int  = 0; i < lvlArray.length; i++)
      {
      //checking if we move onto the next row
      //this checks if i is divisible by # of columns
      if(i / lvlColumns == int(i / lvlColumns)) 
      {
            row ++
      }
      if(lvlArray[i] == 1) 
      {
      //making a new block
      var newBlock:Block = new Block();
      //drawing the block
      newBlock.graphics.beginFill(0xFFFFFF, 1);
      newBlock.graphics.drawRect(0,0,25,25);
      newBlock.x = (i - (row-1)*lvlColumns)*newBlock.width;
      newBlock.y = (row-1)*newBlock.height;
      //then finally adding it to the stage.
      blockHolder.addChild(newBlock);
      } else if (lvlArray[i] == 'MAIN')
      {
      mcMain.x = (i-(row-1)*lvlColumns)*newBlock.width;
      mcMain.y = (row-1)*newBlock.height;
      }
 
      }
//reset the row for another use
row = 0;
//then we center the screen on the main character
//this variable will tell us how far away we have to move everything
//250 is about centered flr mcMain we'll use that number
var mainMove:int = 250-mcMain.x;
//then we move mcMain and the entire level to center on him
mcMain.x += mainMove;
 
}
 
//running the createLvl function
createLvl();
В данном коду mcMain - мувиклип шарика, т.е. главный герой.
Это лишь кусок кода, создающий уровень.
До меня трудно доходит чужой код(не знаю, у всех ли так поначалу было...), поэтому не могу понять, что он делает в деталях.