image drawing done.......... for now

This commit is contained in:
Sebastian Cabrera 2019-08-29 02:55:00 -04:00
parent ca8dfb9735
commit 1da6cd5ea9
12 changed files with 13 additions and 9 deletions

View file

@ -2,5 +2,6 @@
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="res"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

Binary file not shown.

BIN
pixels/bin/test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
pixels/res/test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -75,8 +75,8 @@ public class GameContainer implements Runnable {
} }
if (render) { if (render) {
renderer.test(); //renderer.test();
//renderer.clear(); renderer.clear();
game.render(renderer); game.render(renderer);
Window.update(); Window.update();

View file

@ -30,12 +30,14 @@ public class Renderer {
if ((x < 0 || x >= pW || y < 0 || y >= pH) || value == 0xffff00ff) { if ((x < 0 || x >= pW || y < 0 || y >= pH) || value == 0xffff00ff) {
return; return;
} }
p[x + y * pW] = value;
} }
public void drawImage(Image image, int offX, int offY) { public void drawImage(Image image, int offX, int offY) {
for (int y = 0; y < image.getH(); y++) { for (int y = 0; y < image.getH(); y++) {
for (int x = 0; x < image.getW(); x++) { for (int x = 0; x < image.getW(); x++) {
setPixel(x + offX, y + offY, image.getP()[x + y * image.getW()]);
} }
} }
} }

View file

@ -28,7 +28,7 @@ public class Window {
} }
public void create() { public void create() {
window.setSize(width, height); window.setSize(width * scale, height * scale);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new BorderLayout()); window.setLayout(new BorderLayout());
window.add(viewport, BorderLayout.CENTER); window.add(viewport, BorderLayout.CENTER);

View file

@ -5,24 +5,25 @@ import java.awt.event.KeyEvent;
import bz.bronze.pixels.engine.AbstractGame; import bz.bronze.pixels.engine.AbstractGame;
import bz.bronze.pixels.engine.GameContainer; import bz.bronze.pixels.engine.GameContainer;
import bz.bronze.pixels.engine.Renderer; import bz.bronze.pixels.engine.Renderer;
import bz.bronze.pixels.engine.gfx.Image;
public class GameManager extends AbstractGame { public class GameManager extends AbstractGame {
static GameContainer gc; static GameContainer gc;
private Image image;
public GameManager() { public GameManager() {
image = new Image("/test.png");
} }
@Override @Override
public void update(float dt) { public void update(float dt) {
if (gc.input.isKey(KeyEvent.VK_SPACE)) {
System.out.println("pop goes the weasel");
}
} }
@Override @Override
public void render(Renderer r) { public void render(Renderer r) {
r.drawImage(image, gc.input.mouseX - image.getW() / 2, gc.input.mouseY - image.getH() / 2);
} }
public static void main(String[] args) { public static void main(String[] args) {