Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 29th, 2004, 6:24 PM   #1
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
There are still a few things I'd like to do before I say I'm finished with this. First of all, I get exceptions at times which I'd like to get rid of. If anyone can help me out with fixing those I'd really appreciate it. Secondly, I'd like to get new images so that the aliens don't all look alike on each level (by the way, in case you don't know, I bummed those images off of starcraft). Another thing I was wondering about was why it runs so slowly on some computers, even the faster ones. My laptop is 2.4 ghz, 512 ram, and 64 mb video card yet it takes nearly 30 seconds just to load my background image. Now, at school this game works perfectly, but those are 3.2 ghz, 1 gb ram machines. Anyway, enough talk. Here it is.

http://jupiter.walagata.com/w/mjorda...ceinvaders.zip

Ammo:
package IAmmo;
import ICraft.Craft;
import java.awt.*;


public class Ammo implements Craft
{
	private int myX;
	private int myY;
	private int mySpeed;
	private int damage;
	private boolean shot;
  private Image myImage;
  private int impact=0;
  private int xInc;
  private int yInc;
  
  
  public Ammo()
	{
 myX = 0;
 myY = 0;
 mySpeed = 7;
 myImage = Toolkit.getDefaultToolkit().getImage("ammo.jpg");
 shot = false;
 damage = 5;
 
	}
	
	

  public Ammo(int initX, int initY) 
  {
   myX = initX;
   myY = initY;
   mySpeed = 7;
   myImage = Toolkit.getDefaultToolkit().getImage("ammo.jpg");
   shot = false;
   damage = 5;
  }

  public Ammo(int initX, int initY, String imageName)
  {
    myX = initX;
   myY = initY;
   myImage = Toolkit.getDefaultToolkit().getImage(imageName);
   shot = true;
   damage = 5;
   mySpeed = 7;
   
  }
 
  
	public void setLoc( int X, int Y)
	{
 myX = X;
 myY = Y;
	} 
  public void setX( int X )
  {
  	myX = X;
  }
  
  public void setY( int Y )
  {
  	myY = Y;
  }
  public void setSpeed( int S )
  {
  	mySpeed = S;
  }

  public void moveUp()
  {
  	myY -= mySpeed;
  }
  public void moveDown()
  {
  	myY += mySpeed;
  }
  public void moveLeft()
  {
  	myX -= mySpeed;
  }
  public void moveRight()
  {
  	myX += mySpeed;
  }
  
  public int getX()
  {
  	return myX;
  }
  public int getY()
  {
  	return myY;
  }
  public int getSpeed()
  {
  	return mySpeed;
  }
  public Image getImage()
  {
  	return myImage;
  }	
  
  public void setImage(String alienImage)
  {
  	myImage = Toolkit.getDefaultToolkit().getImage(alienImage);
  }
  
  public int getDamage()
  {
  	return damage;
  }
  
  public void setDamage(int newDamage)
  {
  	damage = newDamage;
  }
  
  public void setShot(boolean newShot)
  {
  	shot = newShot;
  }
  
  public boolean isActive()
  {
  	return shot;
  }

	
  
  public void act()
  {
  	if(myY>=0)
  	{
   moveUp();
  	}
  	else
  	{
   setShot(false);
  	}
	}
	
	public void setActive(boolean x)
	{
 shot = x;	
	}
	
	public void actAlien()
  {
  	if(myY<=480)
  	{
   moveDown();
  	}
  
  	else
  	{
   setShot(false);
  	}
	}
	
	public void smartShot(int x, int y)
	{
 if(myY<=480)
 {
 	int shipX = x;
 	int shipY = y;
 	myY+=10;
 	int xDist = Math.abs(myX - x);
 	int xMove = xDist/10;
 	if(myX>x)
 	{
  myX-=xMove;
 	}
 	if(myX<x)
 	{
  myX+=xMove;
 	}
 }
 else
 {
 	setShot(false);
 }
	}

}

Craft.java:
package ICraft;

import java.awt.*;



public interface Craft 
{
  public void setLoc( int X, int Y); 
  public void setX( int X );
  public void setY( int Y );
  public void setSpeed( int S );

  public void moveUp();
  public void moveDown();
  public void moveLeft();
  public void moveRight();
  
  public int getX();
  public int getY();
  public int getSpeed();

	public Image getImage(); 
	public void act();
	public boolean isActive(); 
	public void setActive(boolean x);
}

Game.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Game {
    
  private SpaceCanvas canvas;

  public Game() 
  {
    canvas = new SpaceCanvas(); 

  }


  public static void main(String[] args) {
    Game TheGame = new Game();
  }


}

Ship.java
package SIShip;
import java.awt.*;
import IAmmo.Ammo;
import ICraft.Craft;

public class Ship implements Craft
{
  private int myX;
  private int myY;
  private int mySpeed;
  private int health;
  private Image myImage;
  public Ammo [] myAmmo = new Ammo[5];
  private boolean active;
  
 
	public Ship()
	{
 myX = 0;
 myY = 0;
 mySpeed = 10;
 myImage = Toolkit.getDefaultToolkit().getImage("ship.jpg");
 initializeAmmo();
 health = 50;
 active = true;
	}

  public Ship(int initX, int initY) 
  {
   myX = initX;
   myY = initY;
   mySpeed = 10;
   myImage = Toolkit.getDefaultToolkit().getImage("ship.jpg");
  	initializeAmmo();
  	health = 50;
  	active = true;
  }

  public Ship(int initX, int initY, int iSpeed)
  {
    myX = initX;
   myY = initY;
   iSpeed = mySpeed;
   myImage = Toolkit.getDefaultToolkit().getImage("ship.jpg");
  	initializeAmmo();
  	health = 50;
  	active = true;
  }
 
  public void setLoc( int X, int Y) 
  {
 myX = X;
 myY = Y;
  }


  public void setX( int X ) 
  {
  	myX = X;  
  }

	public void initializeAmmo()
	{
 for(int i = 0; i<myAmmo.length; i++)
 {
 	myAmmo[i] = new Ammo();
 }
	}

  public void setY( int Y ) 
  {
  	myY = Y;  
  }
  
  public void setSpeed( int S ) 
  {
  	mySpeed = S;  
  }  
  
  public void moveUp()
  {
  	if(myY>240)
   myY-=10;
  }
  
  public void moveDown()
  {
  	if(myY<420)
   myY+=10;
  }
  
  public void moveLeft()
  {
  	myX-=10;
  	if(myX<20)
  	{
   myX=580;
  	}
  }
  
  public void moveRight()
  {
  	myX+=10;
  	if(myX>600)
  	{
   myX = 20;
  	}
  }
  
  
  public int getX() 
  {
    return myX;
  }


  public int getY() 
  {
    return myY;
  }
  
  public int getSpeed()
  {
    return mySpeed;
  }
  
  public String toString()
  {
  	return getX() + " " + getY();	
	}
	
	public Image getImage()
	{
 return myImage;
	}
	
	public Ammo shoot()
	{
 System.out.println("h");
 for(int j = 0; j<myAmmo.length; j++)
 {
 	if(!myAmmo[j].isActive())
 	{
  myAmmo[j].setLoc(this.getX(), this.getY());
  myAmmo[j].setShot(true);
  return myAmmo[j];  
 	}
 	
 }
 return null;
	}
	
	public void act(){}
	
	public boolean isActive()
	{
 return active;
	}
	
	public void setActive(boolean x)
	{
 active = false;
	}
	public int getHealth()
	{
 return health;
	}
	
	public void isHit()
	{
 health -= 5;
	}
}

SpaceCanvas.java:
import IAmmo.Ammo;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
import java.io.*;
import SIShip.Ship;
import ICraft.Craft;
import java.awt.image.*;
import SIAlien.Alien;
public class SpaceCanvas extends JFrame implements KeyListener {

	
	boolean draw;
	private int X;  //this var stores the values read in for X
	private int Y;  //this var stores the values read in for Y
	private ArrayList <Craft> onScreen;
	private ArrayList <Alien> aliens;
	private ArrayList <Ammo> ammo;
	private Ship myShip;
	BufferedImage grid;
  private String myImageName; 
  private Image myImage;	
  private Image background = Toolkit.getDefaultToolkit().getImage("background.jpg");
  private Image alien = Toolkit.getDefaultToolkit().getImage("alien.jpg");
  private Alien myAlien[][] = new Alien[3][6];
  private boolean alien2;
  private boolean breaker = false;
  private int level;
  
  
  private boolean Keys[] = new boolean[5];

	public SpaceCanvas () //this method sets up the screen so that you can draw on it
	{
  alien2 = false;
  setSize( 640, 480 ); //this sets the size of the window
  setBackground(Color.white); //This sets the color of the window
  //this makes sure the window appears on the screen
  level = 1; 	
  X = 320;
  Y = 420;
  aliens = new ArrayList();
  
  for(int r=0; r<3;r++)
  {
  for(int c = 0; c<6; c++)
  {
  	myAlien[r][c] = new Alien((c*100+80), (r*60+20));	
  	myAlien[r][c].myAmmo.setImage("ammo2.jpg");
  	aliens.add(myAlien[r][c]);
  }
  }
  
  myShip = new Ship(X,Y, 10);
  onScreen = new ArrayList();
  ammo = new ArrayList();

  //if you wanted to add in timing for something
   Timer timer;  
   final int FREQ = 30; //the larger the # slows down anim	
   
   timer = new Timer(FREQ, new ActionListener()
   {
     public void actionPerformed(ActionEvent evt)
     {
      repaint();
     }
     
   });

   timer.start();

   addKeyListener(this);  //starts the key thread running
   
   show();
   
  
	}
	
	public void paint( Graphics window ) 
	{
 	Graphics2D g2 = (Graphics2D)window;
 	int w = this.getWidth();
  	int h = this.getHeight();
 	grid = (BufferedImage)(this.createImage(w,h));
 	Graphics gc = grid.createGraphics();
 	
 if(myShip.isActive())	
 {	
 	if ( Keys[0] == true ) 
     {
       myShip.moveLeft();
      

      
    	}

     if ( Keys[1] == true ) 
     {
       myShip.moveRight();
      
      
       }	

    if ( Keys[2] == true ) 
     {
       myShip.moveUp();
     
     }
    
    if ( Keys[3] == true ) 
    {
      myShip.moveDown();
      
    }  
  gc.drawImage(background, 0, 0, 640, 480, this);
  if(draw)
  {
  	for(int l = 0; l<aliens.size(); l++)
  	{	
   Ammo thisAmmo = null;
   aliens.get(l).act(1);
   double randomNum = Math.random()*aliens.get(l).getShotFactor();
   if(randomNum <1 && !aliens.get(l).myAmmo.isActive())
   {
   	thisAmmo = aliens.get(l).shoot();
   }
   if(thisAmmo!=null)
   {
   	ammo.add(thisAmmo);
   }
  	}
  	draw = false;
  	}
  	
  	else
  	{
   draw = true;
  	}
  	
  	for(int j = 0; j<ammo.size(); j++)
   {
   	if(((ammo.get(j).getX() <= (myShip.getX() + 40)) && ammo.get(j).getX()+20 >= (myShip.getX())) && ((ammo.get(j).getY() >= (myShip.getY() - 40)) && ammo.get(j).getY() <= (myShip.getY())))	
   	{
  	ammo.get(j).setActive(false);
  	ammo.remove(j);
    myShip.isHit();
    System.out.println(myShip.getHealth());
    if(myShip.getHealth()<=0)
    {
    	myShip.setActive(false);
    }
    
   	}
   }
  	
  	gc.setColor(Color.red);
  	double bufferedHealth = (double)myShip.getHealth()/50;
  	
  	int currentHealth = (int)(bufferedHealth*480);
  	
  	gc.fillRect(0, 480-currentHealth, 20, currentHealth);
  	
  	for(int l = 0; l<ammo.size(); l++)
  	{
   if(level == 1)
   	ammo.get(l).actAlien();
   if(level == 2 || level == 3)	
   	ammo.get(l).smartShot(myShip.getX(), myShip.getY());
   gc.drawImage(ammo.get(l).getImage(), ammo.get(l).getX(), ammo.get(l).getY(), 30, 30, this);
   if(ammo.get(l).isActive()==false)
   {
   	ammo.remove(l);
   }
   
   
  	}
  	
   for(int l = 0; l<aliens.size(); l++)
   {
   	
   	if(aliens.get(l).getHealth()<=0)
   	{
    
    aliens.get(l).setActive(false);
    aliens.remove(l);
   	}
   	
   	if(aliens.get(l).isActive())
   	{
    gc.drawImage(aliens.get(l).getImage(), aliens.get(l).getX(), aliens.get(l).getY(), 50, 50, this);
   	}
   }
   if(win())
   {
   	if(level<3)
   	{
    level++;
    if(level == 2)	
    {
    	Alien2 [] alien2 = new Alien2[3];
    	for(int start = 0; start <3; start++)
    	{
     alien2[start] = new Alien2(start*200+20, 30);
     aliens.add(alien2[start]);
    	}
    }
    if(level==3)
    {
    	BigBoss boss = new BigBoss(20, 30);
    	aliens.add(boss);
    }
   	}
       
   }
   gc.drawImage(myShip.getImage(), myShip.getX(), myShip.getY(), 50, 60, this);
  	
   for(int j = 0; j<onScreen.size(); j++)
   {
   	onScreen.get(j).act();
   	
   	if(onScreen.get(j).isActive())
   	{
    for(int l = 0; l<aliens.size(); l++)	
    {
    	if(j>=onScreen.size() || l>=aliens.size()){
     System.out.println("break");
     breaker = true;
     break;
     
    	}
    	
    	if(((onScreen.get(j).getX() <= (aliens.get(l).getX() + 40)) && onScreen.get(j).getX() >= (aliens.get(l).getX())) && ((onScreen.get(j).getY() <= (aliens.get(l).getY() + 40)) && onScreen.get(j).getY() >= (aliens.get(l).getY())))
    	{
     aliens.get(l).isHit();
     onScreen.get(j).setActive(false);
     onScreen.remove(j);
      	
    	} 
    	
    	System.out.println(j + " " + onScreen.size());
    	
    }  
   }
    
    	
    
   	if(breaker)
   	{
    	breaker = false;
    	break;
   	}
    
   
   	if(onScreen.get(j)!=null)
    	gc.drawImage(onScreen.get(j).getImage(), onScreen.get(j).getX(), onScreen.get(j).getY(), 25, 25, this); 
   	
   	if(!onScreen.get(j).isActive())
   	{
    onScreen.remove(j);
    }
    
    
   
   
   }
   
   
   
  	g2.drawImage(grid, null, 0, 0);
	
  
	}
	else
	{
 gc.setColor(Color.red);
 gc.drawString("you lose", 320, 240);
	}
	}

  public void keyPressed(KeyEvent e) 
  {
  	if (e.getKeyCode() == KeyEvent.VK_LEFT)
    {
      
      Keys[0] = true;
      
    }
    
    if (e.getKeyCode() == KeyEvent.VK_RIGHT)
         
    {
     	Keys[1] = true;
    }
    
    if (e.getKeyCode() == KeyEvent.VK_UP) 
    {
     	Keys[2] = true;
    }
    
    if (e.getKeyCode() == KeyEvent.VK_DOWN) 
    {
    	Keys[3] = true;
    }
    
    if(e.getKeyCode() == KeyEvent.VK_SPACE)
    {
    	Keys[4] = true;
    }
    
    
    
    
  }

  public void keyReleased(KeyEvent e) 
  {
  	if(Keys[4] == true)
    {
    	Ammo temp = myShip.shoot();
    	if(temp != null)
    	{
     onScreen.add(temp);
    	}
    	
    }

  	
  	if (e.getKeyCode() == KeyEvent.VK_LEFT)
    {
      
      Keys[0] = false;
      
    }
    
    if (e.getKeyCode() == KeyEvent.VK_RIGHT)
         
    {
     	Keys[1] = false;
    }
    
    if (e.getKeyCode() == KeyEvent.VK_UP) 
    {
     	Keys[2] = false;
    }
    
    if (e.getKeyCode() == KeyEvent.VK_DOWN) 
    {
    	Keys[3] = false;
    }
    
    if(e.getKeyCode() == KeyEvent.VK_SPACE)
    	Keys[4] = false;

  }
  
	public void keyTyped(KeyEvent e) 
	{

    
  }

	public static void main( String args[] ) 
	{
  //SpaceCanvas test = new SpaceCanvas ();  
	}
	
	public boolean win()
	{
 if(aliens.size()==0)
 {
 	return true;
 }
 
 return false;
	}
}

Alien.java:
package SIAlien;
import java.awt.*;
import IAmmo.Ammo;
import ICraft.Craft;
import java.lang.Math;

public class Alien implements Craft
{	
	int moveCount = 0;
	private int myX;
	private int myY;
	private int mySpeed;
  private int health;
  private Image myImage;
  public Ammo myAmmo;	
  private boolean active;
  private boolean shot = false;
  private int whereToMove;
  private int LEFT = 1;
  private int RIGHT = 2;
  private int DOWN = 3;
  private int UP = 4;
  private int shotFactor;
    
  public Alien()
  {
 myY = 0;
  	myX = 0;
  	mySpeed = 10;
  	health = 10;
  	myImage = Toolkit.getDefaultToolkit().getImage("Alien.jpg");
  	myAmmo = new Ammo();
  	active = true;
  	whereToMove = LEFT;
  	shotFactor = 30;
  }
  
  public Alien(int initX, int initY) 
  {
   myX = initX;
   myY = initY;
   mySpeed = 5;
   myImage = Toolkit.getDefaultToolkit().getImage("Alien.jpg");
  	health = 10;
  	myAmmo = new Ammo();
    active = true;
  	whereToMove = LEFT;
  	shotFactor = 30;
  }
  
  public Alien(int initX, int initY, int iSpeed)
  {
    myX = initX;
   myY = initY;
   iSpeed = mySpeed;
   myImage = Toolkit.getDefaultToolkit().getImage("Alien.jpg");
  	health = 50;
  	myAmmo = new Ammo();
  	active = true;
  	whereToMove = LEFT;
  	startMoving();
  	shotFactor = 30;
  }
  
  public void setLoc( int X, int Y) 
  {
 myX = X;
 myY = Y;
  }


  public void setX( int X ) 
  {
  	myX = X;  
  }
  
  public void setY( int Y ) 
  {
  	myY = Y;  
  }
  
  public void setSpeed( int S ) 
  {
  	mySpeed = S;  
  }  
  
  public void moveUp()
  {
  	myY-=10;//0;
  }
  
  public void moveDown()
  {
  	myY+=10;//0;
  }
  
  public void moveLeft()
  {
  	myX-=10;//0;
  }
  
  public void moveRight()
  {
  	myX+=10;//0;
  }
  
  
  public int getX() 
  {
    return myX;
  }


  public int getY() 
  {
    return myY;
  }
  
  public int getSpeed()
  {
    return mySpeed;
  }
  
  public String toString()
  {
  	return getX() + " " + getY();	
	}
	
	public Image getImage()
	{
 return myImage;
	}
	
	public void move()
	{
	
 for(int i = 0; i<4; i++)
 {
 	moveDown();
 }
	
 for(int i = 0; i<4; i++)
 {
 	//movet();
 }
 
 for(int i = 0; i<4; i++)
 {
 	moveLeft();
 }
 
 for(int i = 0; i<4; i++)
 {
 	moveLeft();
 }
 
	}
	public void act(){}
	public void act(int x)
	{
 
 if(moveCount == 20)
 {
 	moveCount = 0;
 }
 if(moveCount< 5)
 {
 	moveLeft();
 	moveCount++;
 }
 
 if(moveCount <10&& moveCount >=5)
 {
 	moveDown();
 	moveCount++;
 }	
 if(moveCount <15&& moveCount >=10)
 {
 	moveRight();
 	moveCount++;
 }
 if(moveCount <20&& moveCount >=15)
 {
 	moveUp();
 	moveCount++;
 }
 
	
	}
	
	public boolean isActive()
	{
 return active;
	}
	
	public void isHit()
	{
 health -= 5;
	}
	
	public int getHealth()
	{
 return health;
	}
	
	public void setActive(boolean x)
	{
 active = x;
	}
	
	public void startMoving()
	{
 if(whereToMove == LEFT)	
 {
 	for(int i = 0; i<40; i++)
 	{
  moveLeft();
 	//	SpaceCanvas.repaint();
 	}
 	whereToMove = DOWN;
 }
 
 else if(whereToMove == DOWN)	
 {
 	for(int i = 0; i<40; i++)
 	{
  moveDown();
  //SpaceCrepaint();
 	}
 	whereToMove = RIGHT;
 }
 
 else if(whereToMove == RIGHT)	
 {
 	for(int i = 0; i<40; i++)
 	{
  moveRight();
 // repaint();
 	}
 	whereToMove = UP;
 }
 
 else if(whereToMove == UP)	
 {
 	for(int i = 0; i<40; i++)
 	{
  moveUp();
 // repaint();
 	}
 	whereToMove = LEFT;
 }
	}
	
	public Ammo shoot()
	{
 
 	myAmmo.setLoc(this.getX(), this.getY());
 	myAmmo.setShot(true);
 	return myAmmo;  
 
	}
	
	public void setHealth(int x)
	{
 health = x;
	}
	
	public int getShotFactor()
	{
 return shotFactor;
	}
	
	public void setShotFactor(int newShotFactor)
	{
 shotFactor = newShotFactor;
	}
	public void setImage(String imageName)
	{
 myImage = Toolkit.getDefaultToolkit().getImage(imageName);
	}
}

Alien2.java:
import java.awt.*;
import IAmmo.Ammo;
import ICraft.Craft;
import java.lang.Math;
import SIAlien.Alien;

public class Alien2 extends Alien
{
	private int direction;
	private int FORWARD = 1;
	private int BACKWARD = 2;
	private int moveCount=1;
	Ammo [] shots = new Ammo[6];
	
	public Alien2()
	{
 super();
 setHealth(50);
 direction = FORWARD;
 setShotFactor(8);
 for(int i = 0; i<shots.length; i++)
 {
 	shots[i] = new Ammo();
 	shots[i].setImage("ammo2.jpg");
 }
	}
	
	public Alien2(int initX, int initY)
	{
 super(initX, initY);
 setHealth(50);
 direction = FORWARD;
 setShotFactor(8);
 for(int i = 0; i<shots.length; i++)
 {
 	shots[i] = new Ammo();
 	shots[i].setImage("ammo2.jpg");
 }
	}	
	public Alien2(int initX, int initY, int iSpeed)
	{
 super(initX, initY, iSpeed);
 setHealth(50);
 direction = FORWARD;
 setShotFactor(8);
 for(int i = 0; i<shots.length; i++)
 {
 	shots[i] = new Ammo();
 	shots[i].setImage("ammo2.jpg");
 }
	}
	
	public void act(int x)
	{
 if(direction == FORWARD)
 {
 	if(moveCount<=10)
 	{
  setX(getX()+4);
  setY(getY()+10);  
  moveCount++;
 	}
 	else if(moveCount > 10 && moveCount <= 20)
 	{
  setX(getX()+4);
  setY(getY()-10);
  moveCount++;  	
 	}
 	else if(moveCount > 20 && moveCount <=30)
 	{
  setX(getX()+4);
  setY(getY()+10);
  moveCount++;
 	}
 	else if(moveCount>30 && moveCount <= 40)
 	{
  setX(getX()+4);
  setY(getY()-10);
  moveCount++;
 	}
 	else if(moveCount>40)
 	{
  moveCount = 39;
  direction = BACKWARD;
 	}
 }
 	
 if(direction == BACKWARD)
 {
 	if(moveCount>=30)
 	{
  setX(getX()-4);
  setY(getY()+10);  
  moveCount--;
 	}
 	else if(moveCount >= 20 && moveCount < 30)
 	{
  setX(getX()-4);
  setY(getY()-10);
  moveCount--;  	
 	}
 	else if(moveCount >= 10 && moveCount <20)
 	{
  setX(getX()-4);
  setY(getY()+10);
  moveCount--;
 	}
 	else if(moveCount>=0 && moveCount <= 10)
 	{
  setX(getX()-4);
  setY(getY()-10);
  moveCount--;
 	}
 	else if(moveCount<=0)
 	{
  moveCount = 1;
  direction = FORWARD;
 	}
 }
	}
	
	public Ammo shoot()
	{
 System.out.println("h");
 for(int j = 0; j<shots.length; j++)
 {
 	if(!shots[j].isActive())
 	{
  shots[j].setLoc(this.getX(), this.getY());
  shots[j].setShot(true);
  return shots[j];  
 	}
 	
 }
 return null;
	}
}

BigBoss.java:
import java.awt.*;
import IAmmo.Ammo;
import ICraft.Craft;
import java.lang.Math;
import SIAlien.Alien;

public class BigBoss extends Alien2
{
	Ammo [] shots = new Ammo[15];
	int direction;
	int FORWARD = 1;
	int BACKWARD = 0;

	public BigBoss()
	{
 super();
 setHealth(25*5);
 direction = FORWARD;
 setShotFactor(4);
 for(int i = 0; i<shots.length; i++)
 {
 	shots[i] = new Ammo();
 	shots[i].setImage("ammo2.jpg");
 }
	}
	
	public BigBoss(int initx, int inity)
	{
 super(initx, inity);
 setHealth(25*5);
 direction = FORWARD;
 setShotFactor(4);
 for(int i = 0; i<shots.length; i++)
 {
 	shots[i] = new Ammo();
 	shots[i].setImage("ammo2.jpg");
 }
	}
	
	public BigBoss(int initx, int inity, int ispeed)
	{
 super(initx, inity, ispeed);
 setHealth(25*5);
 direction = FORWARD;
 setShotFactor(4);
 for(int i = 0; i<shots.length; i++)
 {
 	shots[i] = new Ammo();
 	shots[i].setImage("ammo2.jpg");
 }
	}
	
	public void act(int x)
	{
 if(direction==FORWARD)
 {
 	setX(getX()+10);
 	if(getX() == 600)
 	{
  direction = BACKWARD;
 	}
 }
 if(direction == BACKWARD)
 {
 	setX(getX()-10);
 	if(getX()==20)
 	{
  direction = FORWARD;
 	}
 }
	}
	
	public Ammo shoot()
	{
 System.out.println("h");
 for(int j = 0; j<shots.length; j++)
 {
 	if(!shots[j].isActive())
 	{
  shots[j].setLoc(this.getX(), this.getY());
  shots[j].setShot(true);
  return shots[j];  
 	}
 	
 }
 return null;
	}
}

What would you guys reccomend for me to improve this? I'll go through and clean up the code a little bit, but later.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Oct 29th, 2004, 7:07 PM   #2
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,667
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
how would i go about compiling so i can run this? thanks
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   Reply With Quote
Old Oct 29th, 2004, 10:03 PM   #3
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
You'll need jdk 1.4.2 at least. I'm not sure how it works for Linux. This was all done on a windows machine, Big_k, so I can't help there. Sorry.

I guess the first think to compile would be the Craft class, then the Ammo class, then Ship, then Alien, Alien2, BigBoss, SpaceCanvas, then Game. After that, run Game. That should work.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Oct 29th, 2004, 11:55 PM   #4
Overmind
Professional Programmer
 
Overmind's Avatar
 
Join Date: Jun 2004
Location: South Africa, Johannesburg
Posts: 301
Rep Power: 5 Overmind is on a distinguished road
Quote:
My laptop is 2.4 ghz, 512 ram, and 64 mb video card yet it takes nearly 30 seconds just to load my background image.
Ill try it sometime....but first, ill overclock my 2500+ to 3000...just to make sure it all works smoothly.
__________________
[SIGPIC][/SIGPIC]
Overmind is offline   Reply With Quote
Old Oct 31st, 2004, 11:20 PM   #5
zeta
Newbie
 
Join Date: Oct 2004
Posts: 7
Rep Power: 0 zeta is on a distinguished road
how do run this thanks?
What do you mean by compiling btw...(sorry i m kinda newb at this)
__________________

<span style='color:blue'>Html : 1 year experience</span>
<span style='color:red'>XML: newbie</span>
<span style='color:purple'>CSS:newbie</span>
<span style='color:orange'>Java: beginner</span>
<span style='color:green'>PS: beginner</span>
A website that I made
home.cogeco.ca/~sngyen/chemistryweb.htm
zeta is offline   Reply With Quote
Old Nov 1st, 2004, 11:55 AM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
BTW MJ, it'll probably be the images that slow the game down - Windows isn't very fast with that sort of thing. This can't be said enough - if you want to make games, use C++.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 1st, 2004, 3:53 PM   #7
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
I figured it was the images, but just wanted to make sure. Unfortunately, our teacher is forcing us to use Java, so C/C++ isn't an option.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Nov 2nd, 2004, 12:29 PM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Using Java to make a game??? Kinda retarded if you ask me - the language simply isn't geared that way.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 2nd, 2004, 12:32 PM   #9
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Tell our teacher that. He seems to think that Java is god. He also seems to think that Linux is the devil, so he's questionable, but he does know what he's doing. Smart man, even though my opinions clash with his. I'm sure he knows what he's doing.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Nov 4th, 2004, 4:13 PM   #10
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
You need at least 1.5.0 to compile, just in case anyone was wondering, or having trouble.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC