Implement tile highlighting based on level renderer view

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent 95a923fad3
commit bdc22767f5
  1. 16
      src/sig/RabiClone.java
  2. 41
      src/sig/engine/Panel.java
  3. 8
      src/sig/engine/Point.java
  4. 3
      src/sig/objects/LevelRenderer.java
  5. 1
      src/sig/objects/Player.java

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.List;
import sig.engine.Panel;
import sig.engine.Point;
import sig.map.Maps;
import sig.objects.LevelRenderer;
import sig.objects.Player;
@ -24,6 +25,10 @@ public class RabiClone{
public static int BASE_WIDTH=512;
public static int BASE_HEIGHT=288;
public static int SIZE_MULTIPLIER=1;
public static Point MOUSE_POS;
public static LevelRenderer level_renderer;
public static Maps CURRENT_MAP = Maps.WORLD1;
public static void main(String[] args) {
@ -34,6 +39,8 @@ public class RabiClone{
ChooseBestRatio();
p = new Panel(f);
MOUSE_POS=p.mousePos;
p.init();
@ -43,7 +50,7 @@ public class RabiClone{
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
OBJ.add(new LevelRenderer(p));
OBJ.add(level_renderer = new LevelRenderer(p));
OBJ.add(new Player(p));
p.render();
@ -63,10 +70,9 @@ public class RabiClone{
}
}
private static void ChooseBestRatio() {
int multiplier=1;
while (f.getWidth()*(multiplier+1)<Toolkit.getDefaultToolkit().getScreenSize().getWidth()) {
multiplier++;
while (f.getWidth()*(SIZE_MULTIPLIER+1)<Toolkit.getDefaultToolkit().getScreenSize().getWidth()) {
SIZE_MULTIPLIER++;
}
f.setSize(f.getWidth()*multiplier,(int)((f.getWidth()*multiplier)/1.77777777778d));
f.setSize(f.getWidth()*SIZE_MULTIPLIER,(int)((f.getWidth()*SIZE_MULTIPLIER)/1.77777777778d));
}
}

@ -11,6 +11,7 @@ import java.util.HashMap;
import java.util.List;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
@ -19,6 +20,7 @@ import java.awt.event.KeyListener;
import sig.DrawLoop;
import sig.RabiClone;
import sig.map.Tile;
public class Panel extends JPanel implements Runnable,KeyListener {
JFrame window;
@ -41,7 +43,8 @@ public class Panel extends JPanel implements Runnable,KeyListener {
boolean mouseHeld=false;
public double nanaX = 0;
public double nanaY = 0;
java.awt.Point mousePos=new java.awt.Point(0,0);
public Point mousePos=new Point(0,0);
public Point highlightedSquare = new Point(0,0);
public HashMap<Integer,Boolean> KEYS = new HashMap<>();
public Panel(JFrame f) {
@ -52,16 +55,14 @@ public class Panel extends JPanel implements Runnable,KeyListener {
this.addMouseListener(new MouseInputListener(){
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
mouseHeld=true;
mousePos=e.getPoint();
System.out.println(e.getX()+","+e.getY());
System.out.println(MouseData());
mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
//System.out.println(e.getX()+","+e.getY());
//System.out.println(MouseData());
}
private String MouseData() {
@ -71,14 +72,12 @@ public class Panel extends JPanel implements Runnable,KeyListener {
@Override
public void mouseReleased(MouseEvent e) {
mouseHeld=false;
mousePos=e.getPoint();
System.out.println(MouseData());
mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
//System.out.println(MouseData());
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
@ -87,18 +86,34 @@ public class Panel extends JPanel implements Runnable,KeyListener {
@Override
public void mouseDragged(MouseEvent e) {
mousePos=e.getPoint();
System.out.println(MouseData());
}
@Override
public void mouseMoved(MouseEvent e) {
}
});
this.addMouseMotionListener(new MouseMotionListener(){
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent e) {
mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
UpdateHighlightedSquare();
}
});
}
private static void UpdateHighlightedSquare() {
RabiClone.p.highlightedSquare.setX((int)((RabiClone.level_renderer.getX()+RabiClone.MOUSE_POS.getX())/Tile.TILE_WIDTH));
RabiClone.p.highlightedSquare.setY((int)((RabiClone.level_renderer.getY()+RabiClone.MOUSE_POS.getY())/Tile.TILE_HEIGHT));
//System.out.println(RabiClone.p.highlightedSquare);
}
/**
* Get Best Color model available for current screen.
* @return color model

@ -25,6 +25,14 @@ public class Point {
this.y = y;
}
public void set(int x,int y) {
setX(x);setY(y);
}
public void update(int x,int y) {
set(x,y);
}
@Override
public String toString() {
return "Point(" + x + "," + y + ")";

@ -32,6 +32,9 @@ public class LevelRenderer extends Object{
public void draw(int[] p) {
for (int y=(int)(0+this.getY()/Tile.TILE_HEIGHT);y<(int)(RabiClone.BASE_HEIGHT/Tile.TILE_HEIGHT+this.getY()/Tile.TILE_HEIGHT+1);y++) {
for (int x=(int)(0+this.getX()/Tile.TILE_WIDTH);x<(int)(RabiClone.BASE_WIDTH/Tile.TILE_WIDTH+this.getX()/Tile.TILE_WIDTH+1);x++) {
if (x==RabiClone.p.highlightedSquare.getX()&&y==RabiClone.p.highlightedSquare.getY()) {
DrawTile(x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),Tile.WALL);
}
if (RabiClone.CURRENT_MAP.getTile(x,y)!=Tile.VOID) {
DrawTile(x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getTile(x,y));
//System.out.println((x*Tile.TILE_WIDTH+(this.getX()%Tile.TILE_WIDTH) )+","+(y*Tile.TILE_HEIGHT+(this.getY()%Tile.TILE_HEIGHT)));

@ -4,7 +4,6 @@ import sig.RabiClone;
import sig.engine.Object;
import sig.engine.Panel;
import sig.engine.Sprite;
import java.awt.event.KeyEvent;
public class Player extends Object{

Loading…
Cancel
Save