generated from sigonasr2/JavaProjectTemplate
Fix screen clipping with scaled sprites
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
883649be4d
commit
7f15a8dc19
@ -26,8 +26,8 @@ class Player{
|
|||||||
|
|
||||||
public class JavaProjectTemplate {
|
public class JavaProjectTemplate {
|
||||||
public static final String PROGRAM_NAME="Sig's Java Project Template";
|
public static final String PROGRAM_NAME="Sig's Java Project Template";
|
||||||
public static int WINDOW_WIDTH=1280;
|
public static int WINDOW_WIDTH=640;
|
||||||
public static int WINDOW_HEIGHT=720;
|
public static int WINDOW_HEIGHT=320;
|
||||||
public static Panel game;
|
public static Panel game;
|
||||||
|
|
||||||
Player pl = new Player();
|
Player pl = new Player();
|
||||||
@ -40,6 +40,7 @@ public class JavaProjectTemplate {
|
|||||||
//Initialize your game here.
|
//Initialize your game here.
|
||||||
game.SetBorderColor(Color.BRIGHT_BLACK);
|
game.SetBorderColor(Color.BRIGHT_BLACK);
|
||||||
game.Cursor_SetCursor(new Sprite("cursor.png"),0,0);
|
game.Cursor_SetCursor(new Sprite("cursor.png"),0,0);
|
||||||
|
|
||||||
backgroundMusic.play();
|
backgroundMusic.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
|
|||||||
mImageProducer.setAnimated(true);
|
mImageProducer.setAnimated(true);
|
||||||
mImageProducer.setFullBufferUpdates(true);
|
mImageProducer.setFullBufferUpdates(true);
|
||||||
if (p.ACTUAL_WINDOW_WIDTH!=0&&p.ACTUAL_WINDOW_HEIGHT!=0) {
|
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()){
|
if(runThread && thread.isInterrupted() || !thread.isAlive()){
|
||||||
thread.start();
|
thread.start();
|
||||||
@ -582,7 +582,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
|
|||||||
boolean vertical = transform==Transform.VERTICAL||transform==Transform.HORIZ_VERTIC;
|
boolean vertical = transform==Transform.VERTICAL||transform==Transform.HORIZ_VERTIC;
|
||||||
for(int X=(int)xOffset;X<(int)(w+xOffset);X++){
|
for(int X=(int)xOffset;X<(int)(w+xOffset);X++){
|
||||||
for(int Y=(int)yOffset;Y<(int)(h+yOffset);Y++){
|
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;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
int index =
|
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.
|
newindex+=XX; //Everytime we reset we move the X marker over.
|
||||||
for (int YY=0;YY<scaley;YY++) {
|
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.
|
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));
|
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.
|
newindex+=XX; //Everytime we reset we move the X marker over.
|
||||||
for (int YY=0;YY<scaley;YY++) {
|
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.
|
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(
|
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.r * col.r / 255.0f)),
|
||||||
(int)Math.min(255.0f,Math.max(0,(float)img.g * col.g / 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");
|
public final static File SOUNDS_FOLDER = new File("..","sounds");
|
||||||
AudioInputStream data;
|
AudioInputStream data;
|
||||||
Clip c;
|
Clip c;
|
||||||
|
java.lang.String filename;
|
||||||
boolean loop;
|
boolean loop;
|
||||||
public Sound(java.lang.String filename){
|
public Sound(java.lang.String filename){
|
||||||
this(filename,false);
|
this(filename,false);
|
||||||
}
|
}
|
||||||
public Sound(java.lang.String filename,boolean loop) {
|
public Sound(java.lang.String filename,boolean loop) {
|
||||||
this.loop=loop;
|
this.loop=loop;
|
||||||
|
this.filename=filename;
|
||||||
try {
|
try {
|
||||||
data=AudioSystem.getAudioInputStream(new File(SOUNDS_FOLDER.getAbsolutePath(),filename));
|
data=AudioSystem.getAudioInputStream(new File(SOUNDS_FOLDER.getAbsolutePath(),filename));
|
||||||
c = AudioSystem.getClip();
|
c = AudioSystem.getClip();
|
||||||
@ -41,6 +43,7 @@ public class Sound {
|
|||||||
c.close();
|
c.close();
|
||||||
data.close();
|
data.close();
|
||||||
c=null;
|
c=null;
|
||||||
|
System.out.println("Unloaded sound for "+filename+".");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user