I am working on making a TF2 demake for the Notch followers since he hasn't worked on it since the new game and I want to improve from where he left off.
I am basically watching the videos and looking at how he is styling the code so everyone likes it.
This is the videos of him doing it.
realnotch - Not working on anything, just herping the derp.
I am going to quickly give away my src cause I am in major trouble if I can't get this fixed.
I am having an error on line 15 in the Art file and am trying to figure out what I did wrong. Any help is appreciated and I know I shouldn't be doing it because it is his, but most of the people asked me on the forums since I made a couple of nice mods to do it since I stopped modding. If you could help, or at least look through it, thank you.
Here is the error message:
Since I don't know how to do the code type on this forum I am going to put it in quotes till I find out.Exception in thread "Game Thread" java.lang.Error: Unresolved compilation problem:
Default constructor cannot handle exception type IOException thrown by implicit super constructor. Must define an explicit constructor
at com.Impostor.start.Art.<init>(Art.java:15)
at com.Impostor.start.Art.init(Art.java:12)
at com.Impostor.start.ImpostorFortress.init(ImpostorF ortress.java:39)
at com.Impostor.start.ImpostorFortress.run(ImpostorFo rtress.java:45)
at java.lang.Thread.run(Unknown Source)
ImpostorFortress.java
package com.Impostor.start; import java.awt.Canvas; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.*; import javax.swing.JFrame; public class ImpostorFortress extends Canvas implements Runnable { private static final long serialVersionUID = 1L; private static final int WIDTH = 320; private static final int HEIGHT = 240; private static final int SCALE = 2; private boolean keepRunning = true; private BufferedImage screenImage; private BitMap screenBitMap; public ImpostorFortress() { Dimension size = new Dimension(WIDTH*SCALE, HEIGHT*SCALE); setPreferredSize(size); setMaximumSize(size); setMinimumSize(size); } public void start() { new Thread(this, "Game Thread").start(); } public void stop() { keepRunning = false; } public void init() { Art.init(); screenImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB); screenBitMap = new BitMap(screenImage); } public void run() { init(); while (keepRunning) { tick(); render(screenBitMap); try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } swap(); } } private void swap() { BufferStrategy bs = getBufferStrategy(); if (bs==null) { this.createBufferStrategy(2); return; } Graphics g = bs.getDrawGraphics(); int screenW = getWidth(); int screenH = getHeight(); int w = WIDTH*SCALE; int h = HEIGHT*SCALE; g.setColor(Color.BLACK); g.fillRect(0, 0, screenW, screenH); g.drawImage(screenImage, (screenW*w)/2, (screenH*h)/2, w, h, null); g.dispose(); bs.show(); } private void render(BitMap screen) { screen.draw(Art.i.sprites[0][0], 0, 0); } private void tick() { } public static void main(String[] args) { ImpostorFortress gameComponent = new ImpostorFortress(); JFrame frame = new JFrame("Impostor Fortress"); frame.add(gameComponent); frame.pack(); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); gameComponent.start(); } }
Art.java
package com.Impostor.start; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; public class Art { public static Art i; public static void init() { i = new Art(); } //This BitMap[][] sprites line is the one with the error and the only one public BitMap[][] sprites = loadAndCut("/chars.png", 16, 16); private BitMap[][] loadAndCut(String name, int sw, int sh) throws IOException { BufferedImage img; try { img = ImageIO.read(Art.class.getResource(name)); } catch (IOException e) { throw new RuntimeException("Failed to load " + name); } int xSlices = img.getWidth()/sw; int ySlices = img.getHeight()/sh; BitMap[][] result = new BitMap[xSlices][ySlices]; for (int x=0; x < xSlices; x++) { for (int y=0; y < ySlices; y++) { result[x][y] = new BitMap(sw, sh); img.getRGB(x * sw, y * sh, sw, sh, result[x][y].pixels, 0, sw); } } return result; }
BitMap.java
package com.Impostor.start; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; public class BitMap { public final int[] pixels; public final int w, h; public BitMap(int w, int h) { this.w = w; this.h = h; pixels = new int[w*h]; } public BitMap(int w, int h, int[] pixels) { this.w = w; this.h = h; this.pixels = pixels; } public BitMap(BufferedImage img) { this.w = img.getWidth(); this.h = img.getHeight(); pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData(); } public void draw(BitMap b, int xp, int yp) { int x0 = xp; int x1 = xp + b.w; int y0 = yp; int y1 = yp + b.h; if (x0 < 0) x0 = 0; if (y0 < 0) y0 = 0; if (x1 > w) x1 = w; if (y1 > h) y1 = h; for (int y=y0; y<y1; y++) { int sp = (y-y0) * b.w - xp; int dp = (y) * b.w; for (int x = x0; x < x1; x++) { pixels[dp + x] = b.pixels[sp + x]; } } } }
Thank you if you can help.