4 Replies - 2818 Views - Last Post: 04 August 2012 - 05:15 PM Rate Topic: -----

#1 tfc225  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 9
  • Joined: 03-August 12

Would I need to my old shooting mechanics to make this work?

Posted 04 August 2012 - 04:47 AM

Well I'm currently working on a game (in Java with Slick/LWJGL) where you play as a ship and shoot incoming enemies, I have finally gotten the shooting to work the way I want it to, and I realized that I need to be able to shoot more than one bullet at a time. I'm aware that I need to make some kind of Array list and use objects, but is there an easier way to do this without scrapping my old method completely?
Is This A Good Question/Topic? 1
  • +

Replies To: Would I need to my old shooting mechanics to make this work?

#2 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Re: Would I need to my old shooting mechanics to make this work?

Posted 04 August 2012 - 09:52 AM

Code please :)
Was This Post Helpful? 0
  • +
  • -

#3 Benzoate  Icon User is offline

  • D.I.C Head


Reputation: 51
  • View blog
  • Posts: 232
  • Joined: 29-February 12

Re: Would I need to my old shooting mechanics to make this work?

Posted 04 August 2012 - 12:50 PM

I would like the answer as well... Slick and LWJGL is what I use for my game design too o.O
Was This Post Helpful? 0
  • +
  • -

#4 tfc225  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 9
  • Joined: 03-August 12

Re: Would I need to my old shooting mechanics to make this work?

Posted 04 August 2012 - 04:08 PM

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.List;
import java.awt.geom.AffineTransform;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Timer;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Point;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.particles.ConfigurableEmitter;
import org.newdawn.slick.particles.ParticleIO;
import org.newdawn.slick.particles.ParticleSystem;
 
public class Main extends BasicGame{
 


	
	final static int width =900;
	final static int height =600;
    Image plane = null;
    Image land = null;
    static float x = width/2;
    static float y = -20;
    static float speed=0.2f;
    boolean ic=true;
    boolean start=true;
    boolean stars=true;
    float bx;
    float by;
   
  
    
    public Main()
    {
        super("The Galaxy");
      
    }
 
    @Override
    public void init(GameContainer gc)throws SlickException {

    	plane = new Image("res/player.png");

    	
    }

Image bullet;


    @Override
    public void update(GameContainer gc, int delta)throws SlickException
   {
  	  Input input = gc.getInput();
     	if(input.isKeyPressed(Input.KEY_SPACE)&&readyToFire)//||input.isKeyDown(Input.KEY_SPACE)&&readyToFire)
     		{
        		bx=x;
        		by=y;
        		bullet=new Image("res/bullet.png");  
        		shot=true;
        		bullet.setRotation(plane.getRotation());
        		rotation1=plane.getRotation();
        		 
    			
    		}
    
    
    	  																													//afsasdafda
   
    	
    	if(y>299&&start){
    		readyToFire=true;
    		ic=true;
        	start=false;
        	
        	}
    	//colision detection
    	
    	if(y<300&&start==true){
        	y=y+0.15f;
        
    	}
    	if(y<25&&ic==true){
    	y=25;
    	}if(y>575&&ic==true){
        	y=575;
        	}
    	if(x<24&&ic==true){
    		x=24;
    	}
    	if(x>875&&ic==true){
    		x=875;
    	}
    	//Done
    	
      
 
        if(input.isKeyDown(Input.KEY_A)&&ic==true)
        {
            plane.rotate(-0.2f * delta);
        }
 
        if(input.isKeyDown(Input.KEY_D)&&ic==true)
        {
            plane.rotate(0.2f * delta);
        }
 
        if(input.isKeyDown(Input.KEY_W)&&ic==true&&!start)
        {
        	
            float hip = speed * delta;
 
            float rotation = plane.getRotation();
 
            x+= hip * Math.sin(Math.toRadians(rotation));
            y-= hip * Math.cos(Math.toRadians(rotation));
        } if(input.isKeyDown(Input.KEY_S)&&ic==true&&!start)
        {
            float hip = -speed * delta;
 
            float rotation = plane.getRotation();
 
            x+= hip * Math.sin(Math.toRadians(rotation));
            y-= hip * Math.cos(Math.toRadians(rotation));
        
        }
     
   }
    boolean shot=false;
    boolean readyToFire=false;
  
    
    static float rotation1 ;
    public void render(GameContainer gc, Graphics g)throws SlickException{
    
    

    	if(shot){
        	     float hip = speed*10 ;
        	     bx+= hip * Math.sin(Math.toRadians(rotation1));
                 by-= hip * Math.cos(Math.toRadians(rotation1));
             
        	bullet.drawCentered(bx,by);
        	
        	}
    		
    	
    		 plane.drawCentered(x, y);
    }
 
    
    public static void main(String[] args)throws SlickException {
         AppGameContainer app =
			new AppGameContainer( new Main() );
 
         app.setDisplayMode(width, height, false);
        app.setShowFPS(false);
        app.start();
       
             
    }
    
  
    
  
    
   
}
    




thanks so much(:
Was This Post Helpful? 1
  • +
  • -

#5 tfc225  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-August 12

Re: Would I need to my old shooting mechanics to make this work?

Posted 04 August 2012 - 05:15 PM

I apologize for my sloppy code(:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1