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?
4 Replies - 1091 Views - Last Post: 04 August 2012 - 05:15 PM
#1
Would I need to my old shooting mechanics to make this work?
Posted 04 August 2012 - 04:47 AM
Replies To: Would I need to my old shooting mechanics to make this work?
#2
Re: Would I need to my old shooting mechanics to make this work?
Posted 04 August 2012 - 09:52 AM
Code please
#3
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
#4
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(:
#5
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(:
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|