Allow setting the background frame as an image

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
gpu
sigonasr2 2 years ago
parent 7d009f8f49
commit bcdbfe16cb
  1. BIN
      sprites/rainbowBorder.png
  2. 12
      src/sig/JavaProjectTemplate.java
  3. 12
      src/sig/engine/Panel.java

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

@ -26,12 +26,13 @@ class Player{
public class JavaProjectTemplate {
public static final String PROGRAM_NAME="Sig's Java Project Template";
public static int WINDOW_WIDTH=640;
public static int WINDOW_HEIGHT=320;
public static int WINDOW_WIDTH=1280;
public static int WINDOW_HEIGHT=720;
public static Panel game;
Player pl = new Player();
Sprite bookSpr = new Sprite("book.png");
Sprite rainbowBorder = new Sprite("rainbowBorder.png");
Sound backgroundMusic = new Sound("battle.wav",true);
Sound laserShootSound = new Sound("laserShoot.wav");
@ -69,6 +70,13 @@ public class JavaProjectTemplate {
laserShootSound.play();
}
if (Key.isPressed(KeyEvent.VK_INSERT)) {
game.SetBorderImage(rainbowBorder);
}
if (Key.isPressed(KeyEvent.VK_DELETE)) {
game.SetBorderColor(Color.BRIGHT_BLACK);
}
if (Mouse.isPressed(2)) { //If middle click is pressed, reset the player position.
pl.x=pl.y=200;
}

@ -64,6 +64,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
public static long scaleTime;
public static Panel p;
public static JFrame f;
Sprite backgroundImg;
List<Sound> currentlyPlayingSounds = new ArrayList<Sound>();
@ -280,15 +281,24 @@ public class Panel extends JPanel implements Runnable,KeyListener {
}
public void SetBorderColor(Color col){
backgroundImg=null;
borderCol=new java.awt.Color(col.r,col.g,col.b);
}
public void SetBorderImage(Sprite spr){
backgroundImg=spr;
}
@Override
public void paintComponent(Graphics g) {
// perform draws on pixels
long startTime = System.currentTimeMillis();
g.setColor(borderCol);
g.fillRect(0,0,getWidth(),getHeight());
if (backgroundImg==null) {
g.fillRect(0,0,getWidth(),getHeight());
} else {
g.drawImage(backgroundImg.getImg(),0,0,getWidth(),getHeight(),0,0,backgroundImg.width,backgroundImg.height,this);
}
g.drawImage(imageBuffer,vViewPos.x,vViewPos.y,vViewSize.x+vViewPos.x,vViewSize.y+vViewPos.y,0,0,ACTUAL_WINDOW_WIDTH,ACTUAL_WINDOW_HEIGHT,this);
scaleTime=System.currentTimeMillis()-startTime;
}

Loading…
Cancel
Save