PDA

View Full Version : Shooting game in actionscript


matti9
06-30-2008, 03:46 AM
i am making my first game ever. it is also my first flash ever. period. i have never done this before. in the game an object will move left and right, using the arrow keys. when you click, i need for a "bullet" to come out of this object, no matter what its position. i have no idea how to do this. i already have a separate layer with a button that takes up the whole screen. now i just need the code to tell it that when i click on it, the object will "shoot". please help.

GMaker0507
06-30-2008, 08:58 PM
try going to http://gotoandplay.it/_articles/index.php

then at the top, in the topics combo box, choose shooting, then click go

tango88
07-01-2008, 05:58 AM
Here's the code from the game I'm working on:

//initialise variables
fired=0;dep=0;bulletnum=0;

//add mouselistener
var mlistener:Object = new Object();
Mouse.addListener(mlistener);

//mouseclick to fire
mlistener.onMouseDown = function () { if(fired<5){shot.play();fired++;bulletnum++;
_root.attachMovie("bullet","bullet"+bulletnum,++dep,{_x:hero._x,_y:hero._y});
if(bulletnum==15){bulletnum=1;}
}};//fire

This code presupposes that you have a clip in the library with the identifier "bullet" and an instance of a moveclip on stage with the name "hero"

For the motion for the bullet, put that in the gameloop or in the bullet timeline

Hopefully I haven't confused you, but it's something to work on, anyways.

beeblebrox
07-01-2008, 10:04 AM
maybe a look into my SHMUP prototype (http://www.actionscript.org/forums/showthread.php3?t=175652) enlightens you :)

tango88
07-02-2008, 01:53 AM
Hi,

Well, you're on the right track. I would say that you need a bigger stage size or the game will feel cramped. As I mentioned, have the actions in a gameloop with onEnterFrame on the main timeline instead of a separate clip.

The motion will feel smoother if you move the character according to the difference between the character and the mouse rather than just following the mouse itself.

As for the clicking, you can still hack the code I posted before. BTW that code is used in this prototype: www.flashbynight.com/moov and that prototype also has the mouse action that I mentioned.