Flash :: Tower Defense - Detecting If The Bullet Hits The Enemies
Apr 22, 2011
I am creating a tower defense game and I want to make a tower that shoots a bullet and every enemy that the bullet hits is damaged. The bullet can hurt multiple units. My problem is detecting if the bullet hits the enemies. Right now, I have the enemies in an array. With other towers, when an enemy is in range, the tower fires and when it hits its original target, it causes damage to that target.
For the tower I want to make, it will shoot the bullet the maximum range every time and I need it to damage every unit it hits on the way to that final destination.
I found a tutorial on the internet and have begun toying with it. I figured out what all the segments did and how they worked and effected the game (mostly through trial and error...) once i figured out what EXACTLY i had i started making changes.
-What i want - once the bullet hits a monster OR goes out side of the range of the gun it disappears and another shot can be fired (which is done automatically via my script no user input needed)
-What i have - when the bullet goes off the page (x>550, x<0, Y>400, Y<0) it disappears and another shot can be fired... obviously this is problematic to game play...
-What i want - once the bullet hits a monster OR goes out side of the range of the gun it disappears and another shot can be fired (which is done automatically via my script no user input needed)
-What i have - when the bullet goes off the page (x>550, x<0, Y>400, Y<0) it disappears and another shot can be fired... obviously this is problematic to game play...
I am hammering out a Tower Defense type game. I'm starting to design my custom unit mechanics. I've used numerous other tutorials for the framework here (largely one mans blog - credited in my AS3 file..) I want when a unit dies, that it runs a function - checks a field I've created within the unit called a 'tag' - and depending on that do other things. From within the kill() function I successfully call my infantryDeath() function, and I've verified within kill() it's recognizing the dead objects tag. I've verified the entry into infantryDeath() and that the tag is still the same.
Here's the problem: function infantryDeath(creep){ //inGameMessage("infantryDeath() successfully called"); <-- works //inGameMessage("Unit died with ID: " + creep.tag); <-- properly shows the ID of the "creep" it received inGameMessage(this); <-- prints out _level0 (the id for the level itself) if (creep.tag = c1) <-- the unit with this tag dies, and triggers this block successfully{ [Code] .....
I have no clue why the object I'm supposedly working with changes just by virtue of being within the "if" block. If I pass an object into a function shouldn't manipulating that object remain constant within that function?
I'm making a little tower defence game but i've run into a problem;I need a code to randomise my enemies (like in which direction they come from, and how many come)
I have been reading these forums for like 2 months, thus i never felt like being able to post something as a valuable answer to someone's problem, since i've been AS3ing for like 3 months now. I have a small problem here on a game that i am trying to create. I am trying to make a shooter game . Like the ones u kill enemies and then the the level advances ( imagine the pseydomovement depth feel of the background giving the player the taste of further movement of the field , yes like old airplane games ). Ok to the point.
1) created a main .as where all the code is running. The movement of the player is written there also. no problem with that. 2) created a bullet class where i assign the bullet speed and i check for the collisions with enemies. the problem occurs somewhere here i have created a statement where every some time ( like 0,5 secs ) an enemy appears and takes a random road till the stageHeight . here is the code .
[Code]...
So when all 5 mikros are out i start firing them . BUT only the last child of mikros seems to follow the hittestobject procedure of my code. Which means that if all of the 5 mikros are on stage the one with the smallest .y value will disappear when hit by "sfera". I know it is huge but this pains my head for like 1 week and i cannot think anything . Tried some staff. but i do not know if this is proper thinking or if my programming is proper for this and i must redo all.
I have created a class named Bullet() and I create a child named bullet_mc every second.This bullet_mc moves to a direction on the stage.I also created a class named Plane() and I create a child named myPlane_mc every two seconds. Also, every myPlane_mc moves to a direction on the stage.
I'm trying to program this code: public function enemiesDie(){ enemyLoop: for (var k:int = enemies.length -1;k>= 0; k--){ bulletLoop: for (var i:int = bullets.length -1; i>=0; i--){ if (enemies[k].hitTestObject(bullets[i])){ trace("hit"); [Code] ....
To detect when a bullet hits an enemy in a game I'm trying to make and I get this error: TypeError: Error #1006: hitTestObject is not a function. at Space_Hooligans/enemiesDie() at Space_Hooligans/gameLoop()
as from title above, minimap where enemies spawn and can be shown on the minimap and enemies warp like player_mc do. ps: i'm new to this forum. attached files below
I'm currently making my own shoot'em up game where the player can switch between two player types which will fire their own bullet type in this case, squares and circles. I've setup the player switch function via pressing "space" button (switching between the two player types) and the default bullet type is "squares" and I'm not sure to approach the coding with changing the bullet type to "circles".I've written 2 classes for the bullet and player setup:Player Class: Creates instance of bullet on screen and enables the switch player type function
Bullet Class: Enables bullet properies and bullet types Player Class: Code:function onKeyDown(event:KeyboardEvent):void {if (event.keyCode == 32) //// pressing/holding "space bar" to function
I'm trying to make my platform game character shoot a gun, my character and gun are one movieclip and the bullet is another. The bullet mc starts on a blank frame with a stop() function, when I press the space bar the bullet mc plays from frame 2 which is a motion tween of the bullet quickly moving across the page. I've set the bullet's y and x values relative to the character mc so that the bullet always comes from the gun.
My issue is that if I press the space bar a bullet will fly out of the gun (great!) but if I press the space bar again, the first bullet disappears and the bullet animation starts again. I want to be able to shoot a new bullet every time I press the space bar without effecting the bullets that have already been shot.
i have 2 classes, one for ship one for bullet.i was trying to set the bullet.x to ship.x in the bullet class but it keeps telling me undefined. but clearly it is in my ship class.
i have a shooting game that works with some sort of rounds, for instance, this round is gonna show 4 enemies on the screen that the user has to shoot. I show the 4 enemies at a half seconds interval of each one so it doesnt all appear on the same time. Using something like:
enemiesShowTimer = new Timer(0.5 * 1000, 1); enemiesShowTimer.addEventListener(TimerEvent.TIMER, showEnemyAtTime); enemiesShowTimer.start();
The player has 2 seconds to kill each enemy after they appear, so i also use this:
enemiesCleanTimer = new Timer(roundConfig.getSecondsPerEnemy() * 1000, 1); enemiesCleanTimer.addEventListener(TimerEvent.TIMER, cleanEnemies); enemiesCleanTimer.start();
The problem is, after the player dies i change scene and if i still have like 3 alive, enemies, the threads will try to run the methods and it will crash. I'm using always the same variable to the start the timer whenever i need it. How can i solve this? Will i have to store each "thread" (timer) on a list and then stop each one separately? Because the way it is, the other threads are in some sort of "limbo" and i cant stop then, just the last one.
My character is spawned in the middle of the screen, and i'm not sure how to make zombies spawn from the left and right side of the screen, and moving towards the middle. My goal is to make the zombies spawn automatically, and the character in the middle is able to shoot them down. I've just started working on AS3, but i know that i'll need to make an array to do this, but not sure how to implement this.
we just recently defended our graduation project which is a platform game like mario. one of the modifications suggested by our panelists is to make level 1 generate random places for enemies and coins after one of them said that mario was a stupid game because you already know where the enemies are, the powerups, etc. i said i'll give it a go and see what i can do. but recently i realized that i havent played any platform game that generates random places for the enemies, coins and other objects. it is only in rpg games like ragnarok that i have seen enemies spawning at random places.
im doing a tower defence game and i have a problem rotating my towers towards the minions.my idea is, on the Main class e create an array with all the minions, than, on the Tower class i want it to go through the entire array and search for the closer one.the problem is, i cant access the array from the Tower class.How can i solve this, and if it isnt possible, how can i make the tower rotate?
I have a tower defence and when you lose I have a button to go back to the main screen. Only problem is that I cannot find a way to remove the enemies from the screen as well. Here is all of the code for the game, because I figure I might as well give you everything now, than later. I also wanted to give you all my variable names that would be used...
Code: stop(); // Params = Number, Health, Speed, Time between releases, Gold per creep); _root.waves = [[10, 50, 2.500000E+000, 2000, 2],
I am playing around with ActionScript 3 and trying to build a very simple prototype for a video game (top-down action/shooter) and realized that handling bullets is a little bit more challenging than I originally imagined.
In order to get a fairly decent "flight" of the bullet between the character and the target, I ended up using a highly modified version of Bresenham's Line Algorithm to determine the flight path of the bullet and then merely draw a tiny flash.geom.Rectangle object at the appropriate place on that "flight path" during the draw-frame stage of my application.
I haven't noticed any real problems, but I just can't imagine this being the best way to handle bullets in a Flash game. I imagine that once there are multiple enemy players on the screen and lots of bullets flying around (especially once I code in automatic weapons) that things could come grinding to a halt.
What am I missing here? I'm not really a game developer and so most of the things I'm doing I've just "made up" on the spot, but I can't figure out how to effectively handle bullets in Flash.
EDIT: As requested, here is "my" Bresenham code. I say "my" in quotes, because I basically ripped this from somewhere on the internet. My changes to the algorithm basically involve the lines at the bottom. The original implementation would find the path from player character to the target, except that every once in a while (and I wasted a little bit of time trying to figure this out but never got anywhere) it will generate the path from the target to the player. To "fix" this, I ended up just checking the first X/Y values from the path array and reversing the array if those values didn't match the X/Y values of my player character.
My goal is to shoot a bullet everytime I click on ship. What happens, in fact, is that If I click on it once, the bullet is shot, but if I click on it twice before the first bullet is off the screen, the first bullet literally stops(it does not disappear, only stops) and the second bullet is shot.
public var ship:Ship = new Ship(); public var bullet:Bullet = new Bullet(); stage.addChild(ship);[code]...
What I'm trying to do - remove/delete a movie-clip once a button has been pressed (Selling a tower)My problem - Is that from my limited knowledge none of the following work.
removeChild(myTower); Turret.removeChild(myTower); - (trying to reference the class of the turret so that it can access the movieclip) Turret.parent.removeChild(Turret) Turret(root).removeChild(Turret)
This function is placed in the first frame of the source.fla where all main functions are.The turret has its own class defining its properties and such.Basically what i want to happen is when the button function is activated to remove the movieclip Turret and the class from running.
One of my buttons, flash will not read it as a button when I publish it and run the swf file. The cursor stays as a arrow meaning its not a button in the swf file. Inside of the fla file it is a button with a hit. There is no movie or tweening or anything like that. I think it's not reading it as a button because Flash is placing the hit behind the actual button. Inside of my button there is only 1 layer. When placing the hit usually it covers the button. But in this case, the hit is going behind the image. I think this is why when its ran, its not reading it as a button.
I even removed the AS3 code from the button to see if it was a coding error. Rather if theres code in there or not the swf should still read it as a button and the cursor should change to a hand by default. Because of this, I tried to create another button in another area on the stage to see if it's just that one area thats having that problem. I created a new button from scratch, placed a hit, no AS3 coding added, and it works. The swf reads it as a button. But with that button, I added a AS3 CODE to go to an external website and now Flash isnt reading the AS3 code for that button. Heres the code:
import flash.net.URLRequest;import flash.display.Loader;import flash.net.navigateToURL; itunesBTN.addEventListener(MouseEvent.CLICK, gotoITUNES); function gotoITUNES (event:MouseEvent):void{ var req:URLRequest = new
I have a grid of objects that have been added to the stage dynamically, the objects are either of a Class Red or Class Blue, how do I perform a hit test on the Classes? I want the Blue object to disappear once it hits a Red one.
I've got tree movieclips called: greenpip(this is the dragable object, which is visable), greenpip_target(which is invisible, but becames visible when greenpip hits it, and grrenpip is becaming invisible) and then the third one: greenpip_flask (which is the animation I want to play when the greenpip hits the greenpip_target). Everything works but I don't know how to make the greenpip_flask play, when grrenpip hits the greenpip_target. This scenario takes place three times with three sets of objects
I'm making a Space Shooter Game for school and I just can't find how to put my enemies in an array. I found this code in an other thread
[Code]...
So what I need to make is 2 arrays, one arrEnemies where I put my emenies in and the other one arrBullets where the bullets go. Then these 2 arrays do a collision check
I just started Flash like 2 weeks ago, so im not very good. Im making a game where you pick a character, and shoot pigs. Every pig you shoot adds 500 points to your score. Problem is only one pig works. If i copy and paste that pig and his code (as2), when i shoot one pig both pigs explode, giving me 1000 points. How can i make it so that when i shoot one pig, one pig explodes, and i get 500 points?[code]...
i will explain my problem according the 11th enemy (the last enemy in the level). i past here the answers i gave to people fron other forums..I'm making a platform game, and i have a problem. i am attaching 11 enemys, and my last enemy not appears. the _X of the 11th enemy is 3300.I tried a lot of stuff, and think, I discovered the source of the problem.on my hero class i wrote this:
_root._x -= (_root._x + (_x - 275)) / 5;
and when i changed it to this:
_root._x = -_x;
the last enemy appears!but i want it to be like first one.but it doesnt work.also, i found that if i placed the hero close to the last enemy, the last enemy appears.the _root._x refer to the stage and the _x refer to the hero.i found that if i remove this code(the gravity in the enemy class):
im making a script where it spwans enemies when the enemy count is lower then or equal to the CurrentEnemys. but it spawns like 200 enemys and says the function is looping and my CurretEnemys trace says NaN..
Hers the script.
enemyCount = 0; CurrentEnemys = 5; function startwave(){
Everytime a monster dies, I want the monsters killed dynamic text field to increase the number by 1. I gave it a good shot but it feels like im missing something basic, Im fairly new to this still but picking it up quickly. The following code is inside of a movieClip dealing with the monsters. The second block of code is on my main timeline.
This one concept has been bugging me for days now and I can't seem to solve it. You see, I'm trying to rotate my enemies along an uneven surface. So far, they follow along it perfectly, using my hitTestPoint collision checks.But I don't know how to rotate the collision points and thus rotate the movieclip along the curve so it remains clipped to the ground like in Fancy Pants Adventure 2 or a tanks game.Here is what it looks like right now