⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 breakoutconstants.java

📁 一款小游戏 希望能帮助初学者 一些基本的知识 是作业作品
💻 JAVA
字号:
/**
  * Constants used in
  * the BreakOut game.
  *
  * @author		Adriana Ferraro
  * @version  	S2, 2007
*/
import java.awt.*;

public class BreakOutConstants {
	private static final int EDGE = 20;
	private static final int GAME_WIDTH = 400 + EDGE*2; 
	private static final int GAME_HEIGHT = GAME_WIDTH* 9 / 8;


	
//-------------------------------------------------------------------
//-------- Constants used to define the GAME and panel size --------
//-------------------------------------------------------------------		
	public static final int PANEL_WIDTH = GAME_WIDTH + EDGE*2;
	public static final int PANEL_HEIGHT = GAME_HEIGHT + EDGE*3 + 30;
	
	public static final int FRAME_WIDTH = 6 + GAME_WIDTH + EDGE*2;
	public static final int FRAME_HEIGHT = 55 + GAME_HEIGHT + EDGE*3 + 30;		
//-------------------------------------------------------------------
//-------- Constants used to define the GAME size ------------------
//-------------------------------------------------------------------		
	public static final Point GAME_TOP_LEFT = new Point(EDGE, EDGE*3);
	public static final Point GAME_TOP_RIGHT = new Point(PANEL_WIDTH, EDGE*3);
	
	public static final Rectangle GAME_AREA = new Rectangle(GAME_TOP_LEFT.x, GAME_TOP_LEFT.y, GAME_WIDTH, GAME_HEIGHT);
	
	public static final int GAME_AREA_MIDDLE_X = GAME_AREA.x + GAME_AREA.width/2;	
	public static final int GAME_AREA_MIDDLE_Y = GAME_AREA.y + GAME_AREA.height/2;
//-------------------------------------------------------------------
//-------- Constants used to define the ball size ------------------
//-------------------------------------------------------------------	
	public static final int BALL_SIZE = 20;
	public static final Rectangle BALL_START_RECT = new Rectangle(GAME_AREA_MIDDLE_X - BALL_SIZE/2, GAME_AREA_MIDDLE_Y-BALL_SIZE/2, BALL_SIZE, BALL_SIZE);
//-------------------------------------------------------------------
//-------- Constants used to define the GAME boundaries ------------
//-------------------------------------------------------------------		
	public static final Rectangle NORTH_BOUNDARY = new Rectangle(GAME_AREA.x-BALL_SIZE, GAME_AREA.y-BALL_SIZE*2,GAME_AREA.width+BALL_SIZE*2, BALL_SIZE*2);
	public static final Rectangle SOUTH_BOUNDARY = new Rectangle(GAME_AREA.x-BALL_SIZE, GAME_AREA.y+GAME_AREA.height, GAME_AREA.width+BALL_SIZE*2, BALL_SIZE*2);
	public static final Rectangle EAST_BOUNDARY = new Rectangle(GAME_AREA.x+GAME_AREA.width, GAME_AREA.y-BALL_SIZE, BALL_SIZE*2, GAME_AREA.height+BALL_SIZE*2);
	public static final Rectangle WEST_BOUNDARY = new Rectangle(GAME_AREA.x-BALL_SIZE*2, GAME_AREA.y-BALL_SIZE, BALL_SIZE*2+1, GAME_AREA.height+BALL_SIZE*2);	
//-------------------------------------------------------------------
//-------- Constants used to define the paddle positions ------------
//-------------------------------------------------------------------			
	public static final int PADDLE_WIDTH = BALL_SIZE*6;
		//Use the following to make the paddle width the 
		//whole game area width.  This is useful for testing
		//the end of the game when the user wins.
	//public static final int PADDLE_WIDTH = GAME_AREA.width;
	public static final int PADDLE_HEIGHT = GAME_WIDTH/30;
	public static final int PADDLE_Y = GAME_AREA.y + GAME_AREA.height - PADDLE_HEIGHT - 10;	
	public static final int PADDLE_START_X = GAME_AREA_MIDDLE_X - PADDLE_WIDTH/2;  	
	public static final Rectangle PADDLE_AT_START = new Rectangle(PADDLE_START_X, PADDLE_Y, PADDLE_WIDTH, PADDLE_HEIGHT);	
//-------------------------------------------------------------------
//--- Miscellaneous constants used to define  ----------------------- 
//--- direction of movement, status, paddle type --------------------
//-------------------------------------------------------------------			
	public static final int PADDLE_MOVE_AMOUNT = BALL_SIZE * 3;		
	public static final int MOVE_RIGHT = 0;
	public static final int MOVE_LEFT = 1;
	
	public static final int HIT_LEFT_SIDE = 1;
	public static final int HIT_RIGHT_SIDE = 2;
	public static final int HIT_TOP_SIDE = 3;
	public static final int HIT_BOTTOM_SIDE = 4;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -