本文整理汇总了Java中org.newdawn.slick.geom.Vector2f类的典型用法代码示例。如果您正苦于以下问题:Java Vector2f类的具体用法?Java Vector2f怎么用?Java Vector2f使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Vector2f类属于org.newdawn.slick.geom包,在下文中一共展示了Vector2f类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RadialGradientFill
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
/**
* 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);
}
示例2: LinearGradientFill
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
/**
* 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);
}
示例3: getValue
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
/**
* 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;
}
示例4: init
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
/**
* @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);
}
};
}
示例5: drawTextWithDropShadow
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
/**
* 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);
}
示例6: draw
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
/**
* 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);
}
示例7: Player
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
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;
}
示例8: getCollisionPoint
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
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;
}
示例9: Gorilla
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
/** 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);
}
示例10: setUp
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
@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();
}
示例11: searchPath
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
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;
}
示例12: init
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
@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());
}
示例13: update
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
@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;
}
}
示例14: getCoordFor
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
/**
* @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);
}
示例15: getCoordFor
import org.newdawn.slick.geom.Vector2f; //导入依赖的package包/类
/**
* @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);
}