Einzelnen Beitrag anzeigen
Alt 03-01-2010, 23:02   #1 (permalink)
mxmxmx
Neuer User
 
Registriert seit: Jan 2010
Beiträge: 11
Problem beim Programmieren eines Shooters

Ich bin neu im forum und hab bisher noch keinen Beitrag zu meinem Porblem gefunden bzw. weiß auch nich wonach ich genau suchen soll.
Ich wollte mich eig an einem kleinem Spiel versuchen..ich hab zwar noch nicht so viel Erfahrung mit Flash aber bis jetzt hab ichs geschafft.
Das Problem ist nur, dass die bullets auch wenn sie schon "abgeschossen" wurden, immer noch in die Richtung der Maus fliegen.
Code:
ball_mc.onEnterFrame = function() {
	var xMouse = _root._xmouse;
	var yMouse = _root._ymouse;
	if(Math.abs(xMouse - this._x) < 1) {
		this._x = xMouse;
		this._y = yMouse;
	} else {
		this._x -= (this._x-xMouse) / 6;
		this._y -= (this._y-yMouse) / 6;
	}
}
var bulletSpeed = 12;
var bulletReady = true;
var bulletDelay = 150;
var bulletArray = [];
var bulletCount = 0;
function createBullets(){
	var bulletMc = this.attachMovie("bullet","bullet"+bulletCount,1000+bulletCount);
	bulletCount++;
	bulletMc._x = this.ball_mc._x-(bulletMc._width/2);
	bulletMc._y = this.ball_mc._y;
	bulletArray.push(bulletMc);
}
function moveBullets(){
	if(bulletReady && Key.isDown(Key.CONTROL)){
		bulletReady = false;
		currentTime = getTimer();
		createBullets();
	} else{
		if(currentTime+bulletDelay<=getTimer()){
			bulletReady = true;
		}
	}
	for(var i = 0;i<bulletArray.length;i++){
		var an = point._x-ball_mc._x;
		var geg = point._y-ball_mc._y; 
		var hyp = Math.sqrt((an*an)+(geg*geg));
		if(point._x>=ball_mc._x){
		bulletArray[i]._x += bulletSpeed*Math.cos(Math.asin((point._y-ball_mc._y)/hyp));//bulletSpeed-1;//(point._y-ball_mc._y)/(point._x-ball_mc._x)*bulletArray[i]._x;
		bulletArray[i]._y += bulletSpeed*Math.sin(Math.asin(geg/hyp));
		} else {
			bulletArray[i]._x +=
-1*(bulletSpeed*Math.cos(Math.asin((point._y-ball_mc._y)/hyp)));
			bulletArray[i]._y += (bulletSpeed*Math.sin(Math.asin(geg/hyp)));
		}
	}
}
onEnterFrame = function (){
	moveBullets();
	this.attachMovie("ball_mc","ball_mc",1);
	i = this.ball_mc._x;
	d = this.ball_mc._y;
	this.attachMovie("point","point",1);
	this.point._x = 1+(i + _root._xmouse)/2;
	this.point._y = 1+(d + _root._ymouse)/2;
};
-der Movieclip ball_mc ist ein Kreis, der der Maus folgt
-point ist ein Punkt, der vor dem Kreis fliegt und sozusagen die Zielrichtung der bullets anzeigt
-bullet erklärt sich von selbst
Wär nett, wenn mir jemand helfen könnte
mxmxmx ist offline   Mit Zitat antworten