@Override public void render(float delta) { delta = Math.min(0.06f, delta); backgroundFX.render(); Collision.collisionCheck(); gameBatch.begin(); // Bubbles GameInstance.getInstance().bubbleParticles.draw(gameBatch); GameInstance.getInstance().bigBubbleParticles.draw(gameBatch); // Factorys for (Ship ship : GameInstance.getInstance().factorys) { if (ship.alive) { ship.draw(gameBatch); } else { GameInstance.getInstance().factorys.removeValue(ship, true); if (GameInstance.getInstance().factorys.size < 2) gameOver = true; } } // Frigate for (Ship ship : GameInstance.getInstance().frigates) { if (ship.alive) { ship.draw(gameBatch); } else { GameInstance.getInstance().frigates.removeValue(ship, true); } } // Bomber for (Ship ship : GameInstance.getInstance().bombers) { if (ship.alive) { ship.draw(gameBatch); } else { GameInstance.getInstance().bombers.removeValue(ship, true); } } // Fighter for (Ship ship : GameInstance.getInstance().fighters) { if (ship.alive) { ship.draw(gameBatch); } else { GameInstance.getInstance().fighters.removeValue(ship, true); } } // Laser for (Ship ship : GameInstance.getInstance().bullets) { if (ship.alive) { ship.draw(gameBatch); } else { GameInstance.getInstance().bullets.removeValue((Bullet) ship, true); } } // Explosions GameInstance.getInstance().sparkParticles.draw(gameBatch); GameInstance.getInstance().explosionParticles.draw(gameBatch); // font.draw(gameBatch, "fps: " + Gdx.graphics.getFramesPerSecond(), 10, 30); gameBatch.end(); // show touch area notification if (numPlayers > 0 && touchedP1) { touchFadeP1 = Math.max(touchFadeP1 - delta / 2.f, 0); } if (numPlayers > 0 && (!touchedP1 || touchFadeP1 > 0)) { gameBatch.begin(); stouchAreaP1.setColor( stouchAreaP1.getColor().r, stouchAreaP1.getColor().g, stouchAreaP1.getColor().b, touchFadeP1); stouchAreaP1.draw(gameBatch); p1.setColor(p1.getColor().r, p1.getColor().g, p1.getColor().b, touchFadeP1); p1.draw(gameBatch); gameBatch.end(); } if (numPlayers > 1 && touchedP2) { touchFadeP2 = Math.max(touchFadeP2 - delta / 2.f, 0); } if (numPlayers > 1 && (!touchedP2 || touchFadeP2 > 0)) { gameBatch.begin(); stouchAreaP2.setColor( stouchAreaP2.getColor().r, stouchAreaP2.getColor().g, stouchAreaP2.getColor().b, touchFadeP2); stouchAreaP2.draw(gameBatch); p2.setColor(p2.getColor().r, p2.getColor().g, p2.getColor().b, touchFadeP2); p2.draw(gameBatch); gameBatch.end(); } if (numPlayers > 2 && touchedP3) { touchFadeP3 = Math.max(touchFadeP3 - delta / 2.f, 0); } if (numPlayers > 2 && (!touchedP3 || touchFadeP3 > 0)) { gameBatch.begin(); stouchAreaP3.setColor( stouchAreaP3.getColor().r, stouchAreaP3.getColor().g, stouchAreaP3.getColor().b, touchFadeP3); stouchAreaP3.draw(gameBatch); p3.setColor(p3.getColor().r, p3.getColor().g, p3.getColor().b, touchFadeP3); p3.draw(gameBatch); gameBatch.end(); } if (numPlayers > 3 && touchedP4) { touchFadeP4 = Math.max(touchFadeP4 - delta / 2.f, 0); } if (numPlayers > 3 && (!touchedP4 || touchFadeP4 > 0)) { gameBatch.begin(); stouchAreaP4.setColor( stouchAreaP4.getColor().r, stouchAreaP4.getColor().g, stouchAreaP4.getColor().b, touchFadeP4); stouchAreaP4.draw(gameBatch); p4.setColor(p4.getColor().r, p4.getColor().g, p4.getColor().b, touchFadeP4); p4.draw(gameBatch); gameBatch.end(); } if (!gameOver && fade > 0 && fade < 100) { fade = Math.max(fade - delta / 2.f, 0); fadeBatch.begin(); blackFade.setColor( blackFade.getColor().r, blackFade.getColor().g, blackFade.getColor().b, fade); blackFade.draw(fadeBatch); fadeBatch.end(); } if (gameOver) { gameOverTimer -= delta; } if (gameOver && gameOverTimer <= 0) { fade = Math.min(fade + delta / 2.f, 1); fadeBatch.begin(); blackFade.setColor( blackFade.getColor().r, blackFade.getColor().g, blackFade.getColor().b, fade); blackFade.draw(fadeBatch); fadeBatch.end(); if (fade >= 1) game.setScreen(new MainMenu(game)); } // shapeRenderer.setProjectionMatrix(cam.combined); // // shapeRenderer.begin(ShapeType.Line); // shapeRenderer.setColor(1, 1, 0, 1); // shapeRenderer.line(touchAreaP1.min.x, touchAreaP1.min.y, touchAreaP1.max.x, // touchAreaP1.max.y); // shapeRenderer.line(touchAreaP2.min.x, touchAreaP2.min.y, touchAreaP2.max.x, // touchAreaP2.max.y); // shapeRenderer.line(touchAreaP3.min.x, touchAreaP3.min.y, touchAreaP3.max.x, // touchAreaP3.max.y); // shapeRenderer.line(touchAreaP4.min.x, touchAreaP4.min.y, touchAreaP4.max.x, // touchAreaP4.max.y); // shapeRenderer.end(); }
@Override public void resize(int width, int height) { this.width = width; this.height = height; if (width == 480 && height == 320) { cam = new OrthographicCamera(700, 466); this.width = 700; this.height = 466; } else if (width == 320 && height == 240) { cam = new OrthographicCamera(700, 525); this.width = 700; this.height = 525; } else if (width == 400 && height == 240) { cam = new OrthographicCamera(800, 480); this.width = 800; this.height = 480; } else if (width == 432 && height == 240) { cam = new OrthographicCamera(700, 389); this.width = 700; this.height = 389; } else if (width == 960 && height == 640) { cam = new OrthographicCamera(800, 533); this.width = 800; this.height = 533; } else if (width == 1366 && height == 768) { cam = new OrthographicCamera(1280, 720); this.width = 1280; this.height = 720; } else if (width == 1366 && height == 720) { cam = new OrthographicCamera(1280, 675); this.width = 1280; this.height = 675; } else if (width == 1536 && height == 1152) { cam = new OrthographicCamera(1366, 1024); this.width = 1366; this.height = 1024; } else if (width == 1920 && height == 1152) { cam = new OrthographicCamera(1366, 854); this.width = 1366; this.height = 854; } else if (width == 1920 && height == 1200) { cam = new OrthographicCamera(1366, 800); this.width = 1280; this.height = 800; } else if (width > 1280) { cam = new OrthographicCamera(1280, 768); this.width = 1280; this.height = 768; } else if (width < 800) { cam = new OrthographicCamera(800, 480); this.width = 800; this.height = 480; } else { cam = new OrthographicCamera(width, height); } cam.position.x = 400; cam.position.y = 240; cam.update(); backgroundFX.resize(width, height); gameBatch.getProjectionMatrix().set(cam.combined); if (numPlayers == 1) { p1.setRotation(-90); stouchAreaP1.setRotation(-90); touchAreaP1 = new BoundingBox( new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0), new Vector3( -((this.width - 800) / 2) + (this.width), -((this.height - 480) / 2) + this.height, 0)); stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40); p1.setPosition(touchAreaP1.min.x + 10, touchAreaP1.getCenter().y - 105); } else if (numPlayers == 2) { p1.setRotation(-90); p2.setRotation(90); stouchAreaP1.setRotation(-90); stouchAreaP2.setRotation(90); touchAreaP1 = new BoundingBox( new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0), new Vector3( -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2) + this.height, 0)); touchAreaP2 = new BoundingBox( new Vector3( -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0), new Vector3( -((this.width - 800) / 2) + this.width, -((this.height - 480) / 2) + this.height, 0)); stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40); p1.setPosition(touchAreaP1.min.tmp().x + 10, touchAreaP1.getCenter().y - 105); stouchAreaP2.setPosition(touchAreaP2.max.x - 170, touchAreaP2.getCenter().y - 40); p2.setPosition(touchAreaP2.max.x - 190, touchAreaP2.getCenter().y - 15); } else if (numPlayers == 3) { p1.setRotation(-90); p2.setRotation(-90); p3.setRotation(90); stouchAreaP1.setRotation(-90); stouchAreaP2.setRotation(-90); stouchAreaP3.setRotation(90); touchAreaP1 = new BoundingBox( new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0), new Vector3( -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2) + (this.height / 2), 0)); touchAreaP2 = new BoundingBox( new Vector3( -((this.width - 800) / 2), -((this.height - 480) / 2) + (this.height / 2), 0), new Vector3( -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2) + this.height, 0)); touchAreaP3 = new BoundingBox( new Vector3( -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0), new Vector3( -((this.width - 800) / 2) + this.width, -((this.height - 480) / 2) + this.height, 0)); stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40); p1.setPosition(touchAreaP1.min.tmp().x + 10, touchAreaP1.getCenter().y - 105); stouchAreaP2.setPosition(touchAreaP2.min.x, touchAreaP2.getCenter().y - 40); p2.setPosition(touchAreaP2.min.x + 10, touchAreaP2.getCenter().y - 105); stouchAreaP3.setPosition(touchAreaP3.max.x - 170, touchAreaP3.getCenter().y - 40); p3.setPosition(touchAreaP3.max.x - 190, touchAreaP3.getCenter().y - 15); } else if (numPlayers == 4) { p1.setRotation(-90); p2.setRotation(-90); p3.setRotation(90); p4.setRotation(90); stouchAreaP1.setRotation(-90); stouchAreaP2.setRotation(-90); stouchAreaP3.setRotation(90); stouchAreaP4.setRotation(90); touchAreaP1 = new BoundingBox( new Vector3(-((this.width - 800) / 2), -((this.height - 480) / 2), 0), new Vector3( -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2) + (this.height / 2), 0)); touchAreaP2 = new BoundingBox( new Vector3( -((this.width - 800) / 2), -((this.height - 480) / 2) + (this.height / 2), 0), new Vector3( -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2) + this.height, 0)); touchAreaP3 = new BoundingBox( new Vector3( -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2), 0), new Vector3( -((this.width - 800) / 2) + this.width, -((this.height - 480) / 2) + (this.height / 2), 0)); touchAreaP4 = new BoundingBox( new Vector3( -((this.width - 800) / 2) + (this.width / 2), -((this.height - 480) / 2) + (this.height / 2), 0), new Vector3( -((this.width - 800) / 2) + this.width, -((this.height - 480) / 2) + this.height, 0)); stouchAreaP1.setPosition(touchAreaP1.min.x, touchAreaP1.getCenter().y - 40); p1.setPosition(touchAreaP1.min.tmp().x + 10, touchAreaP1.getCenter().y - 105); stouchAreaP2.setPosition(touchAreaP2.min.x, touchAreaP2.getCenter().y - 40); p2.setPosition(touchAreaP2.min.x + 10, touchAreaP2.getCenter().y - 105); stouchAreaP3.setPosition(touchAreaP3.max.x - 170, touchAreaP3.getCenter().y - 40); p3.setPosition(touchAreaP3.max.x - 190, touchAreaP3.getCenter().y - 15); stouchAreaP4.setPosition(touchAreaP4.max.x - 170, touchAreaP4.getCenter().y - 40); p4.setPosition(touchAreaP4.max.x - 190, touchAreaP4.getCenter().y - 15); } }