Use static reference for mouse position settings

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 2 years ago committed by GitHub
parent 0afec767d2
commit 0787ac4d5d
  1. BIN
      bin/RabiClone.jar
  2. 6
      src/sig/RabiClone.java
  3. 9
      src/sig/engine/Panel.java
  4. 6
      src/sig/events/DataEvent.java
  5. 8
      src/sig/events/Event.java
  6. 6
      src/sig/events/SpawnEvent.java
  7. 6
      src/sig/events/WaterEvent.java
  8. 8
      src/sig/objects/LevelRenderer.java

Binary file not shown.

@ -49,9 +49,9 @@ public class RabiClone{
public static int BASE_WIDTH = 512;
public static int BASE_HEIGHT = 288;
public static int EVENT_BOUNDARY_RANGE = 8;
public static final int EVENT_BOUNDARY_RANGE = 8;
public static int SIZE_MULTIPLIER = 1;
public static Point MOUSE_POS;
public static final Point MOUSE_POS = new Point(0,0);
public static boolean PLAYER_COLLISION[] = new boolean[RabiClone.BASE_WIDTH*RabiClone.BASE_HEIGHT];
public static boolean ENEMY_COLLISION[] = new boolean[RabiClone.BASE_WIDTH*RabiClone.BASE_HEIGHT];
@ -105,8 +105,6 @@ public class RabiClone{
p = new Panel(f);
MOUSE_POS = p.mousePos;
p.init();
f.add(p);

@ -45,7 +45,6 @@ public class Panel extends JPanel implements Runnable,KeyListener {
final long TARGET_FRAMETIME = 8333333l;
public double nanaX = 0;
public double nanaY = 0;
public Point mousePos=new Point(0,0);
public int button = 0;
public HashMap<Integer,Boolean> MOUSE = new HashMap<>();
public static byte[] generalPalette = new byte[]{
@ -129,7 +128,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
@Override
public void mousePressed(MouseEvent e) {
MOUSE.put(e.getButton(),true);
mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
RabiClone.MOUSE_POS.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
//System.out.println("Mouse List: "+MOUSE);
for(int i=0; i<RabiClone.OBJ.size();i++){
@ -140,7 +139,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
@Override
public void mouseReleased(MouseEvent e) {
MOUSE.put(e.getButton(),false);
mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
RabiClone.MOUSE_POS.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
for(int i=0; i<RabiClone.OBJ.size();i++){
RabiClone.OBJ.get(i).MouseReleased(e);
@ -166,12 +165,12 @@ public class Panel extends JPanel implements Runnable,KeyListener {
this.addMouseMotionListener(new MouseMotionListener(){
@Override
public void mouseDragged(MouseEvent e) {
mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
RabiClone.MOUSE_POS.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
}
@Override
public void mouseMoved(MouseEvent e) {
mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
RabiClone.MOUSE_POS.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
}
});
this.addMouseWheelListener(new MouseWheelListener(){

@ -11,5 +11,11 @@ public class DataEvent implements Event{
public boolean performCollision(int x, int y) {
return true;
}
@Override
public boolean performScreenLoad(int x, int y) {
// TODO Auto-generated method stub
return false;
}
}

@ -9,6 +9,14 @@ public interface Event{
* {@code False} to remove this event from the game after it runs.
*/
public boolean perform(int x, int y);
/**
* Runs this event when the camera is positioned on that screen.
* @param x The X Coordinate in pixel space the event is occuring in. (NOT Tile coordinates)
* @param y The Y Coordinate in pixel space the event is occuring in. (NOT Tile coordinates)
* @return {@code True} to keep this event alive after it runs.
* {@code False} to remove this event from the game after it runs.
*/
public boolean performScreenLoad(int x, int y);
/**
* Runs a player collision event on this tile at the given position.
* @param x The X Coordinate in pixel space the event is occuring in. (NOT Tile coordinates)

@ -29,5 +29,11 @@ public class SpawnEvent implements Event{
public boolean performCollision(int x, int y) {
return false;
}
@Override
public boolean performScreenLoad(int x, int y) {
// TODO Auto-generated method stub
return false;
}
}

@ -12,7 +12,13 @@ public class WaterEvent implements Event{
@Override
public boolean performCollision(int x, int y) {
return true;
}
@Override
public boolean performScreenLoad(int x, int y) {
RabiClone.CURRENT_MAP.getMap().setWaterLevel((char)(y/Tile.TILE_HEIGHT*Tile.TILE_HEIGHT));
System.out.println("Set Water level "+System.currentTimeMillis());
return true;
}

@ -59,6 +59,14 @@ public class LevelRenderer extends Object{
RabiClone.CURRENT_MAP.ModifyDataTile(x, y, DataTile.NULL);
}
}
if (RabiClone.CURRENT_MAP.getDataTileRawValue(x,y)<8192&&RabiClone.CURRENT_MAP.getDataTile(x,y)!=DataTile.NULL&&
x<((int)(this.getX()/RabiClone.BASE_WIDTH+1)*RabiClone.BASE_WIDTH)/Tile.TILE_WIDTH && x>=((int)(this.getX()/RabiClone.BASE_WIDTH)*RabiClone.BASE_WIDTH)/Tile.TILE_WIDTH &&
y<((int)(this.getY()/RabiClone.BASE_HEIGHT+1)*RabiClone.BASE_HEIGHT)/Tile.TILE_HEIGHT && y>=((int)(this.getY()/RabiClone.BASE_HEIGHT)*RabiClone.BASE_HEIGHT)/Tile.TILE_HEIGHT
) {
if (!RabiClone.CURRENT_MAP.getDataTile(x,y).getEvent().performScreenLoad(x*Tile.TILE_WIDTH,y*Tile.TILE_HEIGHT)) {
RabiClone.CURRENT_MAP.ModifyDataTile(x, y, DataTile.NULL);
}
}
}
}
if ((staggerTimer-=updateMult)<=0) {

Loading…
Cancel
Save