/** * @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); }
/** * Ellenfelek frissítő metódusa. Feladata a játékos pozíciója alapján meghatározni a mozgás irányát. * * @param delta * Legutóbbi frissítés óta eltelt idő. */ public void updateEnemy(int delta) { Circle pC = FieldDirector.sharedFieldDirector().playerCircle(); float angle = FieldDirector.calculateAngleForTwoPoints(outline, pC); float sX = speedX*((float)Math.sin(((-angle)*Math.PI/180))); float sY = speedY*((float)Math.cos(((-angle)*Math.PI/180))); if (sX >= 0) { goRightBy(delta*sX, false); } else { goLeftBy(-delta*sX, false); } if (sY >= 0) { goDownBy(delta*sY, false); } else { goUpBy(-delta*sY, false); } // kép forgatása image.rotate(delta*rotation); }
/** * Statikus tagfüggvény az ütközésvizsgálat lebonyolításához. */ static void runCollisionDetection(ArrayList<BaseObject> objectList) { // TODO János int length = objectList.size(); for (int i = 0; i < length; i++) { for (int j = i+1; j < length; j++) { BaseObject object1 = objectList.get(i); BaseObject object2 = objectList.get(j); Circle rect1 = object1.outline(); Circle rect2 = object2.outline(); /*System.out.println("rect1: " + rect1.getX() + " " + rect1.getY() + " " + rect1.getWidth() + " " + rect1.getHeight()); System.out.println("rect2: " + rect2.getX() + " " + rect2.getY() + " " + rect2.getWidth() + " " + rect2.getHeight()); System.out.println();*/ if (rect1.intersects(rect2)) { // System.out.println("!!!!!!!"); object1.collidedWithObject(object2); object2.collidedWithObject(object1); } } } }
/** * Két pont közötti elfordulási szöget kiszámoló függvény. * * @param base * Bázispont. * @param target * Célpont. * @return Bázispont és célpont közötti elfordulási szög fokban. */ public static float calculateAngleForTwoPoints(Circle base, Circle target) { float px = base.getCenterX(); float py = base.getCenterY(); float ex = target.getCenterX(); float ey = target.getCenterY(); float angle = 0; if (px < ex && py < ey) { angle = -(float) (Math.atan(Math.abs(px - ex) / Math.abs(py - ey)) * 180 / Math.PI); } else if (px < ex && py > ey) { angle = (float) (Math.atan(Math.abs(px - ex) / Math.abs(py - ey)) * 180 / Math.PI) - 180.0f; } else if (px > ex && py > ey) { angle = -(float) (Math.atan(Math.abs(px - ex) / Math.abs(py - ey)) * 180 / Math.PI) - 180.0f; } else if (px > ex && py < ey) { angle = (float) (Math.atan(Math.abs(px - ex) / Math.abs(py - ey)) * 180 / Math.PI) - 360.0f; } return angle; }
/** * 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(); }
@Override public void render(GameContainer container, Graphics g) throws SlickException { if (faceRight) { setGraphic(imgRight); } else { setGraphic(imgLeft); } // g.drawImage(ResourceManager.getImage(G.SHADOW), x, y); super.render(container, g); if (invisible) { currentImage.drawFlash(x, y, currentImage.getWidth(), currentImage.getHeight(), Color.gray); } // steps if (!isCollide(x + 32, y)) { g.drawImage(ResourceManager.getImage("step"), x + 32, y); } if (!isCollide(x - 32, y)) { g.drawImage(ResourceManager.getImage("step"), x - 32, y); } if (!isCollide(x, y + 32)) { g.drawImage(ResourceManager.getImage("step"), x, y + 32); } if (!isCollide(x, y - 32)) { g.drawImage(ResourceManager.getImage("step"), x, y - 32); } if (ME.debugEnabled) { PlayerEntity target = G.playerEntity; int tx = (int) (target.x + G.TILE_SIZE / 2); int ty = (int) (target.y + G.TILE_SIZE / 2); Circle circle = new Circle(tx, ty, G.sight * G.TILE_SIZE); g.draw(circle); } }
public void render(GameContainer gameContainer, StateBasedGame stateBasedGame, Graphics g) throws SlickException { if (this.gameController != null) { this.gameController.drawGameMap(g); this.gameController.drawGamePlayers(g); this.gameController.drawGameShots(g); if (GlobalVariable.debug == true) { // debug if (this.gameController.getCollisionController() != null) { g.setColor(Color.red); for (int i = 0; i < this.gameController.getCollisionController().getCollisionObjects().size(); ++i) { CollisionObject current = this.gameController.getCollisionController().getCollisionObjects().get(i); if (current.isAlive()) { g.draw(current.getShape()); } } } //debug if (CurrentUser.isInGame()) { g.setColor(Color.red); g.drawRect(this.gameController.getPlayer(CurrentUser.getId()).getTank().getTankState().getGraphicalX() - 2, this.gameController.getPlayer(CurrentUser.getId()).getTank().getTankState().getGraphicalY() - 2, 5, 5); g.drawRect(this.gameController.getPlayer(CurrentUser.getId()).getTank().getTankState().getGraphicalX(), this.gameController.getPlayer(CurrentUser.getId()).getTank().getTankState().getGraphicalY(), 1, 1); g.drawRect(this.gameController.getPlayer(CurrentUser.getId()).getTank().getTankState().getX() - 2, this.gameController.getPlayer(CurrentUser.getId()).getTank().getTankState().getY() - 2, 5, 5); g.drawRect(this.gameController.getPlayer(CurrentUser.getId()).getTank().getTankState().getX(), this.gameController.getPlayer(CurrentUser.getId()).getTank().getTankState().getY(), 1, 1); g.draw(new Circle(this.gameController.getPlayer(CurrentUser.getId()).getTank().getTankState().getX(), this.gameController.getPlayer(CurrentUser.getId()).getTank().getTankState().getY(), this.gameController.getPlayer(CurrentUser.getId()).getTank().getTankWeapon().getMaxRangeShot())); } g.setColor(Color.darkGray); for (Pair<Integer, Integer> pos : this.mousePos) { g.drawRoundRect(pos.getV1() - 1, pos.getV2() - 1, 3, 3, 50); } } } this.gameOverlay.draw(g); }
public Bullet(Vector2f initPos){ this.position = initPos.copy(); this.dir = new Vector2f(0, -2); this.shape = new Circle(this.position.x, this.position.y, 5); this.fill = new GradientFill(-10, -10, Color.white, 10, 10, Color.white, true); this.isDestroyed = false; }
public void drawGrid(Graphics g, int to) { String sign = Parameters.getParams().hemisphere ? "+" : "-"; for (int i = 80; i >= to; i -= 10) { float radius = (float) Math.cos(Math.toRadians(i)); Circle c = new Circle(centre.x, centre.y, radius * scale); g.setColor(new Color(51, 102, 255, 100)); g.draw(c); g.setColor(new Color(51, 102, 255, 220)); g.drawString(sign + i, centre.x + radius * scale + 2f, centre.y); } }
@Override public void renderEntity(Graphics g) { float nx = posX; float ny = posY; int textureIndex = (this.getHp() < this.getMaxHp() / 2) ? 1 : 0; this.sheet.getSubImage(0, textureIndex).draw(nx, ny); // Draw bounding box if debug mode is on if (Main.DEBUG_MODE) { g.setLineWidth(2); g.setColor(owner.playerColor); g.draw(boundingBox); g.setLineWidth(1); } // Draw range circle if (this.isSelected) { Circle c = new Circle(this.getPosition().getX(), this.getPosition().getY(), this.attack.getMaxRange() * 24); g.setColor(Color.yellow); g.draw(c); } // Render repairing wrench if (this.repairIconBlink) { repairImage.draw(this.boundingBox.getX() + this.boundingBox.getWidth() / 2 - repairImage.getWidth() / 2, this.boundingBox.getY() + this.boundingBox.getHeight() / 2 - repairImage.getHeight() / 2); } }
@Override public void renderEntity(Graphics g) { float nx = posX; float ny = posY; int textureIndex = (this.getHp() < this.getMaxHp() / 2) ? this.CORRUPTED_OFFSET + this.currentFrame : this.currentFrame; this.sheet.getSubImage(0, textureIndex).draw(nx, ny); // Draw bounding box if debug mode is on if (Main.DEBUG_MODE) { g.setLineWidth(2); g.setColor(owner.playerColor); g.draw(boundingBox); g.setLineWidth(1); } // Draw range circle if (this.isSelected) { Circle c = new Circle(this.getPosition().getX(), this.getPosition().getY(), this.attack.getMaxRange() * 24 - this.autoTarget.RANGE_TOLERANCE); g.setColor(Color.yellow); g.draw(c); } // Render repairing wrench if (this.repairIconBlink) { repairImage.draw(this.boundingBox.getX() + this.boundingBox.getWidth() / 2 - repairImage.getWidth() / 2, this.boundingBox.getY() + this.boundingBox.getHeight() / 2 - repairImage.getHeight() / 2); } }
public void drawCYCircles(Graphics g) { g.setColor(Color.gray); g.setLineWidth(2); for (EntityBuilding eb : this.player.getBase().getBuildings()) { if (eb instanceof EntityConstructionYard) { Circle c = new Circle(eb.getTileX() + (eb.sizeWidth / 2), eb.getTileY() + (eb.sizeHeight / 2), Base.BUILDING_CY_RANGE * 24); g.draw(c); } } g.setLineWidth(1); }
/** * Inicializáló konstruktor. Fontos, hogy nem minden tagváltozó kap használható értéket a hívásakor. Az animation * objektumot később kell inicializálni. * @param x Objektum x koordinátája. * @param y Objektum y koordinátája. * @param t Objektum típusa. */ public BaseObject(float x, float y, ObjectType t) { type = t; outline = new Circle(0, 0, DEFAULT_RADIUS); outline.setX(x); outline.setY(y); // az aniation alapértelmezetten null! image = null; }
/** * A pályán lévő ellenségek közül kiválasztja a legközelebbi ellenfelet. Ez * lesz az autómatikus célzórendszer célpontja. */ private boolean findClosestEnemy() { if (enemyList.isEmpty()) { targetEnemy = null; System.out.println("Target enemy NOT found!"); return false; } if (enemyList.size() == 1) { targetEnemy = enemyList.get(0); // System.out.println("Target enemy found!"); return true; } int targetIndex = 0; float min = 800.0f; Circle pC = playerCircle(); float px = pC.getCenterX(); float py = pC.getCenterY(); for (int i = 0; i < enemyList.size(); i++) { Enemy enemy = enemyList.get(i); Circle eC = enemy.outline(); float ex = eC.getCenterX(); float ey = eC.getCenterY(); float tempMin = (float) Math.sqrt(Math.pow(Math.abs(ex - px), 2) + Math.pow(Math.abs(ey - py), 2)); if (tempMin < min) { min = tempMin; targetIndex = i; } } targetEnemy = enemyList.get(targetIndex); // System.out.println("Target enemy found!"); return true; }
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { g.setColor(Color.white); g.drawString("Red indicates a collision, green indicates no collision", 50, 420); g.drawString("White are the targets", 50, 435); g.pushTransform(); g.translate(100,100); g.pushTransform(); g.translate(-50,-50); g.scale(10, 10); g.setColor(Color.red); g.fillRect(0,0,5,5); g.setColor(Color.white); g.drawRect(0,0,5,5); g.popTransform(); g.setColor(Color.green); g.fillRect(20,20,50,50); g.popTransform(); g.setColor(Color.white); g.draw(rect); g.draw(circle); g.setColor(rect1.intersects(rect) ? Color.red : Color.green); g.draw(rect1); g.setColor(rect2.intersects(rect) ? Color.red : Color.green); g.draw(rect2); g.setColor(roundRect.intersects(rect) ? Color.red : Color.green); g.draw(roundRect); g.setColor(circle1.intersects(rect) ? Color.red : Color.green); g.draw(circle1); g.setColor(circle2.intersects(rect) ? Color.red : Color.green); g.draw(circle2); g.setColor(circle3.intersects(circle) ? Color.red : Color.green); g.fill(circle3); g.setColor(circle4.intersects(circle) ? Color.red : Color.green); g.draw(circle4); g.fill(roundRect2); g.setColor(Color.blue); g.draw(roundRect2); g.setColor(Color.blue); g.draw(new Circle(100,100,50)); g.drawRect(50,50,100,100); }
public Turret(Particle p) { super(p, 0.0); this.fireSound = AssetManager.getManager().getSound(Turret.FIRE_SOUND); this.collider = new Circle(position.x, position.y, 36.0f); this.lerp = null; this.target = null; this.health = Turret.HEALTH_MAX; this.projectiles = new ArrayList<Projectile>(); this.created = p.getCreated(); this.lastProjectile = 0L; }
/** * Cria um c�rculo ao redor do ponto piv�. * @param point */ protected void createHookCircle(Vec2 point) { this.hookCircle = new Circle(point.x + HOOK_CIRCLE_RADIUS, point.y + HOOK_CIRCLE_RADIUS, HOOK_CIRCLE_RADIUS); this.waitTime = 0; }
public Circle getShape(){ return shape; }
public Circle getVision() { return mVision; }
/** * Collidable interfész megvalósítása. */ public Circle outline() { return outline; }
/** * Automatikus célzásnál beállítja a célpont koordinátáit. Ha meghívódik, beindítja az automatikus célzási rendszert, * ami a játékoshoz hasonlóan beállítja a a forgást úgy, hogy a legközelebbi ellenfélre mutasson a célkereszt mindig. * @param targetCircle */ public void setTargetPosition(Circle targetCircle) { autoAim = true; targetAngle = FieldDirector.calculateAngleForTwoPoints(outline, targetCircle); }