360 Grad Rotation

maeggi07

Grünschnabel
hallo,

ich bin noch ein anfänger in flash und wie jeder anfänger, fängt man immer klein an.
ich habe schon viele tutorials durch genommen und beherrsche auch die grundlagen von flash. jetzt bin ich dabei erstmal fertige tutorials zu bearbeiten, um noch mehr funkionen kennen zu lernen.

ich bin dabei ein einfaches snake spiel, zu programmieren.
bin auch schon fast fertig, habe da noch ein paar probleme. aber keine die man nicht auch lösen könnte *G*

es gibt ein problem wo ich nicht weiter komme.
und auch keine tutorials für finde, in deutsch.

es geht darum das ich den wurm um 360 grad drehen möchte. wie auch zb. hier zu sehen ist.

wie würdet ihr das angehen?

oder kennt ihr vieleicht eine deutsches tutorial, wo das erklärt wird?

ich hänge mal meine fla datei dran.

also erstmal vielen dank für eure hilfe.

wünsche euch noch einen schönen abend

mfg maeggi
 

Anhänge

  • snake.zip
    24 KB · Aufrufe: 69
Zuletzt bearbeitet:
Guten Morgen,

Ich habe es Dank @Modokan, geschaft. das der wurm sich um 360 Grad dreht. Jetzt habe

Jetzt funkioniert aber der andere Teil des Wurms nicht mehr(der schwanz des wurmes).

Ich habe nur die Steuerung verändert. Hier mal der AS, wenn es funkioniert, ohne 360 Grad Steuerung.
Das der AS vom HEAD

PHP:
 onClipEvent (load) { 
   kill = 0; 
    var count=0; 
 
function replicate () { 
        count+=1; 
      if (count>=300) { 
         count = 0; 
      } 
duplicateMovieClip (_root.tail, "tail"+ count, 10+count); 
      _root["tail"+count]._x = this._x; 
      _root["tail"+count]._y = this._y; 
       
 
if(dir=="right"){_root["tail"+count]._rotation=0} 
else 
if(dir=="left"){_root["tail"+count]._rotation=180} 
else 
if(dir=="down"){_root["tail"+count]._rotation=90} 
else 
if(dir=="up"){_root["tail"+count]._rotation=-90} 
 
   } 
function checkEdges(){ 
    if (_x>550){this._x=-10} 
else if (_x<-15){this._x=540} 
else if (_y>400){_y=-10} 
else if (_y<-15){_y=380} 
} 
 
 
   } 
 
onClipEvent (enterFrame) { 
 
 
checkEdges() 
 
   if(!_root.head.kill){ 
   if (Key.isDown(Key.RIGHT) and dir != "left") { 
      dir = "right"; 
      speedx = 10; 
      speedy = 0; 
      this._rotation=0 
      replicate () 
       
   } else if (Key.isDown(Key.LEFT) and dir != "right") { 
      dir = "left"; 
      speedx = -10; 
      speedy = 0; 
      replicate () 
      this._rotation=180 
   } else if (Key.isDown(Key.UP) and dir != "down") { 
      dir = "up"; 
      speedy = -10; 
      speedx = 0; 
      replicate () 
      this._rotation=260 
   } else if (Key.isDown(Key.DOWN) and dir != "up") { 
      dir = "down"; 
      speedx = 0; 
      speedy = 10; 
      replicate () 
      this._rotation=90 
   }else {replicate ()} 
    
   this._x += speedx; 
   this._y += speedy; 
   } 
    
    
}


So funkioniert das einwandfrei.

Wenn Ich das Jetzt mit der Steuerung änder(360 Grad), dann funkioniert das nicht mehr.

Hier der AS.


PHP:
 onClipEvent (load) { 
   kill = 0; 
    var count=0; 
 
function replicate () { 
        count+=1; 
      if (count>=300) { 
         count = 0; 
      } 
duplicateMovieClip (_root.tail, "tail"+ count, 10+count); 
      _root["tail"+count]._x = this._x; 
      _root["tail"+count]._y = this._y; 
       
 
   } 
function checkEdges(){ 
    if (_x>550){this._x=-10} 
else if (_x<-15){this._x=540} 
else if (_y>400){_y=-10} 
else if (_y<-15){_y=380} 
} 
 
 
   } 
 
onClipEvent (enterFrame) { 
 
 
checkEdges() 
speed = 5; 
 
   if(!_root.head.kill){ 
   if (Key.isDown(Key.RIGHT)) { 
       this._rotation += 7; 
      replicate () 
      } else if (Key.isDown(Key.LEFT)) { 
        this._rotation -= 7; 
   }else {replicate ()} 
    
        this._x += speed * Math.cos(this._rotation * (Math.PI / 180)); 
        this._y += speed * Math.sin(this._rotation * (Math.PI / 180)); 
   } 
    
    
}


Die 360 Grad Steuerung funkioniert.
Aber der Wurm wird nicht länger, und nach dem ich die 2te Nahrung gegessen habe, gehe ich immer GAMEOVER.

Hier mal die SWF

KLICK MICH

Ist natürlich nur die Beispiel Version.

Hier auch nochmal der AS für den Schwanz des Wurmes.

PHP:
 onClipEvent (load){var c=0;} 
onClipEvent (enterFrame){ 
c=c+1; 
 
if ( c>=_root.life){removeMovieClip (this);} 
 
 
if ( this.hitTest(_root.pill)){_root.pill.change_pos=1;} 
 
if (this.hitTest (_root.head._x,_root.head._y,true)) 
{_root.head.kill=1; 
 
_root.pill._x=-100; 
 
_root.msg="Game Over"; 
 
} 
 
}


Wieso funkioniert das so nicht? Was mache ich Falsch?

Ich hoffe mir kann da jemand bei Helfen.

Das wäre echt super, wenn da mal jemand drüber gucken könnte.

Vielen Dank

mfg maeggi07
 
Hi maeggi07

Wenn eine funktion erstellst ähnlich dieser ?

for (n=0; n<snakelength; n++) {}

oder guckst du hier mal rein.

Ist auch ein gutes Tut was anwenden kannst.
 
hallo Monte Djego,

for (n=0; n<snakelength; n++) {}

was ist n=0; ?

kannst du vieleicht ein beispiel machen?
das wäre mir eine ssehr große hilfe.
hast du noch meine fla?

ich bin jetzt gerade dabei die hittest abfrage von den wänden zumachen.
das aber schnell gemacht.

vielen dank für deine hilfe

mfg maeggi

EDIT: hier nochmal die fla datei.
Klick Mich
 
Zuletzt bearbeitet:
for (n=0; n<snakelength; n++) {}

Die Schlange muss ja eine maximal länge haben, oder ? z.b.:12

dann steigt doch der n wert.

also so hier ungefähr: for (n=0; n<snakelength; n++) {}

n=0; der Startwert der Schlange,
n<12; die maximale schlangenlänge;
n++ wenn ein Teil gefressen wurde, bzw aufgenommen wurde zur Schlange.

Hoffe verstehst was ich damit meine.

Ja deine fla datei hab ich noch.
 

Anhänge

  • beispiel-snake.zip
    11,9 KB · Aufrufe: 42
Zuletzt bearbeitet:
ja danke, habe ich verstanden.

das würde bei mir dann ja ungefär so aussehen

(head=0; head<snakelength; head++) {}

und mehr brauche ich dafür nicht?

wie sieht es denn mit der position aus?
muss ich die nicht errechnen(_x und _y)?

mfg maeggi

EDIT: ich muss jetzt schnell mal weg. ich versuche es später mal. ich antworte dann hier nochmal.
 
Zuletzt bearbeitet:
hallo,

danke für deine hilfe @Monte Djego,

ich habe es aber anders lösen können, habe einfach noch ein

this._x += speed * Math.cos(this._rotation * (Math.PI / 180));
this._y += speed * Math.sin(this._rotation * (Math.PI / 180));

bei duplicateMovieClip mit dran gehängt.
so sieht das jetzt aus.


PHP:
 onClipEvent (load) { 
   kill = 0; 
    var count=0; 
 
function replicate () { 
        count+=1; 
      if (count>=300) { 
         count = 0; 
      } 
duplicateMovieClip (_root.tail, "tail"+ count, 10+count); 
      speed = 5;
      _root["tail"+count]._x = this._x; 
      _root["tail"+count]._y = this._y; 
      this._x += speed * Math.cos(this._rotation * (Math.PI / 180)); 
      this._y += speed * Math.sin(this._rotation * (Math.PI / 180)); 
   
 
   } 
function checkEdges(){ 
    if (_x>550){this._x=-10} 
else if (_x<-15){this._x=540} 
else if (_y>400){_y=-10} 
else if (_y<-15){_y=380} 
} 
 
 
   } 
 
onClipEvent (enterFrame) { 
 
 
checkEdges() 
speed = 5; 
 
   if(!_root.head.kill){ 
   if (Key.isDown(Key.RIGHT)) { 
       this._rotation += 7; 
      replicate () 
      } else if (Key.isDown(Key.LEFT)) { 
        this._rotation -= 7; 
   }else {replicate ()} 
    
        this._x += speed * Math.cos(this._rotation * (Math.PI / 180)); 
        this._y += speed * Math.sin(this._rotation * (Math.PI / 180)); 
   } 
    
    
}

mein problem ist jetzt nur noch das er jetzt irgendwann einfach gameover geht. worankann das liegen?

vieleicht kann mir, da ja einer helfen. dann sind alle meine problem gelöst *G*

also erstmal vielen dank


mfg maeggi
 
Zurück