View Single Post
  #1 (permalink)  
Old 12-06-2007, 07:24 PM
MurderfaceX4 MurderfaceX4 is offline
Member
 
Join Date: Dec 2007
Location: TX
Posts: 1
MurderfaceX4 is on a distinguished road
I need help with my MouseMotionAdapter and MouseListener.
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;

public class Shooter extends Canvas implements MouseListener
{
public int width, height;
public BufferStrategy bs; // <--- lol, bs.
public final Image ship = Toolkit.getDefaultToolkit().createImage("Ship.bmp" );
public final Image ground = Toolkit.getDefaultToolkit().createImage("ground.bm p");
public final Cursor c = Toolkit.getDefaultToolkit().createCustomCursor(shi p, new Point(0, 0) , "cursor");
public Graphics g = bs.getDrawGraphics();
Thread t;
Frame f;

public boolean cached = false;

public Shooter()
{
Frame f = new Frame();
f.setCursor(c);
f.setLayout(new FlowLayout());
f.resize(900, 900);
f.addWindowListener(new WindowHandler());
f.setVisible(true);
try
{
repaint();
Thread.sleep( 1000 );
}
catch(Exception e) {System.out.println(e);}
}
public static void main(String[] args)
{

}

public void mouseClicked(MouseEvent arg0) {Toolkit.getDefaultToolkit().beep();}
public void mouseEntered(MouseEvent arg0) {}
public void mouseExited(MouseEvent arg0) {}
public void mousePressed(MouseEvent arg0) {}
public void mouseReleased(MouseEvent arg0) {}

}
class WindowHandler extends WindowAdapter
{
public void windowClosing(WindowEvent event)
{
System.exit(0);
}
}
class Ship
{
public int lives = 3;
public int speed = 3;
public boolean moving = false;
public boolean fire = true;

}
class Display extends Canvas
{
public Ship s = new Ship();
public static int score = 0;
public static int level = 1;

public final Image ship = Toolkit.getDefaultToolkit().createImage("Ship.bmp" );
public final Image ground = Toolkit.getDefaultToolkit().createImage("ground.bm p");

public static final int WIDTH = 900;
public static final int HEIGHT = 900;

public long gameTime;
public long numNums;
public Display()
{
Frame f = new Frame();
f.setSize(WIDTH, HEIGHT);
f.setLocation(50, 50);
f.setUndecorated(true);
f.add(this);
this.setFocusable(false);
f.addWindowListener(new WindowHandler());

}
public void drawScreen(Graphics g)
{
Graphics2D g2d = (Graphics2D) g;

g2d.drawImage(ship, -100, -100, this);
g2d.drawImage(ground, getWidth(), getHeight(), this);

g2d.setColor(Color.BLACK);
g2d.fillRect(0,0, getWidth(), getHeight());

g2d.setColor(Color.WHITE);
g2d.drawString("Score: " + score, 20, 20);
g2d.drawString("Lives: " + s.lives, 20, 30);
g2d.drawString("Level " + level, WIDTH - 60, 20);
}
public void update(Graphics g)
{
drawScreen(g);
}
}
class Mouse extends MouseAdapter
{
public void mouseClicked(MouseEvent me)
{
// i want to make it where you click the mouse and,
// a bullet will come out. I have the collision detecting already.
}
}

class Mouse2 extends MouseMotionAdapter
{
public void mouseMoved(MouseEvent me)
{
// i want to make the mouse the ship.
//like every time you move your mouse the ship moves.
}
}
Reply With Quote
Sponsored Links