Colision de duplicate movie clip

danizooska Messages postés 9 Date d'inscription dimanche 1 août 2004 Statut Membre Dernière intervention 26 juin 2006 - 12 févr. 2005 à 01:08
Blacknight91titi Messages postés 1732 Date d'inscription jeudi 17 juin 2004 Statut Membre Dernière intervention 9 mars 2015 - 12 févr. 2005 à 16:40
Salut ! j'ai commencer a faire un jeu... On est un personnage qui tombe et il y a des obstacle qu'il faut eviter car lorsqu'on lestouche, on monte en haut de lecran et si nous touchons la limite nous mourrons.. (falldown pour ceux qui connaissent). Alors j'ai commencer par faire mon hero (personnage principal) et j'ai mis ce code dedans :

onClipEvent (load) {
var fall_vit = 5;
var vit = 10;
var i = 1;
}
onClipEvent (enterFrame) {
if (!_root.obstacle.hitTest(this._x, this._y+13, true)) {
this._y += fall_vit;
} else {
this._y -= vit;
}
if (Key.isDown(key.LEFT)) {
this._x -= vit;
}
if (Key.isDown(key.RIGHT)) {
this._x += vit;
}
}

ensuite j'ai crer un obstacle et j'ai mi ce code dedans :

onClipEvent (load) {
this._y = 420;
this._x = random(450);
}
onClipEvent (enterFrame) {
this._y -= _root.hero.fall_vit;
}

ensuite sur le calque j'ai mis ce code :

function crer_obstacle() {
obstacle.duplicateMovieClip("obstacle"+_root.hero.i, _root.hero.i);
_root.hero.i++;
}
setInterval(crer_obstacle, 1000);

Bon voila c'est pas très optimiser mais c'est pas grave pour l'instant ! Alors les obstacles se créer mais je ne sais pas comment gerer la collison ensuite avec eux ...
J'ai essayer if (!this["obstacle"+i].hitTest(this._x, this._y+13, true)) { mais sans succès...
Merci d'avance !!!

3 réponses

Blacknight91titi Messages postés 1732 Date d'inscription jeudi 17 juin 2004 Statut Membre Dernière intervention 9 mars 2015 2
12 févr. 2005 à 11:19
Tu dois utiliser une boucle
for (i=0;i<=nombredeclip;i++) {
if (!this["obstacle"+i].hitTest(this._x, this._y+13, true)) {
//ton code

}
}

Quelque chose dans ce genre la.

Blacknight91Titi
Et comme chaque jour je t'aime davantage, aujourd'hui plus qu'hier mais bien moins que demain !
0
danizooska Messages postés 9 Date d'inscription dimanche 1 août 2004 Statut Membre Dernière intervention 26 juin 2006
12 févr. 2005 à 16:29
J'ai beaucoup de diffilcultés...
J'ai changé quelques codes...

mon code de personnage principal :

onClipEvent (load) {
var fall_vit = 5;
var vit = 10;
}
onClipEvent (enterFrame) {
///////////////////////////////////////////////////////////////////////////
///////////////////////////COLLISON AVEC LES OBSTACLES/////////////////////
///////////////////////////////////////////////////////////////////////////
for (_root.i; i<50; _root.i) {
if (!this["obstacle"+_root.i].hitTest(this._x, this._y+13, true)) {
this._y += fall_vit;
} else {
this._y -= vit;
}
}
///////////////////////////////////////////////////////////////////////
///////////////////////DÉPLACEMENT/////////////////////////////////////
///////////////////////////////////////////////////////////////////////
if (Key.isDown(key.LEFT)) {
this._x -= vit;
}
if (Key.isDown(key.RIGHT)) {
this._x += vit;
}
}

Pour mon obstacle :

onClipEvent (load) {
this._y = 420;
this._x = random(450);
}
onClipEvent (enterFrame) {
this._y -= _root.hero.fall_vit;
}

Pour mon calque :

var i = 1;
function crer_obstacle() {
obstacle.duplicateMovieClip("obstacle"+i, i);
i++;
}
setInterval(crer_obstacle, 1000);

bon voila... j'ai beaucoup de difficulté a utiliser le for... mon personnage ne bouge plus a cause de cela...
0
Blacknight91titi Messages postés 1732 Date d'inscription jeudi 17 juin 2004 Statut Membre Dernière intervention 9 mars 2015 2
12 févr. 2005 à 16:40
Oui en effet ....
Avec tout ses for ton animation doit énormément ramer...
Mais a mon avis pour sa tu devrait utiliser une grille.
http://www.flashkod.com/code.aspx?ID=28222
Va voir la dessus sa t'aidera.
Evidement sa changerai pas mal ton code.
Il y a aussi une de mes sources si tu veu :
http://www.flashkod.com/code.aspx?ID=28006

Bonne chance, je suis la si tu as d'autres questions

Blacknight91Titi
Et comme chaque jour je t'aime davantage, aujourd'hui plus qu'hier mais bien moins que demain !
0
Rejoignez-nous