Original Post
Nice to see everyone :) Hope your all hve a good day, Anyway, yeah as u can tell by the sibject im making a 2D shooter game using tiles. I'll paste wat ive done below, i just need to know if i can make the game work from what ive already got, of do i need to start again with a new design?? I really kjnow nothing about game programming, and hve really only been doing Java for 4 yr's im in yr 11. //War //My First Game //Nicholad Paul //Started 25 Febuary 2005 import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import java.nio.*; import java.net.*; public class War extends JFrame{ int width; int height; int tileWidth; int tileHeight; WarPanel panel; public War(){ super("War"); } public static void main(String args[]){ War war = new War(); war.panel = new WarPanel(); war.add(war.panel, BorderLayout.CENTER); BufferedImage cur = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR); Cursor customCursor = Toolkit.getDefaultToolkit().createCustomCursor(cur,new Point(0,0),""); war.setCursor(customCursor); war.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); war.setSize(800,800); war.setVisible(true); } } //War //My First Game //Nicholad Paul //Started 25 Febuary 2005 import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import java.nio.*; import java.net.*; public class WarPanel extends JPanel{ int difference; int width; int height; int tileWidth; int tileHeight; int crossHairX = 400; int crossHairY = 300; int crossHairWidth = 10; int crossHairHeight = 10; int playerX = 400; int playerY = 380; int pX; int pY; int imgCropx1; int imgCropy1; int imgCropx2; int imgCropy2; MouseHandler Mhandler; KeyHandler Khandler; Map map; BufferedImage image; Graphics g1; BufferedImage timage; public WarPanel(){ super(); setFocusable(true); setBackground( Color.GREEN ); map = new Map(); Mhandler = new MouseHandler(); Khandler = new KeyHandler(); //Add Listeners this.addKeyListener(Khandler); this.addMouseMotionListener(Mhandler); this.addMouseListener(Mhandler); imgCropx1 = 0; imgCropy1 = 0; imgCropx2 = 800; imgCropy2 = 800; image = map.drawMap(0, 0); repaint(); } public void paintComponent(Graphics g){ super.paintComponent(g); g.drawImage(image, 0, 0, 800, 800, imgCropx1, imgCropy1, imgCropx2, imgCropy2, this); g.drawOval(crossHairX - 5, crossHairY - 5, crossHairWidth, crossHairHeight); g.setColor(Color.BLUE); g.fillRect(playerX, playerY, 20, 20); } public class MouseHandler implements MouseListener, MouseMotionListener{ public MouseHandler(){ } public void mouseMoved( MouseEvent event ){ crossHairX = event.getX(); crossHairY = event.getY(); crossHairWidth = 10; crossHairHeight = 10; repaint(); System.out.println("" + event.getX() + " " + event.getY()); } public void mouseDragged( MouseEvent event ){ crossHairX = event.getX(); crossHairY = event.getY(); crossHairWidth = 15; crossHairHeight = 15; repaint(); System.out.println("" + event.getX() + " " + event.getY()); } public void mousePressed( MouseEvent event ){ crossHairX = event.getX(); crossHairY = event.getY(); crossHairWidth = 15; crossHairHeight = 15; repaint(); System.out.println("" + event.getX() + " " + event.getY()); } public void mouseReleased( MouseEvent event ){ crossHairX = event.getX(); crossHairY = event.getY(); crossHairWidth = 10; crossHairHeight = 10; repaint(); System.out.println("" + event.getX() + " " + event.getY()); } public void mouseExited( MouseEvent event ){ } public void mouseEntered( MouseEvent event ){ } public void mouseClicked( MouseEvent event ){ System.out.println("Making Bullet"); new Bullet(playerX, playerY, event.getX(), event.getY()).run(); } } public class KeyHandler implements KeyListener{ public void keyPressed( KeyEvent event ){ System.out.println("KeyPressed"); System.out.println(event.getKeyChar()); if(event.getKeyChar() == 'a'){ imgCropx1 = imgCropx1 - 4; imgCropx2 = imgCropx2 - 4; repaint(); } if(event.getKeyChar() == 'd'){ imgCropx1 = imgCropx1 + 4; imgCropx2 = imgCropx2 + 4; repaint(); } if(event.getKeyChar() == 'w'){ imgCropy1 = imgCropy1 - 4; imgCropy2 = imgCropy2 - 4; repaint(); } if(event.getKeyChar() == 's'){ imgCropy1 = imgCropy1 + 4; imgCropy2 = imgCropy2 + 4; repaint(); } if(event.getKeyChar() == ' '){ } } public void keyReleased( KeyEvent event ){ } public void keyTyped( KeyEvent event ){ } } public class Bullet{ float x; float y; float dx; float dy; float by; float bx; float m; Graphics g; public Bullet(int px, int py, int x1, int y1){ g = getGraphics(); x = px; y = py; dx = x1; dy = y1; } public void run(){ try{ System.out.println("Bullet Started"); System.out.println("Current Destination " + x + "," + y + "Required Destination " + dx + "," + dy + ""); m = (dy - y) / (dx - x) ; by = y; bx = x; if( dx <= x ){ m = m * -1; while(x >= dx){ g.drawOval((int)bx,(int)by, 10, 10); by = by + (10 * m); bx = x; repaint(); x = x - 10; } } else{ while(x <= dx){ g.drawOval((int)bx,(int)by, 10, 10); by = by + (10 * m); bx = x; repaint(); x = x + 10; } } System.out.println(bx + " " + by); }catch(Exception e){System.out.println(e);} } } } import javax.swing.*; import java.awt.image.*; import java.awt.*; public class Map{ //Grass = 0 //Rock = 2 //Sky = 3 //Player = 4 //TopLeftRock 5 //TopMiddleRock 6 //TopRightRock 7 //MiddleRock 9 //MiddleLeftRock 8 //MiddleRightRock 10 //BottomRightRock 13 //BottomMiddleRock 12 //BottomLeftRock 11 int positionx = 0; int positiony = 0; int playerx; int playery; int[][] map ={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0}, {0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0}, {0,0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,0,0,0,0,0,0,0,0,0},}; BufferedImage buffImage; ImageIcon grass; ImageIcon rock; ImageIcon sky; ImageIcon water; public Map(){ buffImage = new BufferedImage(32 * 50, 34 * 50, BufferedImage.TYPE_INT_ARGB); grass = new ImageIcon("Grass.jpg"); rock = new ImageIcon("Rock.jpg"); sky = new ImageIcon("stars.jpg"); water = new ImageIcon("Water.jpg"); } public BufferedImage drawMap(int p, int p1){ Graphics g2D = buffImage.createGraphics(); positionx = positionx + p; positiony = positiony + p1; if(positionx < 0){ positionx = 0; } if(positiony < 0){ positiony = 0; } for(int x = 0; x < 34; x++){ for(int y = 0; y < 32; y++){ if(map[x + positiony][y + positionx] == 0){ g2D.drawImage(grass.getImage(), y * 50, x * 50, null); } if(map[x + positiony][y + positionx] == 1){ g2D.drawImage(rock.getImage(), y * 50, x * 50, null); } if(map[x + positiony][y + positionx] == 2){ g2D.drawImage(rock.getImage(), y * 50, x * 50, null); } if(map[x + positiony][y + positionx] == 4){ g2D.drawImage(water.getImage(), y * 50, x * 50, null); } } } return buffImage; } } Problems - *The bullet looking like 10 bullets when its just 1 really, this must be a repaint issue, i dotn know how to solve it. *Im not sure how i am going to check if the bullet hits the target, simple because the bullet is given the plaerys current position which is always 400, 380 (BEcause the player never moves from the middle of the screen, and the X Y of where the mouse was clicked on the screen, problem is that if u scroll while shooting the bull travells to that position on the screen not the map. *I have no idea on how im going to show the other player on the map once i make this networked. Actually all up im lost, i dont know where to go. Sorry for the length of this question, ive been on these forums for awhile now, and ive always got good responses, so thats why i came here. Thanks in advance for any help :)