Java simulation key Wizard - Introduction to basic concepts

  the code in the previous article shows that Java can operate the keyboard and mouse perfectly. This is the basis of the button wizard. Here are some basic concepts and principles to facilitate the understanding of development ideas. For senior developers, you can skip this chapter directly.

Screen coordinate system

  1. The origin O(0,0) of the screen coordinate system is in the upper left corner of the screen; Usually x is the abscissa and y is the ordinate
  2. The screen coordinate range is related to the display sub ratio; For example, the fractional ratio is 1366X768 pixels, indicating that the abscissa x range is [0, 1366], and the ordinate is [0, 768]; Negative coordinates are displayed outside the screen
  3. The screen coordinate system is not directly related to the game map coordinate; When we move the mouse, it is calculated according to the screen coordinates. To move the mouse to a certain position of the game map coordinates, you need to convert the game map coordinates into screen coordinates.

Some principles in the development process

  in order to simplify, the following principles are followed in the development process.
4. Make full use of the existing functions in the game. For example, automatic pathfinding is too troublesome to develop an automatic pathfinding, which violates the original intention of a simple game.
5. Try to use keyboard shortcuts. Mouse operation depends on screen coordinate information, and its universality is poor. Changing the resolution or moving the window will cause the operation to fail.
6. Try to use the existing coordinates to calculate the unknown coordinates; This is still considering generality
7. Try to use specific colors to locate the position; The color does not change with the change of machine, resolution and window position. It has good universality.

Introduction to game functions

  1. The built-in functions of the game used in the development process: automatic hang-up and automatic road finding
  2. Core game shortcuts used in the development process
Shortcut keyfunction
F9Baggage opening key
MAutomatic route finding map key
Ctrl+Alt+XAutomatic hook on key
ESCClose all open windows in the game
Alt+RRefresh the baggage, so that the items of the baggage can be arranged one by one

   the method of using these shortcut keys is a secondary development based on the basic functions of the previous article. The code:

package com.analog.games.mir2.tools;

import com.analog.tools.CommonUtil;
import com.sun.glass.events.KeyEvent;

public class Mir2Tools {
	
	public static boolean GRID_WINDOW_OPEN = false;
	
	public static boolean SEARCH_PATH_WINDOW_OPEN = false;
	
	public static boolean AUTO_PLAY = false;
	
	public static boolean WAIGUA_WINDOW_OPEN = false;
	
	/**
	 * //Close the existing window (internal hook cannot be closed) press ESC
	 */
	public static void closeAllWindows(){
		CommonUtil.pressOneKey(KeyEvent.VK_ESCAPE);
		
		GRID_WINDOW_OPEN = false;
		SEARCH_PATH_WINDOW_OPEN = false;
		
	}

	/**
	 * Switch pack press F9
	 */
	public static void switchGrid(){
		CommonUtil.pressOneKey(KeyEvent.VK_F9);
		
		//Switch baggage switch status
		GRID_WINDOW_OPEN = GRID_WINDOW_OPEN ? false:true;
	}
	
	/**
	 * On hook key press Ctrl+Alt+X
	 */
	public static void switchGuaji(){
		int keys[] = new int[]{KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_X};
		CommonUtil.pressKeys(keys);
		
		AUTO_PLAY = AUTO_PLAY ? false:true;
	}
	/**
	 * Characters stop unexpectedly, hang up again press Ctrl+Alt+X
	 */
	public static void switchGuaji(boolean guajiStatus) {
		int keys[] = new int[]{KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_X};
		CommonUtil.pressKeys(keys);
		
		AUTO_PLAY = guajiStatus;
		
	}
	/**
	 * Plug in key press F12
	 */
	public static void switchWaigua(){
		CommonUtil.pressOneKey(KeyEvent.VK_F12);
		
		//Switch baggage switch status
		WAIGUA_WINDOW_OPEN = WAIGUA_WINDOW_OPEN ? false:true;
		
	}
	
	/**
	 * Map key press TAB
	 */
	public static void pressTAB(){
		CommonUtil.pressOneKey(KeyEvent.VK_TAB);
	}
	
	/**
	 * Wayfinding map key press M
	 */
	public static void switchFindPathMap(){
		CommonUtil.pressOneKey(KeyEvent.VK_M);
		SEARCH_PATH_WINDOW_OPEN = SEARCH_PATH_WINDOW_OPEN ? false:true;
	}
	
	/**
	 * Refresh pack press Alt+R
	 */
	public static void burdenFresh(){
		int keys[] = new int[]{KeyEvent.VK_ALT, KeyEvent.VK_R};
		CommonUtil.pressKeys(keys);
	}
}

  some methods of the code were used at the beginning. Later, a better scheme was found and gave up, but the code was not deleted. For example, to open the pathfinding map, presstab () was called three times (according to the settings in the game, press TAB once to open the small map, press again to open the panoramic small map, and then press again to open the pathfinding map). Later, it was found that the "M" key can directly open / close the pathfinding map.
   the above content is the basis for developing key wizard. There will be more detailed analysis later...

Keywords: Java Game Development

Added by dsoftnet on Sun, 16 Jan 2022 15:05:42 +0200