当前位置: 首页>>代码示例>>Java>>正文


Java Polygon类代码示例

本文整理汇总了Java中org.newdawn.slick.geom.Polygon的典型用法代码示例。如果您正苦于以下问题:Java Polygon类的具体用法?Java Polygon怎么用?Java Polygon使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Polygon类属于org.newdawn.slick.geom包,在下文中一共展示了Polygon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	this.container = container;

	rect = new Rectangle(400,100,200,150);
	round = new RoundedRectangle(150,100,200,150,50);
	round2 = new RoundedRectangle(150,300,200,150,50);
	center = new Rectangle(350,250,100,100);
	
	poly = new Polygon();
	poly.addPoint(400,350);
	poly.addPoint(550,320);
	poly.addPoint(600,380);
	poly.addPoint(620,450);
	poly.addPoint(500,450);
	
	gradient = new GradientFill(0,-75,Color.red,0,75,Color.yellow,true);
	gradient2 = new GradientFill(0,-75,Color.blue,0,75,Color.white,true);
	gradient4 = new GradientFill(-50,-40,Color.green,50,40,Color.cyan,true);
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:23,代码来源:GradientTest.java

示例2: init

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	this.container = container;
	
	image1 = new Image("testdata/grass.png");
	image2 = new Image("testdata/rocks.png");
	
	fill = new GradientFill(-64,0,new Color(1,1,1,1f),64,0,new Color(0,0,0,0));
	shape = new Rectangle(336,236,128,128);
    poly = new Polygon();
	poly.addPoint(320,220);
	poly.addPoint(350,200);
	poly.addPoint(450,200);
	poly.addPoint(480,220);
	poly.addPoint(420,400);
	poly.addPoint(400,390);
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:20,代码来源:GradientImageTest.java

示例3: init

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
    shapes = new ArrayList();
    rect = new Rectangle(10, 10, 100, 80);
    shapes.add(rect);
    roundRect = new RoundedRectangle(150, 10, 60, 80, 20);
    shapes.add(roundRect);
    ellipse = new Ellipse(350, 40, 50, 30);
    shapes.add(ellipse);
    circle = new Circle(470, 60, 50);
    shapes.add(circle);
    polygon = new Polygon(new float[]{550, 10, 600, 40, 620, 100, 570, 130});
    shapes.add(polygon);
    
    keys = new boolean[256];
    lastChar = new char[256];
    createPoly(200,200);
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:21,代码来源:ShapeTest.java

示例4: init

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	this.container = container;
	
	image = new Image("testdata/logo.tga", true);
	
	Image temp = new Image("testdata/palette_tool.png");
	container.setMouseCursor(temp, 0, 0);
	
	container.setIcons(new String[] {"testdata/icon.tga"});
	container.setTargetFrameRate(100);
	
	poly = new Polygon();
	float len = 100;
	
	for (int x=0;x<360;x+=30) {
		if (len == 100) {
			len = 50; 
		} else {
			len = 100;
		}
		poly.addPoint((float) FastTrig.cos(Math.toRadians(x)) * len, 
					  (float) FastTrig.sin(Math.toRadians(x)) * len);
	}
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:28,代码来源:GraphicsTest.java

示例5: Claymore

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
public Claymore(Particle p_) {
	super(p_, 0.0);
	
	this.explosion = AssetManager.getManager().getSound(Claymore.EXP_SOUND);
	
	float mTheta = theta - (float)(Math.PI / 2);
	float magX1 = (float)(Math.cos(mTheta - (SHRAPNEL_SPREAD / 2)) * EXP_RANGE);
	float magY1 = (float)(Math.sin(mTheta - (SHRAPNEL_SPREAD / 2)) * EXP_RANGE);
	float magX2 = (float)(Math.cos(mTheta + (SHRAPNEL_SPREAD / 2)) * EXP_RANGE);
	float magY2 = (float)(Math.sin(mTheta + (SHRAPNEL_SPREAD / 2)) * EXP_RANGE);
	this.collider = new Polygon(new float[] { position.x, position.y, 
											  (position.x + magX1), (position.y + magY1), 
											  (position.x + magX2), (position.y + magY2) 
											});
	
	this.shrapnel = new ArrayList<Projectile>();
	this.exploded = false;
	this.shrapnelCreated = false;
}
 
开发者ID:packetpirate,项目名称:Generic-Zombie-Shooter-Redux,代码行数:20,代码来源:Claymore.java

示例6: update

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
public static void update(int delta) {
	ArrayList<EntityBase> ingameEntites = IngameState.getInstance().entityManager.getIngameEntities();
	for(EntityBase entityCheck : ingameEntites) {
		if(entityCheck instanceof ICollisionDetection) {
			Polygon p1 = entityCheck.collisionShape;
			for(EntityBase entity : ingameEntites) {
				if(!entity.equals(entityCheck)) {
					Polygon p2 = entity.collisionShape;
					double d1 = p1.getBoundingCircleRadius();
					double d2 = p2.getBoundingCircleRadius();
					//uses the squared distance because sqrt is extremely expensive
					double distance = distanceSquaredBetweenPolygon(p1, p2);
					if(distance <= Math.pow(d1+d2, 2)) {
						((ICollisionDetection) entityCheck).onCollision(entity);
					}
				}
			}
		}
	}
}
 
开发者ID:thetorine,项目名称:sdd-major,代码行数:21,代码来源:CollisionDetector.java

示例7: update

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
/**
 * Creates a polygon at each step and checks if the user has the mouse over
 * it (using polygon.contains). If it does, set that polygon to
 * "mouseOver = true" which, in turn, will set "highlighted = true".
 * 
 * @param container
 * @param game
 * @param delta
 * @param mouseX
 * @param mouseY
 */
public void update(int delta, int mouseX, int mouseY) {

	// Creates the Polygon to check for the Mouse Over check
	polygon = new Polygon(new float[] { points[0] + xOffset,
			points[1] + yOffset, points[2] + xOffset, points[3] + yOffset,
			points[4] + xOffset, points[5] + yOffset, points[6] + xOffset,
			points[7] + yOffset });

	// Checks if the user has the mouse inside the Polygon (Tile)
	if (polygon.contains((float) mouseX / GameSystem.globalScale,
			(float) mouseY / GameSystem.globalScale)) {
		mouseOver = true;
		highlighted = true;
	} else {
		mouseOver = false;
	}
}
 
开发者ID:lucas-tulio,项目名称:awesome-game-store,代码行数:29,代码来源:GameTile.java

示例8: drawSolidPolygon

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
/**
 * @see org.jbox2d.callbacks.DebugDraw#drawSolidPolygon(org.jbox2d.common.Vec2[], int, org.jbox2d.common.Color3f)
 */
@Override
public void drawSolidPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
       
        int[] xInts = xIntsPool.get(vertexCount);
        int[] yInts = yIntsPool.get(vertexCount);
        Polygon p = new Polygon();
        
        
        for(int i=0; i<vertexCount; i++){
                getWorldToScreenToOut(vertices[i], temp);
                xInts[i] = (int)temp.x;
                yInts[i] = (int)temp.y;
                p.addPoint(xInts[i], yInts[i]);
        }
        
        g.setColor(new Color(color.x,color.y,color.z));
        g.fill(p); //Draws shape filled with colour
        g.setColor(Color.white);
        //drawPolygon(vertices, vertexCount, color);
}
 
开发者ID:Kairus101,项目名称:soccerRobots,代码行数:24,代码来源:Slick2dDebugDraw.java

示例9: Ship

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
public Ship(ShipFires fires) {

    this.speed = 0.5f;
    this.fires = fires;
    this.size = 0.4f;

    Transform t = Transform.createScaleTransform(size, size);
    this.shipPoly = AnimShip.getPolygon();
    this.shipPoly = (Polygon) shipPoly.transform(t);

    this.shipRec = new Rectangle(0, 0, 170, 343);
    Shape p = shipRec.transform(t);
    this.shipRec = new Rectangle(p.getX(), p.getY(), p.getWidth(), p.getHeight());
    this.shipPoly.setCenterX(shipRec.getCenterX());
    this.shipPoly.setCenterY(shipRec.getCenterY());

    this.anim_ship = new AnimShip();
  }
 
开发者ID:Hettomei,项目名称:SpaceInvaderSlick,代码行数:19,代码来源:Ship.java

示例10: processPoly

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
/**
 * Process the points in a polygon definition
 * 
 * @param poly The polygon being built
 * @param element The XML element being read
 * @param tokens The tokens representing the path
 * @return The number of points found
 * @throws ParsingException Indicates an invalid token in the path
 */
private static int processPoly(Polygon poly, Element element, StringTokenizer tokens) throws ParsingException {
	int count = 0;
	
	while (tokens.hasMoreTokens()) {
		String nextToken = tokens.nextToken();
		if (nextToken.equals("L")) {
			continue;
		}
		if (nextToken.equals("z")) {
			break;
		}
		if (nextToken.equals("M")) {
			continue;
		}
		if (nextToken.equals("C")) {
			return 0;
		}
		
		String tokenX = nextToken;
		String tokenY = tokens.nextToken();
		
		try {
			float x = Float.parseFloat(tokenX);
			float y = Float.parseFloat(tokenY);
			
			poly.addPoint(x,y);
			count++;
		} catch (NumberFormatException e) {
			throw new ParsingException(element.getAttribute("id"), "Invalid token in points list", e);
		}
	}
	
	return count;
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:44,代码来源:LineProcessor.java

示例11: createPoly

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
public void createPoly(float x, float y) {
	int size = 20;
	int change = 10;

	randomShape = new Polygon();
	// generate random polygon
	randomShape.addPoint(0 + (int)(Math.random() * change), 0 + (int)(Math.random() * change));
	randomShape.addPoint(size - (int)(Math.random() * change), 0 + (int)(Math.random() * change));
	randomShape.addPoint(size - (int)(Math.random() * change), size - (int)(Math.random() * change));
	randomShape.addPoint(0 + (int)(Math.random() * change), size - (int)(Math.random() * change));

	// center polygon
	randomShape.setCenterX(x);
	randomShape.setCenterY(y);
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:16,代码来源:ShapeTest.java

示例12: generateSpace

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
/**
 * So this is going to generate a quad space that holds that segments the
 * shapes into quads across the map. This makes it tunable and limits the number
 * of comparisons that need to be done for each shape
 * 
 * @param shapes The shapes to be segments
 * @param minx The minimum x value of the map
 * @param miny The mimimum y value of the map
 * @param maxx The maximum x value of the map
 * @param maxy The maximum y value of the map
 * @param segments The number of segments to split the map into
 */
private void generateSpace(ArrayList shapes, float minx, float miny, float maxx, float maxy, int segments) {
	quadSpace = new ArrayList[segments][segments];
	quadSpaceShapes = new Shape[segments][segments];
	
	float dx = (maxx - minx) / segments;
	float dy = (maxy - miny) / segments;
	
	for (int x=0;x<segments;x++) {
		for (int y=0;y<segments;y++) {
			quadSpace[x][y] = new ArrayList();
			
			// quad for this segment
			Polygon segmentPolygon = new Polygon();
			segmentPolygon.addPoint(minx+(dx*x), miny+(dy*y));
			segmentPolygon.addPoint(minx+(dx*x)+dx, miny+(dy*y));
			segmentPolygon.addPoint(minx+(dx*x)+dx, miny+(dy*y)+dy);
			segmentPolygon.addPoint(minx+(dx*x), miny+(dy*y)+dy);
			
			for (int i=0;i<shapes.size();i++) {
				Shape shape = (Shape) shapes.get(i);
				
				if (collides(shape, segmentPolygon)) {
					quadSpace[x][y].add(shape);
				}
			}
			
			quadSpaceShapes[x][y] = segmentPolygon;
		}
	}
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:43,代码来源:GeomUtilTileTest.java

示例13: init

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	poly = new Polygon();
	poly.addPoint(300, 100);
	poly.addPoint(320, 200);
	poly.addPoint(350, 210);
	poly.addPoint(280, 250);
	poly.addPoint(300, 200);
	poly.addPoint(240, 150);
	
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:14,代码来源:PolygonTest.java

示例14: init

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
/**
 * Perform the cut
 */
public void init() {
	Polygon source = new Polygon();
	source.addPoint(100,100);
	source.addPoint(150,80);
	source.addPoint(210,120);
	source.addPoint(340,150);
	source.addPoint(150,200);
	source.addPoint(120,250);
	this.source = source;
	
	circle = new Circle(0,0,50);
	rect = new Rectangle(-100,-40,200,80);
	star = new Polygon();
	
	float dis = 40;
	for (int i=0;i<360;i+=30) {
		dis = dis == 40 ? 60 : 40;
		double x = (Math.cos(Math.toRadians(i)) * dis);
		double y = (Math.sin(Math.toRadians(i)) * dis);
		star.addPoint((float) x, (float) y);
	}
	
	this.cut = circle;
	cut.setLocation(203,78);
	xp = (int) cut.getCenterX();
	yp = (int) cut.getCenterY();
	makeBoolean();
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:32,代码来源:GeomUtilTest.java

示例15: init

import org.newdawn.slick.geom.Polygon; //导入依赖的package包/类
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	container.getGraphics().setBackground(Color.white);
	
	curve = new Curve(p2,c2,c1,p1);
	poly = new Polygon();
	poly.addPoint(500,200);
	poly.addPoint(600,200);
	poly.addPoint(700,300);
	poly.addPoint(400,300);
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:14,代码来源:CurveTest.java


注:本文中的org.newdawn.slick.geom.Polygon类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。