protected Entity createBullet (float x, float y, float vx, float vy, float angle, int exps) { Entity bullet = create(true); bullet.add(type, sprite, opos, pos, vel, radius, expires); Canvas canvas = graphics().createCanvas(5, 2); canvas.setFillColor(0xFFFFFFFF).fillRect(0, 0, 5, 2); ImageLayer layer = new ImageLayer(canvas.toTexture()); layer.setOrigin(2.5f, 1); layer.setRotation(angle); int id = bullet.id; type.set(id, BULLET); sprite.set(id, layer); opos.set(id, x, y); pos.set(id, x, y); vel.set(id, vx, vy); radius.set(id, 2); expires.set(id, exps); return bullet; }
protected Entity createAsteroid (Size sz, float x, float y, float vx, float vy) { Entity ast = create(true); ast.add(type, size, sprite, opos, pos, vel, spin, radius); float side = sz.size; int iidx = rando.getInt(8); float ah = asteroids.height(); ImageLayer layer = new ImageLayer(asteroids.region(iidx*ah, 0, ah, ah)); layer.setOrigin(ah/2, ah/2); layer.setScale(side/ah); layer.setRotation(rando.getFloat(MathUtil.TAU)); int id = ast.id; type.set(id, ASTEROID); size.set(id, sz); sprite.set(id, layer); spin.set(id, rando.getInRange(-MAXSPIN, MAXSPIN)); opos.set(id, x, y); pos.set(id, x, y); vel.set(id, vx, vy); radius.set(id, side*0.425f); return ast; }
protected Entity createShip (float x, float y) { Entity ship = create(true); ship.add(type, sprite, opos, pos, vel, spin, radius); Canvas canvas = graphics().createCanvas(30, 20); Path path = canvas.createPath(); path.moveTo(0, 0).lineTo(30, 10).lineTo(0, 20).close(); canvas.setFillColor(0xFFCC99FF).fillPath(path); ImageLayer layer = new ImageLayer(canvas.toTexture()); layer.setOrigin(15, 10); layer.setRotation(-MathUtil.HALF_PI); int id = ship.id; type.set(id, SHIP); sprite.set(id, layer); opos.set(id, x, y); pos.set(id, x, y); vel.set(id, 0, 0); radius.set(id, 10); return ship; }
@Override public void init() { Image orange = game.assets.getImage("images/orange.png"); ImageLayer l1 = new ImageLayer(orange); game.rootLayer.addAt(l1.setScale(2).setRotation(FloatMath.PI/8), 50, 50); l1.events().connect(new Mover(l1).listener(game.input)); ImageLayer l2 = new ImageLayer(orange); game.rootLayer.addAt(l2.setScale(1.5f).setRotation(FloatMath.PI/4), 150, 50); l2.events().connect(new Mover(l2).listener(game.input)); Image mdb = game.assets.getRemoteImage("https://www.samskivert.com/images/headshot.jpg"); ImageLayer l3 = new ImageLayer(mdb); game.rootLayer.addAt(l3.setRotation(-FloatMath.PI/4), 50, 150); l3.events().connect(new Mover(l3).listener(game.input)); String l4url = "https://www.samskivert.com/images/2012/12/spellwood-app-icon.png"; game.net.req(l4url).execute().onSuccess(rsp -> { try { Image icon = rsp.payloadImage(new Scale(2)); ImageLayer l4 = new ImageLayer(icon); game.rootLayer.addAt(l4.setRotation(FloatMath.PI/4), 150, 150); l4.events().connect(new Mover(l4).listener(game.input)); } catch (Exception e) { game.log.warn("Failed to decode image: " + e); } }).onFailure(t -> game.log.warn("Failed to load image: " + l4url, t)); }
i1.setRotation(elapsed * FloatMath.PI/2); s1.setRotation(elapsed * FloatMath.PI/2); g2.setWidth(Math.round(Math.abs(100 * FloatMath.sin(elapsed)))); inner.setOrigin(FloatMath.sin(elapsed * 2f) * 50, FloatMath.cos(elapsed * 2f) * 50);