E-learn.ro
Panou utilizatori
Utilizator Parola
Creeaza cont nou    Recupereaza parola
Login
Newsletter
Introdu adresa ta de email
Inscrie-te
Inchide panoul de utilizatori
Add to Google

Tutoriale Adobe Flash

Descarca toolbar

Toolbar E-learn.ro Facebook Twitter

GRAFICA 2D  /  Adobe Flash  /  ActionScript (14)

Implementarea unui joc tip platforma in AS3 (partea I)

28.10.2008
Implementarea unui joc tip platforma in AS3 (partea I)

Iata-ne la un tutorial pentru avansati in care vom crea un joc de tip platforma in Action Script 3.

Total vizualizari: 6569 6569 afisari   |   Comentarii  1   |   Rating   |   (6 voturi)   |   Timp necesar: 45 min 45 min   |   Nivel de cunostiinte necesar: Avansat  Avansat

Sursa:  Mrsunstudios.com  
Autor:  Mr. Sun
Adauga la tutoriale favorit Adauga la tutoriale favorite
Pagina:
« 12 3
comenteaza printeaza

Daca vei testa, vei vedea ca personajul sare cand loveste blocul. Ultimul lucru pe care il vei face este miscarea fundalului odata cu personajul principal, daca acesta se misca prea departe in partea stanga sau dreapta. Ca sa poti face acest lucru trebuie sa schimbi lvlArray1 cu:

var lvlArray1:Array = new Array(
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1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ar pentru a face ca acest cod sa mearga trebuie sa inlocuiesti functia standard cu:

function createLvl():void{
    //afla nivelul curent 
    var lvlArray:Array = MovieClip(root)['lvlArray'+lvlCurrent];
    //afla pana unde tine nivelul
    //pentru a stii cand sa trecem la randul urmator
    //vor fi intotdeauna 16 randuri
    //ceea ce va face ca formarea lvl sa fie foarte stricta
    var lvlColumns:int = Math.ceil(lvlArray.length/16);
    //cream nivelul
    for(var i:int = 0;i<lvlArray.length;i++){
//verificam daca trebuie sa trecem la nivelul urmator
//daca i este divizibil la numarul de coloane
        if(i/lvlColumns == int(i/lvlColumns)){
            row ++;
        }
        if(lvlArray[i] == 1){
            // cream un nou bloc
            var newBlock:Block = new Block();
            //desenam blocul
            newBlock.graphics.beginFill(0xFFFFFF/*Culoarea formei*/,1/*Transparenta formei - 1 pentru opac*/);
            //desenam un patrat
            newBlock.graphics.drawRect(0,0,25,25);
            //schimbam coordonatele blocului
            newBlock.x = (i-(row-1)*lvlColumns)*newBlock.width;
            newBlock.y = (row-1)*newBlock.height;
            //adaugam blocul pe scena
            blockHolder.addChild(newBlock);
        } else if (lvlArray[i] == 'MAIN'){
            mcMain.x = (i-(row-1)*lvlColumns)*newBlock.width;
            mcMain.y = (row-1)*newBlock.height;
        }
    }
    //reseteaza variabila row
    row = 0;
    //centram ecranul pe personajul principal
    //aceasta variabila ne va spune cu cat trebuie deplasat ecranul
    //250 e aproximativ pozitia personajul, deci folosim aceasta valoarea
    var mainMove:int = 250 - mcMain.x;
    //muta personajul si intreg nivelul impreuna cu el
    mcMain.x += mainMove;
    blockHolder.x += mainMove;
}

De acum inainte ecranul va fi centrat pe personajul principal indiferent de nivel si de locul unde il asezi. In continuare, ai nevoie ca fundalul sa se miste odata cu personajul pentru a-l putea urmari in orice moment. Asta chiar va fi usor - in functia moveChar() inlocuieste:

if(leftKeyDown){
    mcMain.x -= mainSpeed;
}
if(rightKeyDown){
    mcMain.x += mainSpeed;
}

Cu:

if(leftKeyDown){
    blockHolder.x += mainSpeed;
}
if(rightKeyDown){
    blockHolder.x -= mainSpeed;
}

Usor, nu? Mai e o singura problema pe care vreau sa o rezolvi pana sa trecem la pasul urmator. Personajul nu sare indeajuns de mult, asa ca va trebui sa recodam putin aceasta parte:

//continua saltul daca se afla in aer
if(jumpSpeed < 0){
    jumpSpeed *= 1 - jumpSpeedLimit/75;
    if(jumpSpeed > -jumpSpeedLimit/5){
        jumpSpeed *= -1;
    }
}
if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit){
    jumpSpeed *= 1 + jumpSpeedLimit/50;
}
mcMain.y += jumpSpeed;
Inlocuieste cu acest cod:
//continua saltul daca se afla in aer
if(jumpSpeed < 0){
    jumpSpeed *= 1 - jumpSpeedLimit/125;
    if(jumpSpeed > -jumpSpeedLimit/5){
        jumpSpeed *= -1;
    }
}
if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit){
    jumpSpeed *= 1 + jumpSpeedLimit/50;
}
mcMain.y += jumpSpeed;

De asemenea modifica jumpSpeedLimit la 20.


Pagina:
« 12 3
comenteaza printeaza
Alte tutoriale Adobe Flash:
Noteaza acest tutorial
Rating tutorial
 
(6 voturi)
Pentru a nota acest tutorial, trebuie sa fii logat!
COMENTARII (1) spune-ti parerea
andrey andrey , Sambata, 28 August 2010, ora 21:48
#1

cand pun codul sa sara imi da eroare de cod

Raporteaza acest comentariu ca injurios!
Posteaza un comentariu
Pentru a posta un comentariu, trebuie sa fii logat!
0 TOP UTILIZATORI* 0 0
Tutoriale scrise de claibornelara
claibornelara Rang utilizator claibornelara - Incepator
5460
Tutoriale scrise de mcuemica
mcuemica Rang utilizator mcuemica - Incepator
5460
Tutoriale scrise de emonclercheap
emonclercheap Rang utilizator emonclercheap - Incepator
5285
Tutoriale scrise de ellarichards
ellarichards Rang utilizator ellarichards - Incepator
5270
Tutoriale scrise de beacherrosa
beacherrosa Rang utilizator beacherrosa - Incepator
5015
* Acest top reprezinta punctajele acumulate in ultimele 30 de zile.
PHP Python Fotografie Swift 3D XHTML Sony Vegas Dreamweaver Photoshop Fireworks MySQL XML Gimp RoR Lightroom CSS Ruby on Rails COREL DRAW Flash Powerpoint Verilog Javascript SEO Action Script Vista SWF Illustrator Excel JSON Word Bridge HTML PSD AJAX Java StyleSheet Outlook
Promovare:
Daca faci parte din comunitatea E-learn.ro si doresti promovarea acesteia, poti accesa pagina de promovare.
Arhiva newsletter:
Daca ai ratat un numar mai vechi, sau vrei sa revezi care au fost noutatile E-learn.ro la un moment dat, poti accesa arhiva de newslettere.
  Copyright © 2008-2013 E-LEARN.ro. Toate drepturile rezervate. Termeni si conditii.
Conceput si realizat de Neokinetics Software