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 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent d65eb10ef1
commit cedd064da6
  1. 17
      src/sig/RabiClone.java
  2. 16
      src/sig/engine/Panel.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;
}
}

@ -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<Integer,Boolean> 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<sprite.height;x++){
for(int y=0;y<sprite.width;y++){
p[y*getWidth()+x] = sprite.bi_array[y*sprite.width+x];
for(int X=0;X<sprite.height;X++){
for(int Y=0;Y<sprite.width;Y++){
p[(Y+(int)y)*getWidth()+X+(int)x] = sprite.bi_array[Y*sprite.width+X];
}
}
}

Loading…
Cancel
Save