When Creating Multiple Monsters In Space Invaders, Collision Detection Help
Quick question sirs:Consider the code below which creates a monster into the stage every 2 seconds, and you firing a bullet every time you click your mouse...------------------------------------------------------------------------------var monster:MovieClip;var bullet:MovieClip;var monsterMaker:Timer = new Timer (2000, 100);monsterMaker.addEventListener(TimerEvent.TIMER, addMonster);monsterMaker.start();function addMonster(event:TimerEvent):void{ monster = new Monster(); addChild(monster); monster.x = Math.random()*stage.stageWidth; monster.y=0;}stage.addEventListener(MouseEvent.MOUSE_DOWN, fireBullet);function fireBullet(event:MouseEvent):void{ bullet = new Bullet(); addChild(bullet); bullet.x = this.mouseX; bullet.y = this.mouseY;}-----------------------------------------------------------------------------------the monster class has a code which makes the monster move downwards, the bullet class has a code which makes the monster move upward. Assume they work ok Next thing i want to do is to add collision detection into the bullet and here i have a few questions:1.) does each of the monsters have a different instance name? or are they all just "monster"'s? and if so..........2.) if i make a constructor for the Bullet class something like... var enemy:MovieClip; function Bullet(target:MovieClip) { enemy = target; this.addEventListener(Event.ENTER_FRAME, moveBullet); } //then in the Bullet class, i put a HitTestObject to detect collision... function moveBullet(event:Event):void { this.y -=20; if (this.hitTestObject(enemy)==true) //*Inserts a Function That Will Destroy Enemy * //(something like, this.parent.removeChild(enemy)?) } then, in the Main Time Line, everytime i fire a bullet:function fireBullet(event:MouseEvent):void{ bullet = new Bullet(monster); addChild(bullet); bullet.x = this.mouseX; bullet.y = this.mouseY;} here is my question: there seems to be an error in my logic if there are more than 1 monsters in the stage.. If my bullet hits any one of the monsters, the code will think it has hit all of the monsters and thus destroy all monsters in the stage... Is there some other way to correct this? How will it know which monster was hit by the bullet if each of my monsters are maybe identical to the code?
KirupaForum > Flash > ActionScript 3.0
Posted on: 09-10-2008, 01:19 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Multiple Collision Detection
Hello all, this is my first post on Flash Kit so go easy on me!
This is my situation:
I have a movie clip called "instruction_bug" - it is a movie clip of a bug that moves around.
Inside that movie clip is code that calls a function outside of it to make a duplicate movie clip with a number attached to it. ex) instruction_bug duplicates to instruction_bug1...instruction_bug2...etc. based on the variable "count" in the function.
In that same function, I have added the value of the variable "count" into an array called "bug_array". What I want to do is have my collision detection function act upon all duplications of the movie clip "instruction_bug".
Here is the code...all the references to movie clips are working...the only problem is in the indicated text.
_global.bugHit = function() {
if (weapon_mc[aoeType]["aoe_"+aoeType].hitTest(instructions_mc.instruction_bug))
{
hitText.text = "Hit!";
} else {
hitText.text = "Nothing Yet";
}
};
_global.count = 0;
_global.bug_array = [];
//
// Bug duplication scheme
_global.duplicateBug = function() {
if (count<4) {
count++;
bug_array.push(count);
trace(bug_array);
instructions_mc.instruction_bug.duplicateMovieClip ("instruction_bug"+count, count);
}
};
So to sum up, I want to be able to use the information in bug_array[] in the bugHit function...something like if (weapon_mc[aoeType]["aoe_"+aoeType].hitTest(instructions_mcinstruction_bug[bug_array[i]]));
Collision Detection Over Multiple Instances Of MC
Is there any way to detect the collision of an MC against multiple instances of another MC without having to compare to the coords of EACH instance?
An analogy would be a spaceship flying thru an asteroid field - with the asteroids all being instances of the asteroid MC.
As in:
"If ship coords fall within the coords of any asteroid instance.."
Instead of:
"If ship coords fall within asteroid1 coords
or
If ship coords fall within asteroid2 coords
or
If ship coords fall within asteroid3 coords
etc..."
If so, what would be the syntax?
TIA
Ahhhk!
[F8] Multiple Collision Detection And Response
I'm wondering if anyone has successfully created a "physical modelling" algorithm that will handle collision detection and response for large numbers of movieclips (more than 40).
Ideally, I would like to create something similar to this:
http://www.flashkit.com/movies/Scrip...3942/index.php
except with way more movieclips and preferably also written in as2.
If anyone has any suggestions, it would be much appreciated.
[CS3] Collision Detection With Multiple Objects.
Here is what I have. Right now I am creating 40 objects with shapes randomly chosen from the library. They move around the screen and bounce of the edges randomly. I also have an object that follows the mouse. I want to be able to detect when the mouse object *not the mouse* comes in contact with one of the 40 objects.
Here is what I hae tried:
Code:
var basicUnits = 0;
//Places different objects from the library into an array and places them onto the stage.
var tmi = 40;
var instanceNames = new Array("enemy1", "enemy2", "enemy3", "enemy4", "enemy5", "enemy6", "enemy7", "enemy8");
var collisionList = new Array();
for (i=1; i<=tmi; i++) {
var libraryId = instanceNames[random(instanceNames.length)];
_root.attachMovie( libraryId , "circle"+i, i, {x:200, y:50});
collisionList = (i, "circle"+i);
basicUnits++;
}
Code:
//Beginning of collision detection code.
var ship_x = GetProperty ("/ship",_x);
var ship_y = GetProperty ("/ship",_y);
var obj;
for(p = 0; p <= tmi; p++){
//collisionList was created aboe
obj = collisionList[p];
var obj_x = "circle"+ p._x;
var obj_y = "circle" + p._y;
var ship_h = getProperty("ship", _height) / 2;
var obj_h = getProperty("circle" + p, _height) / 2;
var ship_w = getProperty("ship", _width) / 2;
var obj_w = getProperty("circle" + p, _width) / 2;
var distance_x = ship_x-obj_x;
var distance_y = ship_y-obj_y;
var area = (ship_h+ship_w)*(obj_h+obj_w);
if ((distance_x * distance_x) + (distance_y * distance_y) <= area){
trace("collision detected");
}
else{
trace("no collision");
}
}
Right now my trace is constantly reading as "collision detected", even when the mouse object is near nothing. I am going to upload the file, because there is a lot of other code that may be interfering with what I'm trying to do, and I'm not very skilled with Actionscript, so it may help to see everything in the file.
Would there be an easier way to detect collision between these objects? Or why is my code not working. Thank you.
Help With Collision Detection With Multiple Targets
Hello all you nice people and happy holidays.
I'm trying to make make a drag&drop where the idea is to drag a scanner over various images. Only some of the images are detectable and when the scanner is over the correct image, a text appears on the display I found this script that seems to do what I want, but I can't figure out how to make it register more than one target.
Code:
function dragStarter():Void {
this.startDrag("");
}
function dragStopper():Void {
this.stopDrag();
}
function detectCollision():Void {
this.message_txt.text = "";
if (this.hitTest(this._parent.hitArea_mc) ) {
this.message_txt.text = "hit";
}
}
function attachHitterScripts():Void {
this.onPress = dragStarter;
this.onRelease = dragStopper;
this.onReleaseOutside = dragStopper;
this.onEnterFrame = detectCollision;
}
attachHitterScripts.apply(circle01_mc);
Multiple-point Collision Detection
Really, I have this figured out. Or so I thought. No matter how many times I go over this code it appears solid. A little background: the heirarchy goes
_root
..main
....terrain
....user
The user is essentially a 30 by 60 pixel rectangle controlled by arrow keys. At this point, all I'm trying to accomplish is to have the user move around without going through the terrain.
Here's the code on the terrain. If any of the user's points are more than 0.2 pixels deep into the ground, the user is moved 0.1 pixels out. That's the idea, anyhow.
Code:
onClipEvent (load) {
z = 0.2;
y = 0.1;
}
onClipEvent (enterFrame) {
for (i=0; i<=6; i++) {
//Left
if (hitTest(_parent.user._x+_parent._x, i*10+_parent.user._y+_parent._y, true)) {
_parent.user.leftClear = false;
} else {
_parent.user.leftClear = true;
}
while (hitTest(_parent.user._x+_parent._x-z, i*10+_parent.user._y+_parent._y, true)) {
_parent.user._x += y;
}
//Right
if (hitTest(_parent.user._x+_parent._x+30, i*10+_parent.user._y+_parent._y, true)) {
_parent.user.rightClear = false;
} else {
_parent.user.rightClear = true;
}
while (hitTest(_parent.user._x+_parent._x+30+z, i*10+_parent.user._y+_parent._y, true)) {
_parent.user._x -= y;
}
if (i<=3) {
//Up
if (hitTest(i*10+_parent.user._x+_parent._x, _parent.user._y+_parent._y, true)) {
_parent.user.upClear = false;
} else {
_parent.user.upClear = true;
}
while (hitTest(i*10+_parent.user._x+_parent._x, _parent.user._y+_parent._y-z, true)) {
_parent.user._y += y;
}
//Down
if (hitTest(i*10+_parent.user._x+_parent._x, _parent.user._y+_parent._y+60, true)) {
_parent.user.downClear = false;
} else {
_parent.user.downClear = true;
}
while (hitTest(i*10+_parent.user._x+_parent._x, _parent.user._y+_parent._y+60+z, true)) {
_parent.user._y -= y;
}
}
}
}
Multiple Object Collision Detection Help
I read the tutorial about Multiple Object Collision Detection. What I want to do
is have there be 3 circles and 3 squares. the circles are moving randomly while the squares are stationary. The actionscript would need to be checking to see whenever the moving
circles collide with the stationary squares. However, it doesn't seem to be working. I followed the logic of the tutorial pretty closely, by making a separate list for the instance names. Here is the code for the collision detection. Thanks for any help!
target_mc = [ "circle0", "circle1", "circle2"];
target_mc2 = [ "square3", "square4", "square5"];
//
hitTester = function () {
numCircles = target_mc.length;
numCircles2 = target_mc2.length;
for (i=0; i<numCircles; i++) {
circleA = target_mc[i];
for (j=i+1; j<numCircles2; j++) {
circleB = target_mc2[j];
temp_A = eval(circleA);
temp_B = eval(circleB);
if (temp_A.hitTest(temp_B)) {
// Your code
dirChanger(temp_A, temp_B);
//
}
}
}
};
this.onEnterFrame = function() {
hitTester();
};
[MX] Creating Monsters In A Platform Game?
ok so i have a pretty good start a platform game. but before i start creating the whole first level i want to know how i can add in some enemies and i want to know if i can make it sorta like mario and jump on their heads. if not thats fine i can deal with a simple shooting them, thats fine.
i will attach my .fla so you guys can take a look
i have not created a enemy MC yet but i will soon
he will be called "monster"
but here is my code so far:
PHP Code:
onClipEvent(KeyUp){
gotoAndStop(1);
}
onClipEvent (load) {
speed = 7;
isJumping = false;
isFalling = false;
gravity = 7;
jumpAmt = 12;
gotoAndStop(1)
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_root.ground._x -= speed;
_root.bg._x -= speed;
Play();
setProperty ("_root.char", _xscale, 100);
} else if (Key.isDown(Key.LEFT)) {
_root.ground._x += speed;
_root.bg._x += speed;
Play();
setProperty ("_root.char", _xscale, -100);
}
if (_root.ground.hitTest(this._x, this._y, true)) {
if (!isJumping) {
jumpAmt = 12;
}
if (Key.isDown(Key.SPACE) && !isJumping) {
isJumping = true;
}
} else {
if (isJumping && jumpAmt <= 1) {
isJumping = false;
isFalling = true;
_y += gravity;
} else if (!isJumping) {
isFalling = true;
_y += gravity;
}
}
if (isJumping) {
_y -= jumpAmt;
jumpAmt -= 0.5;
}
}
Multiple Movie Clip Collision Detection
I have many instances of a movie clip (by using duplicateMovieClip) on my stage, each with a name of "clip1", "clip2", "clip3" etc.
I have many instances of another movie clip, like the one above, but all derived from a different original movie clip. They're named "something1", "something2" etc.
I want to put an "if" statement that performs a "hitTest" between one of the "something" movie clip instances and ANY of the "clip" instances.
This is the code I have inside the onClipEvent (enterFrame) of the "something" instance:
onClipEvent (enterFrame) {
if (this, hitTest(_root.varClip)) {
this.removeMovieClip();
}
}
and I have this code in a frame on the _root level
for (var i = 1; i<=3; i++) {
_root.varClip = ["clip"+i];
}
Nothing is working this way. Is there some other way that I can check the collision using arrays?
Am I mixing up the paths?
I'd really appreciat some help with this. I feel like I'm so close already.
Thanks
Kevin
Question About: Collision Detection Among Multiple Objects
i have a question about this article. I was wondering if there was possibly a way to simplify this problem dealing with multiple collisions:
http://kirupa.com/developer/actionsc..._collision.htm
is there any way to give each movie clip a variable such as hitMe=true, and somehow write a hittest code that without referencing the name of the movie clip and instead just checking if the variable exists on that movie clip?
----if this hittest (any movie where this variable equals such and such)
--------do (something)
i know i might be dreaming here, im just wondering if there is some usage of code im unaware of to fix this problem.
this would be great for videogames because you say if (my laser) hits (any enemy with varible so and so on it) it dies. putting the code on every enemy the other way around is a bit of a pain sometimes.
anyways, sorry if this is a dumb question.
jason
Space Invaders
I've been working on this game just to learn the basics og Flash scripting, but I fail to grasp why some of my asteroids suddenly become invulnerable, even my spaceship becomes vulnerable. Not always, but sometimes.
My apologies for...ineffective coding.
Space Invaders
I am having trouble with a space invaders game, instead of increasing the lives of the defender (who you control) I want to give the enemies at the top of the screen more lives, at the minute I have it so there is only one enemy at the top (this is after a row of enemies you defeat) and I would like to give this one enemy about 10 lives. Is this even possible?
I need help as soon as possible, if anybody knows how to give an enemy in space invaders more lives (preferably on the movieclip itself) I need help on the actionscript I need to put up there. At the minute it is something like this:
// Set a certain amount of life:
this.bosslives = 10;
// If the bullet touches the Bug:
if (this.bullet.hitTest(this)) {
// Decrement the bosslives:
this.bosslives -= 1;
// Stop at the beginning of the movie:
this.gotoAndStop(1);
}
// If the life is or less than 0:
if (this.bosslives <= 0) {
// Go to and Stop at frame 9:
this.removeMovieClip;
this.gotoAndStop(9);
}
But I know this is completely wrong, any ideas?
Space Invaders
Has anyone created a space invaders game in flash mx. If you have I would love to take a look at it. Doing college project and just want to see the outcome. Maybe pinch a few ideas
Space Invaders Fla
hey everyone,
I was wondering if anyone had a good space invaders fla file they were willing to share with everyone. I wanted one so I could modify it with my own graphics and put it on my site, with a mention to the creator of course. Any takers?? Thanks Guys!
Space Invaders
Has anyone created a space invaders game in flash mx. If you have I would love to take a look at it. Doing college project and just want to see the outcome. Maybe pinch a few ideas
Another Space Invaders Deal
This is probably quite simplistic for the most of you, but here goes:
It's the usual space invaders type deal, the spaceship scolls x, the enemies coming down from various random y coorinates. There's a scoreboard (it's var being scoreBoard,
instance name being theScore).
The initial value of the variable score is 0, of course, thus incremented by 200 with each enemy killed. What I'd like to know is this: I want to start an entirely new level when the score reaches----let's just say 5000,
for instance---How do I go about doing this? I've tried various 'if' statements, but I can't seem to get it to work.
Also, the variable score, the scoreboard, that is, is within a dynamic text box. Any help at all would truly be appreciated!
Space Invaders Tutorial
Anyone know a site with a real good making a space invaders game from scratch tutorial? I have tried looking at various sourcecodes, but I find I am not learning as much as I want to if I just take someone elses code and edit it a bit.
Help With My Space Invaders Game
I recently startd making a space invaders game and have ran into some problems... the ship at the bottom shoots and the monster at the top moves but im not very good with collison detection and i want the monster to disapear or blow up when he is shot....... also i would like to have a game over when one of the aliens hits the bottom of the screen or shoots you ... i inclosed the .fla file at the bottom
thanx for ur help
Recoding Space Invaders
There is a space invaders .fla available on flashkit in the tutorials at this address:
http://www.flashkit.com/movies/Games...7230/index.php
I want to recode it so I can reduce the number of ailens that appear in the lines of aliens but I can't find the code that controls this, can anyone help me here?
Cheers
Howie
Space Invaders Shooting...
Hey everyone, I have reviewed various tutorials, but can't seem to find any that falls under my issue. My problem is that I have created a space invaders game and was wondering how I would make the bullet shoot, and go off the screen...and also be able to shoot multiple bullets....
If anyone has any tutorials to recommend or advice please let me know...
Thanks
Space-Invaders-Shield ?
Hi
Been wondering about the general logic of making a spaceinvader game shield thingy... The lid thingy that the ship at the bottom hides behind while the aliens rain bombs down.
Now some of these just remain there, and don't do much. But the ones I'm thinking of disapear "bit by bit" as they are hit by the aliens bombs.
I could make each lid out of say 50 small block clips and hitTest these... but there must be a better less cpu intensive way surely, because the game already is running shed loads of hitTests from the bombs the aliens drop, to the lasers the ship fires.
Any ideas anyone please?
Space Invaders Question
has anyone here ever worked on a space invaders type of game? The part I'm having difficulty with is figuring out an approach to writing a function to determine which enemy ships will drop their bombs and when, also as you wipe out the bottom rows, the upper rows should begin dropping their bombs instead. If anyone has done this before I'd appreciate any suggestions, thanks.
Space Invaders To Quiz?
Right then, I've got this (pretty naff) Space Invaders game where you shot down celebrities and the like. I'd like to create a quiz so that when players answer a questions correctly they can shoot the celebs, but if they're wrong the celebs will shot them. How do I write a code that links the correct answer to a part of the game?
I've tried and tried but my AS is probably too basic for this, or am I missing something really obvious?
Anyone?
Yossi
Space Invaders Problem
Doing a project in flash at the minute in Space Invaders but don't really know too much about flash mx. The problem I have is that when i shoot the attackers from my ship they're not blowing up and I don't know how the code to do this .My code at the minute for shooting is
onClipEvent(load){
moveSpeed=10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;
}
}
// when the mouse cliks
onClipEvent(mouseDown)
{
// duplicate the bullet mc
_root.bullet.duplicateMovieClip("bullet" + bulletNum,bulletNum);
// set the coords to the mouse clik
eval("_root.bullet" + bulletNum)._x = this._x;
eval("_root.bullet" + bulletNum)._y = this._y;
// increment the bullet number
bulletNum++;
// if more than 50 bullets , start again at 0
if(bulletNum>50)
bulletNum = 0;
}
and for the attacker is
onClipEvent(load){
this._y =0;
speed=10;
}
onClipEvent(enterFrame){
if(this._x <0)
{
// set direction to right
speed=10;
// drop down
this._y +=30;
}
if(this._x > Stage.width)
{
// set direction to left
speed=-10;
// drop down
this._y += 30;
}
// move horizontal
this._x += speed;
}
If anyone could help me with some of the code I would much appreciate it
Space Invaders Problem
Doing a project in flash at the minute in Space Invaders but don't really know too much about flash mx. The problem I have is that when i shoot the attackers from my ship they're not blowing up and I don't know how the code to do this .My code at the minute for shooting is
onClipEvent(load){
moveSpeed=10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;
}
}
// when the mouse cliks
onClipEvent(mouseDown)
{
// duplicate the bullet mc
_root.bullet.duplicateMovieClip("bullet" + bulletNum,bulletNum);
// set the coords to the mouse clik
eval("_root.bullet" + bulletNum)._x = this._x;
eval("_root.bullet" + bulletNum)._y = this._y;
// increment the bullet number
bulletNum++;
// if more than 50 bullets , start again at 0
if(bulletNum>50)
bulletNum = 0;
}
and for the attacker is
onClipEvent(load){
this._y =0;
speed=10;
}
onClipEvent(enterFrame){
if(this._x <0)
{
// set direction to right
speed=10;
// drop down
this._y +=30;
}
if(this._x > Stage.width)
{
// set direction to left
speed=-10;
// drop down
this._y += 30;
}
// move horizontal
this._x += speed;
}
If anyone could help me with some of the code I would much appreciate it
Space Invaders Problem
Space Invaders problem
Doing a project in flash at the minute in Space Invaders but don't really know too much about flash mx. The problem I have is that when i shoot the attackers from my ship they're not blowing up and I don't know how the code to do this .My code at the minute for shooting is
onClipEvent(load){
moveSpeed=10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;
}
}
// when the mouse cliks
onClipEvent(mouseDown)
{
// duplicate the bullet mc
_root.bullet.duplicateMovieClip("bullet" + bulletNum,bulletNum);
// set the coords to the mouse clik
eval("_root.bullet" + bulletNum)._x = this._x;
eval("_root.bullet" + bulletNum)._y = this._y;
// increment the bullet number
bulletNum++;
// if more than 50 bullets , start again at 0
if(bulletNum>50)
bulletNum = 0;
}
and for the attacker is
onClipEvent(load){
this._y =0;
speed=10;
}
onClipEvent(enterFrame){
if(this._x <0)
{
// set direction to right
speed=10;
// drop down
this._y +=30;
}
if(this._x > Stage.width)
{
// set direction to left
speed=-10;
// drop down
this._y += 30;
}
// move horizontal
this._x += speed;
}
If anyone could help me with some of the code I would much appreciate it
Space Invaders To Quiz?
Right then, I've got this (pretty naff) Space Invaders game where you shot down celebrities and the like. I'd like to create a quiz so that when players answer a questions correctly they can shoot the celebs, but if they're wrong the celebs will shot them. How do I write a code that links the correct answer to a part of the game?
I've tried and tried but my AS is probably too basic for this, or am I missing something really obvious?
Anyone?
Yossi
Space Invaders Problem
Doing a project in flash at the minute in Space Invaders but don't really know too much about flash mx. The problem I have is that when i shoot the attackers from my ship they're not blowing up and I don't know how the code to do this .My code at the minute for shooting is
onClipEvent(load){
moveSpeed=10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;
}
}
// when the mouse cliks
onClipEvent(mouseDown)
{
// duplicate the bullet mc
_root.bullet.duplicateMovieClip("bullet" + bulletNum,bulletNum);
// set the coords to the mouse clik
eval("_root.bullet" + bulletNum)._x = this._x;
eval("_root.bullet" + bulletNum)._y = this._y;
// increment the bullet number
bulletNum++;
// if more than 50 bullets , start again at 0
if(bulletNum>50)
bulletNum = 0;
}
and for the attacker is
onClipEvent(load){
this._y =0;
speed=10;
}
onClipEvent(enterFrame){
if(this._x <0)
{
// set direction to right
speed=10;
// drop down
this._y +=30;
}
if(this._x > Stage.width)
{
// set direction to left
speed=-10;
// drop down
this._y += 30;
}
// move horizontal
this._x += speed;
}
If anyone could help me with some of the code I would much appreciate it
Space Invaders Problem
Doing a project in flash at the minute in Space Invaders but don't really know too much about flash mx. The problem I have is that when i shoot the attackers from my ship they're not blowing up and I don't know how the code to do this .My code at the minute for shooting is
onClipEvent(load){
moveSpeed=10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;
}
}
// when the mouse cliks
onClipEvent(mouseDown)
{
// duplicate the bullet mc
_root.bullet.duplicateMovieClip("bullet" + bulletNum,bulletNum);
// set the coords to the mouse clik
eval("_root.bullet" + bulletNum)._x = this._x;
eval("_root.bullet" + bulletNum)._y = this._y;
// increment the bullet number
bulletNum++;
// if more than 50 bullets , start again at 0
if(bulletNum>50)
bulletNum = 0;
}
and for the attacker is
onClipEvent(load){
this._y =0;
speed=10;
}
onClipEvent(enterFrame){
if(this._x <0)
{
// set direction to right
speed=10;
// drop down
this._y +=30;
}
if(this._x > Stage.width)
{
// set direction to left
speed=-10;
// drop down
this._y += 30;
}
// move horizontal
this._x += speed;
}
If anyone could help me with some of the code I would much appreciate it
Space Invaders Problem
Space Invaders problem
Doing a project in flash at the minute in Space Invaders but don't really know too much about flash mx. The problem I have is that when i shoot the attackers from my ship they're not blowing up and I don't know how the code to do this .My code at the minute for shooting is
onClipEvent(load){
moveSpeed=10;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
this._x+=moveSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x-=moveSpeed;
}
}
// when the mouse cliks
onClipEvent(mouseDown)
{
// duplicate the bullet mc
_root.bullet.duplicateMovieClip("bullet" + bulletNum,bulletNum);
// set the coords to the mouse clik
eval("_root.bullet" + bulletNum)._x = this._x;
eval("_root.bullet" + bulletNum)._y = this._y;
// increment the bullet number
bulletNum++;
// if more than 50 bullets , start again at 0
if(bulletNum>50)
bulletNum = 0;
}
and for the attacker is
onClipEvent(load){
this._y =0;
speed=10;
}
onClipEvent(enterFrame){
if(this._x <0)
{
// set direction to right
speed=10;
// drop down
this._y +=30;
}
if(this._x > Stage.width)
{
// set direction to left
speed=-10;
// drop down
this._y += 30;
}
// move horizontal
this._x += speed;
}
If anyone could help me with some of the code I would much appreciate it
Space Invaders Game
Hi, I am working on a space invaders type game. I would like to know the code to make the x pos to move up and down when the up & down arrows keys are pressed. Thanks -mario
Isometric Space Invaders Game- Z Loc?
howdy.
i'm new to actionscript, having worked only with director lingo. i made a flash copy of the zx spectrum game 'manic miner' which is on the main frame of http://www.todayguide.com
now i want to make something a bit more ambitious, isometric space invaders, but i'm already finding actionscript a touch constraining after lingo.
i want to know if there is an actionscript comand which mirrors the lingo locz property, which would effectively override the loc z of layers, or perhaps of clips on the same layer (as you can do manually in authoring with 'arrange.')
if not i shall have to make all the invaders move 'virtually' and the have individual mc's change which invader they represent in order to reflect changes in depth.
which will be rather arduous and may lead me to not bothering at all!
all help much appreciated.
Space Invaders End Of Level Boss
Hi
I'm done a space invaders clone and l like to extend the gameplay by adding a end of level boss each time you complete the level. Anyway l was hoping to implement this, but how can l?
l can upload the fla file privately, but l need some help badly
[CS3] Space Invaders Hit Test Problem
Hi im having problems with my Hittest function
What I want to do is this:
When "lazer" hits "b4"
- b4 goes to frame 20
- the lazer goes to its defult position which i set earlyer as:
Code:
lazerdefaulty = 80;
lazerdefaultx = -50;
- lazer speed sets from 15 to 0
- lazer switch (to stop you shooting whilst a lazer is live) turns back to 0 allowing you to shoot
NOTE THIS IS THE CODE AND IS WITHIN onEnterFrame
Code:
if (_root.lazer, hitTest(_root.formation.b4)) {
_root.formation.b4.gotoAndPlay(20);
_root.lazer._y = lazerdefaulty;
_root.lazer._x = lazerdefaultx;
_root.lazerspeed = 0;
_root.lazerswitch = 0;
}
Thanks
Full Code Below if needed:
Code:
//Initial Stats
lives = 3;
score = 0;
////////////////////////////////////////////////////////////
//Gun Varables
gunminx = 60;
gunmaxx = 895.9;
gunspeed = 10;
defaultgunx = 90;
defaultguny = 630;
////////////////////////////////////////////////////////////
//Formation Varables
formationminx = 60;
formationmaxx = 210;
formationspeed = 5;
////////////////////////////////////////////////////////////
//Lazer Varables
lazerspeed = 0;
lazerminy = 60;
lazerdefaulty = 80;
lazerdefaultx = -50;
lazerswitch = 0;
////////////////////////////////////////////////////////////
//When you enter the frame
onEnterFrame = function () {
////////////////////////////////////////////////////////////
//Movement Left/Right on Gun
if (Key.isDown(Key.RIGHT)) {
lazergun._x = lazergun._x+gunspeed;
}
if (Key.isDown(Key.LEFT)) {
lazergun._x = lazergun._x-gunspeed;
}
////////////////////////////////////////////////////////////
//Control Shoot
if (Key.isDown(Key.SPACE) && lazerswitch ==0) {
lazerswitch = 1;
lazer._x = lazergun._x+44;
lazer._y = lazergun._y;
lazerspeed = 15;
}
////////////////////////////////////////////////////////////
//Lazer auto movement
lazer._y = lazer._y-lazerspeed;
////////////////////////////////////////////////////////////
//Lazer Reset to position "-50(x),80(y)", switch reset to "0" & lazer speed reset to "0"
if (lazer._y<=lazerminy) {
lazer._y = lazerdefaulty;
lazer._x = lazerdefaultx;
lazerspeed = 0;
lazerswitch = 0;
}
////////////////////////////////////////////////////////////
//Guns min & max constraints
if (lazergun._x<=gunminx) {
lazergun._x = gunminx;
}
if (lazergun._x>=gunmaxx) {
lazergun._x = gunmaxx;
}
////////////////////////////////////////////////////////////
//Formation auto movement
formation._x = formation._x+formationspeed;
////////////////////////////////////////////////////////////
//Formation min & max constraints
if (formation._x<=formationminx) {
formationspeed = formationspeed-formationspeed*2;
}
if (formation._x>=formationmaxx) {
formationspeed = formationspeed-formationspeed*2;
}
////////////////////////////////////////////////////////////
//Lazer Hit Test
if (_root.lazer, hitTest(_root.formation.b4)) {
_root.formation.b4.gotoAndPlay(20);
_root.lazer._y = lazerdefaulty;
_root.lazer._x = lazerdefaultx;
_root.lazerspeed = 0;
_root.lazerswitch = 0;
}
////////////////////////////////////////////////////////////
//Score Updater
_root.myscore = score;
};
Shoot Bad Guys In Space Invaders
In this space invaders game I'm working on how would I make the movie clip 'bullet' follow movie clip "ship" and when the space bar is pressed make bullet._alpha+=100 and the bullet move from left to right on the screen and it it hits Movie CLip "BadGuy1" the movie clip "BadGuy1" plays. I need "BadGuy1" to randomly come on to the screen. I am new to scripting flash mx. PLease help Thank you.
Space Invaders Type Game
I'm working on a space invaders type game and I'm working on learning Action Script. If someone can help and tell me the code to make the ship move up and down. The target name is 'ship' Thanks -mario
Space Invaders(choosing Direction Of Laser)
i've been creating a space invader's type game however the game i have been training on was a scroller meaningg that it shoot's sideway's can anyone tell me how to make it shoot up? this is the action script for the laser
onClipEvent (load) {
laserMoveSpeed=20;
this._x=_root.spaceship._x+90;
this._y=_root.spaceship._y;
}
onClipEvent (enterFrame) {
this._x+=laserMoveSpeed;
if (this._x>600){
this.removeMovieClip();
}
}
Space Invaders - Back To The Atari School
I'm after coding or a tutorial for a space invaders game but I can't find anything on flashkit!
Does anyone know of a good tutorial or file download for this game?
Controlling Player Fire In Space Invaders
Hi again,
still working through the tutorial on Space Invaders in Flash MX 2004.
I've got the player craft under mouse control. What I don't like about the game is that you can fire as rapidly as you wan't, though the number of bullets is limited. You can change this limit in the variable - I would rather have it though that you can only fire according to a certain interval - say, you can only fire once every second, or half second.
Here is the code at the moment:
// when the mouse cliks
onClipEvent(mouseDown)
{
// duplicate the bullet mc
_root.bullet.duplicateMovieClip("bullet"+bulletNum ,bulletNum);
// set the coords to the mouse clik
eval("_root.bullet" + bulletNum)._x = this._x;
eval("_root.bullet" + bulletNum)._y = this._y;
// increment the bullet number
bulletNum++;
// if more than 50 bullets , start again at 0
if(bulletNum>50)
bulletNum = 0;
}
Anyone have any code I could use for this, or advise on how to alter my own?
regards,
g
Controlling Fire In Space Invaders Game
Hi again,
still working through the tutorial on Space Invaders in Flash MX 2004 (bit out of date, I know).
I've got the player craft under mouse control. What I don't like about the game is that you can fire as rapidly as you wan't, though the number of bullets is limited. You can change this limit in the variable - I would rather have it though that you can only have a set number of bullets in play at a time (at the moment, if you go over the limit, the uppermost bullets just disapear).
Here is the code:
// when the mouse cliks
onClipEvent(mouseDown)
{
// duplicate the bullet mc
_root.bullet.duplicateMovieClip("bullet"+bulletNum,bulletNum);
// set the coords to the mouse clik
eval("_root.bullet" + bulletNum)._x = this._x;
eval("_root.bullet" + bulletNum)._y = this._y;
// increment the bullet number
bulletNum++;
// if more than 50 bullets , start again at 0
if(bulletNum>50)
bulletNum = 0;
}
What code could I use to have it so that you can only have, say, 3 bullets in play at once, and you can't fire again until they've hit / left the screen?
regards,
g
Controlling Player Fire In Space Invaders Game
Hi all,
I'm working through an online tutorial on Space Invaders in Flash MX 2004.
I've got the player craft under mouse control. What I don't like about the game is that you can fire as rapidly as you wan't, though the number of bullets is limited. You can change this limit in the variable - I would rather have it though that you can only fire according to a certain interval - a bullet every second, or half second for example.
Here is the code:
// when the mouse cliks
onClipEvent(mouseDown)
{
// duplicate the bullet mc
_root.bullet.duplicateMovieClip("bullet"+bulletNum ,bulletNum);
// set the coords to the mouse clik
eval("_root.bullet" + bulletNum)._x = this._x;
eval("_root.bullet" + bulletNum)._y = this._y;
// increment the bullet number
bulletNum++;
// if more than 50 bullets , start again at 0
if(bulletNum>50)
bulletNum = 0;
}
Anyone have any code that could be used for this, or ideas on how I could modify the above?
regards,
g
Making My Enemies Drop Bombs In Space Invaders
Hi all,
I'm in the process of learning flash just now and am completing an online tutorial on Space Invaders. Thing is, the bombs drop from a random location on the screen. I want them to drop from a random enemy (I'm not too bothered just now about making it one on the bottom row or one with no other enemies before them).
At the moment, here is the AS that makes them drop (the frequency is determined elsewhere):
eval("_root.alienBomb" + alienBombNum)._x =random(700);
eval("_root.alienBomb" + alienBombNum)._y = 300*Math.random();
An I can modify it to get a certain one to drop:
eval("_root.alienBomb" + alienBombNum)._x =_root.alienClip2_2._x;
eval("_root.alienBomb" + alienBombNum)._y = _root.alienClip2_2._y;
I can' t get it to randomly choose one - I know I have to use the random function, but don't know how to implement this.
Can anyone help?
regards,
g
Making My Craft Fire In Space Invaders, In MX 2004 - Help Required
Hi all,
I'm working through an online tutorial on space invaders. I've got a MC called "rocketClip" that I want to fire with the mouse click, limiting player fire to once every half second.
I have this piece of (incomplete) code to use on my playerCraft movie clip to get it to fire:
var enableInterval:Number;
var allowFire:Boolean;
function tempDisableFire():Void {
allowFire = false;
enableInterval = setInterval(enableFire, 500); // 500 millisecond delay
};
function enableFire():Void {
allowFire = true;
clearInterval(enableInterval);
};
Though it is incomplete. I think I need to place it inside an "onClipEvent" handler (the event being the mouse click), possibly need to use an "if/else" statement.
It's my first attempt at flash - anyone care to complete this piece of code for me? I don't think it's that far off.
Thanks all,
g
"space Invaders" Help Needed
hey everybody...i am making a new design for my site and i had this wonderful idea....the problem is that i dont know how to do it!! the file can be found at http://deadline.phalanxhost.com/alfp...christian2.swf ...and my question is this. how do i make it so that when the ship "shoots" an alien the alien will disappear or explode or something...i want this to be user activated or whatnot so if anybody could help me out that would be great!!! the .fla file is at http://deadline.phalanxhost.com/alfp...christian2.fla if this would help you out anymore...i GREATLY appreciate ANY help i can get!! thanks!
btw...i am somewhat new at actionscript so if you do post help please try to put it into idiot terms so i can understand it
Space Game And Collision
hey i need help! lol..
here are the two files
http://www.geocities.com/twinnysk8er/game.swf
http://www.geocities.com/twinnysk8er/game.fla
whats wrong is the enemy ship doesnt repeat.. HELP ME!
thanx
p.s. im kinda new at this
Space Detection In Strings
I am looping through a string to detect the last space, I can get it to work on a space or an variable
I think it is because the following does not work
new_string.charAt([i])
Code:
new_string = "12345678989012 34567890123 45678901212";
for (i=0; i<40; i++) {
trace (new_string.charAt([i]))
//if (new_string.charCodeAt([i])==160) {
if (new_string.charAt([i])=="1"){
position = i;
trace(position)
}
}
|