/** * Create a new fill for a radial gradient * * @param shape The shape being filled * @param trans The transform given for the shape in the SVG * @param gradient The gradient to apply across the shape */ public RadialGradientFill(Shape shape, Transform trans, Gradient gradient) { this.gradient = gradient; radius = gradient.getR(); float x = gradient.getX1(); float y = gradient.getY1(); float[] c = new float[] {x,y}; gradient.getTransform().transform(c, 0, c, 0, 1); trans.transform(c, 0, c, 0, 1); float[] rt = new float[] {x,y-radius}; gradient.getTransform().transform(rt, 0, rt, 0, 1); trans.transform(rt, 0, rt, 0, 1); centre = new Vector2f(c[0],c[1]); Vector2f dis = new Vector2f(rt[0],rt[1]); radius = dis.distance(centre); }
/** * Create a new fill for gradients * * @param shape The shape being filled * @param trans The transform given for the shape * @param gradient The gradient to apply */ public LinearGradientFill(Shape shape, Transform trans, Gradient gradient) { this.gradient = gradient; float x = gradient.getX1(); float y = gradient.getY1(); float mx = gradient.getX2(); float my = gradient.getY2(); float h = my - y; float w = mx - x; float[] s = new float[] {x,y+(h/2)}; gradient.getTransform().transform(s, 0, s, 0, 1); trans.transform(s, 0, s, 0, 1); float[] e = new float[] {x+w,y+(h/2)}; gradient.getTransform().transform(e, 0, e, 0, 1); trans.transform(e, 0, e, 0, 1); start = new Vector2f(s[0],s[1]); end = new Vector2f(e[0],e[1]); line = new Line(start, end); }
/** * Get the value to use at a given time value * * @param t The time value (expecting t in [0,1]) * @return The value to use at the specified time */ public float getValue(float t) { // first: determine the segment we are in Vector2f p0 = (Vector2f) curve.get(0); for (int i = 1; i < curve.size(); i++) { Vector2f p1 = (Vector2f) curve.get(i); if (t >= p0.getX() && t <= p1.getX()) { // found the segment float st = (t - p0.getX()) / (p1.getX() - p0.getX()); float r = p0.getY() + st * (p1.getY() - p0.getY()); // System.out.println( "t: " + t + ", " + p0.x + ", " + p0.y // + " : " + p1.x + ", " + p1.y + " => " + r ); return r; } p0 = p1; } return 0; }
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { poly.addPoint(120, 120); poly.addPoint(420, 100); poly.addPoint(620, 420); poly.addPoint(300, 320); image = new Image("testdata/rocks.png"); texPaint = new TexCoordGenerator() { public Vector2f getCoordFor(float x, float y) { float tx = (texRect.getX() - x) / texRect.getWidth(); float ty = (texRect.getY() - y) / texRect.getHeight(); return new Vector2f(tx,ty); } }; }
/** * Draws text with a dropshadow * @param pos center position of the text */ private void drawTextWithDropShadow(Graphics g, Vector2f pos, String text, Color color) { // Reset Color back to the old when done Color old = g.getColor(); // Center Text float x = pos.x - g.getFont().getWidth(text) / 2; // TODO: maybe translucent background // Draw Dropshadow g.setColor(Color.black); g.drawString(text, x + 1, pos.y - 1); // Draw Text g.setColor(color); g.drawString(text, x, pos.y); g.setColor(old); }
/** * Renders the player to the screen * * @param x * the x position to render the player to * @param y * the y position to render the player to * @param g * the graphics context * @param viewerRole * the role of the one viewing this player */ public void draw(float x, float y, Graphics g, Role viewerRole) { if (Role.isRestriced(viewerRole) && "Fuzzi_Traitor.png".equals(texture)) { image = RessourceManager.loadImage("Fuzzi_Innocent.png"); } else image = RessourceManager.loadImage(texture); image.rotate(lookAngle - image.getRotation() + 90); image.draw(x, y); if (this.getInventory()[this.getCurrentWeapon()] != null) this.getInventory()[this.getCurrentWeapon()].draw(x, y); g.setColor(Color.black); g.drawRect(x, y - 12, 32, 8); g.setColor(Color.red); g.fillRect(x + 1, y - 11, lifepoints * 0.31f, 7); Vector2f v = new Vector2f(x + 16, y + 16); Vector2f v1 = new Vector2f(getLookAngle()).scale(130f); Vector2f v2 = v.copy().add(v1); g.drawLine(v.x, v.y, v2.x, v2.y); }
public Player(Vector2f position, Vector2f size, GameMode gameMode, int socketId) { super(position, size, gameMode); mSpeed = 1.5f; mMoving = false; mSocketId = socketId; // TODO REMOVE mStats.setInt(10); // To test the effect intel // END REMOVE /* ProjectileEntity e = new ProjectileEntity(this, mPosition, new Vector2f(25, 25), gameMode); e.setSkinId(2); ProjectileActivableSkill s = new ProjectileActivableSkill(0, mGameMode, "Fireball", "Send a fireball on your enemies!", e); s.setCaster(this); addSkill(s); RandomEntity toSpawn = new RandomEntity(new Vector2f(500, 500), new Vector2f(64, 64), 10, mGameMode); toSpawn.setEnd(20); toSpawn.setSpeed(1.5f); toSpawn.setSkinId(1); InvokeSkill s2 = new InvokeSkill(1, mGameMode, "Random Invoke", "Invoke the 'random' creature.", toSpawn); s2.setCaster(this); addSkill(s2); HealingSpell s3 = new HealingSpell(2, mGameMode, "Healing spell", "Add a heal effect on an entity"); s3.setCaster(this); addSkill(s3);*/ mUseAStar = false; }
private Vector2f getCollisionPoint(Line ray) { ArrayList<Vector2f> collisionPoints = new ArrayList<>(); for (Line l : map.getCollisionLines()) { Vector2f collisionPoint = l.intersect(ray, true); if (collisionPoint != null) { collisionPoints.add(collisionPoint); } } Vector2f point = ray.getEnd(); for (Vector2f pointOfCollision : collisionPoints) { if (point == null || thePlayer.getPos().distance(point) > thePlayer.getPos().distance(pointOfCollision)) point = pointOfCollision; } return point; }
/** Create a new Gorilla * @param pos the gorillas center position */ public Gorilla(Vector2f pos) { super("Gorilla"); if (!Game.getInstance().isTestMode()) { Image[] frames = new Image[] { Assets.loadImage(Assets.Images.GORRILA_LEFT), Assets.loadImage(Assets.Images.GORRILA), Assets.loadImage(Assets.Images.GORRILA_RIGHT) }; component = new AnimationRenderComponent(frames, ANIMATION_SPEED / FRAME_LENGTH, frames[0].getWidth(), frames[0].getHeight(), true); addComponent(component); } else { // In Test Mode set the size explicitly since we don't have a renderer setSize(new Vector2f(37, 42)); } setPosition(pos); }
@Before public void setUp() { adapter = new GorillasTestAdapterExtended2(); buildingCoordinates = new ArrayList<Vector2f>(); buildingCoordinates.add(new Vector2f(0, 570)); // Gorillas should have a width of 37 and a height of 42 in testing // mode. (This is the size of the given gorilla image.) // That is why the gorilla y coordinate in this case has to be 549. leftGorillaCoordinate = new Vector2f(50, 549); rightGorillaCoordinate = new Vector2f(950, 549); adapter.rememberGameData(); }
private AStarNode searchPath(Vector2f dest, int availableIterations) { AStarNode node = mNodes.poll(); if (node != null && availableIterations > 0) { for (Vector2f movement : mMovements) { mPositionToStudy.x = node.getPosition().x + movement.x; mPositionToStudy.y = node.getPosition().y + movement.y; Rectangle rect = new Rectangle(mPositionToStudy.x, mPositionToStudy.y, mEntity.getBounds().getWidth(), mEntity.getBounds().getHeight()); if (!mMap.isSomethingBlocking(rect)) { AStarNode newNode = new AStarNode(node, mPositionToStudy); if (newNode.getPosition().equals(dest)) { return newNode; } if (!nodeIsVisisted(newNode)) { mVisitedNodes.add(newNode); mNodes.add(newNode); } } } return (this.searchPath(dest, availableIterations - 1)); } return null; }
@Override public void init(GameContainer gc, StateBasedGame game) throws SlickException { // Load All Static Content or Ressources (Background Images, Sounds etc) // Lazy Load the UI, this is better for the TestGameContainer if (!Game.getInstance().isTestMode()) { background = Assets.loadImage(Assets.Images.GAMEPLAY_BACKGROUND); float scaleFactor = (float) Gorillas.CANVAS_WIDTH / background.getWidth(); Game.CANVAS_SCALE = scaleFactor; if(Game.CANVAS_SCALE != 1) background = background.getScaledCopy(Game.CANVAS_SCALE); arrow = Assets.loadImage(Assets.Images.ARROW); explosionSound = Assets.loadSound(Assets.Sounds.EXPLOSION); buffer = new Image(Gorillas.CANVAS_WIDTH, Gorillas.CANVAS_HEIGHT); } SCREEN = new Vector2f(gc.getWidth(), gc.getHeight()); }
@Override public void update(GameMode game, GameContainer container, int delta) { if (mTarget == null) { mTarget = Main.game.getGameMode().getEntitiesManager().getPlayerEntity(); return; } Vector2f targetPos = mTarget.getPosition(); float diffX = mCurrentPosition.x - targetPos.x; float diffY = mCurrentPosition.y - targetPos.y; float maxX = container.getWidth() / 2 * FREE_SQUARE_RATIO; float maxY = container.getHeight() / 2 * FREE_SQUARE_RATIO; if (diffX > maxX) { mCurrentPosition.x = targetPos.x + maxX; } else if (diffX < -maxX) { mCurrentPosition.x = targetPos.x - maxX; } if (diffY > maxY) { mCurrentPosition.y = targetPos.y + maxY; } else if (diffY < -maxY) { mCurrentPosition.y = targetPos.y - maxY; } }
/** * @see org.newdawn.slick.geom.TexCoordGenerator#getCoordFor(float, float) */ public Vector2f getCoordFor(float x, float y) { float u = centre.distance(new Vector2f(x,y)); u /= radius; if (u > 0.99f) { u = 0.99f; } return new Vector2f(u,0); }
/** * @see org.newdawn.slick.geom.TexCoordGenerator#getCoordFor(float, float) */ public Vector2f getCoordFor(float x, float y) { Vector2f result = new Vector2f(); line.getClosestPoint(new Vector2f(x,y), result); float u = result.distance(start); u /= line.length(); return new Vector2f(u,0); }
/** * Create an XML element based on a configured value * * @param document * The document the element will be part of * @param name * The name to give the new element * @param value * The configured value * @return A configure XML element based on the value */ private static Element createValueElement(Document document, String name, ConfigurableEmitter.Value value) { Element element = document.createElement(name); // void: now writes the value type if (value instanceof SimpleValue) { element.setAttribute("type", "simple"); element.setAttribute("value", "" + value.getValue(0)); } else if (value instanceof RandomValue) { element.setAttribute("type", "random"); element .setAttribute("value", "" + ((RandomValue) value).getValue()); } else if (value instanceof LinearInterpolator) { element.setAttribute("type", "linear"); element.setAttribute("min", "" + ((LinearInterpolator) value).getMin()); element.setAttribute("max", "" + ((LinearInterpolator) value).getMax()); element.setAttribute("active", "" + ((LinearInterpolator) value).isActive()); ArrayList curve = ((LinearInterpolator) value).getCurve(); for (int i = 0; i < curve.size(); i++) { Vector2f point = (Vector2f) curve.get(i); Element pointElement = document.createElement("point"); pointElement.setAttribute("x", "" + point.x); pointElement.setAttribute("y", "" + point.y); element.appendChild(pointElement); } } else { Log.warn("unkown value type ignored: " + value.getClass()); } return element; }
/** * Convert the list of the given CurvePoint * * @param curve The list of points to convert * @return The new list of points in Point2D format */ private ArrayList convertToPoint2DCurve(ArrayList curve) { ArrayList bla = new ArrayList(); for (int j = 0; j < curve.size(); j++) { CurvePoint c = (CurvePoint) curve.get(j); bla.add(new Vector2f(c.getX(), c.getY())); } return bla; }
/** * Convert a point 2d curve into a curve point curve * * @param point2DCurve The list of points to convert * @return The list of points in CurvePoint format */ private ArrayList convertToCurvePointCurve(ArrayList point2DCurve) { ArrayList curvePointCurve = new ArrayList(); for (int j = 0; j < point2DCurve.size(); j++) { Vector2f c = (Vector2f) point2DCurve.get(j); curvePointCurve.add(new CurvePoint(c.getX(), c.getY())); } return curvePointCurve; }
private void initWorld(int w, int h) { floor = new boolean[w][h]; walls = new boolean[w][h]; item = new boolean[w][h]; saw = new boolean[w][h]; tiles = new Image[w][h]; clear(); Generator g = new Generator(w, h); g.generate(this); // set world limit setWidth(w * G.TILE_SIZE * 10); setHeight(h * G.TILE_SIZE * 10); // init gui gui = new Gui(this); // set camera camera = new Camera(this, G.playerEntity, container.getWidth(), container.getHeight(), 400, 400, new Vector2f(32, 32)); camera.setFollow(G.playerEntity); G.world = this; pathFinder = new AStarPathFinder(this, 100, false); if (G.currentLevel == 1) { gui.addMessage("Welcome to CryptoRl 2 !"); } alphaMap = ResourceManager.getImage("light"); }
private void translateNodesToPath(AStarNode node, List<Vector2f> path) { if (node.getParent() != null) { node.getPosition().x += mEntity.getBounds().getWidth() / 2; node.getPosition().y += mEntity.getBounds().getHeight() / 2; path.add(node.getPosition()); this.translateNodesToPath(node.getParent(), path); } }
@Override public void update(long delta) { if (!mMoving) { // System.out.println("Initial pos: " + mPosition.x + ", " + mPosition.y); float posX = Main.random.nextInt(mGameMode.getGameInstance().getMap().getTmxMap().getWidth()) * mGameMode.getGameInstance().getMap().getTmxMap().getTilewidth(); float posY = Main.random.nextInt(mGameMode.getGameInstance().getMap().getTmxMap().getHeight()) * mGameMode.getGameInstance().getMap().getTmxMap().getTileheight(); goTo(posX, posY); // System.out.println("GOING TO " + posX + " " + posY); ((ActivableSkill)mSkills.get(0)).activate(new Vector2f(300, 300)); } super.update(delta); }
private void renderShadows(Graphics g) { ArrayList<Vector2f> points = new ArrayList<>(); ArrayList<Shape> shapes = new ArrayList<>(map.getCollisionShapes()); shapes.add(new Rectangle(0, 0, background.getWidth(), background.getHeight())); for (Shape s : shapes) { float[] shapePoints = s.getPoints(); for (int i = 0; i < shapePoints.length; i += 2) { Vector2f poi = new Vector2f(shapePoints[i], shapePoints[i + 1]); Vector2f[] cPoints = getCollisionPoints(g, poi); points.addAll(Arrays.asList(cPoints)); } } ShadowPointComparator spComparator = new ShadowPointComparator(thePlayer.getCenter()); points.sort(spComparator); points.add(points.get(0)); for (int i = 0; i < points.size() - 1; i++) { Polygon p = new Polygon(); p.addPoint(points.get(i).x, points.get(i).y); p.addPoint(points.get(i + 1).x, points.get(i + 1).y); p.addPoint(thePlayer.getCenter().x, thePlayer.getCenter().y); g.fill(p); } }
@Test public void testHigherGravityInfluence() { Vector2f nextPosition1_1 = adapter.getNextShotPosition(new Vector2f(0, 400), 45, 80, 0, 10, true, 200); Vector2f nextPosition1_2 = adapter.getNextShotPosition(new Vector2f(0, 400), 45, 80, 0, 20, true, 200); assertTrue("If the gravity is doubled a throw with apart from that same paramatrization should not fly as far as before anymore.", nextPosition1_2.y - nextPosition1_1.y > 0); }
/** * Initialize the test */ @Before public void init() { sg = new SaboteurGame(); sp = new SPPlayer(0, Role.INNOCENT, "TestPlayer", 100, new Vector2f(100, 100), ""); sg.setMainPlayer(sp); }