From cedd064da619367ca890bc552bdcece7e5cbf129 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 23 May 2022 16:50:13 -0500 Subject: [PATCH] Fix animated flags not being set for resized canvas, proof of concept update multiplier Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 --- src/sig/RabiClone.java | 17 ++++++++++++++++- src/sig/engine/Panel.java | 16 ++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/sig/RabiClone.java b/src/sig/RabiClone.java index 92703c4..634d6aa 100644 --- a/src/sig/RabiClone.java +++ b/src/sig/RabiClone.java @@ -30,9 +30,24 @@ public class RabiClone { while (true) { long timePassed = System.nanoTime()-lastGameTime; lastGameTime=System.nanoTime(); + double updateMult = timePassed/1000000000d; if (KeyHeld(KeyEvent.VK_UP)) { - System.out.println("Up Held: "+UPCOUNT+++" (+"+(float)(timePassed/1000000f)+"ms)"); + //System.out.println("Up Held: "+UPCOUNT+++" (+"+(float)(timePassed/1000000f)+"ms)"); + p.nanaY-=16*updateMult; + } + if (KeyHeld(KeyEvent.VK_DOWN)) { + //System.out.println("Up Held: "+UPCOUNT+++" (+"+(float)(timePassed/1000000f)+"ms)"); + p.nanaY+=16*updateMult; + } + if (KeyHeld(KeyEvent.VK_RIGHT)) { + //System.out.println("Up Held: "+UPCOUNT+++" (+"+(float)(timePassed/1000000f)+"ms)"); + p.nanaX+=16*updateMult; + System.out.println(p.nanaX); + } + if (KeyHeld(KeyEvent.VK_LEFT)) { + //System.out.println("Up Held: "+UPCOUNT+++" (+"+(float)(timePassed/1000000f)+"ms)"); + p.nanaX-=16*updateMult; } } diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java index 81d621f..921943c 100644 --- a/src/sig/engine/Panel.java +++ b/src/sig/engine/Panel.java @@ -40,6 +40,8 @@ public class Panel extends JPanel implements Runnable,ComponentListener,KeyListe long lastUpdate=System.nanoTime(); final long TARGET_FRAMETIME = 8333333l; boolean mouseHeld=false; + public double nanaX = 0; + public double nanaY = 0; java.awt.Point mousePos=new java.awt.Point(0,0); public HashMap KEYS = new HashMap<>(); @@ -114,7 +116,7 @@ public class Panel extends JPanel implements Runnable,ComponentListener,KeyListe */ public void init(){ cm = getCompatibleColorModel(); - int screenSize = getWidth() * getHeight(); + int screenSize = getWidth()*getHeight(); if(pixel == null || pixel.length < screenSize){ pixel = new int[screenSize]; } @@ -162,7 +164,7 @@ public class Panel extends JPanel implements Runnable,ComponentListener,KeyListe p[y*getWidth()+x]=(0<<16)+(0<<8)+0;//RGB } } - Draw_Sprite(Sprite.NANA); + Draw_Sprite(nanaX,nanaY,Sprite.NANA); } private void resizeUpdate() { @@ -170,6 +172,8 @@ public class Panel extends JPanel implements Runnable,ComponentListener,KeyListe pixel = new int[getWidth()*getHeight()]; resizing=false; mImageProducer = new MemoryImageSource(getWidth(), getHeight(), cm, pixel,0, getWidth()); + mImageProducer.setAnimated(true); + mImageProducer.setFullBufferUpdates(true); imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer); System.out.println("Window resized."); } @@ -340,11 +344,11 @@ public class Panel extends JPanel implements Runnable,ComponentListener,KeyListe } } - public void Draw_Sprite(Sprite sprite){ + public void Draw_Sprite(double x, double y, Sprite sprite){ int[] p = pixel; - for(int x=0;x