public void tick(int dt) { if (plyr.transitioning > -1) return; ticker += dt / 1000f; if (ticker > 1) ticker = 0; if (open == true) { if (y <= 0) { y = 0; return; } else { y -= (500 / 1000f) * dt; float f = 1 - ((((float) closedy - (float) y) / (float) closedy) * .5f); sound.changeVolume(f); } } else { if (y >= closedy) { y = closedy; return; } else { y += (1000 / 1000f) * dt; float f = 1 - ((((float) closedy - (float) y) / (float) closedy) * .5f); sound.changeVolume(f); } } if (y <= 0) y = 0; if (y >= closedy) y = closedy; this.transitioning = (open == true && y > 0) || (open == false && y < closedy) || open; }
private void comprovar(TextView posicio, int p) { int indexSort = 0; if (CO.p1.equalsIgnoreCase((String) posicio.getText())) { // la posicio es posAgafada1 if (CO.imatge != null) indexSort = CO.sortida.indexOf(CO.p2); posAgafada1.setText(CO.p2); } else { // la posicio es posAgafada2 if (CO.imatge != null) indexSort = CO.sortida.indexOf(CO.p1); posAgafada2.setText(CO.p1); } if (CO.imatge == null) { posicio.setBackgroundColor(CO.bg); posicio.setTextColor(CO.fg); } else { int indexEntr = CO.vecCaselles.indexOf(posicio); CO.vecCaselles.elementAt(indexEntr).setBackgroundColor(Color.TRANSPARENT); CO.vecCaselles.elementAt(indexEntr).setTextColor(Color.TRANSPARENT); vecDraw.elementAt(indexSort).setAlpha(255); CO.vecCaselles.elementAt(indexEntr).setBackgroundDrawable(vecDraw.elementAt(indexSort)); } // recalculo les posicions int correcte = CO.correcte; CO.correcte = 0; CO.incorrecte = 0; for (int i = 0; i < CO.vecCaselles.size(); i++) { if (CO.vecCaselles.elementAt(i) != null) { if (((String) CO.vecCaselles.elementAt(i).getText()) .equalsIgnoreCase(CO.sortida.elementAt(i))) { CO.correcte++; } else CO.incorrecte++; } } ++cont; if (CO.correcte > correcte && cont == 2) { contador++; sounds.playAction_ok(); cont = 0; } else if (cont == 2 || CO.p1.equals(CO.p2)) { contador++; sounds.playActionError(); cont = 0; } setMissatges(); }
private void executarOnClick(TextView posicio) { if (CO.p1.equalsIgnoreCase("<buit>")) { // no tenim res seleccionat encara CO.p1 = (String) posicio.getText(); posAgafada1 = posicio; sounds.playClick(); // CO.cas1.setText(CO.p1); posicio.setBackgroundColor(Color.WHITE); posicio.setTextColor(Color.BLACK); // posar que no posi blanc, sino alpha 100!!! if (CO.imatge != null) { // CO.cas1.setText(""); int indexEntr = CO.vecCaselles.indexOf(posicio); int indexSort = CO.sortida.indexOf(CO.p1); CO.vecCaselles.elementAt(indexEntr).setBackgroundColor(Color.TRANSPARENT); CO.vecCaselles.elementAt(indexEntr).setTextColor(Color.TRANSPARENT); vecDraw.elementAt(indexSort).setAlpha(100); CO.vecCaselles.elementAt(indexEntr).setBackgroundDrawable(vecDraw.elementAt(indexSort)); } } else if (CO.p2.equalsIgnoreCase("<buit>")) { CO.p2 = (String) posicio.getText(); posAgafada2 = posicio; } }
public GameOver(DeepDiveTypingGame game) { this.game = game; Sounds.playPlayerDies(); game.selected = this; game.stopTimer(); doAnalytics(game); }
@Override public void act(float delta) { int acts = logic.advance2(delta); super.act(delta); boolean isGameOver = logic.isGameOver(); if (isGameOver && !gameOverFired) { if (logic.isGameLost()) { gameOverFired = true; mGame.gameLost(); } else { if (timeToFireWon > 0) timeToFireWon -= delta; else { gameOverFired = true; mGame.gameWon(); } } } else if (!isGameOver && gameOverFired) { gameOverFired = false; timeToFireWon = TIME_TO_WAIT_FOR_WON; } sounds.act(delta, acts); // bangs.act(delta); snappers.act(delta); if (isHinting) hint.act(delta); if (isTutorialAvailable && !isHinting && !areSnappersTouched() && (System.currentTimeMillis() - logic.startTime) > WAIT_FOR_TUTORIAL) showHints(true); }
public void keyPressed(int key, char c) { if (key == Input.KEY_Q) { if (!(y == 0 || y == closedy)) return; open = !open; if (open == true) { ticker = 0; sound.playSound("la_inv-open.wav"); // sound.changeVolume(.5f); } else { sound.playSound("la_inv-close.wav"); input.clearKeyPressedRecord(); // sound.changeVolume(1f); } } if (open == true) { if (y <= 0) { for (int i = 0; i < 4; i++) { if (key == Main.keys[i]) { this.selection += Main.vectors[0][i]; this.selection += Main.vectors[1][i] * 2; sound.playSound("la_invmove.wav"); ticker = 0; break; } } if (this.selection > 9) this.selection = 0; else if (this.selection < 0) this.selection = 9; if (key == Input.KEY_S) { Weapon tempweap = plyr.weapons[0]; plyr.weapons[0] = plyr.inventory[this.selection]; plyr.inventory[this.selection] = tempweap; sound.playSound("la_invselect.wav"); } if (key == Input.KEY_D) { Weapon tempweap = plyr.weapons[1]; plyr.weapons[1] = plyr.inventory[this.selection]; plyr.inventory[this.selection] = tempweap; sound.playSound("la_invselect.wav"); } } } }
@ForgeSubscribe public void doSoundsLoad(SoundLoadEvent event) { for (Sounds sound : Sounds.values()) { addSound(event, sound); } }
void swordSpecHelper(Graphics2D g) { if (swordSpec) { player.mana -= 0.5; g.setColor(Color.ORANGE); g.drawRect( (int) (player.x - player.size / 2 - 2), (int) (player.y - player.size / 2 - 2), 68, 68); if (player.mana <= 0) { player.mana = 0; swordSpec = false; // Stop special noise wepspec.stop(); wepspec.reset(); } } }
public void weaponSwap(Input p1) { if (justPressed(p1, Button.C)) { if (inv[slot + 1] == null) { player.weapon.setWeapon(inv[0].getName()); slot = 0; } else { if (swordSpec) { wepspec.stop(); wepspec.reset(); swordSpec = false; } player.weapon.setWeapon(inv[slot + 1].getName()); slot++; delay = 0; spDelay = 0; } System.out.println(slot + " " + inv[slot].getName()); } }
void restart() { Sounds.get().play(Sounds.HIT); load(Levelset.getLevel()); renderer.loadLevelTexs(); // collidedCount = 0; waterCount = 0; // wasCollided = false; paused = false; player.restart(spawnX, spawnY); }
public void getAbility(Ability ability, int x, int y) { player.abilities.add(ability); if (x > 0 && y > 0) removeTile(x, y); Sounds.get().play(Sounds.POWER_UP); switch (ability) { case GAS: player.gravityDirection = 1; break; case SLICK: player.gravityAffection = false; break; case NORMAL: { player.gravityAffection = true; player.gravityDirection = -1; player.abilities.clear(); } break; case SOLID: player.canJump = false; break; } }
private void addSound(SoundLoadEvent event, Sounds sound) { event.manager.soundPoolSounds.addSound( Reference.MODDID + ":" + sound.getName() + sound.getFormat()); }
public void specialAttack(Graphics2D g, Input p1) { swordSpecHelper(g); if (justPressed(p1, Button.B)) { if (player.weapon.name.equals("Short Sword")) { if (swordSpec) { swordSpec = false; // Stop special noise wepspec.stop(); wepspec.reset(); } else if (!swordSpec && player.mana > 0) { // Start special noise weps.loadSound("Resources/Sounds/special.wav"); weps.run(); wepspec.loadSound("Resources/Sounds/fire.wav"); wepspec.runLoop(); swordSpec = true; } } if (player.weapon.name.equals("Greatsword") && player.mana >= 40 && spDelay == 0) { // Greatsword spec sound weps.loadSound("Resources/Sounds/special.wav"); weps.run(); player.mana -= 40; spDelay = player.weapon.delay; for (Enemy enemy : wave.enemies.values()) { if (enemy.x + enemy.size / 2 + arena.xOffset > player.x - 128 && enemy.x - enemy.size / 2 + arena.xOffset < player.x + 128 && enemy.y + enemy.size / 2 + arena.yOffset > player.y - 128 && enemy.y - enemy.size / 2 + arena.yOffset < player.y + 128) { enemy.health -= player.weapon.spDamage; // UP if (enemy.x + arena.xOffset + enemy.size / 2 >= player.x - 32 && enemy.x + arena.xOffset - enemy.size / 2 <= player.x + 32 && enemy.y + arena.yOffset + enemy.size / 2 >= player.y - 96 && enemy.y + arena.yOffset - enemy.size / 2 <= player.y - 33) { enemy.y -= 32; } // DOWN if (enemy.x + arena.xOffset - enemy.size / 2 <= player.x + 32 && enemy.x + arena.xOffset + enemy.size / 2 >= player.x - 32 && enemy.y + arena.yOffset - enemy.size / 2 <= player.y + 96 && enemy.y + arena.yOffset + enemy.size / 2 >= player.y + 33) { enemy.y += 32; } // LEFT if (enemy.x + arena.xOffset - enemy.size / 2 <= player.x - 32 && enemy.x + arena.xOffset + enemy.size / 2 >= player.x - 96 && enemy.y + arena.yOffset - enemy.size / 2 <= player.y + 32 && enemy.y + arena.yOffset + enemy.size / 2 >= player.y - 32) { enemy.x -= 32; } // RIGHT if (enemy.x + arena.xOffset + enemy.size / 2 >= player.x + 32 && enemy.x + arena.xOffset - enemy.size / 2 <= player.x + 96 && enemy.y + arena.yOffset + enemy.size / 2 >= player.y - 32 && enemy.y + arena.yOffset - enemy.size / 2 <= player.y + 32) { enemy.x += 32; } } } g.drawRect((int) (player.x - 128), (int) (player.y - 128), 256, 256); } if (player.weapon.name.equals("Spear") && player.mana >= 25 && spDelay == 0) { wepspec.loadSound("Resources/Sounds/special.wav"); wepspec.run(); player.mana -= 25; spDelay = player.weapon.delay; // UP if (player.direction == 0) { for (Enemy enemy : wave.enemies.values()) { if (enemy.x + enemy.size / 2 + arena.xOffset > player.x - player.size / 2 - 16 && enemy.x - enemy.size / 2 + arena.xOffset < player.x + player.size / 2 + 16 && enemy.y + enemy.size / 2 + arena.yOffset > player.y - player.size / 2 - 192 && enemy.y - enemy.size / 2 + arena.yOffset < player.y - player.size / 2) { enemy.health -= player.weapon.spDamage; enemy.y -= 32; } } g.drawRect( (int) (player.x - player.size / 2 - 16), (int) (player.y - player.size / 2 - 192), 96, 192); } // DOWN if (player.direction == 1) { for (Enemy enemy : wave.enemies.values()) { if (enemy.x + enemy.size / 2 + arena.xOffset > player.x - player.size / 2 - 16 && enemy.x - enemy.size / 2 + arena.xOffset < player.x + player.size / 2 + 16 && enemy.y + enemy.size / 2 + arena.yOffset > player.y + player.size / 2 && enemy.y - enemy.size / 2 + arena.yOffset < player.y + player.size / 2 + 192) { enemy.health -= player.weapon.spDamage; enemy.y += 32; } } g.drawRect( (int) (player.x - player.size / 2 - 16), (int) (player.y + player.size / 2), 96, 192); } // LEFT if (player.direction == 2) { for (Enemy enemy : wave.enemies.values()) { if (enemy.x + enemy.size / 2 + arena.xOffset > player.x - player.size / 2 - 192 && enemy.x - enemy.size / 2 + arena.xOffset < player.x - player.size / 2 && enemy.y + enemy.size / 2 + arena.yOffset > player.y - player.size / 2 - 16 && enemy.y - enemy.size / 2 + arena.yOffset < player.y + player.size / 2 + 16) { enemy.health -= player.weapon.spDamage; enemy.x -= 32; } } g.drawRect( (int) (player.x - player.size / 2 - 192), (int) (player.y - player.size / 2 - 16), 192, 96); } // RIGHT if (player.direction == 3) { for (Enemy enemy : wave.enemies.values()) { if (enemy.x + enemy.size / 2 + arena.xOffset > player.x + player.size / 2 && enemy.x - enemy.size / 2 + arena.xOffset < player.x + player.size / 2 + 192 && enemy.y + enemy.size / 2 + arena.yOffset > player.y - player.size / 2 - 16 && enemy.y - enemy.size / 2 + arena.yOffset < player.y + player.size / 2 + 16) { enemy.health -= player.weapon.spDamage; enemy.x += 32; } } g.drawRect( (int) (player.x + player.size / 2), (int) (player.y - player.size / 2 - 16), 192, 96); } } } if (spDelay > 0) { spDelay--; } }
@Override public void tick(Graphics2D g, Input p1, Input p2, Sound s) { // Menu if (gameState == 0) { // Song sound.loadSound("Resources/Sounds/Menu.wav"); sound.runLoop(); // background g.setColor(Color.BLACK); g.fillRect(0, 0, WIDTH, HEIGHT); // title g.setColor(Color.GREEN); g.setFont(new Font("Arial", Font.BOLD, 100)); centerText("DARKLIGHT 2", g, WIDTH / 2, 180); // selection g.setColor(Color.RED); if (gameState == 0) { // Song sound.loadSound("Resources/Sounds/Menu.wav"); sound.runLoop(); // background g.setColor(Color.BLACK); g.fillRect(0, 0, WIDTH, HEIGHT); // title g.setColor(Color.GREEN); g.setFont(new Font("Arial", Font.BOLD, 100)); centerText("DARKLIGHT 2", g, WIDTH / 2, 180); // selection g.setColor(Color.RED); if (button == 0) { // PLAY g.fillRect(WIDTH / 2 - 160, 240, 320, 90); if (justPressed(p1, Button.U)) { button = 2; } if (justPressed(p1, Button.D)) { button = 1; } if (justPressed(p1, Button.A) || justPressed(p1, Button.B) || justPressed(p1, Button.C)) { inv[0] = wep1; gameState = 1; sound.reset(); sound.stop(); } } else if (button == 1) { // LEADERBOARDS g.fillRect(WIDTH / 2 - 160, 340, 320, 90); if (justPressed(p1, Button.U)) { button = 0; } if (justPressed(p1, Button.D)) { button = 2; } if (justPressed(p1, Button.A) || justPressed(p1, Button.B) || justPressed(p1, Button.C)) { gameState = 5; } } else { // EXIT g.fillRect(WIDTH / 2 - 160, 440, 320, 90); if (justPressed(p1, Button.U)) { button = 1; } if (justPressed(p1, Button.D)) { button = 0; } if (justPressed(p1, Button.A) || justPressed(p1, Button.B) || justPressed(p1, Button.C)) { System.exit(0); } } // option boxes g.setColor(Color.GREEN); g.fillRect(WIDTH / 2 - 150, 250, 300, 70); g.fillRect(WIDTH / 2 - 150, 350, 300, 70); g.fillRect(WIDTH / 2 - 150, 450, 300, 70); // option box text g.setColor(Color.BLACK); g.setFont(new Font("Arial", Font.PLAIN, 30)); centerText("PLAY", g, WIDTH / 2, 295); centerText("LEADERBOARD", g, WIDTH / 2, 395); centerText("EXIT", g, WIDTH / 2, 495); // g.setColor(Color.YELLOW); // g.fillRect(WIDTH/2 - 352, 20, 704, 192); } } // Game if (gameState == 1) { arena.draw(g); // Sound sound.loadSound("Resources/Sounds/ambient.wav"); sound.runLoop(); // // offset borders // g.setColor(Color.RED); // g.drawRect(0, 0, arena.xOffsetBorder, HEIGHT); // left // g.drawRect(WIDTH - arena.xOffsetBorder, 0, arena.xOffsetBorder, HEIGHT); // right // g.drawRect(0, 0, WIDTH, arena.yOffsetBorder); // top // g.drawRect(0, HEIGHT - arena.yOffsetBorder, WIDTH, arena.yOffsetBorder); // bottom if (wave.falling) { count = 0; gameState = 2; } // wave wave.newWave(g, arena, player); wave.maintain(g, arena, player, swordSpec); // If enemy spots, play battle sound for (Enemy enemy : wave.enemies.values()) { if (enemy.spottedPlayer) { // Check to play noise int temp = (int) (Math.random() * 150); if (temp <= 1) { // Check for Ghoul or Golem if (enemy.type <= 60) { // Play Ghoul sound monster.loadSound("Resources/Sounds/ghoul.wav"); monster.run(); } if (enemy.type > 85) { // Play golem sound monster.loadSound("Resources/Sounds/golem.wav"); monster.run(); } } battle.loadSound("Resources/Sounds/Game Song.wav"); battle.runLoop(); break; } } // Stop battle sound, new wave if (wave.waveStart && wave.wave != 0) { battle.stop(); battle.reset(); } // player player.draw(g); player.movement(p1, arena); player.weapon = weapon; basicAttack(g, p1); specialAttack(g, p1); weaponPickup(g, p1, arena); weaponSwap(p1); if (player.health <= 0) { gameState = 3; sound.stop(); sound.reset(); battle.stop(); battle.reset(); } if (justPressed(p1, Button.C)) { wave.enemies.clear(); } g.setColor(Color.BLACK); g.fillRect(0, 0, (int) (player.x - 256), HEIGHT); g.fillRect((int) (player.x + 256), 0, (int) (WIDTH - player.x - 255), HEIGHT); g.fillRect(0, 0, WIDTH, (int) (player.y - 256)); g.fillRect(0, (int) (player.y + 256), WIDTH, (int) (HEIGHT - player.y - 255)); g.drawImage(TextureLoader.light, (int) (player.x - 256), (int) (player.y - 256), null); // HUD int floor = (wave.wave % 10 == 0) ? (wave.wave + 9) / 10 : (wave.wave + 10) / 10; int currentWave = (wave.wave % 10 == 0) ? 10 : wave.wave % 10; g.setColor(Color.WHITE); g.setFont(new Font("Arial", Font.BOLD, 20)); g.drawString("Floor " + floor + " | Wave " + currentWave, 5, 20); g.setFont(new Font("Arial", Font.PLAIN, 10)); g.drawString("Remaining enemies: " + wave.enemies.size(), 5, 30); g.setColor(Color.DARK_GRAY); g.fillRect(347, 531, 330, 10); g.fillRect(347, 541, 10, 20); g.fillRect(507, 541, 10, 20); g.fillRect(667, 541, 10, 20); g.fillRect(347, 561, 330, 15); g.setColor(Color.GREEN); if (player.health <= 100) { g.fillRect(357, 541, (int) (150 * (player.health / 100)), 20); } else { g.fillRect(357, 541, 150, 20); g.setColor(Color.ORANGE); g.fillRect(357, 541, (int) (150 * ((player.health - 100) / 100)), 20); } g.setColor(Color.BLUE); g.fillRect( 517 + (int) (150 - (150 * (player.mana / 100))), 541, (int) (150 * (player.mana / 100)), 20); g.dispose(); } // Floor switching if (gameState == 2) { g.setColor(new Color(0, 0, 0, 4 * count)); g.fillRect(0, 0, WIDTH, HEIGHT); count++; if (count == 60) { arena = new Arena(); player.x = WIDTH / 2; player.y = HEIGHT / 2; wave.falling = false; wave.hole = false; wave.transition.reset(); wave.waveStart = true; wave.difficulty *= 1.1; gameState = 1; } } // Game Over if (gameState == 3) { // Sound sound.loadSound("Resources/Sounds/Death.wav"); sound.runOnce(); g.setColor(Color.RED); g.setFont(new Font("Arial", Font.BOLD, 150)); centerText("GAME OVER", g, WIDTH / 2, HEIGHT / 2); wait++; yourScore = wave.score; waveNum = (wave.wave % 10 == 0) ? 10 : wave.wave % 10; if (justPressed(p1, Button.A) || justPressed(p1, Button.B) || justPressed(p1, Button.C)) { sound.stop(); sound.reset(); gameState = 0; reset(); } if (wait == 3000) { sound.stop(); sound.reset(); gameState = 0; reset(); } } // Enter Your initials if (gameState == 4) { g.setColor(Color.BLACK); g.fillRect(0, 0, WIDTH, HEIGHT); g.setColor(Color.RED); g.setFont(new Font("Arial", Font.PLAIN, 45)); centerText("Enter Your Initials", g, (Game.WIDTH / 2), (Game.HEIGHT / 4)); centerText("Press C to enter", g, (Game.WIDTH / 2), (Game.HEIGHT / 2 + 100)); g.drawString(abcs[i], (Game.WIDTH / 2) - 55, (Game.HEIGHT / 2)); g.drawString(abcs[j], (Game.WIDTH / 2), (Game.HEIGHT / 2)); g.drawString(abcs[k], (Game.WIDTH / 2) + 55, (Game.HEIGHT / 2)); name = abcs[i] + abcs[j] + abcs[k]; if (active1) g.fillRect((Game.WIDTH / 2) - 55, (Game.HEIGHT / 2) + 5, 35, 5); if (active2) g.fillRect((Game.WIDTH / 2) + 5, (Game.HEIGHT / 2) + 5, 35, 5); if (active3) g.fillRect((Game.WIDTH / 2) + 55, (Game.HEIGHT / 2) + 5, 35, 5); if (!pressedBefore) { if (p1.pressed(Button.U) || p1.pressed(Button.D) || p1.pressed(Button.L) || p1.pressed(Button.R) || p1.pressed(Button.A) || p1.pressed(Button.B) || p1.pressed(Button.C)) { pressedBefore = true; } else { pressedBefore = false; } } else { if (!p1.pressed(Button.U) && !p1.pressed(Button.D) && !p1.pressed(Button.L) && !p1.pressed(Button.R) && !p1.pressed(Button.A) && !p1.pressed(Button.B) && !p1.pressed(Button.C)) { pressedBefore = false; } else { return; } } if (p1.pressed(Button.C)) { storeScores.main(); reset(); gameState = 5; } if (active1) { if (p1.pressed(Button.U)) { i += 1; if (i > abcs.length - 1) i = 0; } if (p1.pressed(Button.D)) { i -= 1; if (i < 0) i = abcs.length - 1; } if (p1.pressed(Button.L)) { active1 = false; active3 = true; } if (p1.pressed(Button.R)) { active1 = false; active2 = true; } return; } if (active2) { if (p1.pressed(Button.U)) { j += 1; if (j > abcs.length - 1) j = 0; } if (p1.pressed(Button.D)) { j -= 1; if (j < 0) j = abcs.length - 1; } if (p1.pressed(Button.L)) { active2 = false; active1 = true; } if (p1.pressed(Button.R)) { active2 = false; active3 = true; } return; } if (active3) { if (p1.pressed(Button.U)) { k += 1; if (k > abcs.length - 1) k = 0; } if (p1.pressed(Button.D)) { k -= 1; if (k < 0) k = abcs.length - 1; } if (p1.pressed(Button.L)) { active3 = false; active2 = true; } if (p1.pressed(Button.R)) { active3 = false; active1 = true; } return; } } // high scores if (gameState == 5) { storeScores.Read(); g.setColor(Color.BLACK); g.fillRect(0, 0, WIDTH, HEIGHT); g.setColor(Color.RED); g.setFont(new Font("Arial", Font.PLAIN, 35)); centerText("High Scores", g, (Game.WIDTH / 2), (Game.HEIGHT / 16)); g.drawLine(0, Game.HEIGHT / 16 + 8, 1200, Game.HEIGHT / 16 + 8); g.drawString("Enemies killed", Game.WIDTH / 2 + 150, Game.HEIGHT / 16 + 60); g.drawString("Wave", Game.WIDTH / 2, Game.HEIGHT / 16 + 60); g.drawString("Floor", Game.WIDTH / 2 - 210, Game.HEIGHT / 16 + 60); int height = -80; for (int l = 0; l < 10; l++) { g.drawString(storeScores.nameList.get(l), Game.WIDTH / 2 - 400, Game.HEIGHT / 8 - height); height = height - 40; } // g.drawString(storeScores, Game.WIDTH / 2, Game.HEIGHT / 2); wait++; if (wait == 1005) { sound.stop(); sound.reset(); wait = 0; yourScore = 0; waveNum = 0; i = 0; j = 0; k = 0; floorNum = 0; gameState = 0; } } updateKeyState(p1); }
public void basicAttack(Graphics2D g, Input p1) { if (justPressed(p1, Button.A) && delay == 0) { delay = player.weapon.delay; if (player.weapon.name.equals("Short Sword")) { weps.loadSound("Resources/Sounds/short.wav"); weps.run(); // UP if (player.direction == 0) { AnimationLoader.wick.setAnimation(14); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset - enemy.size / 2 <= player.x + 48 && enemy.x + arena.xOffset + enemy.size / 2 >= player.x - 48 && enemy.y + arena.yOffset - enemy.size / 2 <= player.y - 33 && enemy.y + arena.yOffset + enemy.size / 2 >= player.y - 96) { if (swordSpec) { enemy.health -= (1.5 * player.weapon.damage); } else { enemy.health -= player.weapon.damage; } generateMana(); } } g.drawRect((int) (player.x - 48), (int) (player.y - 96), weapon.width, weapon.length); } // DOWN if (player.direction == 1) { AnimationLoader.wick.setAnimation(4); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset + enemy.size / 2 >= player.x - 48 && enemy.x + arena.xOffset - enemy.size / 2 <= player.x + 48 && enemy.y + arena.yOffset + enemy.size / 2 >= player.y + 36 && enemy.y + arena.yOffset - enemy.size / 2 <= player.y + 96) { if (swordSpec) { enemy.health -= (1.5 * player.weapon.damage); } else { enemy.health -= player.weapon.damage; } generateMana(); } } g.drawRect((int) (player.x - 48), (int) (player.y + 32), weapon.width, weapon.length); } // LEFT if (player.direction == 2) { AnimationLoader.wick.setAnimation(6); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset + enemy.size / 2 >= player.x - 96 && enemy.x + arena.xOffset - enemy.size / 2 <= player.x - 36 && enemy.y + arena.yOffset + enemy.size / 2 >= player.y - 32 && enemy.y + arena.yOffset - enemy.size / 2 <= player.y + 32) { if (swordSpec) { enemy.health -= (1.5 * player.weapon.damage); } else { enemy.health -= player.weapon.damage; } generateMana(); } } g.drawRect((int) (player.x - 96), (int) (player.y - 48), weapon.length, weapon.width); } // RIGHT if (player.direction == 3) { AnimationLoader.wick.setAnimation(5); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset - enemy.size / 2 <= player.x + 96 && enemy.x + arena.xOffset + enemy.size / 2 >= player.x + 36 && enemy.y + arena.yOffset - enemy.size / 2 <= player.y + 32 && enemy.y + arena.yOffset + enemy.size / 2 >= player.y - 32) { if (swordSpec) { enemy.health -= (1.5 * player.weapon.damage); } else { enemy.health -= player.weapon.damage; } generateMana(); } } g.drawRect((int) (player.x + 32), (int) (player.y - 48), weapon.length, weapon.width); } } if (player.weapon.name.equals("Greatsword")) { weps.loadSound("Resources/Sounds/great.wav"); weps.run(); // UP if (player.direction == 0) { AnimationLoader.wick.setAnimation(15); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset + enemy.size / 2 > player.x - 32 && enemy.x + arena.xOffset - enemy.size / 2 < player.x + 32 && enemy.y + arena.yOffset + enemy.size / 2 > player.y - 96 && enemy.y + arena.yOffset - enemy.size / 2 < player.y - 33) { enemy.health -= player.weapon.damage; enemy.y -= 32; generateMana(); } } g.drawRect((int) (player.x - 96), (int) (player.y - 96), weapon.width, weapon.length); } // DOWN if (player.direction == 1) { AnimationLoader.wick.setAnimation(7); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset - enemy.size / 2 < player.x + 32 && enemy.x + arena.xOffset + enemy.size / 2 > player.x - 32 && enemy.y + arena.yOffset - enemy.size / 2 < player.y + 96 && enemy.y + arena.yOffset + enemy.size / 2 > player.y + 33) { enemy.health -= player.weapon.damage; enemy.y += 32; generateMana(); } } g.drawRect((int) (player.x - 96), (int) player.y, weapon.width, weapon.length); } // LEFT if (player.direction == 2) { AnimationLoader.wick.setAnimation(9); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset - enemy.size / 2 < player.x - 32 && enemy.x + arena.xOffset + enemy.size / 2 > player.x - 96 && enemy.y + arena.yOffset - enemy.size / 2 < player.y + 32 && enemy.y + arena.yOffset + enemy.size / 2 > player.y - 32) { enemy.health -= player.weapon.damage; enemy.x -= 32; generateMana(); } } g.drawRect((int) (player.x - 96), (int) (player.y - 96), weapon.length, weapon.width); } // RIGHT if (player.direction == 3) { AnimationLoader.wick.setAnimation(8); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset + enemy.size / 2 > player.x + 32 && enemy.x + arena.xOffset - enemy.size / 2 < player.x + 96 && enemy.y + arena.yOffset + enemy.size / 2 > player.y - 32 && enemy.y + arena.yOffset - enemy.size / 2 < player.y + 32) { enemy.health -= player.weapon.damage; enemy.x += 32; generateMana(); } } g.drawRect((int) player.x, (int) (player.y - 96), weapon.length, weapon.width); } } if (player.weapon.name.equals("Spear")) { weps.loadSound("Resources/Sounds/spear.wav"); weps.run(); // UP if (player.direction == 0) { AnimationLoader.wick.setAnimation(12); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset + enemy.size / 2 >= player.x + weapon.width && enemy.x + arena.xOffset - enemy.size / 2 <= player.x + weapon.width && enemy.y + arena.yOffset + enemy.size / 2 >= player.y - weapon.length - 32 && enemy.y + arena.yOffset - enemy.size / 2 <= player.y - 32) { enemy.health -= player.weapon.damage; generateMana(); } } g.drawRect((int) player.x, (int) (player.y - 160), weapon.width, weapon.length); } // DOWN if (player.direction == 1) { AnimationLoader.wick.setAnimation(13); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset + enemy.size / 2 >= player.x + weapon.width && enemy.x + arena.xOffset - enemy.size / 2 <= player.x + weapon.width && enemy.y + arena.yOffset + enemy.size / 2 >= player.y + 32 && enemy.y + arena.yOffset - enemy.size / 2 <= player.y + weapon.length + 32) { enemy.health -= player.weapon.damage; generateMana(); } } g.drawRect((int) player.x, (int) (player.y + 32), weapon.width, weapon.length); } // LEFT if (player.direction == 2) { AnimationLoader.wick.setAnimation(11); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset + enemy.size / 2 >= player.x - weapon.length - 32 && enemy.x + arena.xOffset - enemy.size / 2 <= player.x - 32 && enemy.y + arena.yOffset + enemy.size / 2 >= player.y + weapon.width && enemy.y + arena.yOffset - enemy.size / 2 <= player.y + weapon.width) { enemy.health -= player.weapon.damage; generateMana(); } } g.drawRect((int) (player.x - 160), (int) player.y, weapon.length, weapon.width); } // RIGHT if (player.direction == 3) { AnimationLoader.wick.setAnimation(10); for (Enemy enemy : wave.enemies.values()) { if (enemy.x + arena.xOffset + enemy.size / 2 >= player.x + 32 && enemy.x + arena.xOffset - enemy.size / 2 <= player.x + 32 + weapon.length && enemy.y + arena.yOffset + enemy.size / 2 >= player.y + weapon.width && enemy.y + arena.yOffset - enemy.size / 2 <= player.y + weapon.width) { enemy.health -= player.weapon.damage; generateMana(); } } g.drawRect((int) (player.x + 32), (int) player.y, weapon.length, weapon.width); } } } if (delay > 0) { delay--; } }
// action listeners public void actionPerformed(ActionEvent e) { // doge click button gives doge if (e.getSource() == dogeClick) { cps = cps + 1; Sounds.run("wow"); // increases size of button temporarily if (animation == 0) { dogeClick.setBounds(460, 110, 80, 80); dogeClick.setIcon(new ImageIcon("Images/dogeopen.jpg")); animation = 1; } else if (animation == 1) { dogeClick.setBounds(450, 100, 100, 100); dogeClick.setIcon(new ImageIcon("Images/doge.jpg")); animation = 0; } // adds doge accordingly and updates JLabel doge = doge + ((clickUpgrade) * clickMultiply) * multiplier; dogeCount.setText("Doge: " + doge); // randomize text flavourClick.setText(flavourText[(int) (Math.random() * 49)]); flavourClick.setBounds( (int) (Math.random() * (800)), (int) ((Math.random() * (401)) + 50), getWidth(), 50); flavourClick.setFont( new Font("Comic Sans MS", Font.BOLD, (int) ((Math.random() * (15)) + 15))); Color colour = Random.getRandomColour(); flavourClick.setForeground(colour); flavourClick.setVisible(true); } // for loop for all buttons for (int i = 0; i < MAX_UPGRADES; i++) { // updates button stats and count if (e.getSource() == producers[i] && doge >= producerStats[i].getCost()) { doge = doge - producerStats[i].getCost(); producers[i].setIcon(new ImageIcon("Images//bought.PNG")); producerStats[i].increaseCount(); producerStats[i].increaseCost(); producers[i].setToolTipText( "Your " + producerStats[i].getButtonName() + " gives " + producerStats[i].getDogeProduction() * producerStats[i].getCount() + " doge per second"); dps = dps + producerStats[i].getDogeProduction(); buyProducers[i].setText( "Buy " + producerStats[i].getButtonName() + " for " + producerStats[i].getCost() + " doge"); buyDetails[i].setText( "You have: " + producerStats[i].getCount() + " " + producerStats[i].getButtonName()); } } // updates click stats and count for (int i = 0; i < MAX_CLICK; i++) { if (e.getSource() == clickers[i] && doge >= clickerStats[i].getCost()) { doge = doge - clickerStats[i].getCost(); clickerStats[i].increaseCount(); clickUpgrade = clickUpgrade + clickerStats[i].getClickBonus(); clickMultiply = clickMultiply * clickerStats[i].getClickMultiplier(); dogeClick.setToolTipText( "Each click gives you " + (clickUpgrade) * clickMultiply + " doge. wow"); clickers[i].setVisible(false); buyClickers[i].setVisible(false); } } // secret developer button in corner if (e.getSource() == devButton) { doge = doge * 2; // plays Sandstorm by Darude Sounds.run("sandstorm"); } if (e.getSource() == options) { // opens options gui Options options = new Options(); } // saves current progress into save file if (e.getSource() == save) { // opens JOtionPane Sounds.run("save"); Save temp = new Save(); String name = JOptionPane.showInputDialog("What is the name of your save file?"); temp.createOutputFile("Save//" + name + ".txt"); String producerCount = ""; String clickCount = ""; String achievementCount = ""; // adds line of code for the amount of producers for (int i = 0; i < MAX_UPGRADES; i++) { producerCount = producerCount + producerStats[i].getCount() + "|"; } // adds line of code for the amount of clickers for (int i = 0; i < MAX_CLICK; i++) { // if bought write true if (clickerStats[i].getCount() != 0) { clickCount = clickCount + "t|"; } else { // if not bought write false clickCount = clickCount + "f|"; } } // adds a line of code for achievements for (int i = 0; i < MAX_ACHIEVEMENTS; i++) { // if possess write true if (achievementStats[i].getCount() != 0) { achievementCount = achievementCount + "t|"; } else { // if do not have write f achievementCount = achievementCount + "f|"; } } // add all lines to file temp.addInfo("" + doge); temp.addInfo("" + producerCount); temp.addInfo("" + clickCount); temp.addInfo("" + achievementCount); temp.closeOutputFile(); } // opens existing save file if (e.getSource() == open) { Save temp = new Save(); String name = JOptionPane.showInputDialog("What is the name of your save file?"); temp.openInputFile("Save//" + name + ".txt"); try { // counters to open save file int add = 0; String data = ""; int producerCount = 0; int clickCount = 0; int achievementCount = 0; // turn each line into char array doge = Long.parseLong(temp.getInfo()); char producerSave[] = temp.getInfo().toCharArray(); char clickSave[] = temp.getInfo().toCharArray(); char achievementSave[] = temp.getInfo().toCharArray(); // looks at producer line and adjusts values and resets Jlabel // text for (int i = 0; i < producerSave.length; i++) { if (producerSave[i] != '|') { data = data + Character.getNumericValue(producerSave[i]); } else { // updates data in producers add = Integer.parseInt(data); producerStats[producerCount].setCount(add); producerStats[producerCount].setCost( (int) (producerStats[producerCount].getCost() * (add * producerStats[producerCount].getCostIncrease()))); buyProducers[producerCount].setText( "Buy " + producerStats[producerCount].getButtonName() + " for " + producerStats[producerCount].getCost() + " doge"); buyDetails[producerCount].setText( "You have: " + producerStats[producerCount].getCount() + " " + producerStats[producerCount].getButtonName()); producers[producerCount].setToolTipText( "Your " + producerStats[producerCount].getButtonName() + " gives " + producerStats[producerCount].getDogeProduction() * producerStats[producerCount].getCount() + " doge per second"); dps = dps + (producerStats[producerCount].getDogeProduction() * producerStats[producerCount].getCount()); data = ""; producerCount++; add = 0; } } // reads clicker upgrades saves for (int i = 0; i < MAX_CLICK * 2; i++) { if (clickSave[i] == 't') { // updates data in clickers clickerStats[clickCount].setCount(1); clickUpgrade = (clickUpgrade + clickerStats[clickCount].getClickBonus()) * clickerStats[clickCount].getClickMultiplier(); dogeClick.setToolTipText("Each click gives you " + clickUpgrade + " doge. wow"); clickers[clickCount].setVisible(false); buyClickers[clickCount].setVisible(false); clickCount++; } else if (clickSave[i] == 'f') { clickCount++; } } // reads achievement lines for (int i = 0; i < MAX_ACHIEVEMENTS * 2; i++) { if (achievementSave[i] == 't') { // updates achievements achievementStats[achievementCount].setCount(1); achievements[achievementCount].setVisible(true); achievementCount++; } else if (achievementSave[i] == 'f') { achievementCount++; } } dogeCount.setText("Doge: " + doge); } catch (IOException e1) { // access invalid file e1.printStackTrace(); System.out.println("Invalid file!"); } // closes input file try { temp.closeInputFile(); } catch (IOException e1) { // access invalid file e1.printStackTrace(); System.out.println("Invalid file!"); } } }
protected void onDestroy() { if (maxTime != 0) timer.cancel(); sounds.unloadAll(); super.onDestroy(); }
@TargetApi(3) private void setMissatges() { if (CO.solucioVisible) { // CO.miss.setText(""); // CO.missCorrectes.setText(""); // CO.cas1.setText(""); CO.p1 = "<buit>"; CO.p2 = "<buit>"; } else { final Context aC = this; Dialog dialog = new Dialog(aC, R.style.Dialog); dialog.setContentView(R.layout.menu_clic); dialog.setCanceledOnTouchOutside(true); MenuActivitats ma = new MenuActivitats(timer); ma.butsMenu(dialog, aC, vecDraw); TextView textFinal = (TextView) dialog.findViewById(R.id.tMenuClic); if ((maxIntents != 0 && maxIntents == contador && CO.correcte != CO.casIni)) { sounds.playFinished_error(); if (Parser.getActivitats().elementAt(CO.activitatActual).getMissatgeFi() != null) textFinal.setText(Parser.getActivitats().elementAt(CO.activitatActual).getMissatgeFi()); else textFinal.setText("Superat els intents màxims"); if (maxTime != 0) timer.cancel(); // CO.missCorrectes.setText("Prem aquí per continuar."); // CO.missCorrectes.setBackgroundColor(Color.WHITE); // CO.missCorrectes.setTextColor(Color.BLACK); dialog.show(); bloquejarJoc(true); } if (contadorT == maxTime && maxTime != 0) { sounds.playFinished_error(); if (Parser.getActivitats().elementAt(CO.activitatActual).getMissatgeFi() != null) textFinal.setText(Parser.getActivitats().elementAt(CO.activitatActual).getMissatgeFi()); else textFinal.setText("Superat el temps màxims"); if (maxTime != 0) timer.cancel(); // CO.missCorrectes.setText("Prem aquí per continuar."); // CO.missCorrectes.setBackgroundColor(Color.WHITE); // CO.missCorrectes.setTextColor(Color.BLACK); dialog.show(); bloquejarJoc(true); } else if (CO.correcte == CO.casIni) { // Hem acabat el joc if (maxTime != 0) timer.cancel(); sounds.playFinished_ok(); if (Parser.getActivitats().elementAt(CO.activitatActual).getMissatgeFi() != null) textFinal.setText(Parser.getActivitats().elementAt(CO.activitatActual).getMissatgeFi()); else textFinal.setText("Joc finalitzat!"); // CO.missCorrectes.setText("Prem aquí per continuar."); // CO.missCorrectes.setBackgroundColor(Color.WHITE); // CO.missCorrectes.setTextColor(Color.BLACK); dialog.show(); bloquejarJoc(true); } else { /* * if(Parser.getActivitats().elementAt(CO.activitatActual). * getMissatgeIni() != null) * CO.miss.setText(Parser.getActivitats * ().elementAt(CO.activitatActual).getMissatgeIni()); else * CO.miss.setText("Comença el joc!"); */ int displayedIntents; if (IntentCountDown && maxIntents != 0) { displayedIntents = maxIntents - contador; } else displayedIntents = contador; int displayedTime; if (TimeCountDown && maxTime != 0) { displayedTime = maxTime - contadorT; } else displayedTime = contadorT; intentos.setText(Integer.toString(displayedIntents)); // actualitza // numero // intents CO.missCorrectes.setText(Integer.toString(CO.correcte)); // actualitza // numero // caselles // correctes // CO.missCorrectes.setText("C = " + CO.correcte + ", I = " + // CO.incorrecte +" In ="+displayedIntents + // "T ="+displayedTime); } } }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.exchange_hole_puzzle); sounds = new Sounds(this.getApplicationContext()); // aciertos = (TextView) findViewById(R.id.editAciertos); intentos = (TextView) findViewById(R.id.editIntentos); ttiempo = (TextView) findViewById(R.id.tiempo); tiempo = (ProgressBar) findViewById(R.id.progressTime); tiempo.setMax(maxTime); tiempo.setProgress(0); if (maxTime == 0) { tiempo.setVisibility(tiempo.INVISIBLE); ttiempo.setVisibility(ttiempo.INVISIBLE); } bMenu = (Button) findViewById(R.id.menu); try { agafarDades(); comprobarInicial(); if (CO.imatge != null) { if (CO.exemple) { InputStream in = this.getAssets().open(CO.imatge); File dst = new File("/sdcard/tmp/jclic/imatge.jpg"); dst.createNewFile(); OutputStream out = new FileOutputStream(dst); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); posarImatges(dst.getAbsolutePath()); } else { if (Descompressor.descompressor(CO.imatge, CO.path)) { posarImatges("/sdcard/tmp/jclic/" + CO.imatge); } } } sounds.playStart(); setOnClickListener(); if (maxTime != 0) { timer = new CountDownTimer(maxTime * 1000, 1000) { @Override public void onFinish() { ++contadorT; tiempo.setProgress(contadorT); setMissatges(); } @Override public void onTick(long arg0) { contadorT++; tiempo.setProgress(contadorT); setMissatges(); } }.start(); } } catch (Exception e) { Log.d("Error", "catch ExchangePuzzle: " + e); } // Insertar esto en una actividad para el uso del menu. final Context aC = this; bMenu.setOnClickListener( new OnClickListener() { public void onClick(View v) { Dialog dialog = new Dialog(aC, R.style.Dialog); dialog.setContentView(R.layout.menu_clic); dialog.setCanceledOnTouchOutside(true); dialog.show(); MenuActivitats ma = new MenuActivitats(timer); ma.butsMenu(dialog, aC, vecDraw); } }); }
// gui constructor public Gui() throws IOException { // sets frame text and features super("Doge Clicker 1.0"); this.setIconImage(new ImageIcon("Images//doge.jpg").getImage()); // initializes sound files Sounds.initialize(); // gui dimensions and features setSize(1000, 700); setResizable(false); setLayout(null); Container c = getContentPane(); c.setBackground(new Color(255, 255, 255)); setDefaultCloseOperation(EXIT_ON_CLOSE); // timer for doge per second run method runs every millisecond timer = new Timer(); timer.schedule(new RemindTask(), 1000, 10); // bolded title title = new JLabel("Doge Clicker v1.0"); title.setBounds(0, 0, getWidth(), 40); title.setFont(new Font("Comic Sans MS", Font.BOLD, 26)); title.setForeground(Color.white); title.setHorizontalAlignment(JLabel.CENTER); add(title); // reads news.txt to have import text to array String filePath = "Data\\news.txt"; BufferedReader fileIn = new BufferedReader(new FileReader(filePath)); for (int i = 0; i < line.length; i++) { // reads lines and saves until done reading if ((line[i] = fileIn.readLine()) != null) {} } fileIn.close(); // close file // read flavor text.txt to import text to array filePath = "Data\\flavourtext.txt"; fileIn = new BufferedReader(new FileReader(filePath)); for (int i = 0; i < flavourText.length; i++) { // reads lines until complety reading if ((flavourText[i] = fileIn.readLine()) != null) {} } fileIn.close(); // flavour label that pops up randomly when doge is clicked flavourClick = new JLabel("Wow! Such click!"); flavourClick.setBounds(400, 100, getWidth(), getHeight()); flavourClick.setFont(new Font("Comic Sans MS", Font.BOLD, 25)); flavourClick.setForeground(Color.white); flavourClick.setOpaque(false); add(flavourClick); // label for achievements achievementText = new JLabel("These are your achievements"); achievementText.setBounds(75, 2, getWidth(), 15); achievementText.setFont(new Font("Comic Sans MS", Font.BOLD, 13)); achievementText.setForeground(Color.white); add(achievementText); // label for doge buying and click upgrades dogeProducers = new JLabel("Buy to make more doge"); dogeProducers.setBounds(50, 160, getWidth(), 40); dogeProducers.setFont(new Font("Comic Sans MS", Font.BOLD, 13)); dogeProducers.setForeground(Color.white); add(dogeProducers); dogeClickers = new JLabel("Miscellaneous upgrades wow"); dogeClickers.setBounds(700, 160, getWidth(), 40); dogeClickers.setFont(new Font("Comic Sans MS", Font.BOLD, 13)); dogeClickers.setForeground(Color.white); add(dogeClickers); // doge click button dogeClick = new JButton(new ImageIcon("Images/doge.jpg")); dogeClick.addActionListener(this); dogeClick.setBounds(450, 100, 100, 100); dogeClick.setOpaque(false); dogeClick.setBorder(BorderFactory.createLineBorder(Color.black)); dogeClick.setToolTipText("Each click gives you " + clickUpgrade + " doge. wow"); add(dogeClick); // click multiplier clickMultiplier = new JLabel(multiplier + "x"); clickMultiplier.setBounds(570, 120, getWidth(), 50); clickMultiplier.setFont(new Font("Comic Sans MS", Font.BOLD, 30)); clickMultiplier.setForeground(Color.white); add(clickMultiplier); // clicks per second indicator cpsIndicator = new JLabel(cps + " clicks per second"); cpsIndicator.setBounds(570, 150, getWidth(), 50); cpsIndicator.setFont(new Font("Comic Sans MS", Font.BOLD, 10)); cpsIndicator.setForeground(Color.white); add(cpsIndicator); // event indicator eventIndicator = new JLabel("Welcome to doge clicker!"); eventIndicator.setBounds(700, 530, getWidth(), 50); eventIndicator.setFont(new Font("Comic Sans MS", Font.BOLD, 15)); eventIndicator.setForeground(Color.white); add(eventIndicator); // states the num of doge and doge per second dogeCount = new JLabel("Doge: " + doge); dogeCount.setBounds(0, 0, getWidth(), 120); dogeCount.setFont(new Font("Comic Sans MS", Font.BOLD, 20)); dogeCount.setForeground(Color.white); dogeCount.setHorizontalAlignment(JLabel.CENTER); add(dogeCount); dogePerSecond = new JLabel("You get " + dps + " doge per second"); dogePerSecond.setBounds(0, 25, getWidth(), 120); dogePerSecond.setFont(new Font("Comic Sans MS", Font.BOLD, 11)); dogePerSecond.setForeground(Color.white); dogePerSecond.setHorizontalAlignment(JLabel.CENTER); add(dogePerSecond); dogeClicktext = new JLabel("Click for more doge"); dogeClicktext.setBounds(400, 185, 200, 50); dogeClicktext.setFont(new Font("Comic Sans MS", Font.BOLD, 13)); dogeClicktext.setForeground(Color.white); dogeClicktext.setHorizontalAlignment(JLabel.CENTER); add(dogeClicktext); // doge button testing button devButton = new JButton(new ImageIcon()); devButton.addActionListener(this); devButton.setBounds(0, 0, 50, 50); devButton.setToolTipText("Such Secret"); devButton.setOpaque(false); devButton.setContentAreaFilled(false); devButton.setBorderPainted(false); add(devButton); // options and save buttons options = new JButton(new ImageIcon("Images/option.png")); options.addActionListener(this); options.setBounds(900, 10, 70, 70); options.setOpaque(false); options.setBorder(BorderFactory.createLineBorder(Color.black)); options.setToolTipText("Go to options"); add(options); save = new JButton(new ImageIcon("Images/save.png")); save.addActionListener(this); save.setBounds(820, 10, 70, 70); save.setOpaque(false); save.setBorder(BorderFactory.createLineBorder(Color.black)); save.setToolTipText("Save a file"); add(save); open = new JButton(new ImageIcon("Images/open.png")); open.addActionListener(this); open.setBounds(740, 10, 70, 70); open.setOpaque(false); open.setBorder(BorderFactory.createLineBorder(Color.black)); open.setToolTipText("Open a file"); add(open); // news headline label that will move for (int i = 0; i < 3; i++) { newsHeadline[i] = new JLabel("Welcome to Doge clicker this is a news headline!"); newsHeadline[i].setBounds(-200 - (475 * i), 615, getWidth(), 40); newsHeadline[i].setFont(new Font("Comic Sans MS", Font.BOLD, 13)); newsHeadline[i].setForeground(Color.white); add(newsHeadline[i]); } // create all buttons and button stats and labels for producers for (int i = 0; i < MAX_UPGRADES; i++) { producerStats[i] = new Producers(i); producers[i] = new JButton(new ImageIcon(producerStats[i].getImage())); producers[i].addActionListener(this); producers[i].setOpaque(false); producers[i].setBorder(BorderFactory.createLineBorder(Color.black)); producers[i].setToolTipText( "Your " + producerStats[i].getButtonName() + " gives " + producerStats[i].getDogeProduction() * producerStats[i].getCount() + " doge per second"); producers[i].setBounds(0, 0, 70, 70); buyProducers[i] = new JLabel( "Buy " + producerStats[i].getButtonName() + " for " + producerStats[i].getCost() + " doge"); buyProducers[i].setBounds(0, 0, getWidth(), 100); buyProducers[i].setFont(new Font("Comic Sans MS", Font.PLAIN, 12)); buyProducers[i].setForeground(Color.white); buyDetails[i] = new JLabel( "You have: " + producerStats[i].getCount() + " " + producerStats[i].getButtonName()); buyDetails[i].setBounds(0, 0, getWidth(), 100); buyDetails[i].setFont(new Font("Comic Sans MS", Font.PLAIN, 12)); buyDetails[i].setForeground(Color.white); } // buttons and labels for click upgrades clickers for (int i = 0; i < MAX_CLICK; i++) { clickerStats[i] = new Clickers(i); clickers[i] = new JButton(new ImageIcon(clickerStats[i].getImage())); clickers[i].addActionListener(this); if (clickerStats[i].getClickMultiplier() == 1) { clickers[i].setToolTipText( "Buy this " + clickerStats[i].getButtonName() + " to get +" + clickerStats[i].getClickBonus() + " doge per click"); } else { clickers[i].setToolTipText( "Buy this " + clickerStats[i].getButtonName() + " to get x" + clickerStats[i].getClickMultiplier() + " doge per click"); } clickers[i].setOpaque(false); clickers[i].setBorder(BorderFactory.createLineBorder(Color.black)); clickers[i].setBounds(0, 0, 70, 70); buyClickers[i] = new JLabel( "Buy " + clickerStats[i].getButtonName() + " for " + clickerStats[i].getCost() + " doge"); buyClickers[i].setBounds(0, 0, getWidth(), 100); buyClickers[i].setFont(new Font("Comic Sans MS", Font.PLAIN, 12)); buyClickers[i].setForeground(Color.white); } // labels for achievements for (int i = 0; i < MAX_ACHIEVEMENTS; i++) { achievementStats[i] = new Achievements(i); achievements[i] = new JLabel(new ImageIcon(achievementStats[i].getImage())); achievements[i].setBorder(BorderFactory.createLineBorder(Color.black)); achievements[i].setToolTipText("Achievement: " + achievementStats[i].getButtonName()); achievements[i].setBounds(0, 0, 70, 70); } // JPanel containing achievements JPanel achievementPanel = new JPanel(); achievementPanel.setPreferredSize(new Dimension(350, 70)); achievementPanel.setLayout(null); achievementPanel.setOpaque(false); // JScrollpane containing JPanel for achievements JScrollPane achievementDisplay = new JScrollPane(); achievementDisplay.setViewportBorder(new LineBorder(Color.black)); achievementDisplay.setSize(280, 90); achievementDisplay.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); achievementDisplay.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); achievementDisplay.getVerticalScrollBar().setUnitIncrement(10); achievementDisplay.setLocation(50, 20); achievementDisplay.setOpaque(false); add(achievementDisplay); // adds the panel achievementDisplay.getViewport().add(achievementPanel); achievementDisplay.getViewport().setOpaque(false); // adds all achievements for (int i = 0; i < MAX_ACHIEVEMENTS; i++) { achievementPanel.add(achievements[i]); achievements[i].setLocation(0 + i * 70, 0); achievements[i].setVisible(false); } // jpanel containing upgrades for producers JPanel upgradePanel = new JPanel(); upgradePanel.setPreferredSize(new Dimension(350, 770)); upgradePanel.setLayout(null); upgradePanel.setOpaque(false); // Jscrollpane containing jpanel for producers JScrollPane producerUpgrades = new JScrollPane(); producerUpgrades.setViewportBorder(new LineBorder(Color.black)); producerUpgrades.setSize(350, 300); producerUpgrades.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); producerUpgrades.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); producerUpgrades.getVerticalScrollBar().setUnitIncrement(10); producerUpgrades.setLocation(0, 200); producerUpgrades.setOpaque(false); add(producerUpgrades); producerUpgrades.getViewport().setOpaque(false); producerUpgrades.getViewport().add(upgradePanel); // adds all upgrades for (int i = 0; i < MAX_UPGRADES; i++) { upgradePanel.add(producers[i]); producers[i].setLocation(0, (i) * 70); upgradePanel.add(buyProducers[i]); buyProducers[i].setLocation(90, (i * 70) - 35); upgradePanel.add(buyDetails[i]); buyDetails[i].setLocation(90, (i * 70) - 20); } // jpanel containing upgrades for clickers JPanel clickPanel = new JPanel(); clickPanel.setPreferredSize(new Dimension(350, 350)); clickPanel.setLayout(null); clickPanel.setOpaque(false); // Jscrollpane containing jpanel for clickers JScrollPane clickUpgrades = new JScrollPane(); clickUpgrades.setViewportBorder(new LineBorder(Color.black)); clickUpgrades.setSize(350, 300); clickUpgrades.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); clickUpgrades.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); clickUpgrades.getVerticalScrollBar().setUnitIncrement(10); clickUpgrades.setLocation(650, 200); clickUpgrades.setOpaque(false); add(clickUpgrades); clickUpgrades.getViewport().add(clickPanel); clickUpgrades.getViewport().setOpaque(false); // adds all click upgrades for (int i = 0; i < MAX_CLICK; i++) { clickPanel.add(clickers[i]); clickers[i].setLocation(0, (i) * 70); clickPanel.add(buyClickers[i]); buyClickers[i].setLocation(80, (i * 70) - 30); } // dancing snoop dog image JLabel snoop = new JLabel(new ImageIcon("Images//snoop.gif")); snoop.setBounds(450, 370, 150, 308); snoop.setOpaque(false); add(snoop); // background image JLabel background = new JLabel(new ImageIcon("Images//dogebackground.png")); background.setBounds(0, 0, 1000, 700); add(background); // makes everything above visible setVisible(true); // flavour click will remain invisible flavourClick.setVisible(false); // timer for news headline, runs every 20 milliseconds MyTimerTask task = new MyTimerTask(); Timer newsTimer = new Timer(); newsTimer.scheduleAtFixedRate(task, 0, 20); }
private Rectangle[] checkCollisions() { int px = (int) player.x / BLOCK_SIZE; int py = (int) Math.floor(player.y / BLOCK_SIZE); int[] x = {px, px + 1, px + 1, px}; int[] y = {py, py, py + 1, py + 1}; Rectangle[] r = {new Rectangle(), new Rectangle(), new Rectangle(), new Rectangle()}; try { Tile[] tiles = {map[x[0]][y[0]], map[x[1]][y[1]], map[x[2]][y[2]], map[x[3]][y[3]]}; boolean inWater = false; boolean broke = false; for (int i = 0; i < tiles.length; i++) { if (tiles[i] != null) switch (tiles[i]) { case BLOCK: r[i].set(x[i], y[i], 1, 1); break; case EXIT: { player.win = true; Sounds.get().play(Sounds.WIN); } break; case DEATH: die(); break; case WATER: { if (!inWater) inWater = true; } break; case GLASS: { if (!player.abilities.contains(Ability.SOLID)) r[i].set(x[i], y[i], 1, 1); if (Math.abs(player.vy) == Player.MAX_SPEED_Y && player.abilities.contains(Ability.SOLID)) { map[x[i]][y[i]] = null; broke = true; Sounds.get().play(Sounds.CRASH); } } break; case TUBE_UP: case TUBE_RIGHT: case TUBE_DOWN: case TUBE_LEFT: { if (!player.abilities.contains(Ability.LIQUID)) { r[i].set(x[i], y[i], 1, 1); } else { Point otherTube = tubes.get(new Point(x[i], y[i])); // System.out.printf("Transporting to %d:%d%n", // otherTube.x, otherTube.y); // System.out.printf("Where is %s%n", // map[otherTube.x][otherTube.y]); // System.out.printf("Up is %s%n", // map[otherTube.x][otherTube.y+1]); // System.out.printf("Down is %s%n", // map[otherTube.x][otherTube.y-1]); // System.out.printf("Left is %s%n", // map[otherTube.x-1][otherTube.y]); // System.out.printf("Right is %s%n", // map[otherTube.x+1][otherTube.y]); if (otherTube != null) switch (map[otherTube.x][otherTube.y]) { case TUBE_UP: { /*if (player.vy < 0)*/ { player.stop(); player.x = otherTube.x * BLOCK_SIZE; player.y = otherTube.y * BLOCK_SIZE + BLOCK_SIZE + 1; player.abilities.remove(Ability.LIQUID); Sounds.get().play(Sounds.WHEEP); } } break; case TUBE_RIGHT: { /*if (player.vx < 0)*/ { player.stop(); player.x = otherTube.x * BLOCK_SIZE + BLOCK_SIZE + 1; player.y = otherTube.y * BLOCK_SIZE; player.abilities.remove(Ability.LIQUID); Sounds.get().play(Sounds.WHEEP); } } break; case TUBE_DOWN: { /*if (player.vy > 0)*/ { player.stop(); player.x = otherTube.x * BLOCK_SIZE; player.y = otherTube.y * BLOCK_SIZE - BLOCK_SIZE - 1; player.abilities.remove(Ability.LIQUID); Sounds.get().play(Sounds.WHEEP); } } break; case TUBE_LEFT: { /*if (player.vx > 0)*/ { player.stop(); player.x = otherTube.x * BLOCK_SIZE - BLOCK_SIZE - 1; player.y = otherTube.y * BLOCK_SIZE; player.abilities.remove(Ability.LIQUID); Sounds.get().play(Sounds.WHEEP); } } break; } renderer.cam.position.set(player.x, player.y, 0); } } break; case AB_SWIM: { getAbility(Ability.SWIM, x[i], y[i]); } break; case AB_GAS: { getAbility(Ability.GAS, x[i], y[i]); } break; case AB_SLICK: { getAbility(Ability.SLICK, x[i], y[i]); } break; case AB_NORMAL: { getAbility(Ability.NORMAL, x[i], y[i]); } break; case AB_SOLID: { getAbility(Ability.SOLID, x[i], y[i]); } break; case AB_LIQUID: { getAbility(Ability.LIQUID, x[i], y[i]); } break; default: r[i].set(-1, -1, 1, 1); break; } } if (broke) { player.abilities.remove(Ability.SOLID); player.canJump = true; } if (player.state == State.SWIM) { if (!inWater) { waterCount++; if (waterCount > 25) { player.state = State.RUNNING; player.abilities.remove(Ability.SWIM); } } } else if (inWater) { if (!player.abilities.contains(Ability.SWIM)) die(); else { player.state = State.SWIM; waterCount = 0; } } } catch (IndexOutOfBoundsException e) { for (int i = 0; i < r.length; i++) r[i].set(-1, -1, 0, 0); } return r; }