Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 28-11-2006, 14:34   #1 (permalink)
elk
Neuer User
 
Registriert seit: Feb 2004
Beiträge: 93
Ich programiere schlecht!

Hi,
Ich mache grad ein 2d weihnachtsmannbattle ( 2 weihnachtsmänner werden über die tastatur gesteuert und werfen sich mit schnebällen ab).

So habe ich das gemacht:
-Ein Schneeball (mc_sr1) bekommt die weihnachtsmannsteuerung.
-Wenn der Schneeball auf ein Hinderniss trifft geht er wieder in den weihnachtsmann(mc_santaR).
-wenn weihnachtsmann auf hinderniss trifft wird er ein bissl zurückgestuppst

Das finde ich nciht so toll, da man nicht mehrmals hintereinander schießen kann. Außerdem siht der quelltext echt ******e aus ( geht aber )


Kann mir einer Sagen wie ich die Schiessteuerung besser hinbekomme als oben beschrieben?


PHP-Code:
var 1;
var 
xy 1;
var 
1;
var 
1;
this.mc_santar.onEnterFrame = function() {
    if (
Key.isDown(Key.RIGHT)) {
        
this._x += 5;
        
_root.mc_santar.gotoAndStop(2);
    }
    if (
Key.isDown(Key.LEFT)) {
        
this._x -= 5;
        
_root.mc_santar.gotoAndStop(3);
    }
    if (
Key.isDown(Key.UP)) {
        
this._y -= 5;
        
_root.mc_santar.gotoAndStop(1);
    }
    if (
Key.isDown(Key.DOWN)) {
        
this._y += 5;
        
_root.mc_santar.gotoAndStop(4);
    }
    if ((
Key.isDown(Key.DOWN)) and (Key.isDown(Key.RIGHT))) {
        
this._y -= 2;
        
this._x -= 2;
        
_root.mc_santar.gotoAndStop(5);
    }
    if ((
Key.isDown(Key.DOWN)) and (Key.isDown(Key.LEFT))) {
        
this._y -= 2;
        
this._x += 2;
        
_root.mc_santar.gotoAndStop(6);
    }
    if ((
Key.isDown(Key.UP)) and (Key.isDown(Key.RIGHT))) {
        
this._y += 2;
        
this._x -= 2;
        
_root.mc_santar.gotoAndStop(7);
    }
    if ((
Key.isDown(Key.UP)) and (Key.isDown(Key.LEFT))) {
        
this._y += 2;
        
this._x += 2;
        
_root.mc_santar.gotoAndStop(8);
    }
};
this.mc_sr1.onEnterFrame = function() {
    if (
_root.mc_santar.hitTest(_root.mc_sr1._x_root.mc_sr1._ytrue)) {
        if (
Key.isDown(Key.RIGHT)) {
            
this._x += 5;
        }
        if (
Key.isDown(Key.LEFT)) {
            
this._x -= 5;
        }
        if (
Key.isDown(Key.UP)) {
            
this._y -= 5;
        }
        if (
Key.isDown(Key.DOWN)) {
            
this._y += 5;
        }
        if ((
Key.isDown(Key.DOWN)) and (Key.isDown(Key.RIGHT))) {
            
this._y -= 2;
            
this._x -= 2;
        }
        if ((
Key.isDown(Key.DOWN)) and (Key.isDown(Key.LEFT))) {
            
this._y -= 2;
            
this._x += 2;
        }
        if ((
Key.isDown(Key.UP)) and (Key.isDown(Key.RIGHT))) {
            
this._y += 2;
            
this._x -= 2;
        }
        if ((
Key.isDown(Key.UP)) and (Key.isDown(Key.LEFT))) {
            
this._y += 2;
            
this._x += 2;
        }
    }
};
keyListener = new Object();
Key.addListener(keyListener);
keyListener = new Object();
keyListener.onKeyUp = function() {
    if (
Key.getCode() == Key.SPACE) {
        
boom();
    }
};
Key.addListener(keyListener);
function 
boom() {
    if (
_root.mc_santar.hitTest(_root.mc_sr1._x_root.mc_sr1._ytrue)) {
        if (
_root.== 1) {
            
//trace("oben");
            
schuss(10000000);
        }
        if (
_root.== 2) {
            
//trace("rechts");
            
schuss(01000000);
        }
        if (
_root.== 3) {
            
//trace("links");
            
schuss(00100000);
        }
        if (
_root.== 4) {
            
//trace("unten");
            
schuss(00010000);
        }
        if (
_root.== 5) {
            
//trace("ru");
            
schuss(00001000);
        }
        if (
_root.== 6) {
            
//trace("lu");
            
schuss(00000100);
        }
        if (
_root.== 7) {
            
//trace("ro");
            
schuss(00000010);
        }
        if (
_root.== 8) {
            
//trace("lo");
            
schuss(00000001);
        }
    }
}
function 
schuss(orlurulurolo) {
    
onEnterFrame = function () {
        if (
_root.mc_map.hitTest(_root.mc_santar._x_root.mc_santar._ytrue)) {
            if (
_root.== 1) {
                
_root.mc_santar._y _root.mc_santar._y+5;
                
_root.mc_sr1._y _root.mc_santar._y;
            }
            if (
_root.== 2) {
                
_root.mc_santar._x _root.mc_santar._x-5;
                
_root.mc_sr1._x _root.mc_santar._x;
            }
            if (
_root.== 3) {
                
_root.mc_santar._x _root.mc_santar._x+5;
                
_root.mc_sr1._x _root.mc_santar._x;
            }
            if (
_root.== 4) {
                
_root.mc_santar._y _root.mc_santar._y-5;
                
_root.mc_sr1._y _root.mc_santar._y;
            }
            if (
_root.== 5) {
                
_root.mc_santar._x _root.mc_santar._x-5;
                
_root.mc_santar._y _root.mc_santar._y-5;
                
_root.mc_sr1._x _root.mc_santar._x;
                
_root.mc_sr1._y _root.mc_santar._y;
            }
            if (
_root.== 6) {
                
_root.mc_santar._x _root.mc_santar._x+5;
                
_root.mc_santar._y _root.mc_santar._y-5;
                
_root.mc_sr1._x _root.mc_santar._x;
                
_root.mc_sr1._y _root.mc_santar._y;
            }
            if (
_root.== 7) {
                
_root.mc_santar._x _root.mc_santar._x-5;
                
_root.mc_santar._y _root.mc_santar._y+5;
                
_root.mc_sr1._x _root.mc_santar._x;
                
_root.mc_sr1._y _root.mc_santar._y;
            }
            if (
_root.== 8) {
                
_root.mc_santar._x _root.mc_santar._x+5;
                
_root.mc_santar._y _root.mc_santar._y+5;
                
_root.mc_sr1._x _root.mc_santar._x;
                
_root.mc_sr1._y _root.mc_santar._y;
            }
        }
        if ((
_root.mc_map.hitTest(_root.mc_sr1._x_root.mc_sr1._ytrue)) or (_root.mc_santab.hitTest(_root.mc_sr1._x_root.mc_sr1._ytrue))) {
            if (
_root.mc_santab.hitTest(_root.mc_sr1._x_root.mc_sr1._ytrue)) {
                
tehitr.text i;
                
i+1;
            }
            if (
== 1) {
                
2;
                
_root.mc_sr1._x _root.mc_santar._x;
                
_root.mc_sr1._y _root.mc_santar._y;
            }
        } else if ((
== 1) and (== 1)) {
            
_root.mc_sr1._x -= 10;
        } else if ((
== 1) and (== 1)) {
            
_root.mc_sr1._x += 10;
        } else if ((
== 1) and (== 1)) {
            
_root.mc_sr1._y -= 10;
        } else if ((
== 1) and (== 1)) {
            
_root.mc_sr1._y += 10;
        } else if ((
== 1) and (lo == 1)) {
            
_root.mc_sr1._y -= 5;
            
_root.mc_sr1._x -= 5;
        } else if ((
== 1) and (lu == 1)) {
            
_root.mc_sr1._y += 5;
            
_root.mc_sr1._x -= 5;
        } else if ((
== 1) and (ro == 1)) {
            
_root.mc_sr1._y -= 5;
            
_root.mc_sr1._x += 5;
        } else if ((
== 1) and (ru == 1)) {
            
_root.mc_sr1._y += 5;
            
_root.mc_sr1._x += 5;
        }
    };
    
1;


Geändert von elk (28-11-2006 um 16:30 Uhr) Grund: Oh war Falsche version!
elk ist offline   Mit Zitat antworten
Alt 28-11-2006, 17:48   #2 (permalink)
new user
 
Benutzerbild von PinkDragon
 
Registriert seit: Oct 2005
Beiträge: 140
Wow netter Quelltext :P

Zuerstmal wegen der Schusssteuerung:
Lass den Schneeball am Anfang in der bibliothek und gib ihm eine Verknüpfung. (ich nehm jetzt einfach "ball")
Danach würde ich es so in der Art machen:
PHP-Code:
var santa this.mc_santar;
santa.xspeed 0;
santa.yspeed 0;

santa.onEnterFrame = function(){
    if ((
Key.isDown(Key.DOWN)) and (Key.isDown(Key.RIGHT))) { 
        
this.yspeed 2
        
this.xspeed = -2
        
this.gotoAndStop(5); 
    }
//Die else sind damit er, wenn keine Taste gedrückt ist, stehen bleibt.
    
else if ((Key.isDown(Key.DOWN)) and (Key.isDown(Key.LEFT))) { 
        
this.yspeed 2
        
this.xspeed = -2
        
_root.mc_santar.gotoAndStop(6); 
    }
    else if ((
Key.isDown(Key.UP)) and (Key.isDown(Key.RIGHT))) { 
        
this.yspeed = -2
        
this.xspeed 2
        
this.gotoAndStop(7); 
    } 
    else if ((
Key.isDown(Key.UP)) and (Key.isDown(Key.LEFT))) { 
        
this.yspeed = -2
        
this.xspeed = -2
        
this.gotoAndStop(8); 
    }
    else if (
Key.isDown(Key.RIGHT)) { 
        
this.xspeed 5
        
this.gotoAndStop(2); 
    } 
    else if (
Key.isDown(Key.LEFT)) { 
        
this.xspeed = -5
        
this.gotoAndStop(3); 
    } 
    else if (
Key.isDown(Key.UP)) { 
        
this.yspeed = -5
        
this.gotoAndStop(1); 
    } 
    else if (
Key.isDown(Key.DOWN)) { 
        
this.yspeed 5
        
this.gotoAndStop(4); 
    }
    else{
       
this.xspeed 0;
       
this.yspeed 0;
       
this.gotoAndStop("stand");
    }
  
this._x += xspeed;
  
this._y += yspeed;
}

function 
boom(){
  var 
depth _root.getNextHighestDepth();
  var 
ball _root.attachMovie("ball","ball"+depth,depth);
  
ball._x _root.mc_santar._x;
  
ball._y _root.mc_santar._y;
  
ball.xspeed _root.mc_santar.xspeed*2;
  
ball.yspeed _root.mc_santar.yspeed*2;
  
ball.onEnterFrame = function(){
    
this._x += this.xspeed;
    
this._y += this.yspeed;
    if ((
_root.mc_map.hitTest(this._xthis._ytrue)) or (_root.mc_santab.hitTest(this._xthis._ytrue))){
     [
mach was auch immer]
     
this.removeMovieClip();
  }

Habs nicht getested, müsste aber so in der Art funktionieren.

mfg
PD

PS: Nein der Script ist auch nicht gerade schön, aber dafür war er schnell geschrieben

Geändert von PinkDragon (29-11-2006 um 14:45 Uhr) Grund: Hatte einmal x statt y :P
PinkDragon ist offline   Mit Zitat antworten
Alt 29-11-2006, 14:10   #3 (permalink)
elk
Neuer User
 
Registriert seit: Feb 2004
Beiträge: 93
hm supa!

nur ein problem hab ich mit deiner steuerung.

Wenn ich z.b. links und oben zugleich drücke -- dann links loslasse--- bewegt er sicht nicht nach oben sodnern schräg nach links oben, da er den xwert nicht zurücksätzt ( das else kann ja nicht anspringen, da immerhin noch 1 taste gedrückt wird)
elk ist offline   Mit Zitat antworten
Alt 29-11-2006, 14:44   #4 (permalink)
new user
 
Benutzerbild von PinkDragon
 
Registriert seit: Oct 2005
Beiträge: 140
Hab ja gesagt es geht nur so in der Art. Normalwerweise geh ich davon aus, dass man, wenn man in Flash etwas programmiert auch im Stande ist selber zu Denken...
Aber weil ich heute guter Laune bin, kriegste sogar ne halbe Lösung:
PHP-Code:
 else if (Key.isDown(Key.LEFT)) {  
     
this.xspeed = -5;
     
this.yspeed 0;
     
this.gotoAndStop(3);

Und ausserdem bekommste noch nen kleinen Tipp: Es geht auch nicht stehen zu bleiben und dann zu schießen
Aber ich bin mir sicher, dass du auch das mit ein bischen Denken schaffst zu lösen.

mfg
PD
PinkDragon ist offline   Mit Zitat antworten
Alt 29-11-2006, 16:04   #5 (permalink)
elk
Neuer User
 
Registriert seit: Feb 2004
Beiträge: 93
Hier stand erst was anderes -- habs aber geändert, da ich jetzt raus habe. Ein neues Prob--

attach movies kann ich irgendwie nicht ansprechen bzw einen Hittest mit ihnen machen. In deinem Beispiel musste folgendes doch gehen oder... warum gehts net?

PHP-Code:
if (_root.mc_map.hitTest(this._xthis._ytrue)){ 
 
trace("hallo"); 
this.removeMovieClip(); 
  } 
ich hab für this auch schon mal _root.ball oder so genommen .. klappt aber alles net

Geändert von elk (29-11-2006 um 18:10 Uhr)
elk ist offline   Mit Zitat antworten
Alt 29-11-2006, 20:02   #6 (permalink)
new user
 
Benutzerbild von PinkDragon
 
Registriert seit: Oct 2005
Beiträge: 140
Was genau geht nicht? Wird die Funktion nicht aufgerufen? Wird die If-Abfrage nicht wahr? Wird der trace nicht ausgegeben? Wird der MovieClip nicht entfernt?
Lass einfach mal folgendes ausgeben:
PHP-Code:
trace("MC: "+this);
var 
hit _root.mc_map.hitTest(this._xthis._ytrue);
trace("Hit: "+hit);
if (
hit){  
  
trace("hallo");
  
trace("MC: "+this);
  
this.removeMovieClip();

Ausgabe sollte bestenfalls in etwa so aussehen:
PHP-Code:
MC_leveo0.ballx
Hit
true
hallo
MC
_level0.ballx 
PinkDragon ist offline   Mit Zitat antworten
Alt 29-11-2006, 20:29   #7 (permalink)
elk
Neuer User
 
Registriert seit: Feb 2004
Beiträge: 93
Bei meinem hallo hat er nichts ausgegeben.

bei dir gibt er das aus:

MC: _level0
Hit: false
elk ist offline   Mit Zitat antworten
Alt 30-11-2006, 13:11   #8 (permalink)
new user
 
Benutzerbild von PinkDragon
 
Registriert seit: Oct 2005
Beiträge: 140
Dann schau mal ob deine Funktion
PHP-Code:
ball.onEnterFrame = function(){} 
stimmt. Gib einfach mal nur
PHP-Code:
ball.onEnterFrame = function(){
  
trace(this);

Hmm da fällt mir gerade etwas auf: Hast du mein bsp im kontext probiert oder extra? sollte den onClipEvent einfach ersetzen:
PHP-Code:
 ball.onEnterFrame = function(){
  
trace("MC: "+this); 
  var 
hit _root.mc_map.hitTest(this._xthis._ytrue); 
  
trace("Hit: "+hit); 
  if (
hit){   
    
trace("hallo"); 
    
trace("MC: "+this); 
    
this.removeMovieClip(); 
  }

Ohne das "ball.onEnterFrame = function()" kann es nicht funktionieren da sonst das "this" nicht der Ball sondern die Bühne ist.
PinkDragon ist offline   Mit Zitat antworten
Alt 03-12-2006, 13:16   #9 (permalink)
elk
Neuer User
 
Registriert seit: Feb 2004
Beiträge: 93
hatte ein grundsätzliches Problem in ner Logic--- hat sich jetzt geklährt
elk ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 18:16 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele