Pirate's Space Game Tutorial, Part 1 [Flash][Actionscript]

Started by: The Pirate | Replies: 65 | Views: 18,425

Apples
2

Posts: 1,931
Joined: Dec 2005
Rep: 10

View Profile
May 23, 2007 11:52 PM #33725
Mine wont work on the shooting part.
Greenfire

Posts: 0
Joined: Jul 2026
May 24, 2007 2:09 AM #33742
I have a problem, My ship shoots it's lazor, but if you hold space, it just stays in one spot. Also, it will only ever have 1 on screen, even though I have it set to 10.
Arch-Angel
2

Posts: 9,496
Joined: Jan 2007
Rep: 10

View Profile
May 24, 2007 2:38 AM #33748
I don't think u guys are experienced enough in AS for this, Cept DA. Mainly for the moving and missiles. Because the tutorial is very clear on what to do and stuff. I can understand about the respawning ships thing, cuz that is tricky and to me, not well explained. Non the less its a great tutorial. I would like if you could explain the ship spawn part a little more, because when you said that the "remove clip" thing would remove it and it wouldn't do anything else with the movie clip, I looked at my ships AS and it has more than 1 part of AS like that. It confuses me.

All others having problems. Read what it says. And when it tells you to put AS in a '}', you simply go to the line with the '}', hit enter, and on the new line under the '}', paste the AS. for the shotmin and stuff. you'd go to the line with the shotmin or speed (the lowest line of it), hit enter and paste the AS under it.

Another good help thing is to not just read where to put your AS, copy it and paste it. Read what each part of it does so you learn what you'll need when making a game by yourself, and you'll know how to fix an AS problem yourself.
The Pirate
2

Posts: 563
Joined: May 2006
Rep: 10

View Profile
May 24, 2007 10:19 AM #33769
Quote from theblindsamurai_135
I can understand about the respawning ships thing, cuz that is tricky and to me, not well explained. Non the less its a great tutorial. I would like if you could explain the ship spawn part a little more, because when you said that the "remove clip" thing would remove it and it wouldn't do anything else with the movie clip, I looked at my ships AS and it has more than 1 part of AS like that. It confuses me.


Wasn't quite sure what you were talking about here. Can you show me what part of the code you were having trouble with?


DA (Archangel, whatver) try this.

onClipEvent (enterFrame) {
gotoAndStop(1);
if (Key.isDown(Key.SPACE)) {
gotoAndPlay(6);
}
if (Key.isDown(Key.RIGHT)) {
gotoAndStop(12);
_x += 5;
}
if (Key.isDown(Key.LEFT)) {
gotoAndStop(13);
_x -= 5;
}
}



@Greenfire - Read my explanation of depths and how to set the depth range. It sounds to me like you've set the depths to only allow one value of shotnum.
Arch-Angel
2

Posts: 9,496
Joined: Jan 2007
Rep: 10

View Profile
May 24, 2007 10:22 AM #33770

onClipEvent(enterFrame){
if (this._name == "player") {

*ALL THE CODE YOU TYPED PREVIOUSLY SHOULD BE HERE WITHIN THIS NEW SET OF CURLY BRACKETS*

}
}


that. The thing that lets u die or something
Scorpioxxx
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
May 24, 2007 5:23 PM #33804
I found the single weapon thind boring but when i added another it went odd i have a MC with the instance name mini yet when i press control it duplicats the 'shot' MC instread, also, there arn't any errors, heres the code;
onClipEvent (load) {
speed = 5;
shotnum = 10;
shotmin = 10;
shotmax = 15;
reload = 25;
nextshot = 0;
shotmini = 10;
shotminimin = 10;
shotminimax = 30;
minireload = 3;
mininextshot = 0;
}
onClipEvent (enterFrame) {
if (this._name == "player") {
if (Key.isDown(Key.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
if (Key.isDown(Key.UP)) {
_y -= speed;
}
if (Key.isDown(Key.DOWN)) {
_y += speed;
}
if (_x>_root.stagex) {
_x = _root.stagex;
}
if (_x<0) {
_x = 0;
}
if (_y>_root.stagey) {
_y = _root.stagey;
}
if (_y<0) {
_y = 0;
}
if (Key.isDown(Key.SPACE)) {
if (nextshot == 0) {
nextshot = reload;
shotnum++;
_root.shot.duplicateMovieClip("shot"+shotnum, shotnum);
_root["shot"+shotnum]._x = this._x;
_root["shot"+shotnum]._y = this._y;
}
}
if (nextshot>0) {
nextshot--;
}
if (shotnum>=shotmax) {
shotnum = shotmin;
}
if (Key.isDown(Key.CONTROL)) {
if (mininextshot == 0) {
mininextshot = minireload;
shotmini++;
_root.shot.duplicateMovieClip("mini"+shotmini, shotmini);
_root["mini"+shotmini]._x = this._x;
_root["mini"+shotmini]._y = this._y;
}
}
if (mininextshot>0) {
mininextshot--;
}
if (shotmini>=shotminimax) {
shotmini = shotminimin;
}
}
}
The Pirate
2

Posts: 563
Joined: May 2006
Rep: 10

View Profile
May 24, 2007 6:35 PM #33808
_root.shot.duplicateMovieClip("mini"+shotmini, shotmini);

This line of code here is your problem. _root.shot is telling Flash which object to duplicate, and you still have it set to the normal shot. I'm assuming you made a second object called "minishot" or something, so write:

_root.minishot.duplicateMovieClip("mini"+shotmini, shotmini);
Arch-Angel
2

Posts: 9,496
Joined: Jan 2007
Rep: 10

View Profile
May 24, 2007 6:53 PM #33809
Quote from Dragora
that. The thing that lets u die or something

lol. I got a name change

onClipEvent(enterFrame){
if (this._name == "player") {

*ALL THE CODE YOU TYPED PREVIOUSLY SHOULD BE HERE WITHIN THIS NEW SET OF CURLY BRACKETS*

}
}


thats the AS im talking about (2nd page)
Scorpioxxx
2

Posts: 1,454
Joined: Apr 2006
Rep: 10

View Profile
May 24, 2007 7:01 PM #33811
Quote from The Pirate
_root.shot.duplicateMovieClip("mini"+shotmini, shotmini);

This line of code here is your problem. _root.shot is telling Flash which object to duplicate, and you still have it set to the normal shot. I'm assuming you made a second object called "minishot" or something, so write:

_root.minishot.duplicateMovieClip("mini"+shotmini, shotmini);

Missed that, i should get glasses.....
The Pirate
2

Posts: 563
Joined: May 2006
Rep: 10

View Profile
May 24, 2007 7:05 PM #33815
Quote from Dragora
thats the AS im talking about (2nd page)


Alright, that part of the tutorial just meant to put that new set of brackets, if(this._name == "player"){, around all the other code in onClipEvent(enterFrame). The reason for doing that, was so when we create a duplicate of the players ship, the base object wont still be flying around and running its code.

The code that actually lets you die is here:

if (this.hitTest(_root.player)) {
_root.expnum++;
_root.explosion.duplicateMovieClip("explosion"+_root.expnum, _root.expnum);
_root["explosion"+_root.expnum]._x = this._x;
_root["explosion"+_root.expnum]._y = this._y;
_root.player.removeMovieClip(); <--- add this new line
this.removeMovieClip();
}


This code is found in the enemy movie clip. It simply uses removeMovieClip(); to delete the player's ship.

Does that help at all?
Arch-Angel
2

Posts: 9,496
Joined: Jan 2007
Rep: 10

View Profile
May 24, 2007 7:16 PM #33817
so all I have to add is brackets? or "if(this._name == "player"){
The Pirate
2

Posts: 563
Joined: May 2006
Rep: 10

View Profile
May 24, 2007 10:18 PM #33847
Quote from Dragora
so all I have to add is brackets? or "if(this._name == "player"){


onClipEvent(enterFrame){
if (this._name == "player") {

*ALL THE CODE YOU TYPED PREVIOUSLY SHOULD BE HERE WITHIN THIS NEW SET OF CURLY BRACKETS*

}
}


Like this, you just put if(this._name == "player"){ right below onClipEvent(enterFrame){, and add an extra } curly bracket at the end. The rest of the code you entered is within the new set of brackets, that way it will only execute if the object has the proper instance name.
Arch-Angel
2

Posts: 9,496
Joined: Jan 2007
Rep: 10

View Profile
May 24, 2007 10:32 PM #33848
do i duplicate my ship? Because i did that and named one base ship
The Pirate
2

Posts: 563
Joined: May 2006
Rep: 10

View Profile
May 24, 2007 11:42 PM #33849
Quote from Dragora
do i duplicate my ship? Because i did that and named one base ship


Oh I see where you're getting confused now.

All of the "duplicates" are created by the code, the same code used to make the lasers shoot, and the enemies spawn. You don't physically copy and paste the ship to make a duplicate. You move the ship off the screen entirely, it IS the base ship. The new duplicate ship is created by some code in the next step.
Arch-Angel
2

Posts: 9,496
Joined: Jan 2007
Rep: 10

View Profile
May 25, 2007 12:04 AM #33855
Oh, so I just move the ship off the screen. do I still need to change the name to "playerbase"?

also, my boundaries are messed up. You can leave the stage on the right side


1 last problem. Then it's onto the "kills" box and making finishing touches.

this
if (this.hitTest(_root.player)) {
_root.expnum++;
_root.explosion.duplicateMovieClip("explosion"+_root.expnum, _root.expnum);
_root["explosion"+_root.expnum]._x = this._x;
_root["explosion"+_root.expnum]._y = this._y;
_root.player.removeMovieClip(); <--- add this new line
this.removeMovieClip();
}


where do i add that onto my collision code, which should be in my enemy right?
but about that code. Do i only add _root.player.removeMovieClip();




-to everyone else. A nifty trick i discovered. It's pretty obvious. Seeing as how your enemies are movie clips, you can add like fire coming out of the rockets or something, to give it a little more feel or something like that.

Sorry, another problem. I only have my "playerbase" movieclip. I moved it off the stage. when i start my game everythings fine, but what's this, after 5 seconds another ship flies in and is like attatched to you on an invisible cord

http://www.swfup.com/file/10942
thats my game so far.