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>
This commit is contained in:
parent
d65eb10ef1
commit
cedd064da6
@ -30,9 +30,24 @@ public class RabiClone {
|
|||||||
while (true) {
|
while (true) {
|
||||||
long timePassed = System.nanoTime()-lastGameTime;
|
long timePassed = System.nanoTime()-lastGameTime;
|
||||||
lastGameTime=System.nanoTime();
|
lastGameTime=System.nanoTime();
|
||||||
|
double updateMult = timePassed/1000000000d;
|
||||||
|
|
||||||
if (KeyHeld(KeyEvent.VK_UP)) {
|
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();
|
long lastUpdate=System.nanoTime();
|
||||||
final long TARGET_FRAMETIME = 8333333l;
|
final long TARGET_FRAMETIME = 8333333l;
|
||||||
boolean mouseHeld=false;
|
boolean mouseHeld=false;
|
||||||
|
public double nanaX = 0;
|
||||||
|
public double nanaY = 0;
|
||||||
java.awt.Point mousePos=new java.awt.Point(0,0);
|
java.awt.Point mousePos=new java.awt.Point(0,0);
|
||||||
public HashMap<Integer,Boolean> KEYS = new HashMap<>();
|
public HashMap<Integer,Boolean> KEYS = new HashMap<>();
|
||||||
|
|
||||||
@ -114,7 +116,7 @@ public class Panel extends JPanel implements Runnable,ComponentListener,KeyListe
|
|||||||
*/
|
*/
|
||||||
public void init(){
|
public void init(){
|
||||||
cm = getCompatibleColorModel();
|
cm = getCompatibleColorModel();
|
||||||
int screenSize = getWidth() * getHeight();
|
int screenSize = getWidth()*getHeight();
|
||||||
if(pixel == null || pixel.length < screenSize){
|
if(pixel == null || pixel.length < screenSize){
|
||||||
pixel = new int[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
|
p[y*getWidth()+x]=(0<<16)+(0<<8)+0;//RGB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Draw_Sprite(Sprite.NANA);
|
Draw_Sprite(nanaX,nanaY,Sprite.NANA);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resizeUpdate() {
|
private void resizeUpdate() {
|
||||||
@ -170,6 +172,8 @@ public class Panel extends JPanel implements Runnable,ComponentListener,KeyListe
|
|||||||
pixel = new int[getWidth()*getHeight()];
|
pixel = new int[getWidth()*getHeight()];
|
||||||
resizing=false;
|
resizing=false;
|
||||||
mImageProducer = new MemoryImageSource(getWidth(), getHeight(), cm, pixel,0, getWidth());
|
mImageProducer = new MemoryImageSource(getWidth(), getHeight(), cm, pixel,0, getWidth());
|
||||||
|
mImageProducer.setAnimated(true);
|
||||||
|
mImageProducer.setFullBufferUpdates(true);
|
||||||
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
|
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
|
||||||
System.out.println("Window resized.");
|
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;
|
int[] p = pixel;
|
||||||
for(int x=0;x<sprite.height;x++){
|
for(int X=0;X<sprite.height;X++){
|
||||||
for(int y=0;y<sprite.width;y++){
|
for(int Y=0;Y<sprite.width;Y++){
|
||||||
p[y*getWidth()+x] = sprite.bi_array[y*sprite.width+x];
|
p[(Y+(int)y)*getWidth()+X+(int)x] = sprite.bi_array[Y*sprite.width+X];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user