Gravitation & Kugelwurf

Status
Nicht offen für weitere Antworten.

Matthias Kannengiesser

Erfahrenes Mitglied
Hi Folks,

Hier zwei Funktionen zum bearbeiten und zerpflücken:

Code:
function setGravity(obj,pLinks,pRechts,pOben,pUnten,pX,pY,pGravitation) {
	this[obj].feld = {links:pLinks, rechts:pRechts, oben:pOben, unten:pUnten};
	this[obj].vektor = [pX, pY];
	this[obj].gravitation = pGravitation;
	this[obj].onEnterFrame = function() {
		this._x += this.vektor[0];
		this._y -= this.vektor[1];
		if (this._x <= this.feld.links) {
			this._x = this.feld.links;
			this.vektor[0] *= -1;
		} else if (this._x >= this.feld.rechts) {
			this._x = this.feld.rechts;
			this.vektor[0] *= -1;
		}
		if (this._y <= this.feld.oben) {
			this._y = this.feld.oben;
			this.vektor[1] *= -1;
		} else if (this._y >= this.feld.unten) {
			this._y = this.feld.unten;
			this.vektor[1] *= -1;
		}
		this.vektor[0] *= .96;
		this.vektor[1] *= .96;
		this.vektor[1] -= this.gravitation;
	};
	this[obj].onPress = function() {
		this.vektor = [-this._xmouse * 2, this._ymouse * 2.5];
	};
}

setGravity("kugel_mc",40,260,40,260,0,0,2);
setGravity("kugel_mc2",40,260,40,260,0,0,4);
setGravity("kugel_mc3",40,500,40,260,0,0,4);

Beispiel:
http://www.flashangel.de/mx/fsgravity2.swf

Code:
function setWurf(obj,pLinks,pRechts,pOben,pUnten,pX,pY,pGravitation) {
	this[obj].feld = {links:pLinks, rechts:pRechts, oben:pOben, unten:pUnten};
	this[obj].vektor = [pX, pY];
	this[obj].gravitation = pGravitation;
	this[obj].onEnterFrame = function() {
		if (this.ziehen) {
			this._x = this._parent._xmouse;
			this._y = this._parent._ymouse;
			this.letztePos = this.aktPos;
			this.aktPos = [this._x, this._y];
			this.ziehVektor = [this.aktPos[0] - this.letztePos[0], this.letztePos[1] - this.aktPos[1]];
		} else {
			this._x += this.vektor[0];
			this._y -= this.vektor[1];
			if (this._x <= this.feld.links) {
				this._x = this.feld.links;
				this.vektor[0] *= -1;
			} else if (this._x >= this.feld.rechts) {
				this._x = this.feld.rechts;
				this.vektor[0] *= -1;
			}
			if (this._y <= this.feld.oben) {
				this._y = this.feld.oben;
				this.vektor[1] *= -1;
			} else if (this._y >= this.feld.unten) {
				this._y = this.feld.unten;
				this.vektor[1] *= -1;
			}
			this.vektor[0] *= .96;
			this.vektor[1] *= .96;
			this.vektor[1] -= this.gravitation;
		}
	};
	this[obj].onPress = function() {
		this.aktPos = [this._x, this._y];
		this.ziehen = true;
	};
	this[obj].onRelease = this[obj].onReleaseOutside = function () {
		this.ziehen = false;
		this.vektor = this.ziehVektor;
	};
}

setWurf("kugel_mc",40,260,40,260,0,0,4);
setWurf("kugel_mc2",40,400,40,260,0,0,3);
setWurf("kugel_mc3",40,500,40,260,0,0,2);

Beispiel:
http://www.flashangel.de/mx/fswerfen2.swf

Hinweis: Nicht wundern auch das kam bei einer längeren Bahnfahrt zustande wollte ich Euch nicht vorenthalten.

Achtung: Dort wo die Smilies im Code sind bitte durch einen Doppelpunkt ersetzen.

Liebe Grüsse
Matze K.
 
Status
Nicht offen für weitere Antworten.

Neue Beiträge

Zurück