Count Collisions Problem in Shooting Game

Hi,  I am working a simple game in which a ship fires at approaching asteroids and I am having problems with the collision between the ship and the
asteroid. In the ship movieClipI have made it glow red from frame 6 to signify the first 3 collisions and loss of life and then then for the fourth collision I
have made a alpha tween from frame 87 inside the ship so that it disappears to signify end of game. I have used a counter as shown below but all the ship
does is glow so never gets to frame 87. Thanks for taking time to view this.
//import some important flash libraries.
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Sprite;
var countCollisions:Number =0 ;
var astArray:Array = new Array();
var speed:Number = 10;
//initializes variables.
var key_left:Boolean = false;
var key_right:Boolean = false;
var key_up:Boolean = false;
var key_down:Boolean = false;
var key_space:Boolean = false;
var shootLimiter:Number=0;
//Checks if the player presses a key.
var timer:Timer = new Timer(2000, 10);
timer.addEventListener(TimerEvent.TIMER, AddAsteroid);
timer.start();
stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP,KeyUp);
var ship:MovieClip = new Ship()
var backgr:MovieClip = new Background();
backgr.x = 0;
backgr.y = 45;
addChild(backgr);
addChild(ship);
function AddAsteroid(e:TimerEvent):void
var asteroid:MovieClip = new Asteroid();   
asteroid.x = 800;
asteroid.y = Math.round(Math.random()*700);
astArray.push(asteroid);  
addChild(asteroid);
asteroid.addEventListener(Event.ENTER_FRAME,asteroidmove);   
function asteroidmove(e:Event):void
asteroid.x--
for(var i=0; i<astArray.length; i++)
  if(astArray[i].hitTestObject(ship))
  countCollisions++;
  ship.gotoAndPlay(6);
   if(countCollisions ==4)
   ship.gotoAndPlay(87);
  if(astArray[i].stage)
        removeChild(astArray[i]);
        removeEventListener(Event.ENTER_FRAME,asteroidmove);
addEventListener(Event.ENTER_FRAME,backgroundmove);
function backgroundmove(e:Event):void
backgr.x -= 1;
if(backgr.x < -2110)
backgr.x = 0;
//Lets the function main play every frame.
addEventListener(Event.ENTER_FRAME,Main);
//create the function main.
function Main(event:Event){
CheckKeys();
//create the function KeyDown.
function KeyDown(event:KeyboardEvent){
if(event.keyCode == 37){  //checks if left arrowkey is pressed.
  key_left = true;
if(event.keyCode == 39){  //checks if right arrowkey is pressed.
  key_right = true;
if(event.keyCode == 38){  //checks if up arrowkey is pressed.
  key_up = true;
if(event.keyCode == 40){  //checks if down arrowkey is pressed.
  key_down = true;
if(event.keyCode == 32){  //checks if down arrowkey is pressed.
  key_space = true;
function KeyUp(event:KeyboardEvent){
if(event.keyCode == 37){  //checks if left arrowkey is released.
  key_left = false;
if(event.keyCode == 39){  //checks if right arrowkey is released.
  key_right = false;
if(event.keyCode == 38){  //checks if up arrowkey is released.
  key_up = false;
if(event.keyCode == 40){  //checks if down arrowkey is released.
  key_down = false;
if(event.keyCode == 32){  //checks if down arrowkey is released.
  key_space = false;
function CheckKeys()
shootLimiter += 1;
if(key_left)
  setDirection(1);
  ship.x -= 5;
if(key_right)
  setDirection(0);
  ship.x += 5;
if(key_up){
  ship.y -= 5;
if(key_down){
  ship.y += 5;
if((key_space) && (shootLimiter > 8))
shootLimiter = 0;
var b = new Bullet();
addChild(b);
b.x = ship.x + 50;
b.y = ship.y + 3;
addEventListener(Event.ENTER_FRAME,moveBullet);
function moveBullet(e:Event):void
b.x +=10;
  if(b.x > 600)
   if(contains(b))
   removeChild(b);
          removeEventListener(Event.ENTER_FRAME,moveBullet);
for(var i=0; i<astArray.length; i++)
  if(astArray[i].hitTestObject(b))
  removeChild(b);
  removeChild(astArray[i]);
  removeEventListener(Event.ENTER_FRAME,moveBullet);
function setDirection(param) {
if (param == 0) {
  ship.scaleX = 1;
} else {
  ship.scaleX = -1;

Thanks for your comments. I have amended the code but get the following error and the ship goes to frame 87 on the second collision.
Can you tell me if I am on the right lines ?
The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at Function/<anonymous>()
for(var i=0; i<astArray.length; i++)
  if(astArray[i].hitTestObject(ship))
  countCollisions++;
  removeChild(astArray[i]);
   if(countCollisions >= 4)
   ship.gotoAndPlay(87);
   removeEventListener(Event.ENTER_FRAME,asteroidmove);
   else
   ship.gotoAndPlay(6);
  //if(astArray[i].stage)
        //removeChild(astArray[i]);
  //MovieClip(astArray[i]).removeEventListener(Event.ENTER_FRAME, asteroidmove);
        //removeEventListener(Event.ENTER_FRAME,asteroidmove);

Similar Messages

  • Some Help Please. Shooting Game

    Right the basic story is that im making this game where
    animals cross the screen and you shoot them (aka click the mouse on
    them) and get points. Im having a couple of problems.
    I wanted to have the gunshot noise whenever i clicked
    ANYWHERE so i put it in the mousup in a frame script but when i
    click on a sprite which has its own behavior, it doesnt play
    Secondly, there are items on the stage such as waves and
    grass that the animals can hide behind and i can still click on
    them even if i cant see them, ie click the part of the grass they
    are hiding behind. How do i correct this...
    Any help would be appreaciated. Thank you!!!

    You don't normally attach user event code to a frame. User
    events, like
    mouse clicks, are normally associated with an individual
    item, like a
    sprite. Shooter games get around this limitation by using key
    events for
    the shooting action. Since key events are read by the
    computer and then
    sent to the Director movie, they can be read by a keyDown or
    keyUp
    script.
    There is a corollary for the mouse, the mouseDown and the
    mouseUp
    script. Since any system wide property like a keyDownScript
    or a
    mouseDownScript will take all key or mouse events, they need
    to be used
    with care and caution. While this is not usually a big
    problem with key
    events, mouse events are likely to cause some difficulty.
    While the
    mouseDownScript will always execute first, it will most
    likely pass the
    event on to any active sprite. This may or may not be what
    you want to
    have happen, you may want an either/or situation not an and
    situation.
    A simple way to block a sprite's behavior when it is hidden
    is to place
    a stopEvent command on the sprite that sits on top.
    Rob
    Rob Dillon
    Adobe Community Expert
    http://www.ddg-designs.com
    412-243-9119
    http://www.macromedia.com/software/trial/

  • Shooting game

    Hi~
    I want to write a shooting game
    in this game I shoot the aircraft by clicking the target
    for example the following triangle is the target
    actually the image is in *.png format with alpha channel
    and without any number on the graph just the triangle
    <img src="http://www.geocities.com/paste001/temp.jpg">
    when I click area2, the triangle disappear
    however when I click area1 the triangle also disappare
    how can I solve this problem?

    In brief, only non-transparent area can detect mouseEvent.

  • Shooting Game Help!!

    i have a shooting game with a few problems. One, during the
    reload stage of the gun, you can still shoot. Two, once the man
    walks off screen it dosent go to a game over page. i have no idea
    how to fix this and all my attempts fail. I cant send you the game
    because the source file is to big even after cut down. ill give u
    the actionscript.
    The Walking Guy:
    onClipEvent (load) {
    speedx = 0.9;
    onClipEvent (enterFrame) {
    this._x -= speedx;
    if (this._x<=100) {
    gotoAndStop("loose");
    on (release) {
    this.gotoAndPlay(2);
    this.enabled = false;
    speedx = 0
    The man is inside a MC. i dont know how to make it so that
    when he walks off the screen it goes to a Game over page.
    The Crosshair:
    onClipEvent (enterFrame) {
    startDrag(this, true);
    Mouse.hide();
    onClipEvent (mouseDown) {
    if (_root.bullet == true) {
    this.gotoAndPlay(2);
    _root.bullet = false;
    tellTarget (_parent.bulet) {
    gotoAndStop(2);
    When nothing is hylighted:
    _root.bullet = true;
    stop();
    Inside the Crosshair MC:
    First Frame:
    Stop();
    Last Frame:
    tellTarget (_parent) {
    _root.bullet = true;
    tellTarget (_parent.bulet) {
    gotoAndStop(1);
    What needs to be added to not allow the gun to work when
    reloading???
    How do i create a game over page when the stick has walked
    off the screen??
    All answers would be greatly appreaciated!!!
    Thanks
    Sterockicy

    try the actionscript forum.
    --> **Adobe Certified Expert**
    --> www.mudbubble.com
    --> www.keyframer.com
    Sterockicy wrote:
    > i have a shooting game with a few problems. One, during
    the reload stage of the
    > gun, you can still shoot. Two, once the man walks off
    screen it dosent go to a
    > game over page. i have no idea how to fix this and all
    my attempts fail. I cant
    > send you the game because the source file is to big even
    after cut down. ill
    > give u the actionscript.
    >
    > The Walking Guy:
    >
    > onClipEvent (load) {
    > speedx = 0.9;
    > }
    > onClipEvent (enterFrame) {
    > this._x -= speedx;
    > if (this._x<=100) {
    > gotoAndStop("loose");
    > }
    > }
    > on (release) {
    > this.gotoAndPlay(2);
    > this.enabled = false;
    > speedx = 0
    > }
    >
    > The man is inside a MC. i dont know how to make it so
    that when he walks off
    > the screen it goes to a Game over page.
    >
    >
    > The Crosshair:
    >
    > onClipEvent (enterFrame) {
    > startDrag(this, true);
    > Mouse.hide();
    > }
    > onClipEvent (mouseDown) {
    > if (_root.bullet == true) {
    > this.gotoAndPlay(2);
    > _root.bullet = false;
    > tellTarget (_parent.bulet) {
    > gotoAndStop(2);
    > }
    > }
    > }
    >
    >
    > When nothing is hylighted:
    >
    > _root.bullet = true;
    > stop();
    >
    >
    > Inside the Crosshair MC:
    >
    > First Frame:
    >
    > Stop();
    >
    >
    > Last Frame:
    >
    > tellTarget (_parent) {
    > _root.bullet = true;
    > }
    > tellTarget (_parent.bulet) {
    > gotoAndStop(1);
    > }
    >
    >
    > What needs to be added to not allow the gun to work when
    reloading???
    > How do i create a game over page when the stick has
    walked off the screen??
    >
    > All answers would be greatly appreaciated!!!
    >
    > Thanks
    >
    > Sterockicy
    >

  • Various problems in certains games.... please help me guys

    Hi, I have a weird problem when I start up Pacific Fighters and Chronicles of Riddick.
    The thing is, the game takes at least 15 minutes to open and when using the Caps Lock key, the green button on the keyboard takes quite some time to enlighten because the PC lags badly, so is the sound. In PF, the music is terribly affected when this bug occurs.
    This happens about the 1/5 of the time I try to boot the game and the only ways to fix the problem is to:
    1) Simply restart the computer;
    2) Set the computer to sleep mode and then, come back to the game.
    All of my games and my drivers are up to date and something important I'd like you to know is:
    When the game boots normally, I can play easily up to 3 hours without any problem. Right now, I have about 15 games installed on my PC. Just to numerate a few, I have Far Cry, Half-Life 2 and never encountered any problem with these games.
    On the other hand, Battlefield 2, when trying to connect to the server, will freeze and then again, the Caps Lock light on my keyboard will have problem to open (So that shows that the PC lags a lot) and then, it will de-freeze and the game says that I was disconnected from the server (That's quite normal, I've been inactive for 30 seconds). Yet, after returning to the game, the PC isn't completly in its original shape as when using the Teamspeak program, I can hear the others talking but their voice is quite sluggish and skipped every 5 seconds. The sound does the exact same thing in Pacific Fighters when it freezes (It goes mostly as follow: Clack clack clack clack, you know what I mean?)
    If someone, please, knows why I have this problem, any help would be greatly appreciated. I have above 15 000pts in 3Dmarks 03 and my global performance on my PC is very good, except for this annoying bug.
    In BF2, I didn't encounter any problem before, so I don't understand...
    I have a
    -Amd athlon 64 3000+ venice @ 40 degres in ful load
    -Asus A8N-E @ lastest bios + driver 6.70 @ 38 degres in full load
    -Msi NX7800GT @ 81.85 driver @ 45 degres in full load
    -Soundblaster live 24bits
    -Disc dur 160GB WD SATA II that has just been defragmented with diskeeper and that contains no viruses
    -Thermaltake 420WATTS purepower
    -3x512 DDR 400 OCZ
    I also get problems in Bf2 clean sweep map only and only at 1 place : see http://img154.imageshack.us/my.php?image=screen0028ud.jpg
    And also in BF:V   http://img131.imageshack.us/my.php?image=bit6oz.jpg
    Thanks to read this and please help me 

    I also want to precise that in BF:V, this is the only vehicle that is bugged like this..

  • Help with simple shooter game

    I am doing a school project and no one seems to know how to use graphics, sound, and most importantly KEY AND MOUSE EVENTS.
    Anyways I can't get my events for the mouse and keyboard to work correctly, so if anyone knows what is wrong or has some suggestions I would really appreciate it. Here is the code:
    the program is called from an application just so you know... this is the application:
    public class AnimateTest
    public static void main (String[] args)
    Animate pic = new Animate (10);
    //and this is the proram itself
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.MouseListener.*;
    import java.awt.event.MouseAdapter.*;
    import java.awt.event.MouseEvent.*;
    import java.awt.event.KeyAdapter.*;
    import java.awt.event.KeyListener.*;
    import java.awt.event.KeyEvent.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.applet.AudioClip;
    public class Animate extends Frame //implements KeyListener//implements MouseListener
    // The image of the background.
    protected Image background;
    // The gun images.
    protected Image gun1, gun2, gun3, gun4, gun5, gun6, gun7, gun8, gun9, gun10;
    //the status bar images
    protected Image hpbox;
    protected Image scorebox;
    //declares the blood explosion image
    protected Image blood;
    //declares the window icon
    protected Image icon;
    // The canvas where the images are drawn.
    protected AnimatePictureCanvas canvas;
    // The number of guns.
    protected int numGuns;
    // Flag to indicate when to quit.
    protected boolean quitting = false;
    //declares the cursor so it can be set to a targeting reticle
    Cursor reticle;
    //declares a variable which designates which gun is in use
    int i = 0;
    //the user's health points
    int hp = 100;
    //enemy arrays
    boolean alive [];
    boolean onScreen [];
    //enemy integers
    int currentDude = 3;
    int liveCount = 10;
    int screenCount = 0;
    //damage variables
    int damage = 0;
    int moreHits;
    int chance;
    //the x and y coordinates of the enemies
    int ex1 = 175;
    int ex2 = 345;
    int ex3 = 520;
    int ex4 = 25;
    int ex5 = 240;
    int ex6 = 370;
    int ex7 = 470;
    int ex8 = 626;
    int ex9 = 260;
    int ex10 = 120;
    int ey1 = 228;
    int ey2 = 190;
    int ey3 = 115;
    int ey4 = 210;
    int ey5 = 35;
    int ey6 = 330;
    int ey7 = 202;
    int ey8 = 192;
    int ey9 = 210;
    int ey10 = 140;
    //blood variables
    int splat = 0;
    int bloodx = -100;
    int bloody = -100;
    // The constructor. Create the Frame, make it visible, load the
    // images, and when the images are loaded, call the animate method
    // to move the images around the window.
    public Animate (int numGuns)
    super ("Stupid Shooting Game"); // Create a Frame.
    //sets the window icon
    icon = getToolkit ().getImage ("icon.jpg");
    prepareImage (icon, this);
    setIconImage (icon);
    this.numGuns = numGuns;
    //initialize the arrays for the enemies
    alive = new boolean [10];
    for (int z = 0 ; z <= 9 ; z++)
    alive [z] = true;
    onScreen = new boolean [10];
    onScreen [0] = true;
    onScreen [1] = true;
    onScreen [2] = true;
    onScreen [3] = false;
    onScreen [4] = false;
    onScreen [5] = false;
    onScreen [6] = false;
    onScreen [7] = false;
    onScreen [8] = false;
    onScreen [9] = false;
    //initialize the cursor to make the mouse a targeting reticle
    reticle = new Cursor (Cursor.CROSSHAIR_CURSOR);
    setCursor (reticle);
    // Place the loading message in the window.
    Label loadingMessageLabel = new Label ("Loading images...");
    add ("North", loadingMessageLabel);
    // Display the window.
    pack ();
    setVisible (true);
    // Create the Images and add them to the tracker.
    MediaTracker tracker = new MediaTracker (this);
    background = getToolkit ().getImage ("midtown1.jpg");
    tracker.addImage (background, 0);
    //prepares the gun images for the image tracker
    gun1 = getToolkit ().getImage ("ggun1.jpg");
    tracker.addImage (gun1, 1);
    gun2 = getToolkit ().getImage ("ggun2.jpg");
    tracker.addImage (gun2, 2);
    gun3 = getToolkit ().getImage ("ggun3.jpg");
    tracker.addImage (gun3, 3);
    gun4 = getToolkit ().getImage ("ggun4.jpg");
    tracker.addImage (gun4, 4);
    gun5 = getToolkit ().getImage ("ggun5.jpg");
    tracker.addImage (gun5, 5);
    gun6 = getToolkit ().getImage ("ggun6.jpg");
    tracker.addImage (gun6, 6);
    gun7 = getToolkit ().getImage ("ggun7.jpg");
    tracker.addImage (gun7, 7);
    gun8 = getToolkit ().getImage ("ggun8.jpg");
    tracker.addImage (gun8, 8);
    gun9 = getToolkit ().getImage ("ggun9.jpg");
    tracker.addImage (gun9, 9);
    gun10 = getToolkit ().getImage ("ggun0.jpg");
    tracker.addImage (gun10, 10);
    //prepares the status bar images for the tracker
    hpbox = getToolkit ().getImage ("hpbox.jpg");
    tracker.addImage (hpbox, 11);
    scorebox = getToolkit ().getImage ("scorebox.jpg");
    tracker.addImage (scorebox, 12);
    //prepares the blood image
    blood = getToolkit ().getImage ("splash.jpg");
    tracker.addImage (blood, 13);
    // Load the images.
    try
    tracker.waitForAll ();
    catch (InterruptedException e)
    // This exception will not happen in our program, but
    // Java requires that we handle it anyway.
    System.out.println ("Wait interrupted.");
    if (tracker.isErrorAny ())
    loadingMessageLabel.setText ("Image loading failed!");
    else
    // All the images are now loaded. Remove the loading label.
    remove (loadingMessageLabel);
    // Create and place the canvas.
    canvas = new AnimatePictureCanvas (background);
    canvas.setSize (background.getWidth (null),
    background.getHeight (null));
    add ("Center", canvas);
    pack (); // Resize the Frame to fit the canvas.
    validate (); // Force the Frame to be redrawn.
    animate ();
    } // Animate constructor
    // Move the bouncers over the background.
    public void animate ()
    // Create the offscreen bitmap.
    int bgWidth = background.getWidth (null);
    int bgHeight = background.getHeight (null);
    Image offscreen = this.createImage (bgWidth, bgHeight);
    // Get the width and height of the guns.
    int gun1Width = gun1.getWidth (null);
    int gun1Height = gun1.getHeight (null);
    int gun2Width = gun2.getWidth (null);
    int gun2Height = gun2.getHeight (null);
    int gun3Width = gun3.getWidth (null);
    int gun3Height = gun3.getHeight (null);
    int gun4Width = gun4.getWidth (null);
    int gun4Height = gun4.getHeight (null);
    int gun5Width = gun5.getWidth (null);
    int gun5Height = gun5.getHeight (null);
    int gun6Width = gun6.getWidth (null);
    int gun6Height = gun6.getHeight (null);
    int gun7Width = gun7.getWidth (null);
    int gun7Height = gun7.getHeight (null);
    int gun8Width = gun8.getWidth (null);
    int gun8Height = gun8.getHeight (null);
    int gun9Width = gun9.getWidth (null);
    int gun9Height = gun9.getHeight (null);
    int gun10Width = gun10.getWidth (null);
    int gun10Height = gun10.getHeight (null);
    //finds the width and height of the status bar images
    int hpboxWidth = hpbox.getWidth (null);
    int hpboxHeight = hpbox.getHeight (null);
    int scoreboxWidth = scorebox.getWidth (null);
    int scoreboxHeight = scorebox.getHeight (null);
    // Create the arrays containining the location and
    // direction of the bouncers.
    int locX;
    int locY;
    // Initialize the gun Image's location
    locX = (bgWidth - gun1Width);
    locY = (bgHeight - gun1Height);
    // Get the graphics contexts for both the offscreen image and
    // the canvas.
    Graphics offscreenG = offscreen.getGraphics ();
    Graphics canvasG = canvas.getGraphics ();
    while (!quitting)
    //sets the mouse listener to check for shots being fired
    addMouseListener (new MouseAdapter ()
    public void mouseClicked (MouseEvent e)
    int xClick = e.getX ();
    int yClick = e.getY ();
    System.out.println (" " + xClick + " " + yClick);
    delay (1000000);
    fire (xClick, yClick);
    //sets the keylistener to check for a change in the current gun
    // addKeyListener (new KeyAdapter ()
    // public void keyTyped (KeyEvent e)
    // if (e.getKeyChar () == 'f')
    // i += 1;
    // if (i == 10)
    // i = 0;
    // if (e.getKeyChar () == 'd')
    // i -= 1;
    // if (i == -1)
    // i = 9;
    // Draw the background image to the offscreen bitmap, erasing
    // everything that is already there.
    offscreenG.drawImage (background, 0, 0, null);
    //draw the status bar at the bottom of the screen
    offscreenG.setColor (Color.black);
    offscreenG.fillRect (0, bgHeight - gun1Height, bgWidth, bgHeight);
    // Draw each bouncer to the offscreen image. Move each of
    // the bouncers, changing their direction when they encounter
    // an edge.
    offscreenG.drawImage (gun1, locX, locY, null);
    //draws the status bar
    offscreenG.drawImage (hpbox, 15, bgHeight - gun1Height + 10, null);
    offscreenG.drawImage (scorebox, hpboxWidth + 15 + 20, bgHeight - gun1Height + 25, null);
    //draws blood if a target is hit
    if (splat == 1)
    offscreenG.drawImage (blood, bloodx, bloody, null);
    delay (10000000);
    splat = 0;
    if (hp == 0)
    //drawString "you lose"
    break;
    else
    //determines the number of enemies still alive
    liveCount = 10;
    for (int a = 0 ; a <= 9 ; a++)
    if (alive [a] == true)
    else
    liveCount -= 1;
    if (liveCount == 0)
    //drawString "you win... get ready for LVL 2!!!"
    break;
    //determines the number of enemies onscreen and adds more if necessary
    screenCount = 0;
    for (int b = 0 ; b <= 9 ; b++)
    if (onScreen == true)
    screenCount += 1;
    if (screenCount < 3 && liveCount > 3)
    onScreen [currentDude] = true;
    if (currentDude == 9)
    else
    currentDude += 1;
    damage = 0;
    moreHits = 12 / screenCount;
    chance = (int) (Math.random () * moreHits) + 1;
    if (chance == moreHits)
    damage = 10;
    //sets the default color to white so things can be seen on the background
    offscreenG.setColor (Color.white);
    //checks all the enemies to see if they are alive and onscreen,
    //drawing them accordingly
    if (alive [0] == true && onScreen [0] == true)
    offscreenG.fillOval (ex1, ey1, 18, 18);
    if (alive [1] == true && onScreen [1] == true)
    offscreenG.fillOval (ex2, ey2, 13, 13);
    if (alive [2] == true && onScreen [2] == true)
    offscreenG.fillOval (ex3, ey3, 9, 9);
    if (alive [3] == true && onScreen [3] == true)
    offscreenG.fillOval (ex4, ey4, 15, 15);
    if (alive [4] == true && onScreen [4] == true)
    offscreenG.fillOval (ex5, ey5, 11, 11);
    if (alive [5] == true && onScreen [5] == true)
    offscreenG.fillOval (ex6, ey6, 30, 30);
    if (alive [6] == true && onScreen [6] == true)
    offscreenG.fillOval (ex7, ey7, 10, 10);
    if (alive [7] == true && onScreen [7] == true)
    offscreenG.fillOval (ex8, ey8, 10, 10);
    if (alive [8] == true && onScreen [8] == true)
    offscreenG.fillOval (ex9, ey9, 7, 7);
    if (alive [9] == true && onScreen [9] == true)
    offscreenG.fillOval (ex10, ey10, 10, 10);
    // Finally, draw the offscreen image to the canvas.
    canvasG.drawImage (offscreen, 0, 0, null);
    } // animate method
    public void delay (int d)
    for (int x = 1 ; x <= d ; d++)
    public void fire (int x, int y)
    splat = 1;
    bloodx = x;
    bloody = y;
    //play a sound
    //show bloody explosion
    //check to see if a stick man is alive and onscreen
    // Called by the system when an event occurs. Handle the
    // window's close box being pressed by halting the program.
    public boolean handleEvent (Event evt)
    if (evt.id == Event.WINDOW_DESTROY)
    quitting = true; // Set the flag so the animate loop will exit.
    setVisible (false); // Hide the window.
    System.exit (0);
    return true;
    return super.handleEvent (evt);
    } // handleEvent method
    } /* Animate */
    // The "AnimatePictureCanvas" class.
    // This class draws the image passed into its constructor, although it needs
    // only do so when the screen needs repainting.
    class AnimatePictureCanvas extends Canvas
    Image background; // The parent Frame containing all the image info.
    public AnimatePictureCanvas (Image background)
    this.background = background;
    } // AnimatePictureCanvas constructor
    // The paint method is called whenever the canvas needs to be redrawn.
    public void paint (Graphics g)
    g.setColor (Color.black);
    setBackground (Color.black);
    g.drawImage (background, 0, 0, null);
    } // paint method
    } /* AnimatePictureCanvas class */

    I wrote this a while ago so that i would not have to create events for every applet i created, instead I just extended this code. Since applet itself extends panel, you can just drop it anywhere you want (eg in a frame) and use its methpods. Otherwise you can change the code so that you extend frame/Jframe/...
    * EventApplet.java
    * Created on October 7, 2001, 10:55 PM
    package com.moss.util;
    import java.applet.Applet;
    import java.awt.event.ComponentAdapter;
    import java.awt.event.ComponentEvent;
    import java.awt.event.ContainerAdapter;
    import java.awt.event.ContainerEvent;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;
    /** Library that provides a set of handlers for most events.
    * @author  [Black Flag]
    * @version 1.0
    public class EventApplet extends Applet
        /** deals with component events
        public final void setComponentListeners()
            addComponentListener(new ComponentAdapter()
                public void componentResized(ComponentEvent evt)
                    formComponentResized(evt);
                public void componentMoved(ComponentEvent evt)
                    formComponentMoved(evt);
                public void componentShown(ComponentEvent evt)
                    formComponentShown(evt);
                public void componentHidden(ComponentEvent evt)
                    formComponentHidden(evt);
        /** Deals with container events
        public final void setContainerListeners()
            addContainerListener(new ContainerAdapter()
                public void componentAdded(ContainerEvent evt)
                    formComponentAdded(evt);
                public void componentRemoved(ContainerEvent evt)
                    formComponentRemoved(evt);
        /** Deals with focus events
        public final void setFocusListeners()
            addFocusListener(new FocusAdapter()
                public void focusGained(FocusEvent evt)
                    formFocusGained(evt);
                public void focusLost(FocusEvent evt)
                    formFocusLost(evt);
        /** Deals with key events
        public final void setKeyListeners()
            addKeyListener(new KeyAdapter()
                public void keyTyped(KeyEvent evt)
                    formKeyTyped(evt);
                public void keyPressed(KeyEvent evt)
                    formKeyPressed(evt);
                public void keyReleased(KeyEvent evt)
                    formKeyReleased(evt);
        /** Deals with mouse events
        public final void setMouseListeners()
            addMouseListener(new MouseAdapter()
                public void mousePressed(MouseEvent evt)
                    formMousePressed(evt);
                public void mouseReleased(MouseEvent evt)
                    formMouseReleased(evt);
                public void mouseClicked(MouseEvent evt)
                    formMouseClicked(evt);
                public void mouseExited(MouseEvent evt)
                    formMouseExited(evt);
                public void mouseEntered(MouseEvent evt)
                    formMouseEntered(evt);
        /** Deals with mouse motion events
        public final void setMouseMotionListeners()
            addMouseMotionListener(new MouseMotionAdapter()
                public void mouseMoved(MouseEvent evt)
                    formMouseMoved(evt);
                public void mouseDragged(MouseEvent evt)
                    formMouseDragged(evt);
        /** Override to provide this event
         * @param evt The event
        public void formComponentResized(ComponentEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formComponentMoved(ComponentEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formComponentShown(ComponentEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formComponentHidden(ComponentEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formComponentAdded(ContainerEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formComponentRemoved(ContainerEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formFocusGained(FocusEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formFocusLost(FocusEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formKeyTyped(KeyEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formKeyPressed(KeyEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formKeyReleased(KeyEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMousePressed(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseReleased(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseClicked(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseExited(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseEntered(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseMoved(MouseEvent evt)
        /** Override to provide this event
         * @param evt The event
        public void formMouseDragged(MouseEvent evt)
    }You will probably want to declare those last methods abstract. i didn't because i just couldn't be arsed.
    have fun.

  • I have a problem in the game Contract Killer 2 (Glu Games Inc.)

    I have a problem in the game Contract Killer 2 (Glu Games Inc.)
    This application does not function as expected
    I bought a package 4.99$
    My account was debited. But the game does not give me credit.
    Receipt number: ****.
    ID : MH*****J8X.
    Please help my credit or help refund for me.  (2)
    <Edited By Host>

    Most of the people on these forums, including myself, are fellow users - you're not talking to iTunes Support here.
    If you've tried contacting the game's developer and not had a response from them then you can contact iTunes Support via this link and ask them for help : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Open GL Problem in Windows Games

    I have a problem playing Windows Games under Boot Camp in the native screen resolution of my imac (1600 x 1200.) The graphic card is the ATI Radeon HD 2600
    When I try to play Doom 3 and try to set the screen resolution to maximum an annoying error occures: In Doom 3 after restarting the game the screen resolution is back to 640x480 and there is no way to get it startet in 1600x1200. In Medal of Honor the game crashs with a "Could not load open gl" error message. Same error comes in Return to Castle Wolfenstein.
    When I set the screen resolution down to 1280x800 everything works fine in all three games and I can play.
    I think there is a problem with the drivers from ATI in connection with the HD 2600 and Open GL based games. I first got the error with the patched ATI Radeon drivers that can be found on the net, so I managed to use the original ATI driver from ATI's website. No effect. The error is still there.
    Does anyone no, what the problem is? I would be very happy to play the games in high res again. (My Dell PC boosted these games with a resolution of 1920x1200, so this hurts a little bit...)

    Hi and welcome to Discussions,
    you can not use a resolution that is higher than the native resolution of your iMac display, which is 1680x1050.
    Even if only one of the numbers is higher as the native resolution (in this case the 1200, while the 1600 will fit) this resolution is not useable.
    Therefor only the next lower resolution can be used.
    Maybe with tweaking some settings of Doom 3 (and the other games alike) following these hints http://www.techspot.com/tweaks/doom3/doom-2.shtml you might be able to get the 1680x1050 resolution.
    Regards
    Stefan

  • Hello i have a problem with a game on game center can you help me?

    hello i have a problem with a game on game center can you help me?

    Perhaps, but you will need to provide a little more detail.

  • I am having problem with my games application...non of the game run smoothly and also the games close automaticially

    I am having problem with my games application... no idea where is the problem. non of the game run smoothly 1st in 1st its hard to open the apps in it open than also it will close automatically. Please help me out

    Try This...
    Close All Open Apps...  Perform a Reset... Try again...
    Reset  ( No Data will be Lost )
    Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Release the Buttons.
    http://support.apple.com/kb/ht1430
    Also consider Deleting any Apps you have Purchased / Downloaded but you now never use..
    If necessary...
    Connect to iTunes on the computer you usually Sync with and “ Restore “...
    http://support.apple.com/kb/HT1414

  • Any First Person Shooter Games For the iPad?

    Looking for any 1st Person shooter games like Marine Sharpshooter for the iPad, can't seem to find them.

    If you do a Google search, you'll find many pages devoted to discussion of these games... the App Store does not categorize them as such, but they are out there.

  • Develop AI for a bot in first-person shooting game

    Hi, i'm working on a web-based first-person shooting game incorporating VRML and java. As for the AI part of the bot, somebody suggested me using JESS(Java Expert System Shell). I've looked through some tutorial about the API and usage of the software, but that's of little help when it comes to building a complex program contolling the AI of the bot. How do i start? any good reference or sample available on the net? thx for your help!

    Do you mean artificial behaviour (i.e. having the bad guys act like bad guys), rather than actual artificial intelligence?
    There's at least one good article on Artificial Behaviour on Gamasutra.com - it discusses the AI in Thief and Half-Life:
    http://www.gamasutra.com/gdc2003/features/20030307/leonard_01.htm
    (You will need to make a free account with Gamasutra to view this).
    In particular, it covers some pseudocode for the basics of the artificial behaviour.
    I hope this is of some use to you, it's at least interesting to read.

  • Counting lines problem. Please help!!

    Hi all,
    I just have a small problem i cannot resolve, here it is: I read through a file and i like to count the lines of the file there is before a special word.
    E.g
    My file contains:
    "hi
    how are you
    my name is john
    and i live
    britain"
    I'd like to count how much lines there are in the file before the word LIVE ==> result would be 4.
    I proceed with StreamTokenizer, but i don't knor how to specify the word. Here is my code:
         try {FileReader fr = new FileReader("test2.dat");
                   BufferedReader br = new BufferedReader(fr);
                   StreamTokenizer stk = new StreamTokenizer(br);
                   do {
                   n = stk.nextToken();
                   li = stk.lineno();
                   if (n == stk.TT_NUMBER) {
                        n = stk.nextToken();
                   if (n == stk.TT_EOL) {
                        li++;
                        n = stk.nextToken();
                   if (n == stk.TT_WORD) {
                        String str = stk.sval;
                        if ("entier".equals(str)) {
                             System.out.println(li);
                        else {
                             n = stk.nextToken();
                   while (??????????????);
    I want here to specify the word "entier" but how to do this??
    Thanks very much for your precious help....

A: Counting lines problem. Please help!!

Use LineNumberReader, which counts lines for you. Here's a complete program in 16 lines:
import java.io.*;
public class test4 {
  public static void main(String[] argv) {
    if (argv.length < 2) { System.err.println("no arg"); System.exit(0); }
    try {
      LineNumberReader in = new LineNumberReader(new FileReader(argv[1]));
      String line;
      while((line = in.readLine()) != null)
        if (line.indexOf(argv[0]) != -1)
          System.out.println("Found match at line " + in.getLineNumber());
    } catch (IOException e) {
      e.printStackTrace();
}If you want case insensitivity, you can make both lines lower-case before searching. Or you can use regular expressions.

Use LineNumberReader, which counts lines for you. Here's a complete program in 16 lines:
import java.io.*;
public class test4 {
  public static void main(String[] argv) {
    if (argv.length < 2) { System.err.println("no arg"); System.exit(0); }
    try {
      LineNumberReader in = new LineNumberReader(new FileReader(argv[1]));
      String line;
      while((line = in.readLine()) != null)
        if (line.indexOf(argv[0]) != -1)
          System.out.println("Found match at line " + in.getLineNumber());
    } catch (IOException e) {
      e.printStackTrace();
}If you want case insensitivity, you can make both lines lower-case before searching. Or you can use regular expressions.

  • Need help with "Shield" on side scrolling shooter game

    I am horribly new to Flash, and I need lots of help with a lot of things, most notably a shield I'm trying to give the player in a side scrolling shooter game. I need help with:
    1. Making the ship change color when it's activated.
    2. Making it so enemies die on contact with the ship.
    3. Making the "shield" variable go down constantly while in use.
    If anyone could help, I would appreciate it a lot.

    I wouldn't want any of you to write this program for me because I want to learn it myself. Yes I'm a student and I have to write some game with my groupe for a telephone in java like language doja. We decided to let it be a chess game. However I'm looking for an already written game in java that preferebly has some comments above the program lines so I can see what they've done. Offcourse if nobody has anything like this, yes I'm looking for a way to make an algorithm that makes the cpu move each time the player makes it's move. I have no idea on how to do this. I was hoping it can be solved with for, while, if and genest for statements. Yes it wil be a game with graphics but I think we can manage that part ourselves. So main question is the algorithm for the cpu moves. Do I have to pre-program every game in the book or is there another way etc..
    I hope there's anybody that can and is willing to get me on my way since I know it maybee isn't the most simple question.

  • Problem with video games

    Hi all,
    I have a problem with video games on Windows 8.1.
    On my Windows 7 I could play all games without any problems.
    Now I installed Windows 8.1 and I have problems with running video games: lower FPS, game breakdowns and sometimes even texture problems inside the game.
    I tried to reinstall both Windows and Graphic drivers. I tried several versions of drivers.
    I have Radeon HD 6870 and AMD Phenom II X4 955, SSD disk, 12 GB RAM.
    The point is: the same games works perfect on Windows 7 but doesn't work right on Windows 8.1.
    Can you, please, tell me if is there any other solution except going back to Windows 7 ?

    Hi,
    Please verify if these games are compatible with Windows 8.1.
    If yes, please download and install the proper version of game file and driver.
    Karen Hu
    TechNet Community Support

  • Maybe you are looking for

    • Error while configuring weblogic workshop application to cruise control.

      Hi, I have a web application which is created through weblogic workshop 9.2 and want to configure it to cruise control. In that process, i had to change the web app to ear application and created build.xml for configuring it to cruise control but I'm

    • Error in JCA adapter

      Hi, We have a scenario where data is sent from MDM - PI - ECC. To send the data from MDM repository, we are using sender JCA adapter. While testing  scenario, file is getting picked up by  sender adapter with the status 'Message processing completed'

    • Photoshop CS5 won't run under Win7 64-bit

      Photoshop starts, but as soon as I try to open any file, including a small JPEG, I get an annoying "Photoshop is no longer responding" type Windows OS message. This occurs whether it's the 64 bit version or the 32 bit version AMD Phenom 9750 Quad Cor

    • Coldfusion with javascript

      I have checkbox in coldfusion without a form and doing calucation. I would like to get the checkbox value and pass to next page. How can I do that. Again I don't have form. Just checkobxes.. by itself. Thankx

    • Import Song Question

      I am running Itunes 6.0.4 and had a question about importing music into ITunes. There is a setting under the Pref options in Advanced that talks about "Filter Freq. under 10Hz". Does this setting have to be checked? And if not, what does this option