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

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

silent assassin

Posts: 0
Joined: Aug 2025
May 27, 2007 11:56 PM #34161
Um..MY GUN SHOOTS BACKWARDS!!!! WTF?!?!?!

im making a sidescroller..and my common sense isn't that good i suppose...heres the code

onClipEvent(load){
speed = 10;
shotnum = 10;
shotmin = 10;
shotmax = 20;
reload = 8;
nextshot = 0;
}
onClipEvent (enterFrame) {
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 (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;
}
}
The Pirate
2

Posts: 563
Joined: May 2006
Rep: 10

View Profile
May 28, 2007 1:07 AM #34177
Quote from silent assassin
Um..MY GUN SHOOTS BACKWARDS!!!! WTF?!?!?!

im making a sidescroller..and my common sense isn't that good i suppose...heres the code


Clearly not.

If your shot moves backwards, just reverse it's direction. Set the speed to a negative number.
silent assassin

Posts: 0
Joined: Aug 2025
May 28, 2007 2:26 PM #34198
or i could have used ma mega coding skillz and noticed that u used "_y -= speed " in the shot's code so i thought all i had to do is chang it to "x". That was wrong i also had to chang the + to a -. HA coding skillz beats common sense lol... I just wanted to show that to any siderscroller makers.
Scorpioxxx
2

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

View Profile
May 28, 2007 3:44 PM #34208
Quote from silent assassin
Um..MY GUN SHOOTS BACKWARDS!!!! WTF?!?!?!

im making a sidescroller..and my common sense isn't that good i suppose...heres the code

onClipEvent(load){
speed = 10;
shotnum = 10;
shotmin = 10;
shotmax = 20;
reload = 8;
nextshot = 0;
}
onClipEvent (enterFrame) {
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 (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;
}
}


Quote from silent assassin
or i could have used ma mega coding skillz and noticed that u used "_y -= speed " in the shot's code so i thought all i had to do is chang it to "x". That was wrong i also had to chang the + to a -. HA coding skillz beats common sense lol... I just wanted to show that to any siderscroller makers.

You are aware that that part or code is for the player movement and your 'side scroller' has pointless code, i bolded it for you.
silent assassin

Posts: 0
Joined: Aug 2025
May 28, 2007 3:54 PM #34213
i didn't mean a sidescroller exactly...i meant his game...but sideways.... so that code does have a point...

i also found out that the code was wrong for "shot". It was _y -= speed

its supposed to be _x += speed
The Pirate
2

Posts: 563
Joined: May 2006
Rep: 10

View Profile
May 28, 2007 7:10 PM #34237
Quote from silent assassin
i didn't mean a sidescroller exactly...i meant his game...but sideways.... so that code does have a point...

i also found out that the code was wrong for "shot". It was _y -= speed

its supposed to be _x += speed


A top scroller sideways IS a side scroller you silly wanker.
silent assassin

Posts: 0
Joined: Aug 2025
May 28, 2007 10:41 PM #34291
Some people consider a side scroller as a Mario type game. Since its not...there im only agreeing with u...
Gavel
2

Posts: 6,675
Joined: Oct 2006
Rep: 10

View Profile
May 29, 2007 6:14 PM #34375
Alright, I was cruising along nicely with this until I got to the part where you add the code to make your ship die.

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

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

}
}


I've been putting that code like this on my "player" movie clip:
onClipEvent(enterFrame){
if (this._name == "player") {

onClipEvent (enterFrame) {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.LEFT)) {
_x -= speed;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
}
if (Key.isDown(Key.UP)) {
_y -= speed;
}
if (Key.isDown(Key.DOWN)) {
_y += speed;
}
}
}
}


The bolded parts are the new code I put in.

I'm not sure how I'm misunderstanding it.

Oh, and here's my game. You might've noticed that the gunshot isn't firing at the center of the car. Well that's the way I want it, considering the dude's hand is leaning out the window. But the explosions for the enemies are way off. The enemy dissapears and the explosions pops up to far back and to the right.


Yes, I didn't make it space themed. It's called "breaking away from the norm", or something like that. I wanted to do something different than everyone else.
Short1

Posts: 8
Joined: Jul 2006
Rep: 10

View Profile
May 29, 2007 9:46 PM #34392
This is totally cool. : D
I think I'll make a sort of driving game in a desert type background with a dune buggy.
Steyene

Posts: 2,060
Joined: Apr 2006
Rep: 10

View Profile
May 30, 2007 8:08 AM #34473
@Spazzy-Z. I think its because you forgot to code the hit tests between the enemies and the player.
Rather Cheesy
2

Posts: 2,137
Joined: Apr 2007
Rep: 10

View Profile
Aug 6, 2007 2:21 AM #49670
awesome tut pirate, helped me tons, never knew how to duplicate MC's before now

9/10 cause theres no part 2 lol
Gavel
2

Posts: 6,675
Joined: Oct 2006
Rep: 10

View Profile
Aug 23, 2007 11:59 PM #54022
Quote from pokit5
mine dosent shoot. could sombody give me the exact code?


He did give you the exact code (not that this is the only way to do this). You obviously didn't follow the tut properly. Maybe you should actually learn from it and try to understand actionscript so you can see what you're doing wrong.
pagdog9

Posts: 0
Joined: Aug 2025
Sep 1, 2007 1:39 PM #55985
I have the code and i clicked check sintaxis. It says i has no errors but when i shoot my enemy it doesn´t die
Scorpioxxx
2

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

View Profile
Sep 1, 2007 3:09 PM #55988
Have you put in that when the shield/hp/whatever the variable is = 0 or <1 to remopve the movieclip (enemy) an also make sure you even put in to remove a number from the variable when they collide.
pagdog9

Posts: 0
Joined: Aug 2025
Sep 1, 2007 7:56 PM #56050
i cant make me die