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 a II-a)

03.11.2008
Implementarea unui joc tip platforma in AS3 (partea a II-a)

In aceasta parte vei invata cum sa adaugi nivelului scari si alte obstacole.

Total vizualizari: 6283 6283 afisari   |   Comentarii  1   |   Rating   |   (3 voturi)   |   Timp necesar: 1 h 1 h   |   Nivel de cunostiinte necesar: Avansat  Avansat

Sursa:  Mrsunstudios.com   
Autor:  Mr. Sun
Adauga la tutoriale favorit Adauga la tutoriale favorite
Pagina:
« 1 2 34 »
comenteaza printeaza

Adauga acest cod in partea de jos a functiei createLvl() pentru bucla "for":

 if (lvlArray[i] == 3){
  newPlacement = new Sprite();
  //desenam obstacolul
  newPlacement.graphics.beginFill(0x00FF00,1);
  //desenam un patrat
  newPlacement.graphics.drawRect(0,0,25,25);
  //adaugam obiectul pe scena
  bumperHolder.addChild(newPlacement);
  }

El va atasa obiectul pe scena. Acum va trebui sa-l faci pe personaj sa ricoseze de fiecare data cand va atinge acest obstacol. Vei proceda in mod similar ca si cu saritura, dar, mai intai trebuie sa definesti cateva variabile care te vor ajuta:

//VARIABILE PENTRU OBSTACOLE
//variabila booleana care indica daca personajul a intalnit un obstacol
 mainBumping:Boolean = false;
//cat de repede trebuie sa ricoseze personajul
var bumpSpeed:int = 10;

Acum vei realiza o functie care va fi executata atunci cand personajul intalneste un obiect:

function mainBump():void{
    //verifica directia de lovire a obiectului
    var bumpDirection:int;
    if(leftKeyDown){
        bumpDirection = 1;
    } else if (rightKeyDown){
        bumpDirection = -1;
    }
    if(mainBumping){
        lvlHolder.x -= bumpDirection*bumpSpeed;
        bumpSpeed *= .5;
        if(bumpSpeed <= 1){
            mainBumping = false;
        }
    }
}

In plus, adauga acest cod la sfarsitul functiei moveChar():

//verifica daca personajul a lovit vreun obstacol
for(i=0;i<bumperHolder.numChildren;i++){
    //preia referinta la obstacolul curent
    var hitBumper:DisplayObject=bumperHolder.getChildAt(i);
    //verifica daca personajul s-a lovit de obiect
    if(mcMain.hitTestObject(hitBumper)){
        mainBumping = true;
        bumpSpeed = 20;
    }
}
//executa functia mainBump
mainBump();

Asta e tot ce trebuie sa faci. Daca vrei poti testa prin modificarea codului nivelului si prin adaugarea mai multor 3-uri in matricea nivelului.

Ultimul element de care avem nevoie e trambulina. Ea va face personajul sa sara de fiecare data cand o va atinge. O poti colora tot in verde, dar, in loc sa fie patrat va avea o forma circulara. Mai intai, defineste un suport pentru trambulina astfel:

//obiectul care ca contine toate trambulinele
var trampHolder:Sprite = new Sprite();
lvlHolder.addChild(trampHolder);

Apoi adauga acest cod functiei createLvl() in bucla "for".

if (lvlArray[i] == 4){
    newPlacement = new Shape();
    newPlacement.graphics.beginFill(0x00FF00);
    newPlacement.graphics.drawCircle(12.5,25,12.5);
    trampHolder.addChild(newPlacement);
}

Daca vrei, poti testa trambulina schimband codul nivelului astfel:

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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care testeaza lovirea unei trambuline. La fel ca inainte, poti adauga acest cod functiei moveChar() :

//verifica daca personajul a intalnit o trambulina
for(i=0;i<trampHolder.numChildren;i++){
 
    var hitTramp:DisplayObject=trampHolder.getChildAt(i);
    if(mcMain.hitTestObject(hitTramp)){
        //facem personajul sa sara
        mainJump();
    }
}

Acesta a fost, probabil, cel mai usor element de adaugat din toate, incheiand astfel lista.


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

super!

dar se poate face cu programul siun joc simplu multyplayer?

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
4550
Tutoriale scrise de mcuemica
mcuemica Rang utilizator mcuemica - Incepator
4445
Tutoriale scrise de ellarichards
ellarichards Rang utilizator ellarichards - Incepator
4395
Tutoriale scrise de emonclercheap
emonclercheap Rang utilizator emonclercheap - Incepator
4265
Tutoriale scrise de beacherrosa
beacherrosa Rang utilizator beacherrosa - Incepator
4150
* Acest top reprezinta punctajele acumulate in ultimele 30 de zile.
SEO Gimp Dreamweaver Sony Vegas Illustrator Python PSD AJAX PHP Flash Action Script Ruby on Rails RoR MySQL Outlook HTML Excel XHTML SWF Java Fireworks COREL DRAW Word Vista Javascript Verilog Bridge XML Powerpoint StyleSheet Swift 3D Photoshop Fotografie Lightroom CSS JSON
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