// Metodo que devuelve una textura de un Arraylist cada X tiempo (intervalTime). private Texture SwapTextureFromArray( ArrayList<Texture> list, int startIndex, long startTime, float intervalTime) { Texture img = null; if (startIndex < list.size()) { Music sound = soundsList.get(startIndex); if (TimeUtils.timeSinceMillis(startTime) < intervalTime * 1000) { img = list.get(startIndex); if (startIndex < titlesList.size()) { imageTitle.ChangeFontText(titlesList.get(startIndex)); } if (!soundPlayed) { System.out.println("Playing music"); sound.play(); soundPlayed = true; } } else { if (!sound.isPlaying()) { actualImgIndex++; beginTime = TimeUtils.millis(); img = list.get(startIndex); imageTitle.ChangeFontText(titlesList.get(startIndex)); System.out.println("Music finished"); soundPlayed = false; } } } else { img = list.get(texturesList.size() - 1); } return img; }
@Override public void render(SpriteBatch sb) { delta = (TimeUtils.millis() - startTime + 700) / 1000; tweenManager.update(delta); bgManager.render(sb); sb.setProjectionMatrix(camera.combined); sb.begin(); backButton.render(sb); randomCardButton.draw(sb); rareCardButton.draw(sb); Fonts.MFont.draw( sb, "Cost: " + randomCardCost, randomCardButton.getX(), randomCardButton.getY() - 40); Fonts.MFont.draw( sb, "Cost: " + rareCardCost, rareCardButton.getX(), rareCardButton.getY() - 40); Fonts.MFont.draw( sb, currGold, MainGame.WIDTH - Fonts.MFont.getBounds(currGold).width - 40, MainGame.HEIGHT - 50); if (showingCard) { sb.draw(alpha, 0, 0, MainGame.WIDTH, MainGame.HEIGHT); purchasedCard.render( new Vector2( MainGame.WIDTH / 2 - (Card.WIDTH / 2 * cardAnimSprite.getScaleX()), MainGame.HEIGHT / 2 - (Card.HEIGHT / 2 * cardAnimSprite.getScaleX())), cardAnimSprite.getScaleX(), sb); unlockedText.draw(sb); } sb.end(); }
@Override public void create() { ShaderProgram.pedantic = false; String vs = Gdx.files.internal("signed/vertex.glsl").readString(); String fs = Gdx.files.internal("signed/fragment.glsl").readString(); shader = new ShaderProgram(vs, fs); if (!shader.isCompiled()) { throw new IllegalArgumentException( "Error compiling distance field shader: " + shader.getLog()); } mesh = new Mesh(true, 4, 6, new VertexAttribute(VertexAttributes.Usage.Position, 3, "a_position")); float[] vertices = {1, -1, 0, 1, 1, 0, -1, 1, 0, -1, -1, 0}; short[] indices = { 0, 1, 2, 2, 3, 0 }; mesh.setVertices(vertices); mesh.setIndices(indices); startTime = TimeUtils.millis(); }
@Override public void show() { Gdx.input.setInputProcessor(stage); beginTime = TimeUtils.millis(); actualImgIndex = 0; stage = new Stage(); SetupShowStage(); }
private void renderCase() { printSelected(); for (int i = 0; i < 4; i++) { number[i] = rand.nextInt(9) + 1; selected[i] = false; } int num1 = rand.nextInt(4); int num2 = (num1 + rand.nextInt(3) + 1) % 4; answer = number[num1] + number[num2]; caseStartTime = TimeUtils.millis(); }
@Override public void combat_action_1() { float x = direction * Constants.ENEMY_SPEED; float y = amplitude * Math.round(((Math.sin(half_period * body.getPosition().x) * Constants.ENEMY_SPEED))); if (avoidUp && body.getPosition().y < Utils.convertToBox(Constants.WORLD_HEIGHT - 2 * Constants.ENEMY_HEIGHT)) { avoidUp = false; } else if (avoidDown && body.getPosition().y > Utils.convertToBox( GameScreen.cannon.getPosition().y + Utils.convertToBox(Constants.ENEMY_HEIGHT) * 7)) { avoidDown = false; } else if (body.getPosition().y > Utils.convertToBox(Constants.WORLD_HEIGHT) || avoidUp) { y = -1f; avoidUp = true; } else if (body.getPosition().y < GameScreen.cannon.getPosition().y + Utils.convertToBox(Constants.ENEMY_HEIGHT) * 10 || avoidDown) { y = 1f; avoidDown = true; } Vector2 velocity = new Vector2(x, y); body.setLinearVelocity(velocity); if (body.getPosition().x <= Utils.convertToBox(-Constants.ENEMY_WIDTH)) { direction = 1; } if (body.getPosition().x >= Utils.convertToBox((Constants.ENEMY_WIDTH) + Constants.WORLD_WIDTH)) { direction = -1; } if (TimeUtils.millis() - lastFiring > (Math.random() + 10) * MAX_CHARGING) { fire(); lastFiring = (double) TimeUtils.millis(); } }
public void update(AlienSpawner as, float dt) { // Find the closest alien Alien closest = null; float closest_dy = -1, closest_dx = -1; for (Alien alien : as.aliens) { float dy = 480 - alien.getY(); float dx = alien.getMidX() - getMidX(); if (Math.abs(dy) <= Math.abs(closest_dy) || closest_dy == -1) { closest_dy = dy; if (Math.abs(dx) < Math.abs(closest_dx) || closest_dx == -1) { closest_dx = dx; closest = alien; } } alien.unhighlight(); } if (closest != null) { closest.highlight(); float d = closest_dx; float k = 0.05f; float f = k * d; float mass = 10.0f; float accel = f / mass; v += accel; if (v > 0) { v = Math.min(v, max_speed); } else { v = Math.max(v, -max_speed); } double time = TimeUtils.millis(); if (time - last_shot >= shot_cooldown) { if (Math.abs(closest_dx) < (getWidth() / 2 - closest.getWidth() / 2)) { GameEventEmitter.trigger("fire_defender_weapon"); last_shot = time; } } } v *= 0.8; setX(getX() + v); // Make sure the defender stays within the screen bounds if (getX() < 0) setX(0); if (getX() > 800 - getWidth()) setX(800 - getWidth()); }
public static void accumulateTimeStep() { double newTime = TimeUtils.millis() / 1000.0; double frameTime = Math.min(newTime - currentTime, 0.25f); float deltaTime = (float) frameTime; currentTime = newTime; accumulator += deltaTime; // System.out.println("Accumulator / TimeStep: "+(float) accumulator / Physics.TIMESTEP); // interpolation // interpolateTimeStep((float) accumulator / Physics.TIMESTEP); }
private void updateInit() { if (Gdx.input.justTouched()) { game.camera.unproject(touchPosition.set(Gdx.input.getX(), Gdx.input.getY(), 0)); for (int i = 0; i < 4; i++) { if (blockBounds[i].contains(touchPosition.x, touchPosition.y)) { gameState = GameState.Action; selected[i] = true; } } Gdx.app.log(TAG, "updateInit"); printSelected(); } caseStartTime = TimeUtils.millis(); }
@Override public void update() { if (Gdx.input.justTouched()) { touch = MainGame.camera.unprojectCoordinates(Gdx.input.getX(), Gdx.input.getY()); if (showingCard) { TweenCallback myCallBack = new TweenCallback() { @Override public void onEvent(int type, BaseTween<?> source) { purchasedCard = null; showingCard = false; } }; Tween.to(cardAnimSprite, SpriteAccessor.SCALE_XY, 10f) .target(0.001f, 0.001f) .ease(TweenEquations.easeNone) .setCallback(myCallBack) .setCallbackTriggers(TweenCallback.END) .start(tweenManager); startTime = TimeUtils.millis(); } else { if (backButton.checkTouch(touch)) { SoundManager.play(Assets.CLICK); ScreenManager.setScreen(new MainMenuScreen()); } else if (randomCardButton.checkTouch(touch)) { long myGold = MainGame.userStats.getPlayerGold(); if (myGold >= randomCardCost) { MainGame.userStats.addGold(-randomCardCost); purchasedCard = CardCreator.createCard((int) (Math.random() * MainGame.numberOfCards + 1)); MainGame.userStats.getPlayerCardList().insert(0, purchasedCard.getID()); MainGame.saveManager.saveDataValue("PLAYER", MainGame.userStats); currGold = "Gold: " + MainGame.userStats.getPlayerGold(); Tween.to(cardAnimSprite, SpriteAccessor.SCALE_XY, 10f) .target(1.5f, 1.5f) .ease(TweenEquations.easeNone) .start(tweenManager); startTime = TimeUtils.millis(); showingCard = true; } } else if (rareCardButton.checkTouch(touch)) { long myGold = MainGame.userStats.getPlayerGold(); if (myGold >= rareCardCost) { MainGame.userStats.addGold(-rareCardCost); purchasedCard = CardCreator.createCard((int) (Math.random() * MainGame.numberOfCards + 1)); MainGame.userStats.getPlayerCardList().insert(0, purchasedCard.getID()); MainGame.saveManager.saveDataValue("PLAYER", MainGame.userStats); currGold = "Gold: " + MainGame.userStats.getPlayerGold(); Tween.to(cardAnimSprite, SpriteAccessor.SCALE_XY, 10f) .target(1.5f, 1.5f) .ease(TweenEquations.easeNone) .start(tweenManager); startTime = TimeUtils.millis(); showingCard = true; } } } } bgManager.update(); }
@Override public void OnUse(Bob bob, float x, float y, float angle) { // TODO Auto-generated method stub super.OnUse(bob, x, y, angle); if (bob.Grabbed && flag && Gdx.input.justTouched()) { Grabbed = false; parentinv.getOwnerBob().Grabbed = false; parentinv.getOwnerBob().Grablen = 0; // grappleGfx.deleted = true; isUpdating = false; isShooting = false; len = 0; parentinv.getOwnerBob().LastUsed = TimeUtils.millis(); // Vector2 vel = // parentinv.getOwnerBob().LastPos.sub(parentinv.getOwnerBob().bounds.x,parentinv.getOwnerBob().bounds.y); // vel.x *= parentinv.getOwnerBob().omega * 100; // vel.y *= parentinv.getOwnerBob().omega * 100; parentinv .getOwnerBob() .vel .set(parentinv.getOwnerBob().Xspeed * 50, parentinv.getOwnerBob().Yspeed * 50); parentinv.getOwnerBob().Swinging = true; parentinv.getOwnerBob().omega = 0; return; } if (flag && Gdx.input.justTouched()) { float x0 = Gdx.input.getX(0); float y0 = Gdx.graphics.getHeight() - Gdx.input.getY(0); float x2 = parentinv.getOwnerBob().pos.x + 0.5f; float y2 = parentinv.getOwnerBob().pos.y + 0.5f; angle2 = angle; // Gdx.app.debug("", ""+dist*Math.cos(angle) + " " +dist*Math.sin(angle)); if (grappleGfx == null || grappleGfx.deleted) { isShooting = true; bob.Grabber = this; bob.firstShot = true; } else { /* int i = MapRenderer.CurrentRenderer.ToDraw.indexOf(grappleGfx); Vector3 pos = new Vector3(); pos.x = Gdx.input.getX(0); pos.y = Gdx.input.getY(0); MapRenderer.CurrentCam.unproject(pos); MapRenderer.CurrentRenderer.ToDraw.get(i).x = x2-2; MapRenderer.CurrentRenderer.ToDraw.get(i).y = y2-2; Pixmap map = new Pixmap(32,32, Format.Alpha); map.setColor(0,255,0,180); map.drawPixel((int)magX, (int)magY); magX += Math.cos(angle); magY += Math.sin(angle); */ // Gdx.app.debug("", ""+magX + " "+magY); // MapRenderer.CurrentRenderer.ToDraw.get(i).texture = new Texture(map); // MapRenderer.CurrentRenderer.ToDraw.get(i).Height += 0.2f; // MapRenderer.CurrentRenderer.ToDraw.get(i).Width = 0.3f; } } }
public static long getTime() { check(); return prefs.getLong(Consts.PREF_TIME, TimeUtils.millis()); }