Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Little shooter game: Enemies' Shootaction doesn't work

  1. #1
    A13X is offline Member
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Unhappy Little shooter game: Enemies' Shootaction doesn't work

    Hey people!
    I've made a little wavebased shooter game on JavaScript long time ago and now I want to make the same game on Java.
    My biggest problem is: Javascript is NOT Java, but this is another story...

    I noticed, that only the first enemy spawned in the game is shooting, although there is a for-loop getting ALL Enemies to make them shoot.
    code:
    Java Code:
                    
    		for(int i=0;i<actingimgs.size();i++){//actingimgs is a vector, filled with all Sprites "acting" in this game
    		if(actingimgs.get(i) instanceof Enemy){
    		if(ecooledDown)//cooled down is a boolean, preventing the enemy to shoot too often
    		{
                            if(random.nextInt()%50<=40){//randomizes the bullets
    			BufferedImage[] shot=loadImgs("imgs/shot.png",8);
    			shootFrom="enemy";
    			Shot eshot=new Shot(shot, actingimgs.get(i).getX(), actingimgs.get(i).getY()+25, 4,"enemy", null);
    			eshot.setXSpeed(-200);
    			actingimgs.add(eshot);
    			ecooledDown=false;
    			timer.restart();
                            }
    		}
    		}
    		}
    Thanks
    Last edited by A13X; 08-02-2013 at 08:26 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Little shooter game: Enemies' Shootaction doesn't work

    We can't really do anything with this snippet, since we have no idea what the rest of the code does. I suggest posting an SSCCE that demonstrates your problem- something that we can compile and run, but not your entire project either. Boil the problem down to as small an example as you can make it, and we'll go from there.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: Little shooter game: Enemies' Shootaction doesn't work

    ... but before you post that SSCCE please do learn how to correctly indent code for readability: Code Conventions for the Java Programming Language: Contents

    db
    KevinWorkman likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    A13X is offline Member
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Default Re: Little shooter game: Enemies' Shootaction doesn't work

    Quote Originally Posted by KevinWorkman View Post
    We can't really do anything with this snippet, since we have no idea what the rest of the code does. I suggest posting an SSCCE that demonstrates your problem- something that we can compile and run, but not your entire project either. Boil the problem down to as small an example as you can make it, and we'll go from there.
    It IS impossible for me to make a SSCCE Int this case, because it would never be "Self Contained". I already removed everything, which is not necessary and you still can't compile and run it. There are some (7) other classes than this one you need to have first. So should I post a download link for the other classes?

    Quote Originally Posted by DarrylBurke View Post
    ... but before you post that SSCCE please do learn how to correctly indent code for readability: Code Conventions for the Java Programming Language: Contents
    I have no Idea what this supposed to be!
    Last edited by A13X; 08-03-2013 at 10:44 PM.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: Little shooter game: Enemies' Shootaction doesn't work

    1. You make a SSCCE by starting from scratch and adding just enough of what is needed to reproduce your problem. Not by removing stuff from code that you've added and added to without adequate intermediate testing.

    2. You find it too much trouble to click a link and read what it's all about? Tough luck then, since many members here, self included, won't even try to read horribly formatted code.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 11
    Last Post: 03-14-2012, 07:30 PM
  2. Spawning enemies for my game
    By Kridane in forum New To Java
    Replies: 1
    Last Post: 02-17-2012, 12:46 AM
  3. Robot Schreenshot doesn't work in game
    By Giuseppe_Mazzei in forum Advanced Java
    Replies: 1
    Last Post: 05-29-2011, 04:31 AM
  4. 2D Shooter Game
    By just_in_deed in forum Java 2D
    Replies: 1
    Last Post: 08-04-2010, 01:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •