Mouse buttons and scrolling

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
unknown 3 years ago
parent dff8d44172
commit 194f82e374
  1. 8
      Java/scripts/md5
  2. 9
      src/sig/engine/Object.java
  3. 21
      src/sig/engine/Panel.java
  4. 27
      src/sig/objects/LevelRenderer.java
  5. 2
      utils/filelist
  6. 8
      utils/md5

@ -1,4 +1,4 @@
build.sh:55f0208b07ba384f45009d6f92fe88fe -
clean.sh:96ce35f2d2dcb555421e00a6afda23ca -
commit.sh:5e4448db9ad48e72ec3a1ff4f5763b41 -
jar.sh:56f9b7c6dc8e85f28ffefe9ce82b1f07 -
build.sh:55f0208b07ba384f45009d6f92fe88fe *-
clean.sh:96ce35f2d2dcb555421e00a6afda23ca *-
commit.sh:5e4448db9ad48e72ec3a1ff4f5763b41 *-
jar.sh:56f9b7c6dc8e85f28ffefe9ce82b1f07 *-

@ -61,4 +61,13 @@ public abstract class Object implements GameEntity{
protected boolean KeyHeld(int key) {
return panel.KEYS.getOrDefault(key,false);
}
protected boolean MouseHeld(int mb) {
return panel.MOUSE.getOrDefault(mb,false);
}
protected boolean MouseScrolled(int scrolled) {
//-1 is UP, 1 is DOWN
return true;
}
}

@ -12,6 +12,8 @@ import java.util.List;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
@ -40,12 +42,13 @@ public class Panel extends JPanel implements Runnable,KeyListener {
boolean resizing=false;
long lastUpdate=System.nanoTime();
final long TARGET_FRAMETIME = 8333333l;
boolean mouseHeld=false;
public double nanaX = 0;
public double nanaY = 0;
public Point mousePos=new Point(0,0);
public int button = 0;
public Point highlightedSquare = new Point(0,0);
public HashMap<Integer,Boolean> KEYS = new HashMap<>();
public HashMap<Integer,Boolean> MOUSE = new HashMap<>();
public Panel(JFrame f) {
super(true);
@ -59,13 +62,14 @@ public class Panel extends JPanel implements Runnable,KeyListener {
@Override
public void mousePressed(MouseEvent e) {
mouseHeld=true;
MOUSE.put(e.getButton(),true);
mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
//System.out.println("Mouse List: "+MOUSE);
}
@Override
public void mouseReleased(MouseEvent e) {
mouseHeld=false;
MOUSE.put(e.getButton(),false);
mousePos.set(e.getX()/RabiClone.SIZE_MULTIPLIER,e.getY()/RabiClone.SIZE_MULTIPLIER);
}
@ -86,7 +90,6 @@ public class Panel extends JPanel implements Runnable,KeyListener {
}
});
this.addMouseMotionListener(new MouseMotionListener(){
@Override
public void mouseDragged(MouseEvent e) {
@ -98,6 +101,16 @@ public class Panel extends JPanel implements Runnable,KeyListener {
UpdateHighlightedSquare();
}
});
this.addMouseWheelListener(new MouseWheelListener(){
//-1 is UP, 1 is DOWN
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
for(int i=0; i<RabiClone.OBJ.size();i++){
Object current_obj = RabiClone.OBJ.get(i);
current_obj.MouseScrolled(e.getWheelRotation());
}
}
});
}
private static void UpdateHighlightedSquare() {

@ -1,6 +1,8 @@
package sig.objects;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import sig.RabiClone;
import sig.engine.Object;
import sig.engine.Panel;
@ -14,23 +16,32 @@ public class LevelRenderer extends Object{
this.setSprite(Sprite.TILE_SHEET);
}
@Override
@Override
public void update(double updateMult) {
int right = KeyHeld(KeyEvent.VK_RIGHT)?1:0;
int left = KeyHeld(KeyEvent.VK_LEFT)?1:0;
int up = KeyHeld(KeyEvent.VK_UP)?1:0;
int down = KeyHeld(KeyEvent.VK_DOWN)?1:0;
int right = KeyHeld(KeyEvent.VK_RIGHT)||KeyHeld(KeyEvent.VK_D)?1:0;
int left = KeyHeld(KeyEvent.VK_LEFT)||KeyHeld(KeyEvent.VK_A)?1:0;
int up = KeyHeld(KeyEvent.VK_UP)||KeyHeld(KeyEvent.VK_W)?1:0;
int down = KeyHeld(KeyEvent.VK_DOWN)||KeyHeld(KeyEvent.VK_S)?1:0;
if (right-left!=0) {
setX(getX()+(right-left)*256*updateMult);
setX(getX()+(right-left)*512*updateMult);
}
if (up-down!=0) {
setY(getY()+(down-up)*256*updateMult);
setY(getY()+(down-up)*512*updateMult);
}
boolean left_mb = MouseHeld(MouseEvent.BUTTON1);
boolean middle_mb = MouseHeld(MouseEvent.BUTTON2);
boolean right_mb = MouseHeld(MouseEvent.BUTTON3);
}
@Override
protected boolean MouseScrolled(int scrolled) {
//System.out.println("Scrolled");
return true;
}
@Override
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 y=(int)(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 (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));

@ -1,5 +1,5 @@
.coauthors
.updateDirectories
define.sh
main.sh
search.sh
.updateDirectories

@ -1,4 +1,4 @@
define.sh:883c4033be11b6d1268b852beada5463 -
main.sh:663ac9bb9ee46eb8cd1d717e8eb5e486 -
search.sh:2a471ffc3daa12f96157e613873f589d -
.updateDirectories:0ede00461e947494545e694040787b3f -
.updateDirectories:0ede00461e947494545e694040787b3f *-
define.sh:883c4033be11b6d1268b852beada5463 *-
main.sh:663ac9bb9ee46eb8cd1d717e8eb5e486 *-
search.sh:2a471ffc3daa12f96157e613873f589d *-

Loading…
Cancel
Save