Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ Client CLI options:
- `--norandom` to disable randomization for shots
- `--username` to set username from CLI and skip inputting it

### In-game control

When playing, the only relevant buttons are on the mouse. Mouse button 1 (left
button) strokes the ball, all other buttons on the mouse will change the
shooting mode: the game will draw a dashed line towards cursor and solid line to
the direction of stroke.

If cheating is allowed, the cheating can be toggled on/off by pressing `c` on
keyboard.

## Compatibility

Tested:
Expand Down
1 change: 1 addition & 0 deletions client/src/main/java/agolf/GolfGameFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void defineImages(ImageManager imageManager) {
imageManager.defineImage("language-flags.png");
imageManager.defineImage("credit-background.jpg");
imageManager.defineImage("tf-background.gif");
imageManager.defineImage("game-cursor.png");
}

public void createImages() {
Expand Down
79 changes: 45 additions & 34 deletions client/src/main/java/agolf/game/GameCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GameCanvas extends GameBackgroundCanvas
private static final double magicOffset = Math.sqrt(2.0D) / 2.0D;
private static final int diagOffset = (int) (6.0D * magicOffset + 0.5D);
private static final Cursor cursorDefault = new Cursor(Cursor.DEFAULT_CURSOR);
private static final Cursor cursorCrosshair = new Cursor(Cursor.CROSSHAIR_CURSOR);
private Cursor cursorCrosshair = new Cursor(Cursor.CROSSHAIR_CURSOR);
private static final Color colourAimLine = new Color(128, 0, 32);
private static final Font gameFont = new Font("Dialog", Font.PLAIN, 10);
private static final Color blackColour = Color.black;
Expand Down Expand Up @@ -79,14 +79,16 @@ public class GameCanvas extends GameBackgroundCanvas
private double hackedY = 0;
private boolean isCheating = false;

protected GameCanvas(GameContainer gameContainer, Image image) {
protected GameCanvas(GameContainer gameContainer, Image image, Cursor c) {
super(gameContainer, image);
this.ballSprites = gameContainer.spriteManager.getBalls();
this.playerCount = this.currentPlayerID = this.mouseX = this.mouseY = -1;
this.playerNamesDisplayMode = 0;
this.gameState = 0;
this.anInt2839 = anInt2838;
this.norandom = Parameters.getBooleanValue(gameContainer.params.getParameter("norandom"));
// TODO: would be cool if user can set their own cursor
this.cursorCrosshair = c;
}

@Override
Expand Down Expand Up @@ -151,8 +153,27 @@ public void update(Graphics g) {
}

if (isCheating) {
graphics.fillRect(
(int) (hackedX - 5), (int) (hackedY - 5), 10, 10); // afaik the coords are the centre of ball
// TODO could add ImageFilter here to distinguish the hacked ball
// from real ball.

// Draw the player ball into
int x = (int) (hackedX - 6.5D + 0.5D);
int y = (int) (hackedY - 6.5D + 0.5D);
int ballSpriteOffset = 0;
if (super.gameContainer.graphicsQualityIndex == 3) {
ballSpriteOffset = (x / 5 + y / 5) % 2 * 4;
}
graphics.drawImage(
this.ballSprites[this.currentPlayerID + ballSpriteOffset],
x,
y,
x + 13,
y + 13,
0,
0,
13,
13,
this);
}

g.drawImage(this.anImage2840, 0, 0, this);
Expand Down Expand Up @@ -613,26 +634,23 @@ public void mouseMoved(MouseEvent var1) {
}

@Override
public void mouseDragged(MouseEvent var1) {}
public void mouseDragged(MouseEvent event) {}

@Override
public void mouseEntered(MouseEvent var1) {
this.mouseMoved(var1);
public void mouseEntered(MouseEvent event) {
this.mouseMoved(event);
}

@Override
public void mouseExited(MouseEvent var1) {
public void mouseExited(MouseEvent event) {
this.mouseX = this.mouseY = -1;
this.repaint();
}

@Override
public synchronized void mousePressed(MouseEvent event) {
if (this.gameState == 1) {
if (event.isMetaDown()) {
this.shootingMode = (this.shootingMode + 1) % 4;
this.repaint();
} else {
if (event.getButton() == MouseEvent.BUTTON1) {
int x = event.getX();
int y = event.getY();
this.mouseX = x;
Expand All @@ -651,43 +669,35 @@ public synchronized void mousePressed(MouseEvent event) {
this.doStroke(this.currentPlayerID, true, x, y, this.shootingMode);
}
}
} else {
this.shootingMode = (this.shootingMode + 1) % 4;
this.repaint();
}
}
}

@Override
public void mouseReleased(MouseEvent var1) {
public void mouseReleased(MouseEvent event) {
if (this.gameState == 1) {
var1.consume();
event.consume();
}
}

@Override
public void mouseClicked(MouseEvent var1) {}
public void mouseClicked(MouseEvent event) {}

@Override
public synchronized void keyPressed(KeyEvent var1) {

public synchronized void keyPressed(KeyEvent event) {
if (allowCheating) {
// code for the aimbot.
if (var1.getKeyCode() == KeyEvent.VK_C) {
if (event.getKeyCode() == KeyEvent.VK_C) {
isCheating = !isCheating;
} else {
if (this.gameState == 1) {
this.shootingMode = (this.shootingMode + 1) % 4;
this.repaint();
}
}
}

if (this.gameState == 1) {
this.shootingMode = (this.shootingMode + 1) % 4;
this.repaint();
}
}

@Override
public void keyReleased(KeyEvent var1) {}
public void keyReleased(KeyEvent event) {}

@Override
public void keyTyped(KeyEvent var1) {}
Expand Down Expand Up @@ -892,13 +902,13 @@ protected boolean method134() {
return this.aString2835 != null;
}

protected void startTurn(int playerId, boolean canLocalPlayerPlay, boolean var3) {
protected void startTurn(int playerId, boolean canLocalPlayerPlay, boolean requestFocus) {
this.currentPlayerID = playerId;
this.aBooleanArray2834[playerId] = true;
this.mouseX = this.mouseY = -1;
this.shootingMode = 0;
if (canLocalPlayerPlay) {
this.method162(var3);
this.setStrokeListeners(requestFocus);
this.gameState = 1;
} else {
this.gameState = 0;
Expand Down Expand Up @@ -1023,7 +1033,8 @@ private void doHackedStroke(int playerId, boolean isLocalPlayer, int mouseX, int
boolean temp_aBoolean2832 = this.isLocalPlayer;
boolean temp_aBoolean2843 = this.aBoolean2843;
Seed temp_aSeed_2836 = rngSeed.clone();
// int temp_anInt2816 = super.gameContainer.gamePanel.isValidPlayerID(playerId) ? playerId :
// int temp_anInt2816 = super.gameContainer.gamePanel.isValidPlayerID(playerId)
// ? playerId :
// -1;
int temp_anInt2816 = playerId;

Expand Down Expand Up @@ -1851,12 +1862,12 @@ private void drawPlayer(Graphics g, int playerid, double var3) {
}
}

private void method162(boolean var1) {
private void setStrokeListeners(boolean requestFocus) {
this.addMouseMotionListener(this);
this.addMouseListener(this);
this.setCursor(cursorCrosshair);
this.addKeyListener(this);
if (var1) {
if (requestFocus) {
// this.requestFocus();//todo this is annoying as fuck
}
}
Expand Down
8 changes: 7 additions & 1 deletion client/src/main/java/agolf/game/GamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import agolf.GameContainer;
import agolf.GolfGameFrame;
import agolf.SynchronizedBool;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Toolkit;
import java.util.StringTokenizer;
import org.moparforia.client.Launcher;

Expand Down Expand Up @@ -566,7 +569,10 @@ private void create(Image image) {
this.playerInfoPanel = new PlayerInfoPanel(this.gameContainer, 735, 60);
this.playerInfoPanel.setLocation(0, 0);
this.add(this.playerInfoPanel);
this.gameCanvas = new GameCanvas(this.gameContainer, image);
Image cursorImage = this.gameContainer.imageManager.getImage("game-cursor");
Toolkit toolkit = Toolkit.getDefaultToolkit();
Cursor c = toolkit.createCustomCursor(cursorImage, new Point(11, 11), "game-cursor");
this.gameCanvas = new GameCanvas(this.gameContainer, image, c);
this.gameCanvas.setLocation(0, 65);
this.add(this.gameCanvas);
this.gameControlPanel = new GameControlPanel(this.gameContainer, this.playerInfoPanel, 95, 80);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.