All kinds of improvements
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package se.urmo.my2dgame.object;
|
||||
|
||||
import se.urmo.my2dgame.entity.Player;
|
||||
import se.urmo.my2dgame.main.Screen;
|
||||
|
||||
import java.awt.*;
|
||||
@ -8,19 +9,15 @@ import java.awt.image.BufferedImage;
|
||||
public class SuperObject {
|
||||
public String name;
|
||||
public BufferedImage image;
|
||||
public boolean collision = false;
|
||||
public int worldX;
|
||||
public int worldY;
|
||||
|
||||
public void draw(Graphics2D g2d, Screen screen) {
|
||||
// Only drawImage for tiles within camera
|
||||
if (worldX + screen.TILE_SIZE > screen.player.worldX - screen.player.SCREEN_X &&
|
||||
worldX - screen.TILE_SIZE < screen.player.worldX + screen.player.SCREEN_X &&
|
||||
worldY + screen.TILE_SIZE > screen.player.worldY - screen.player.SCREEN_Y &&
|
||||
worldY - screen.TILE_SIZE < screen.player.worldY + screen.player.SCREEN_Y) {
|
||||
int screenX = worldX - screen.player.worldX + screen.player.SCREEN_X;
|
||||
int screenY = worldY - screen.player.worldY + screen.player.SCREEN_Y;
|
||||
g2d.drawImage(image, screenX, screenY, screen.TILE_SIZE, screen.TILE_SIZE, null);
|
||||
if(screen.isWithinScreen(worldX, worldY)) {
|
||||
int screenX = worldX - screen.player.worldX + Player.SCREEN_X;
|
||||
int screenY = worldY - screen.player.worldY + Player.SCREEN_Y;
|
||||
g2d.drawImage(image, screenX, screenY, Screen.TILE_SIZE, Screen.TILE_SIZE, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user