Java Code Examples for com.badlogic.gdx.utils.TimeUtils

The following are top voted examples for showing how to use com.badlogic.gdx.utils.TimeUtils. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: StarshipFighters   File: IntroState.java   View source code 6 votes vote down vote up
@Override
public void init() {
	
	// Timer
	timer = TimeUtils.millis();
	
	// Strings
	segaPathname = "data/audio/sound/Sega.wav";
	segaSoundName = "Sega Sound";
	segaLogoPathName = "data/background/segalogo.png";
	
	// Start Sound
	soundManager = gsm.getGame().getSoundManager();
	soundManager.addSound(segaPathname, segaSoundName);
	
	// Texture
	texture = new Texture(Gdx.files.internal(segaLogoPathName));
	
	// Play Sound
	soundManager.playSound(segaSoundName, 1.0f);
}
 
Example 2
Project: StarshipFighters   File: BasicAlien.java   View source code 6 votes vote down vote up
private void init() {

		// Start Shooting
		bulletCooldown = TimeUtils.millis();
		enemyBulletSpeed = 5;
		randomAttackCooldown = MathUtils.random(200, 1000);
		
		// Drop Chance | 10% chance
		dropChance = MathUtils.random(0, 9);

		// Start Sprites
		allTexture = new Texture(Gdx.files.internal(pathName));
		TextureRegion[][] tmp = TextureRegion.split(allTexture, allTexture.getWidth() / 3, allTexture.getHeight() / 1);
		rolls = new TextureRegion[3];
		for (int i = 0; i < rolls.length; i++) {
			rolls[i] = tmp[0][i];
		}

		// Start rectangle
		collisionBounds = new Rectangle(x, y, allTexture.getWidth() / 3, allTexture.getHeight());
	}
 
Example 3
Project: school-game   File: SaveData.java   View source code 6 votes vote down vote up
/**
 * Speichert die Daten in die Spieldatei.
 *
 * @param slot der Slot in den gespeichert werden soll. Wenn null, wird der letzte Slot verwendet
 *
 * @see SaveData#load()
 */
public void save(Slot slot)
{
    if (slot == null)
        slot = this.slot;
    else
        this.slot = slot;

    if (this.slot == null) return;

    playTime += TimeUtils.timeSinceMillis(startTime);

    prefs.putString(slot.name() + PLAYER_NAME, playerName);
    prefs.putBoolean(slot.name() + MALE, male);
    prefs.putLong(slot.name() + PLAY_TIME, playTime);
    prefs.putString(slot.name() + LEVEL_NAME, levelName);
    prefs.putString(slot.name() + LEVEL_ID, levelId);
    prefs.flush();

    startTime = TimeUtils.millis();

}
 
Example 4
Project: guitar-finger-trainer   File: TrainingScreen.java   View source code 6 votes vote down vote up
TrainingScreen(GftGame game) {
    this.game = game;

    this.guiCam = new OrthographicCamera(800, 480);
    this.guiCam.position.set(800 / 2, 480 / 2, 0);

    this.backBounds = new Rectangle(7, 432, 48, 48);
    this.playPauseBounds = new Rectangle(7, 7, 48, 48);
    this.restartBounds = new Rectangle(62, 7, 48, 48);
    this.backFowardtBounds = new Rectangle(127, 7, 48, 48);
    this.soundBounds = new Rectangle(192, 7, 48, 48);
    this.minusBounds = new Rectangle(590, 7, 48, 48);
    this.plusBounds = new Rectangle(699, 7, 48, 48);

    this.touchPoint = new Vector3();

    this.grid = new Grid(this.game);
    this.grid.loadTraining();

    this.bottomBar = new BottomBar(this.game);

    this.firstRun = 3;
    this.lastUpdateTime = TimeUtils.millis();
    this.bpm = MINUTE_IN_MILLIS / SettingsUtil.bpm;
}
 
Example 5
Project: cykacommander   File: CykaSplashScreen.java   View source code 6 votes vote down vote up
@Override
public void render(float delta) {
    Gdx.gl.glClearColor(0.845f, 0.845f, 0.845f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    game.batch.begin();
    game.batch.draw(appLogo, viewport.getWorldWidth()/2 - 60, viewport.getWorldHeight()/2 - 60, 120, 120);
    Color color = game.batch.getColor();
    color.a = 0.4f;
    game.batch.setColor(color);
    game.batch.draw(samukiLogo, viewport.getWorldWidth()/2-32, 32, 64, 64);
    game.batch.draw(updateText, viewport.getWorldWidth()/2-198, viewport.getWorldHeight()-100, 396, 42);
    color.a = 1f;
    game.batch.setColor(color);
    game.batch.end();

    if (TimeUtils.millis()>(startTime+1250))
        game.setScreen(new MenuScreen(game));
    stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1/30f));
    stage.draw();
}
 
Example 6
Project: Undertailor   File: AnimatedTile.java   View source code 6 votes vote down vote up
@Override
public void render(float x, float y) {
    long runtime = TimeUtils.timeSinceMillis(AnimatedTile.origin) % length;
    long duration = 0;
    Sprite frame = null;
    for (int i = 0; i < this.frames.size; i++) {
        Tuple<Long, Sprite> key = this.frames.get(i);
        duration += key.getA();
        frame = key.getB();
        if (duration > runtime) {
            break;
        }
    }

    if (frame != null) {
        frame.render(x, y);
    }
}
 
Example 7
Project: TheFreeBird   File: Bird.java   View source code 6 votes vote down vote up
public void recalculateDinamicFlyingPoints(){
    float wingY;
    if (isGlyding())
        wingY = wingLT.y;
    else {
        float dinamicValue = (wingLT.y - wingLB.y) * (1.3f*MathUtils.cos(MathUtils.PI2 * TimeUtils.timeSinceNanos(nanotimeAnimationStart) / BIRD_NANOTIME_FRAME));
        wingY = wingLB.y - dinamicValue;
    }
    wingLB.set(wingLT).add(-0.5f * BIRD_SCALE, -2.2f * BIRD_SCALE);
    wingRB.set(wingRT).add(0.5f * BIRD_SCALE, -2.2f * BIRD_SCALE);

    wingLL.set(wingLT.x - 6f * BIRD_SCALE, wingY);
    wingRR.set(wingRT.x + 6f * BIRD_SCALE, wingY);

    tailL.set(position.x - 3f * BIRD_SCALE, position.y + 5.5f * BIRD_SCALE);
    tailR.set(position.x + 3f * BIRD_SCALE, position.y + 5.5f * BIRD_SCALE);
}
 
Example 8
Project: TheFreeBird   File: Bird.java   View source code 6 votes vote down vote up
private void transformFoodToEnergyAndPoop() {
    if ((TimeUtils.timeSinceMillis(timeCounterFoodTransform) > BIRD_FOOD_DIGEST_TIME) && (food > 0))
    {
        if (energy < BIRD_ENERGY_MAX){
            energy += BIRD_ENERGY_ADD;
            if (energy > BIRD_ENERGY_MAX)
                energy = BIRD_ENERGY_MAX;
        }
        if (poop < BIRD_POOP_MAX)
            poop++;
        else
            dropPoop();
        timeCounterFoodTransform = TimeUtils.millis();
        food--;
    }
}
 
Example 9
Project: TheFreeBird   File: Caterpillar.java   View source code 6 votes vote down vote up
public Caterpillar(ShapeRenderer renderer, Vector2 position,boolean facingRight) {
    super(renderer, position, facingRight);
    float x = position.x - 4 *CATERPILLAR_TIGHT_RADIUS;
    float y = position.y;

    circles = new Array<Circle>();
    for ( int i = 0 ; i< CATERPILLAR_CIRCLES_NUMBER; i++) {
        circles.add(new Circle(x, y, CATERPILLAR_RADIUS));
        x += 2 * CATERPILLAR_TIGHT_RADIUS;
    }

    if (facingRight) {
        velocity.set(CATERPILLAR_SPEED_X, 0f);
    }
    else{
        velocity.set(-CATERPILLAR_SPEED_X, 0f);
    }

    nanotimeAnimationStart = TimeUtils.nanoTime();

    eye = new Vector2();
}
 
Example 10
Project: TheFreeBird   File: Caterpillar.java   View source code 6 votes vote down vote up
public void updateCircles(){

        float x = position.x - 4 *CATERPILLAR_TIGHT_RADIUS;
        float ydelta = CATERPILLAR_Y_DELTA *
                MathUtils.cos(MathUtils.PI2 *
                        TimeUtils.timeSinceNanos(nanotimeAnimationStart)/CATERPILLAR_NANOTIME_FRAME);
        float y = position.y + ydelta;


        for ( int i = 0 ; i< CATERPILLAR_CIRCLES_NUMBER; i++) {
            circles.get(i).setPosition(x, y);
            x += 2 * CATERPILLAR_TIGHT_RADIUS;
            ydelta = - ydelta;
            y = position.y + ydelta;
        }
    }
 
Example 11
Project: TheFreeBird   File: Cat.java   View source code 6 votes vote down vote up
public Cat(ShapeRenderer renderer, Boolean facingRight) {

        super(renderer, new Vector2(), facingRight);

        if (facingRight) {
            position.set(CAT_START_X_LEFT, CAT_Y);

            velocity.set(CAT_SPEED_X, 0f);
        }
        else{
            position.set(CAT_START_X_RIGHT, CAT_Y);
            velocity.set(-CAT_SPEED_X, 0f);
        }

        catCreateMillis = TimeUtils.millis();
        circle = new Circle(0,0, CAT_HEAD_RADIUS);
        rectangle = new Rectangle(0,0, CAT_BODY_LENGTH, CAT_BODY_WIDTH);
        update(0);
    }
 
Example 12
Project: TempoGDX   File: TapTempoCalculator.java   View source code 6 votes vote down vote up
public Integer tap() {
  if (currentClearTask != null) {
    currentClearTask.cancel();
  }

  currentClearTask = Timer.schedule(clearTask, clearInterval);

  if (tapTimes.size() == numberOfTaps) {
    tapTimes.remove(0);
  }

  tapTimes.add(TimeUtils.nanoTime());

  long sum = 0;
  if (tapTimes.size() > 1) {
    for (int i = 1; i < tapTimes.size(); i++) {
      sum += tapTimes.get(i) - tapTimes.get(i - 1);
    }
    float averageSeconds = sum / (tapTimes.size() - 1) / 1000000000f;
    int bpm = (int) (60f / averageSeconds);
    return bpm;
  } else {
    return null;
  }
}
 
Example 13
Project: Inspiration   File: PathFinderQueue.java   View source code 6 votes vote down vote up
@Override
public void run (long timeToRun) {
	// Keep track of the current time
	requestControl.lastTime = TimeUtils.nanoTime();
	requestControl.timeToRun = timeToRun;

	requestControl.timeTolerance = TIME_TOLERANCE;
	requestControl.pathFinder = pathFinder;
	requestControl.server = this;

	// If no search in progress, take the next from the queue
	if (currentRequest == null) currentRequest = requestQueue.read();

	while (currentRequest != null) {

		boolean finished = requestControl.execute(currentRequest);

		if (!finished) return;

		// Read next request from the queue
		currentRequest = requestQueue.read();
	}
}
 
Example 14
Project: origin   File: ModelManager.java   View source code 6 votes vote down vote up
public void loadModelList()
{
	File file = Gdx.files.internal("assets/objects.json").file();
	try
	{
		ModelDesc[] list = _gson.fromJson(new FileReader(file), ModelDesc[].class);
		for (ModelDesc item : list)
		{
			item._lastUsage = TimeUtils.millis();
			_modelList.put(item._typeId, item);
		}
	}
	catch (FileNotFoundException e)
	{
		_log.error("objects config not found", e);
		System.exit(-1);
	}
}
 
Example 15
Project: ud405   File: BouncingBall.java   View source code 6 votes vote down vote up
public void update(float delta, Viewport viewport) {

        float secondsSinceLastKick = MathUtils.nanoToSec * (TimeUtils.nanoTime() - lastKick);

        if (secondsSinceLastKick > KICK_INTERVAL) {
            lastKick = TimeUtils.nanoTime();
            randomKick();
        }

        // Drag is proportional to the current velocity
        velocity.x -= delta * DRAG * velocity.x;
        velocity.y -= delta * DRAG * velocity.y;

        position.x += delta * velocity.x;
        position.y += delta * velocity.y;
        radius = RADIUS_FACTOR * Math.min(viewport.getWorldWidth(), viewport.getWorldHeight());

        collideWithWalls(radius, viewport.getWorldWidth(), viewport.getWorldHeight());
    }
 
Example 16
Project: practicos   File: Bullets.java   View source code 6 votes vote down vote up
public void fallenBulletSpawn(){

 for(int i =0;i<monsters.getMonsters().size ;i++){
  if(monsters.getMonsters().get(i) != null && monsters.getMonsters().size != 0){
	  
	  int probability = MathUtils.random(0,800);
	
	  if(probability < 5){	 
			float locX = monsters.getMonsters().get(i).getMonstersOutline().getX()+ monsters.getMonster().getTexture().getWidth()/2;
		 	float locY = monsters.getMonsters().get(i).getMonstersOutline().getY();		
		 	bullet1 = new Bullet(bluebullet, 100, locX,locY);
		 	
		 	fallenBullets.add(bullet1);
		 	lastBulletTime= TimeUtils.nanoTime();
	 		}
		}
 		}
	}
 
Example 17
Project: NoRiskNoFun   File: DiceRollScene.java   View source code 5 votes vote down vote up
/**
 * Roll all dice and update their results
 */
private void diceRoll() {
    Random rnd = new Random(TimeUtils.nanoTime());

    // generate a random number from 1-6
    for (int i = 0; i < data.getAvailableDice(); i++) {
        rollResults[i] = rnd.nextInt(6) + 1;
    }
}
 
Example 18
Project: NoRiskNoFun   File: DiceRollScene.java   View source code 5 votes vote down vote up
/**
 * "Animate" the dice roll
 */
private void randomizeDice() {
    Random rnd = new Random();
    rnd.setSeed(TimeUtils.nanoTime());

    for (int i = 0; i < data.getAvailableDice(); i++) {
        dieObjects.get(i).setDieNumber(rnd.nextInt(6) + 1);
    }
}
 
Example 19
Project: NoRiskNoFun   File: DiceRollScene.java   View source code 5 votes vote down vote up
@Override
public void render(float delta) {

    // set hasBeenShaken to true once hasShaken() registered, so the if statement
    // continues to the animation/result even if device isn't moving anymore
    if ((hasShaken() || hasBeenShaken) && canRoll) {


        // only update if it hasn't been shaken in the last 2 seconds
        if (TimeUtils.millis() - lastShakeTime > 5000) {
            diceRoll();
            lastShakeTime = TimeUtils.millis();
            hasBeenShaken = true;
        }

        // randomize results for 2 seconds after a shake
        if (TimeUtils.millis() - lastShakeTime < 2000) {
            randomizeDice();
        } else {
            showRollResult();
            hasBeenShaken = false;
            canRoll = false;
        }
    }

    super.render(delta);
}
 
Example 20
Project: FlappyChapa   File: PlayState.java   View source code 5 votes vote down vote up
public PlayState(GameStateManager gsm) {
        super(gsm);
        score = 0;
        chapa = new Chapa(50, 300);
        camera.setToOrtho(false, FlappyChapa.WIDTH / 2, FlappyChapa.HEIGHT / 2);
        Texture texture = new Texture("bg.png");
        backGround = new org.academiadecodigo.bootcamp.sprites.Background(camera);
        backGround.start();
        ground = new Texture("ground.png");
        /*table = new Table();
        table.setPosition(camera.position.x,camera.position.y);
        //table.setBounds(camera.position.x,camera.position.y,camera.viewportWidth,camera.viewportHeight/10);
        table.setFillParent(true);*/
        scoreLabel = new Label(String.format("%06d", score), new Label.LabelStyle(new BitmapFont(), Color.WHITE));
        scoreLabel.setPosition(camera.position.x,0);
        startTime = TimeUtils.nanoTime();
        anto = new Anto(camera);
//        groundPos1 = new Vector2(camera.position.x - camera.viewportWidth / 2, GROUND_Y_OFFSET);
//        groundPos2 = new Vector2((camera.position.x - camera.viewportWidth / 2) + ground.getWidth(), GROUND_Y_OFFSET);
        tubes = new Array<Tube>();
        for (int i = 0; i < TUBE_COUNT; i++) {
            tubes.add(new Tube(i * (TUBE_SPACING + Tube.TUBE_WIDTH)));
        }

        music = Gdx.audio.newMusic(Gdx.files.internal("bigSmoke_justAudio.mp3"));
        music.setLooping(true);
        music.setVolume(0.5f);
        music.play();
    }
 
Example 21
Project: Klooni1010   File: TimeScorer.java   View source code 5 votes vote down vote up
public TimeScorer(final Klooni game, GameLayout layout) {
    super(game, layout, Klooni.getMaxTimeScore());
    highScore = Klooni.getMaxTimeScore();

    Label.LabelStyle labelStyle = new Label.LabelStyle();
    labelStyle.font = game.skin.getFont("font");
    timeLeftLabel = new Label("", labelStyle);
    timeLeftLabel.setAlignment(Align.center);
    layout.updateTimeLeftLabel(timeLeftLabel);

    startTime = TimeUtils.nanoTime();
    deadTime = startTime + START_TIME;

    pausedTimeLeft = -1;
}
 
Example 22
Project: Klooni1010   File: TimeScorer.java   View source code 5 votes vote down vote up
@Override
public void resume() {
    if (pauseTime != 0L) {
        long difference = TimeUtils.nanoTime() - pauseTime;
        startTime += difference;
        deadTime += difference;

        pauseTime = 0L;
        pausedTimeLeft = -1;
    }
}
 
Example 23
Project: Klooni1010   File: MoneyBuyBand.java   View source code 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    long now = TimeUtils.millis();
    if (now > nextTextUpdate) {
        interpolateText();
        nextTextUpdate = TimeUtils.millis() + SHOW_ONE_CHARACTER_EVERY;
        if (now > nextTempRevertUpdate && showingTemp) {
            // We won't be showing temp anymore if the current money is shown
            showCurrentMoney();
        }
    }
    setColor(Klooni.theme.bandColor);
    infoLabel.setColor(Klooni.theme.textColor);
    super.draw(batch, parentAlpha);
}
 
Example 24
Project: StarshipFighters   File: PlayState.java   View source code 5 votes vote down vote up
@Override
public void init() {

	// Start Game Objects
	shipBullets = new Array<PlayerBullets>();
	enemyBulletList = new Array<EnemyBullets>();
	player = new Player(300, 150, 0, 0, shipBullets, this);
	basicAliens = new Array<GameObjects>();
	explosionList = new Array<Explosion>();
	itemList = new Array<Item>();
	collisionHandling = new CollisionHandling(this);

	// Start Level
	levelLoader = new Level("data/levels/testmap.tmx", this);
	for (int i = 0; i < levelLoader.getEnemyArray().size; i++) {
		basicAliens.add(new BasicAlien(levelLoader.getEnemyArray().get(i).x, levelLoader.getEnemyArray().get(i).y, 0, -5, 1000L, -15, getEnemyBulletList(), -20, this));
	}

	// Start the HUD
	// 0 = Health Bar
	allHUDElements = new HUD[1];
	allHUDElements[0] = new HealthBar(10, 760, 200, 25, true);

	// Timers
	deathTimer = TimeUtils.millis();
	
	// Audio
	soundManager = getGSM().getGame().getSoundManager();
	musicManager = getGSM().getGame().getMusicManager();

}
 
Example 25
Project: StarshipFighters   File: Level1.java   View source code 5 votes vote down vote up
public Level1(Array<GameObjects> enemyList, int levelNumber, PlayState playState) {
	super(enemyList, playState.getExplosionList(), playState.getEnemyBulletList(), levelNumber, playState);

	// Get lists
	this.enemyList = enemyList;
	this.levelNumber = levelNumber;
	this.playState = playState;

	// Start Background
	initializeBackground();

	// Update Timer
	timeSinceLevelBegan = TimeUtils.millis();
	waveTimer = TimeUtils.millis();

	// Initialize the switches
	gameplaySwitch = new boolean[20];
	for (int i = 0; i < gameplaySwitch.length; i++) {
		gameplaySwitch[i] = false;
	}
	gameplaySwitch[0] = true;
	switchCounter = 0;

	// Start Music
	startMusic();

}
 
Example 26
Project: StarshipFighters   File: IntroState.java   View source code 5 votes vote down vote up
@Override
public void update(float dt) {
	
	// Move Next state after Sega
	if (TimeUtils.timeSinceMillis(timer) > 3000) {
		gsm.setState(GameStateManager.MENU);
		soundManager.removeSound(segaSoundName);
	}
	
}
 
Example 27
Project: StarshipFighters   File: Player.java   View source code 5 votes vote down vote up
public Player(float x, float y, float dx, float dy, Array<PlayerBullets> listOfBullets, PlayState playState) {
	super(x, y, dx, dy);
	
	// GamePlay
	this.x = x;
	this.y = y;
	this.dx = dx;
	this.dy = dy;
	this.listOfBullets = listOfBullets;
	this.playState = playState;
	bulletcooldown = TimeUtils.millis();

	// Graphics
	pathname = "data/spaceships/ship1.png";
	animationFrameDuration = 1f/40f;
	
	// SFX
	this.playState = playState;
	soundManager = playState.getGSM().getGame().getSoundManager();
	bulletShotSoundPathName = "data/audio/sound/Basic Shot.wav";
	bulletShotSoundName = "Shoot1";

	// Limits
	maxSpeed = 4;
	//friction = 5;
	minimumSpeed = -4;
	bulletSpeed = 15;
	bulletShootSpeed = 200;

	// Start Player Loading
	init();
	
}
 
Example 28
Project: StarshipFighters   File: BasicAlien.java   View source code 5 votes vote down vote up
public void update(float dt, boolean xWrap, boolean yWrap) {

		// Update Movement
		x += dx;
		y += dy;
		collisionBounds.set(x, y, (96f / 3f), 33);

		// Movement Limits
		moveDownward();
		setLimits();

		// Wraps
		if (xWrap) {
			wrapXBound();
		}

		if (yWrap) {
			wrapYBound();
		}

		// Update Shoot | Don't shoot if out of the screen
		if (TimeUtils.timeSinceMillis(bulletCooldown) > randomAttackCooldown && x < Game.WIDTH && x > 0
				&& y < Game.HEIGHT && y > 0) {
			addEnemyBullets(16, 0);
			randomAttackCooldown = MathUtils.random(1000, 2000);
		}
		
		// Drop Items
		dropItems();

	}
 
Example 29
Project: StarshipFighters   File: SamusShipBoss.java   View source code 5 votes vote down vote up
private void shootBullets() {
	// Shoot Bullets
	// Right Wing
	if (!isRightWingDead && rightWingHealth > 0) {
		if (TimeUtils.timeSinceMillis(bulletCooldownRight) > randomAttackCooldownRight && x < Game.WIDTH && x > 0
				&& y < Game.HEIGHT && y > 0) {
			addBossBullets(175, 0);
			randomAttackCooldownRight = MathUtils.random(200, 1000);
			bulletCooldownRight = TimeUtils.millis();
		}
	}

	// Left Wing
	if (!isLeftWingDead && leftWingHealth > 0) {
		if (TimeUtils.timeSinceMillis(bulletCooldownLeft) > randomAttackCooldownLeft && x < Game.WIDTH && x > 0
				&& y < Game.HEIGHT && y > 0) {
			addBossBullets(20, 0);
			randomAttackCooldownLeft = MathUtils.random(200, 1000);
			bulletCooldownLeft = TimeUtils.millis();
		}
	}

	// Both Wings have died
	if (isLeftWingDead && isRightWingDead && getHP() > 0) {
		if (TimeUtils.timeSinceMillis(bulletCooldown) > randomAttackCooldown && x < Game.WIDTH && x > 0
				&& y < Game.HEIGHT && y > 0) {
			addBossBullets(98, 30);
			randomAttackCooldown = MathUtils.random(200, 800);
			bulletCooldown = TimeUtils.millis();
		}
	}
}
 
Example 30
Project: StarshipFighters   File: SamusShipBoss.java   View source code 5 votes vote down vote up
private void checkWingStatus() {
	// Check if Wings are dead
	if (rightWingHealth <= 0 && !isRightWingDead) {
		if (TimeUtils.timeSinceMillis(rightWingExplosionTimer) > 200 && rightWingExplosionCounter < 10) {
			// Add delayed explosions
			explosionList.add(new Explosion((x + 148) + MathUtils.random(-48, 48), y, 48, height, playState));
			rightWingExplosionTimer = TimeUtils.millis();
			rightWingExplosionCounter++;
		}

		// Kill Right Wing
		if (rightWingExplosionCounter == 10) {
			setRightWingDead(true);
		}
	}

	if (leftWingHealth <= 0 && !isLeftWingDead) {
		if (TimeUtils.timeSinceMillis(leftWingExplosionTimer) > 200 && leftWingExplosionCounter < 10) {
			// Add delayed explosions
			explosionList.add(new Explosion(x + MathUtils.random(-48, 48), y, 48, height, playState));
			leftWingExplosionTimer = TimeUtils.millis();
			leftWingExplosionCounter++;
		}

		// Kill Left Wing
		if (leftWingExplosionCounter == 10) {
			setLeftWingDead(true);
		}
	}

	// If Both wings are dead, then set middle to be vulnerable
	if (isLeftWingDead && isRightWingDead && isMiddleInvincible) {
		isMiddleInvincible = false;
	}
}
 
Example 31
Project: StarshipFighters   File: SamusShipBoss.java   View source code 5 votes vote down vote up
private void checkMiddleHP() {
	if (healthbar < 0) {
		dx = 0;
		dy = 0;
		if (TimeUtils.timeSinceMillis(bossDeathExplosionTimer) > 200 && bossDeathExplosionCounter < 15) {
			// Add delayed explosions
			explosionList.add(new Explosion(x + (0.5f * MathUtils.random(0, width)),
					(y + (0.5f * MathUtils.random(0, height))), width, height, playState));
			bossDeathExplosionTimer = TimeUtils.millis();
			bossDeathExplosionCounter++;
			isDead = true;
		}
	}
}
 
Example 32
Project: StarshipFighters   File: SamusShipBoss.java   View source code 5 votes vote down vote up
private void spawnEnemies() {
	// Check if its been 5 seconds
	if (TimeUtils.timeSinceMillis(timeSinceBattleBegan) > 5000 && healthbar > 0) {
		listOfAliens.add(new BasicAlien(x + (width / 2), y + (height / 2), 3, 0, 1000L, -15, enemyBullets, -20, playState));
		listOfAliens.add(new BasicAlien(x + (width / 2), y + (height / 2), -3, 0, 1000L, -15, enemyBullets, -20, playState));
		timeSinceBattleBegan = TimeUtils.millis();
		soundManager.playSound(bossSpawnSoundName, 1f);
	}

}
 
Example 33
Project: school-game   File: SaveData.java   View source code 5 votes vote down vote up
/**
 * Lädt die Daten aus der Speicherdatei.
 *
 * @see SaveData#save(Slot)
 */
public void load()
{
    startTime = TimeUtils.millis();

    if (this.slot == null) return;
    
    playerName = prefs.getString(slot.name() + PLAYER_NAME, "");
    male = prefs.getBoolean(slot.name() + MALE, false);
    playTime = prefs.getLong(slot.name() + PLAY_TIME, 0);
    levelName = prefs.getString(slot.name() + LEVEL_NAME, "");
    levelId = prefs.getString(slot.name() + LEVEL_ID, "");
}
 
Example 34
Project: school-game   File: Player.java   View source code 5 votes vote down vote up
/**
 * Regiert auf das Drücken einer Taste.
 *
 * Startet eine Attacke oder führt eine Interaktion durch.
 *
 * @param keycode der Tastencode der Taste
 * @return true, wenn auf das Ereignis reagiert wurde
 */
public boolean keyDown(int keycode)
{
    InputManager.Action action = InputManager.checkGameAction(keycode);

    if (action == InputManager.Action.ATTACK && attackSword <= 0f)
    {
        // Attacke
        attackStart = TimeUtils.millis();
        return true;
    }
    else if (action == InputManager.Action.INTERACTION && attackStart == -1)
    {
        // Interaktion
        if (interactionCallback != null)
            interactionCallback.run();

        return true;
    }
    else if (cheatManager.isHealthControlled() && action == InputManager.Action.CHEAT_DAMAGE)
    {
        applyDamage(10);
        return true;
    }
    else if (cheatManager.isHealthControlled() && action == InputManager.Action.CHEAT_HEAL)
    {
        heal(15);
        return true;
    }

    return false;
}
 
Example 35
Project: school-game   File: Player.java   View source code 5 votes vote down vote up
/**
 * Regiert auf das Loslassen einer Taste.
 *
 * Führt die Attacke nach dem Loslassen der entsprechenden Taste durch.
 *
 * @param keycode der Tastencode der Taste
 * @return true, wenn auf das Ereignis reagiert wurde
 */
public boolean keyUp(int keycode)
{
    InputManager.Action action = InputManager.checkGameAction(keycode);

    if (action == InputManager.Action.ATTACK && attackStart > 0)
    {
        // Attacke

        if (attackCallback == null)
            return false;

        long attackTime = TimeUtils.timeSinceMillis(attackStart);
        if (attackTime >= LONG_ATTACK_TIME)
        {
            attackCallback.run((int)(attackTime/400));
            attackSword = 0.4f;
        } else {
            attackCallback.run(1);
            attackSword = 0.2f;
        }

        attackStart = -1;
        return true;
    }
    return false;
}
 
Example 36
Project: guitar-finger-trainer   File: TrainingScreen.java   View source code 5 votes vote down vote up
private void applyRules() {
    if (SettingsUtil.playEnabled) {
        if (this.firstRun > 0) {
            if (TimeUtils.timeSinceMillis(this.lastUpdateTime) >= 1000) {
                AssetsUtil.playSound(AssetsUtil.clickSound);
                this.firstRun--;
                this.lastUpdateTime = TimeUtils.millis();
            }
        } else if (TimeUtils.timeSinceMillis(this.lastUpdateTime) >= this.bpm) {
            AssetsUtil.playSound(AssetsUtil.clickSound);
            this.lastUpdateTime = TimeUtils.millis();

            if (this.grid.forward) {
                this.grid.currentPosition++;
            } else {
                this.grid.currentPosition--;
            }

            if (this.grid.currentPosition == this.grid.noteSequence.length) {
                if (!SettingsUtil.backForwardEnabled) {
                    this.grid.currentPosition = 0;
                    if (SettingsUtil.autoMoveToNext) {
                        this.firstRun = 3;
                        this.grid.loadNextTraining();
                    }
                } else {
                    this.grid.currentPosition--;
                    this.grid.forward = false;
                }
            } else if (!this.grid.forward && this.grid.currentPosition == 0) {
                this.grid.forward = true;
                if (SettingsUtil.autoMoveToNext) {
                    this.firstRun = 3;
                    this.grid.loadNextTraining();
                }
            }
        }
    }
}
 
Example 37
Project: Escapy   File: EscapyShaderRender.java   View source code 5 votes vote down vote up
/**
 * Check status.
 *
 * @param program
 *            the program
 */
protected void checkStatus(ShaderProgram program) {
	System.err.println(program.isCompiled() ? "COMPILED: "+this.toString() : "ERROR: "+this.toString()+"\n"+program.getLog()+"\n");
	if (!program.isCompiled()) {
		FileHandle file = Gdx.files.local("error_log.txt");
		file.writeString(new Date(TimeUtils.millis()).toString()+"\nERROR: "+this.toString()+"\n"+program.getLog()+"\n", true);
	}
}
 
Example 38
Project: Escapy   File: EscapyShaderRender.java   View source code 5 votes vote down vote up
/**
 * Check status.
 *
 * @param program
 *            the program
 */
protected void checkStatus(ShaderProgram program) {
	System.err.println(program.isCompiled() ? "COMPILED: "+this.toString() : "ERROR: "+this.toString()+"\n"+program.getLog()+"\n");
	if (!program.isCompiled()) {
		FileHandle file = Gdx.files.local("error_log.txt");
		file.writeString(new Date(TimeUtils.millis()).toString()+"\nERROR: "+this.toString()+"\n"+program.getLog()+"\n", true);
	}
}
 
Example 39
Project: cgc-game   File: TimerManager.java   View source code 5 votes vote down vote up
public static void setPause(boolean b)
{
	paused = b;
	if (b)
	{
		myTimer.stop();
	}
	else
	{
		myTimer.start();
		milly = TimeUtils.millis();
	}
}
 
Example 40
Project: cykacommander   File: CykaSplashScreen.java   View source code 5 votes vote down vote up
@Override
public void show() {
    //VIEWPORT
    viewport = new FitViewport(CykaGame.SCREEN_WIDTH, CykaGame.SCREEN_HEIGHT, game.camera);
    viewport.setScaling(Scaling.stretch);
    //STAGE
    stage = new Stage(viewport,game.batch);
    Gdx.input.setInputProcessor(stage);
    samukiLogo = new Texture("samuki_logo.png");
    updateText = new Texture("update_text.png");

    startTime = TimeUtils.millis();

    final int ANIMATION_COLS = 1;
    final int ANIMATION_ROWS = 5;
    appLogoAnimation = GameBasic.spriteCutting("splash_screen_logo.png",
                        ANIMATION_COLS, ANIMATION_ROWS);
    appLogo = appLogoAnimation.getKeyFrame(0);

    Timer timer = new Timer();
    timer.scheduleTask(new Timer.Task() {
                        int a = 0;
                            @Override
                            public void run() {
                                appLogo = appLogoAnimation.getKeyFrame(a);
                                a++;
                                if(a == 5)
                                    a = 0;
                            }
                        },
            0f,
            0.111f,
            8);

}