added new drawing method for easily changing the screen size
This commit is contained in:
@@ -10,6 +10,7 @@ import de.miaurizius.jgame2d.tile.interactive.InteractiveTile;
|
||||
import javax.sound.sampled.Clip;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.logging.Level;
|
||||
@@ -19,12 +20,18 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
// SCREEN SETTINGS
|
||||
final int originalTileSize = 16; //16x16 tile
|
||||
final int scale = 3;
|
||||
public final int maxScreenCol = 16;
|
||||
public final int tileSize = originalTileSize * scale; //48x48 tile
|
||||
public final int maxScreenCol = 20;
|
||||
public final int maxScreenRow = 12;
|
||||
public final int screenWidth = tileSize * maxScreenCol; // 768 pixels
|
||||
public final int screenWidth = tileSize * maxScreenCol; // 960 pixels
|
||||
public final int screenHeight = tileSize * maxScreenRow; // 576 pixels
|
||||
|
||||
// FULLSCREEN SETTINGS
|
||||
int fScreenWidth = screenWidth;
|
||||
int fScreenHeight = screenHeight;
|
||||
BufferedImage tempScreen;
|
||||
Graphics2D fg2;
|
||||
|
||||
// WORLD SETTINGS
|
||||
public final int maxWorldCol = 50;
|
||||
public final int maxWorldRow = 50;
|
||||
@@ -88,7 +95,9 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
|
||||
if(delta >= 1) {
|
||||
update();
|
||||
repaint();
|
||||
//repaint(); //since the new drawing method
|
||||
drawTempScreen();
|
||||
drawScreen();
|
||||
delta--;
|
||||
drawCount++;
|
||||
}
|
||||
@@ -136,23 +145,20 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void paintComponent(Graphics graphics) {
|
||||
super.paintComponent(graphics);
|
||||
Graphics2D graphics2d = (Graphics2D) graphics;
|
||||
|
||||
public void drawTempScreen() {
|
||||
// DEBUG
|
||||
long drawStart;
|
||||
drawStart = System.nanoTime();
|
||||
|
||||
// TITLE SCREEN
|
||||
if(gameState == GameState.TITLE) {
|
||||
ui.draw(graphics2d);
|
||||
ui.draw(fg2);
|
||||
return;
|
||||
}
|
||||
|
||||
// GAME
|
||||
tileM.draw(graphics2d);
|
||||
for(Entity entity : iTile) if(entity != null) entity.draw(graphics2d);
|
||||
tileM.draw(fg2);
|
||||
for(Entity entity : iTile) if(entity != null) entity.draw(fg2);
|
||||
|
||||
// ENTITY RENDER SYSTEM
|
||||
entityList.add(player);
|
||||
@@ -162,10 +168,10 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
for(Entity entity : projectileList) if(entity != null) entityList.add(entity);
|
||||
for(Entity entity : particleList) if(entity != null) entityList.add(entity);
|
||||
entityList.sort(Comparator.comparingInt(o -> o.worldY));
|
||||
for(Entity entity : entityList) entity.draw(graphics2d);
|
||||
for(Entity entity : entityList) entity.draw(fg2);
|
||||
entityList.clear();
|
||||
|
||||
ui.draw(graphics2d);
|
||||
ui.draw(fg2);
|
||||
|
||||
long drawEnd = System.nanoTime();
|
||||
long passed = drawEnd - drawStart;
|
||||
@@ -173,17 +179,19 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
// DEBUG
|
||||
if(keyH.debug) {
|
||||
int start = 350;
|
||||
graphics2d.setColor(Color.white);
|
||||
graphics2d.drawString("Draw Time: " + passed, 10, start);
|
||||
graphics2d.drawString("FPS: " + fpsMeasure, 10, start+tileSize);
|
||||
graphics2d.drawString("Invincible: " + player.invincibleCount, 10, start+tileSize*2);
|
||||
graphics2d.drawString("X, Y: " + player.worldX+", "+player.worldY, 10, start+tileSize*3);
|
||||
graphics2d.drawString("Col, Row: " + (player.worldX+player.solidArea.x)/tileSize+", "+(player.worldY+player.solidArea.y)/tileSize, 10, start+tileSize*4);
|
||||
fg2.setColor(Color.white);
|
||||
fg2.drawString("Draw Time: " + passed, 10, start);
|
||||
fg2.drawString("FPS: " + fpsMeasure, 10, start+tileSize);
|
||||
fg2.drawString("Invincible: " + player.invincibleCount, 10, start+tileSize*2);
|
||||
fg2.drawString("X, Y: " + player.worldX+", "+player.worldY, 10, start+tileSize*3);
|
||||
fg2.drawString("Col, Row: " + (player.worldX+player.solidArea.x)/tileSize+", "+(player.worldY+player.solidArea.y)/tileSize, 10, start+tileSize*4);
|
||||
Boot.logger.log(Level.FINE, "Draw Time: " + passed);
|
||||
}
|
||||
|
||||
// END
|
||||
graphics.dispose();
|
||||
}
|
||||
public void drawScreen() {
|
||||
Graphics fg = getGraphics();
|
||||
fg.drawImage(tempScreen, 0, 0, fScreenWidth, fScreenHeight, null);
|
||||
fg.dispose();
|
||||
}
|
||||
|
||||
// MUSIC
|
||||
@@ -211,6 +219,9 @@ public class GamePanel extends JPanel implements Runnable {
|
||||
assetSetter.setMonster();
|
||||
assetSetter.setITiles();
|
||||
gameState = GameState.TITLE;
|
||||
|
||||
tempScreen = new BufferedImage(screenWidth, screenHeight, BufferedImage.TYPE_INT_RGB);
|
||||
fg2 = (Graphics2D) tempScreen.getGraphics();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user