Fix screen clipping with scaled sprites

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
gpu
sigonasr2 2 years ago
parent 883649be4d
commit 7f15a8dc19
  1. 5
      src/sig/JavaProjectTemplate.java
  2. 6
      src/sig/engine/Panel.java
  3. 3
      src/sig/engine/Sound.java

@ -26,8 +26,8 @@ class Player{
public class JavaProjectTemplate {
public static final String PROGRAM_NAME="Sig's Java Project Template";
public static int WINDOW_WIDTH=1280;
public static int WINDOW_HEIGHT=720;
public static int WINDOW_WIDTH=640;
public static int WINDOW_HEIGHT=320;
public static Panel game;
Player pl = new Player();
@ -40,6 +40,7 @@ public class JavaProjectTemplate {
//Initialize your game here.
game.SetBorderColor(Color.BRIGHT_BLACK);
game.Cursor_SetCursor(new Sprite("cursor.png"),0,0);
backgroundMusic.play();
}

@ -272,7 +272,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
mImageProducer.setAnimated(true);
mImageProducer.setFullBufferUpdates(true);
if (p.ACTUAL_WINDOW_WIDTH!=0&&p.ACTUAL_WINDOW_HEIGHT!=0) {
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer).getScaledInstance(ACTUAL_WINDOW_WIDTH,ACTUAL_WINDOW_HEIGHT,Image.SCALE_FAST);
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
}
if(runThread && thread.isInterrupted() || !thread.isAlive()){
thread.start();
@ -582,7 +582,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
boolean vertical = transform==Transform.VERTICAL||transform==Transform.HORIZ_VERTIC;
for(int X=(int)xOffset;X<(int)(w+xOffset);X++){
for(int Y=(int)yOffset;Y<(int)(h+yOffset);Y++){
if (x+(X-xOffset)*scalex<0||y+(Y-yOffset)*scaley<0||(X-xOffset)*scalex+x>=ACTUAL_WINDOW_WIDTH||(Y-yOffset)*scaley+y>=ACTUAL_WINDOW_HEIGHT) {
if (x+(horizontal?sprite.getWidth()-(X-(int)xOffset):X-xOffset)*scalex<0||y+(vertical?sprite.getHeight()-(Y-(int)yOffset-1):Y-yOffset)*scaley<0||x+(horizontal?sprite.getWidth()-(X-(int)xOffset-1):X-xOffset)*scalex>=ACTUAL_WINDOW_WIDTH||y+(vertical?sprite.getHeight()-(Y-(int)yOffset-1):Y-yOffset)*scaley>=ACTUAL_WINDOW_HEIGHT) {
continue;
} else {
int index =
@ -603,6 +603,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
newindex+=XX; //Everytime we reset we move the X marker over.
for (int YY=0;YY<scaley;YY++) {
newindex+=ACTUAL_WINDOW_WIDTH; //The Y marker only moves one pixel down at a time, because we do not reset it.
if (newindex<0||newindex>=pixel.length) continue;
Draw(newindex,sprite.getImg().getRGB(X,Y));
}
}
@ -613,6 +614,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
newindex+=XX; //Everytime we reset we move the X marker over.
for (int YY=0;YY<scaley;YY++) {
newindex+=ACTUAL_WINDOW_WIDTH; //The Y marker only moves one pixel down at a time, because we do not reset it.
if (newindex<0||newindex>=pixel.length) continue;
Draw(newindex,new Color(
(int)Math.min(255.0f,Math.max(0,(float)img.r * col.r / 255.0f)),
(int)Math.min(255.0f,Math.max(0,(float)img.g * col.g / 255.0f)),

@ -13,12 +13,14 @@ public class Sound {
public final static File SOUNDS_FOLDER = new File("..","sounds");
AudioInputStream data;
Clip c;
java.lang.String filename;
boolean loop;
public Sound(java.lang.String filename){
this(filename,false);
}
public Sound(java.lang.String filename,boolean loop) {
this.loop=loop;
this.filename=filename;
try {
data=AudioSystem.getAudioInputStream(new File(SOUNDS_FOLDER.getAbsolutePath(),filename));
c = AudioSystem.getClip();
@ -41,6 +43,7 @@ public class Sound {
c.close();
data.close();
c=null;
System.out.println("Unloaded sound for "+filename+".");
} catch (IOException e) {
e.printStackTrace();
}

Loading…
Cancel
Save