begin process at 2012 05 26 06:27:02
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

ActionScripts

 > MOTEUR PHYSIQUE

MOTEUR PHYSIQUE


 Information sur la source

Note :
3 / 10 - par 2 personnes
3,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :ActionScripts Classé sous :Moteur Physique, Actionscript, Collisions Niveau :Initié Date de création :28/11/2007 Vu / téléchargé :4 883 / 515

Auteur : UHM

Ecrire un message privé
Site perso
Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Moteur Physique

import mx.transitions.Tween;
import mx.transitions.easing.*;
import KeyDetection;
// on importe les classe easing pour les effets visuels.
_global.encart_count = 10;
_global.Encarts = new Array();
var keyDet = new KeyDetection();
keyDet.addCombination("automatique ", Key.CONTROL, 90);
keyDet.addCombination("manual", Key.CONTROL, 89);
_global.automatique = true;
myObj = new Object();
myObj.onKeyCombination = function(name:String) {
switch (name) {
case "automatique" :
_global.automatique = true;
break;
case "manual" :
_global.automatique = false;
break;
}
};
modebutton.onPress = function() {
_global.automatique = !_global.automatique;
//trace(_global.automatique );
};
keyDet.addListener(myObj);
for (var i = 1; i<=_global.encart_count; i++) {
var current_encart:String = "encart"+i;
duplicateMovieClip(encart0, current_encart, i);
eval(current_encart)._x = eval("encart"+(i-1))._x+eval("encart"+(i-1))._widt h+20;
eval(current_encart)._y += random(40);
eval(current_encart).back._width = 60+random(40);
eval(current_encart).back._height = 30+random(40);
with (eval(current_encart)) {
createTextField("tbox", 1, 1, 1, 1, 1);
tbox.border = false;
tbox.type = "dynamic";
tbox.autoSize = true;
tbox.embedfonts = true;
tbox.text = i;
Selection.setFocus(tbox);
myf = new TextFormat();
myf.color = 0x000000;
myf.font = "Arial";
myf.size = 18;
myf.align = "center";
tbox.setTextFormat(myf);
}
_global.E ncarts.push({clip:eval("encart"+(i-1)), px:eval("encart"+(i-1))._x, py:eval("encart"+(i-1))._y});
}
_global.Targets = new Array();
var Page = new Object();
Page.Target = _root.page1;
Page.ClipsIn = new Array();
var BestPlace = new Object();
BestPlace.px = 0;
BestPlace.py = 0;
Page.BestPlace = BestPlace;
_global.Targets.push(Page);
Page = new Object();
Page.Target = _root.page2;
Page.ClipsIn = new Array();
_global.Targets.push(Page);
Page = new Object();
Page.Target = _root.page3;
Page.ClipsIn = new Array();
_global.Targets.push(Page);
//, _root.page2
function getsurface(MC:MovieClip) {
return MC._width*MC._height;
}
function getavailablesurface(MC:MovieClip, clips:Array) {
var cumul = 0;
for (var i = 0; i<clips.length; i++) {
//trace2(clips[i]);
var obj:Object = clips[i].clip;
cumul += obj._width*obj._height;
}
//trace2(getsurface(MC )-cumul);
return getsurface(MC)-cumul;
}
function getbestplace(Current_Clip:MovieClip, Target_Clip:MovieClip, clips:Array, BestPlace:Object) {
Current_Clip.stopDrag();
oldX = Current_Clip._x;
oldY = Current_Clip._y;
var startX:Number = Number(Math.round(Target_Clip._x));
var endX:Number = Number(Math.round(Target_Clip._x+Target_Clip._widt h));
var startY:Number = Number(Math.round(Target_Clip._y));
var endY:Number = Number(Math.round(Target_Clip._y+Target_Clip._heig ht));
pasy = 1;
yy = startY;
xx = startX;
/*
var Touch = false;
Current_Clip._x = BestPlace.px;
Current_Clip._y = BestPlace.py;
for (l=0; l<clips.length && !Touch; l++) {
//x++;
var obj:Object = clips[l].clip;
if (Current_Clip.hitTest(obj) && Current_Clip != obj) {
Touch = true;
}
if (Current_Clip._x+Current_Clip._width>=endX) {
Touch = true;
BestPlace.px = 0;
BestPlace.py = clips[l+1].clip._y;
}
if (Current_Clip._y+Current_Clip._height>=endY) {
Touch = true;
}
}*/
if (clips.length == 0) {
var obj:Object = new Object();
obj.px = xx;
obj.py = yy;
return obj;
}
if (_global.automatique) {
k = 0;
avant = true;
for (i=startY; i<endY; i++) {
trace2(i);
for (j=startX; j<endX; ) {
k++;
var Touch = false;
for (l=0; l<clips.length && !Touch; l++) {
//x++;
var obj:Object = clips[l].clip;
Current_Clip._x = j;
Current_Clip._y = i;
if (Current_Clip.hitTest(obj) && Current_Clip != obj) {
Touch = true;
}
if (Current_Clip._x+Current_Clip._width>=endX) {
avant = false;
Touch = true;
}
if (Current_Clip._y+Current_Clip._height>=endY) {
Touch = true;
}
}
if (!Touch) {
//il faut retourner
Current_Clip._x = oldX;
Current_Clip._y = oldY;
var obj:Object = new Object();
obj.px = j;
obj.py = i;
trace2("trouvée iteration : "+k+" x : "+j+" y :"+i);
return obj;
} else {
trace2("conflit avec le clip : "+obj);
j += obj._width+1;
}
}
}
trace2("non trouvée iteration : "+k);
return undefined;
} else {
var Touch = false;
for (l=0; l<clips.length && !Touch; l++) {
//x++;
var obj:Object = clips[l].clip;
if (Current_Clip.hitTest(obj) && Current_Clip != obj) {
Touch = true;
}
if (Current_Clip._x+Current_Clip._width>=endX) {
avant = false;
Touch = true;
}
if (Current_Clip._y+Current_Clip._height>=endY) {
Touch = true;
}
}
if (!Touch) {
trace2("trouvée ");
var obj:Object = new Object();
obj.px = Current_Clip._x;
obj.py = Current_Clip._y;
Current_Clip.stopDrag();
re turn obj;
} else {
trace2("conflit avec le clip : "+obj);
}
return undefined;
}
}
function findInArray(MC:MovieClip, clips:Array) {
for (var i = 0; i<clips.length; i++) {
if (MC == clips[i].clip) {
return i;
}
}
return -1;
}
function removeFromArray(obj:Object, clips:Array) {
tmp = new Array();
for (var i = 0; i<clips.length; i++) {
if (clips[i].clip != obj) {
tmp.push(clips[i]);
}
}
return tmp;
}
function goAway(MC:MovieClip, Targets:Array) {
//trace2("goAway");
//var obj:Object = clipsMap.findKey("encart"+substring(MC, 15, 2),"name");
var obj:Object = _global.Encarts[findInArray(MC, _global.Encarts)];
//trace2(obj.px+" "+obj.py);
var maTween:Tween = new Tween(MC, "_x", Regular.easeOut, MC._x, obj.px, 20, false);
var maTween:Tween = new Tween(MC, "_y", Regular.easeOut, MC._y, obj.py, 20, false);
//trace2("Targets[i].clip -------------------------: "+Targets.join());
return removeFromTargets(MC, Targets);
}
function goTarget(MC:MovieClip, Targets:Array) {
//trace2("goTarget");
//var obj:Object = clipsMap.findKey("encart"+substring(MC, 15, 2),"name");
var obj:Object = Targets[findInArray(MC, Targets)];
trace2(Targets[findInArray(MC, Targets)].px);
//trace2(obj.px+" "+obj.py);
var maTween:Tween = new Tween(MC, "_x", Regular.easeOut, MC._x, obj.px, 20, false);
var maTween:Tween = new Tween(MC, "_y", Regular.easeOut, MC._y, obj.py, 20, false);
//return removeTarget(MC, Targets);
}
function removeFromTargets(MC:MovieClip, Targets:Array) {
NotFound = true;
for (var i = 0; i<Targets.length && NotFound; i++) {
// trace2("---------------"+findInArray(MC, Targets[i].ClipsIn));
if (findInArray(MC, Targets[i].ClipsIn) != -1) {
// trace2("---------------found");
NotFou nd = false;
Targets[i].ClipsIn = removeFromArray(MC, Targets[i].ClipsIn);
}
}
return Targets;
}
function getTargetIndex(MC:MovieClip, Targets:Array) {
NotFound = true;
Index = -1;
for (var i = 0; i<Targets.length && NotFound; i++) {
if (findInArray(MC, Targets[i].ClipsIn) != -1) {
Index = i;
NotFound = false;
}
}
return Index;
}
function targetNotExiste(MC:MovieClip, Targets:Array) {
for (var i = 0; i<Targets.length; i++) {
if (MC == Targets[i].clip) {
//trace2("found");
return false;
}
}
return true;
}
function dropTarget(MC:MovieClip, Targets:Array) {
for (var i = 0; i<Targets.length; i++) {
if (eval(MC._droptarget) == Targets[i]) {
return Targets[i];
}
}
return undefined;
}
ReleaseTarget = function () {
};
function optimizePlace(newX:Number, newY:Number, Index:Number, Targets:Array) {
trace2("OPTIMIZE : ------------------------- Targets[Index].Target "+Targets[Index].ClipsIn);
/*for (var i = 0; i<Targets.length; i++) {
for (var j = 0; j<Targets.length; j++) {
var objGetBestPlace:Object = getbestplace(_global.Targets[i].ClipsIn[j].clip, _global.Targets[i].Target, _global.Targets[i].ClipsIn);
trace2("objGetBestPl ace x : "+objGetBestPlace.px+" y : "+objGetBestPlace.py);
var maTween:Tween = new Tween(_global.Targets[i].ClipsIn[j].clip, "_x", Regular.easeOut, _global.Targets[i].ClipsIn[j].clip._x, objGetBestPlace.px, 20, false);
var maTween:Tween = new Tween(_global.Targets[i].ClipsIn[j].clip, "_y", Regular.easeOut, _global.Targets[i].ClipsIn[j].clip._y, objGetBestPlace.py, 20, false);
}
}*/
//newX -= startX;
//newY -= startY;
Target_Clip = Targets[Index].Target;
var startX:Number = Number(Math.round(Target_Clip._x));
var endX:Number = Number(Math.round(Target_Clip._x+Target_Clip._widt h));
var startY:Number = Number(Math.round(Target_Clip._y));
var endY:Number = Number(Math.round(Target_Clip._y+Target_Clip._heig ht));
//newX=startX
//newY=startY
for (var i = 0; i<1; i++) {
var Current_Clip:MovieClip = Targets[Index].ClipsIn[i].clip;
trace2("OPTIMIZE : -------------------------"+Current_Clip);
oldX = Current_Clip._x;
oldY = Current_Clip._y;
trace2("new --- "+newX+" "+newY);
Current_Clip._x = newX;
Current_Clip._y = newY;
//Targets[Index].ClipsIn.length
for (var j = 0; j<Targets[Index].ClipsIn.length; j++) {
Touch = false;
if (i != j) {
var obj:Object = Targets[Index].ClipsIn[j].clip;
if (Current_Clip.hitTest(obj)) {
Touch = true;
}
if (Current_Clip._x+Current_Clip._width>endX) {
Touch = true;
}
if (Current_Clip._y+Current_Clip._height>endY) {
Touch = true;
}
}
if (!Touch) {
//Current_Clip._x = oldX;
//Current_Clip._y = oldY;
var maTween:Tween = new Tween(Current_Clip, "_x", Regular.easeOut, oldX, newX, 20, false);
var maTween:Tween = new Tween(Current_Clip, "_y", Regular.easeOut, oldY, newY, 20, false);
Targets[Index].ClipsIn[i].px = newX;
Targets[Index].ClipsIn[i].py = newY;
newX = oldX;
newY = oldY;
//return optimizePlace(newX, newY, Index, Targets);
}
}
}
/*for (var i = 0; i<_global.Targets[Index].ClipsIn.length; i++) {
Current_Clip = Targets[Index].ClipsIn[i].clip;
var objGetBestPlace:Object = getbestplace(Current_Clip, _global.Targets[Index].Target, _global.Targets[Index].ClipsIn);
if (objGetBestPlace != undefined) {
// this.stopDrag();
//trace2(objGetBestPlace +" x : "+objGetBestPlace.px+" y : "+objGetBestPlace.py);
_global.Targets[Index].Cli psIn.push({clip:Current_Clip, px:objGetBestPlace.px, py:objGetBestPlace.py});
var maTween:Tween = new Tween(Current_Clip, "_x", Regular.easeOut, Current_Clip._x, objGetBestPlace.px, 20, false);
var maTween:Tween = new Tween(Current_Clip, "_y", Regular.easeOut, Current_Clip._y, objGetBestPlace.py, 20, false);
} else {
trace2("OPTIMIZE : there is no fit surface return to first place");
//_global.Targets = goAway(this, _global.Targets);
}
}*/
return Targets;
}
for (var i = 1; i<=_global.encart_count; i++) {
var current_encart:String = "encart"+i;
//clipsMap.addItem({name:current_enca rt, px:eval(current_encart)._x,py:eval(current_encart) ._y});
clipsMap.push(eval(current_encart));
eval (current_encart).onPress = function() {
this.startDrag();
};
eval(current_encart).on Release = function() {
this.stopDrag();
var Target:MovieClip;
NoTarget = true;
for (var j = 0; j<_global.Targets.length && NoTarget; j++) {
//trace2("eval(this._droptarget) == _global.Targets[j].Target : "+eval(this._droptarget) +" "+_global.Targets[j].Target);
if (eval(this._droptarget) == _global.Targets[j].Target) {
NoTarget = false;
//trace2("targetNotExiste(this, _global.Targets[j].ClipsIn : "+targetNotExiste(this, _global.Targets[j].ClipsIn));
if (targetNotExiste(this, _global.Targets[j].ClipsIn)) {
if (getsurface(this)<=getavailablesurface(_global.Tar gets[j].Target, _global.Targets[j].ClipsIn)) {
var objGetBestPlace:Object = getbestplace(this, _global.Targets[j].Target, _global.Targets[j].ClipsIn, _global.Targets[j].BestPlace);
if (objGetBestPlace != undefined) {
this.stopDrag();
trace2(objGetBest Place+" x : "+objGetBestPlace.px+" y : "+objGetBestPlace.py);
_global.Targets[j].C lipsIn.push({clip:this, px:objGetBestPlace.px, py:objGetBestPlace.py});
if (_global.automatique) {
var maTween:Tween = new Tween(this, "_x", Regular.easeOut, this._x, objGetBestPlace.px, 20, false);
var maTween:Tween = new Tween(this, "_y", Regular.easeOut, this._y, objGetBestPlace.py, 20, false);
}
} else {
trace2("there is no fit surface return to first place");
_global.Targets = goAway(this, _global.Targets);
}
} else {
trace2("there is no available surface return to first place");
_global.Targets = goAway(this, _global.Targets);
}
//break;
} else {
trace2("encart already existe return to target"+this);
//goTarget(this, _global.Targets[j].ClipsIn);
var objGetBestPlace:Object = getbestplace(this, _global.Targets[j].Target, _global.Targets[j].ClipsIn, _global.Targets[j].BestPlace);
if (objGetBestPlace != undefined) {
this.stopDrag();
//trace2(objGetBest Place+" x : "+objGetBestPlace.px+" y : "+objGetBestPlace.py);
var index = findInArray(this, _global.Targets[j].ClipsIn);
_global.Targets [j].ClipsIn[index].px = objGetBestPlace.px;
_global.Targets[j].Clips In[index].py = objGetBestPlace.py;
if (_global.automatique) {
var maTween:Tween = new Tween(this, "_x", Regular.easeOut, this._x, objGetBestPlace.px, 20, false);
var maTween:Tween = new Tween(this, "_y", Regular.easeOut, this._y, objGetBestPlace.py, 20, false);
}
} else {
trace2("there is no fit surface return to old place in target");
//_global.Targets = goAway(this, _global.Targets);
goTarget(this, _global.Targets[j].ClipsIn);
}
}
}
//break;                                                                
}
if (NoTarget) {
Index = getTargetIndex(this, _global.Targets);
var obj:Object = _global.Targets[Index].ClipsIn[findInArray(this, _global.Targets[Index].ClipsIn)];
var oldX:Number = obj.px;
var oldY:Number = obj.py;
trace2("No Target return to first place ");
_global.Targets = goAway(this, _global.Targets);
/*if (Index>=0) {
trace2(" old --- "+oldX+" "+oldY);
_global.Targets = optimizePlace(oldX, oldY, Index, _global.Targets);
}*/
}
};
}
function trace2(msg) {
//trace(msg);
_root.traceclip.text = msg+'\n'+_root.traceclip.text;
//_root.traceclip. scroll+=1000000;
}




 Conclusion

Moteur Physique

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip Source avec une capture FORD FULKERSON,RECHERCHE OPERATIONNELLE

 Sources de la même categorie

Source avec Zip Source avec une capture OUVRIR UNE ANIMATION EXTERNE DANS UN CLIP VIDE. par KcHeY
Source avec Zip ZOOM SUR UNE IMAGE par yasdar
Source avec Zip Source avec une capture UN PEU DE MATH par yasdar
Source avec Zip Source avec une capture PARTICULE SYSTEM par yasdar
Source avec Zip Source avec une capture GALLERIE PHOTO AVEC XML par yasdar

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture OUVRIR UNE ANIMATION EXTERNE DANS UN CLIP VIDE. par KcHeY
Source avec Zip Source avec une capture COMPOSANT SWC CALENDAR DATE PICKER POUR FLASH CS5 AS3 par nicoflashkod
Source avec Zip Source avec une capture CALCUL DE PI PAR L'ÉQUATION DE LEIBNIZ EN AS3 par Clem_02
Source avec Zip Source avec une capture MOTEUR DE SIMULATION DE LANCE D'OBJET par remy2501
Source avec Zip Source avec une capture FULLSCROLLBAR: AS3 SCROLLBAR CLASS par JeMi

Commentaires et avis

Commentaire de tlecoz le 01/12/2007 16:23:00 3/10

Hello,

J'avous ne pas avoir pris le temps de lire le code, je me suis contenté de regarder le swf. D'une part, je ne vois pas trop dans quel cas appliquer ton anim, d'autre part le temps de calcul est enorme ! C'est casiment instantané sur les 4 premiere elements, mais ca prend plus de 5 seconde a partir du 7eme blocs....Pas trés exploitable quoi !

je te suggère d'aller voir du coté de APE (Actionscript Physic Engine) :
http://www.cove.org/ape/demo1.htm

ou Motors :
http://lab.polygonal.de/category/physics/

ou encore Box2DFlash qui vient de sortir et qui m'a l'air assez genial :) :
http://box2dflash.sourceforge.net/

Tu verras que c'est quand meme un autre niveau (sans vouloir t'offenser)

2/10 pour l'effort

Commentaire de choinet le 04/12/2007 23:31:25 3/10

Tlecoz a raison, ça calcule trop. Je suis une quiche en AS donc je ne critiquerais pas ton code mais si au moins il y avait un minimum de commentaire, je serais moins perdu.

Ceci dit, 415 lignes de code c'est effectivement un bel effort

Choinet

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

actionscript<---->javascript [ par crazypiou ] Je débute l'actionscript et je voudrais savoir s'il y a moyen de récuperer en actionscript des valeurs d'un javascript. POur etre plus concret, je cré Aide pour un son sur un bouton ! [ par SkyCrasher ] Voila je débute tout juste en flash (5 jours)Donc évidemment je ne métrise pas l'ActionScript:J'ai deux boutons PLAY et STOPDès l'affichage, j'aimerai Calques et Actionscript [ par syndrael ] Bonjour,J'aimerai acceder via Action à des objets ki sont dans des calques différents. Auriez vous la syntaxe correcte ?Merci.S. Cours d'actionscript pour flash MX [ par REALOGIK ] Bonjours à toutes et à tousmoi je quelqu'un qui serait disposer à me dispenser des explications voir même des cours sur actionscript.j'ai flash MX, et Problème de concaténation [ par Moska ] Salut!J'ai un problème pour concaténer dans mon code ActionScript.J'ai ce code :chargement.onLoad = function (){ nbImg = this.nbImg; for(i=0;i&lt;nbIm Arg .....besoin d aide comment faire un zoom en Actionscript??? [ par yoyotris ] Salut tout le monde j aimerai avec le code qui permet de faire un zoom sur un clip ou une image , mais pas avec des masque! Je voudrai en action scrip importation d'images depuis MySQL vers Flash [ par totoxnegger ] Bonjour à tous ! Je suis actuellement débutant en actionscript et php, mais on m'a demandé de créer un code php et actionscript afin de pouvoir récupé mouvement ActionScript [ par giank ] est-ce que quelqun pourrait m' expliquer comment remplacer une interpolation de mouvement, par du script.j' ai compris comment faire bouger mon MC, ma Heritage actionscript [ par tinkiete ] Quelqu'un pourrait-il me dire pourquoi le code suivant ne fonctionne pas ? function toto() { trace("constructeur toto"); toto.prototype.f = function( Constantes en actionscript ??? [ par tinkiete ] Question bete, mais est-il possible de définir des constantes dans un actionscript ?Quand je dis constante, j'entend par là l'équivalent du #define en


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,310 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales