public
Created

Stack Log When i run debug mode

  • Download Gist
MainGame.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
package me.bevilacqua.game;
 
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
 
import javax.swing.JFrame;
 
import me.bevilacqua.game.gfx.Screen;
 
public class MainGame extends Canvas implements Runnable {
//SIDESCROLLER!!!
private static final long serialVersionUID = 1L;
private static final int WIDTH = 300;
private static final int HEIGHT = WIDTH / 16 * 9; // 16 * 9 maintains a 16 X 9 aspect ratio
private static final int SCALE = 2;
private static final String TITLE = "Ongoing";
JFrame frame;
public boolean running = false;
private Screen screen;
private BufferedImage image = new BufferedImage(WIDTH , HEIGHT , BufferedImage.TYPE_INT_RGB); //The image the game runs on but you cant edit it without a raster
private int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData(); //Converts the buffered image into an array of intigers to hold pixel data
 
private static Dimension size = new Dimension(WIDTH * SCALE , HEIGHT * SCALE);
public MainGame() {
setSize(size);
setPreferredSize(size);
screen = new Screen(WIDTH , HEIGHT);
frame = new JFrame();
frame.add(this);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setTitle(TITLE);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
public static void main(String Args[]) {
new MainGame().start();
}
public synchronized void start() {
running = true;
new Thread(this).start();
}
public synchronized void stop() {
running = false;
}
public void run() {
long lastTime = System.nanoTime();
double nsPerTick = 1000000000D / 60D;
 
int ticks = 0;
int frames = 0;
long lastTimer = System.currentTimeMillis();
double delta = 0;
while (running) {
long now = System.nanoTime();
delta += (now - lastTime) / nsPerTick;
lastTime = now;
boolean ShouldRender = false;
while (delta >= 1) {
ticks++;
tick();
delta--;
ShouldRender = true;
}
try { Thread.sleep(5); } //Too Slow? make 0
catch (InterruptedException e) { e.printStackTrace(); }
if (ShouldRender) {
frames++;
render();
}
if (System.currentTimeMillis() - lastTimer >= 1000) {
lastTimer += 1000;
frame.setTitle(TITLE + " |" + " Frames: " + frames + " Ticks: " + ticks);
System.out.println(TITLE + " |" + " Frames: " + frames + " Ticks: " + ticks);
frames = 0;
ticks = 0;
}
}
}
 
private void render() {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(4); //Too Slow? make this 3
return;
}
//Optional clearing goes below
screen.clear();
//Rendering goes below:
screen.render();
for (int i = 0 ; i < pixels.length ; i++) { //Sets the pixels array in MainGame to the pixel array in the Screen class
pixels[i] = screen.pixels[i];
}
//Displaying goes below:
Graphics g = bs.getDrawGraphics();
g.drawImage(image, 0, 0, getWidth(), getHeight(), null); //Draws the buffered image (pixels[])
g.setColor(Color.blue);
g.dispose(); //Disposes the graphics
bs.show(); //Shows the next buffer
}
 
private void tick() {
// TODO Auto-generated method stub
}
}
Screen.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
package me.bevilacqua.game.gfx;
 
public class Screen {
private int width;
private int height;
public int[] pixels;
public Screen(int width , int height) {
this.width = width;
this.height = height;
pixels = new int[width * height];
}
public void clear() { //Not neaded but clears screen
for(int i = 0 ; i < pixels.length ; i++)
pixels[i] = 0;
}
public void render() {
for(int y = 0 ; y < height ; y++) {
for(int x = 0 ; x < width ; x++) {
pixels[x + y * width] = 0xff00ff;
}
}
}
}
Stack
1 2 3 4 5 6 7 8
Thread [main] (Suspended (exception FileNotFoundException))
FileInputStream.open(String) line: not available [native method]
FileInputStream.<init>(File) line: not available
Toolkit$1.run() line: not available
AccessController.doPrivileged(PrivilegedAction<T>) line: not available [native method]
Toolkit.initAssistiveTechnologies() line: not available
Toolkit.<clinit>() line: not available
Component.<clinit>() line: not available

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.