/** 这部分资源需要立即载入,其他资源可以异步载入 */ public static void init() { isLoaded = false; assetManager = new AssetManager(); // 读取游戏绘图素材 textureAtlas_background = new TextureAtlas(Gdx.files.internal("data/shoot_background.pack")); // Loading动画 gameLoading = new TextureRegion[4]; gameLoading[0] = new TextureRegion(textureAtlas_background.createSprite("game_loading1")); gameLoading[1] = new TextureRegion(textureAtlas_background.createSprite("game_loading2")); gameLoading[2] = new TextureRegion(textureAtlas_background.createSprite("game_loading3")); gameLoading[3] = new TextureRegion(textureAtlas_background.createSprite("game_loading4")); animation_gameLoading = new Animation(0.5f, gameLoading); }
public Stage_Game(Viewport viewport) { super(viewport); unprojected = new Vector3(0, 0, 0); Gdx.input.setCatchBackKey(true); pauseButton = new ImageButton(skin, "pause"); pauseButton.getStyle().imageChecked.setMinWidth(150); pauseButton.getStyle().imageChecked.setMinHeight(150); pauseButton.setBounds(880, 1720, 150, 150); pauseButton.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { super.clicked(event, x, y); pause = !pause; pauseButton.setChecked(pause); exitButton.setVisible(pause); MainClass.clickSound.play(MainClass.sound); } }); exitButton = new ImageButton(skin, "exit"); exitButton.setBounds(880, 1550, 150, 150); exitButton.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { MainClass.setCurrentStage(new Stage_Menu(getViewport())); MainClass.clickSound.play(MainClass.sound); super.clicked(event, x, y); } }); exitButton.setVisible(false); gameOver = false; pause = false; bodyY = new Array<Float>(); camera = new OrthographicCamera(5.628f, 10.0f); camera.position.set(2.814f, 4, 0); camY = 4; camera.update(); muffinSource = new Actor() { @Override public void draw(Batch batch, float parentAlpha) { super.draw(batch, parentAlpha); muffinSourceSprite.setBounds(425, 1680, 230, 186); muffinSourceSprite.setScale(getScaleX()); muffinSourceSprite.draw(batch); } }; muffinSource.setBounds(425, 1680, 230, 186); muffinSource.addListener( new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (muffinSource.getScaleX() >= 1 && !pause && !gameOver) { newMuffinSound.play(MainClass.sound); unprojected = camera.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0)); muffinBodyDef.position.set(new Vector2(unprojected.x - 0.5f, unprojected.y - 0.5f)); tmpbd = world.createBody(muffinBodyDef); loader.attachFixture(tmpbd, "MuffinModel", muffinFixtureDef, 1.1f, 1.1f, 1.1f); tmpbd.setFixedRotation(true); drag = true; muffinSource.setScale(0.1f); ScaleToAction getNormal = new ScaleToAction(); getNormal.setScale(1); getNormal.setDuration(0.4f); mpHandler.addParticle(unprojected.x, unprojected.y, tmpbd); muffinSource.addAction(getNormal); } return super.touchDown(event, x, y, pointer, button); } }); score = 0; scoreLabel = new Label("Score: 0", skin, "score"); scoreLabel.setPosition(15, 1920 - scoreLabel.getHeight()); /** TEXTURES * */ fireEffect = new ParticleEffect(); fireEffect = AssetLoader.manager.get(AssetLoader.fireParticlePath); mpHandler = new MuffinParticleHandler(fireEffect); textures = AssetLoader.manager.get(AssetLoader.uiAtlasPath, TextureAtlas.class); normalmuffinface = textures.createSprite("muffin_face_normal"); scaredmuffinface = textures.createSprite("muffin_face_scared"); awakemuffinface = textures.createSprite("muffin_face_awake"); traySprite = textures.createSprite("tray"); traySprite.setPosition(0.3f, -1.8f); traySprite.setSize(4.4f, 2.19f); backgrounds = new Sprite[5]; for (i = 0; i < 5; i++) { backgrounds[i] = new Sprite( AssetLoader.manager.get("menu/back" + String.valueOf(i + 1) + ".png", Texture.class)); backgrounds[i].setBounds( camera.position.x - (camera.viewportWidth / 2), camera.position.y - (camera.viewportHeight / 2) + (i * 1920 / 192), (float) 1080 / 192, (float) 1920 / 192); } batch = new SpriteBatch(); batch.setProjectionMatrix(camera.combined); muffinSprite = textures.createSprite("muffin"); muffinSourceSprite = textures.createSprite("muffin"); muffinSourceSprite.setBounds(450, 1714, 180, 146); muffinSourceSprite.setOrigin(90, 73); /** PHYSICS * */ bodies = new Array<Body>(); // WORLD world = new World(new Vector2(0, -10f), true); renderer = new Box2DDebugRenderer(); // PLATE BodyDef plateDef = new BodyDef(); plateDef.type = BodyDef.BodyType.StaticBody; plateDef.position.set(2.814f, 0.25f); plate = world.createBody(plateDef); FixtureDef plateFixtureDef = new FixtureDef(); PolygonShape plateShape = new PolygonShape(); plateShape.setAsBox(1.8f, 0.1f); plateFixtureDef.shape = plateShape; plateFixtureDef.friction = 0.9f; // plateFixtureDef.density = 1; plate.createFixture(plateFixtureDef); plateShape.dispose(); // MUFFIN loader = new BodyEditorLoader(Gdx.files.internal("physics/muffin.json")); muffinBodyDef = new BodyDef(); muffinBodyDef.type = BodyDef.BodyType.DynamicBody; muffinBodyDef.bullet = true; muffinFixtureDef = new FixtureDef(); muffinFixtureDef.density = 0.7f; muffinFixtureDef.friction = 0.5f; muffinFixtureDef.restitution = 0.1f; muffinOrigin = loader.getOrigin("MuffinModel", 1.1f).cpy(); gameOverDialog = new Dialog_GameOver("", skin, "default"); /** SOUNDS * */ newHighScoreSound = AssetLoader.manager.get(AssetLoader.clappingPath, Sound.class); gameOverSound = AssetLoader.manager.get(AssetLoader.gameOverPath, Sound.class); newMuffinSound = AssetLoader.manager.get(AssetLoader.newMuffinPath, Sound.class); addActor(pauseButton); addActor(exitButton); addActor(muffinSource); addActor(scoreLabel); }
public SplashScreen(TweenCallback callback) { this.callback = callback; TextureAtlas atlas = Assets.inst().get("data/splash/pack", TextureAtlas.class); universal = atlas.createSprite("universal"); tween = atlas.createSprite("tween"); engine = atlas.createSprite("engine"); logo = atlas.createSprite("logo"); strip = atlas.createSprite("white"); powered = atlas.createSprite("powered"); gdx = atlas.createSprite("gdxblur"); veil = atlas.createSprite("white"); gdxTex = atlas.findRegion("gdx"); float wpw = 1f; float wph = wpw * Gdx.graphics.getHeight() / Gdx.graphics.getWidth(); camera.viewportWidth = wpw; camera.viewportHeight = wph; camera.update(); Gdx.input.setInputProcessor(inputProcessor); Sprite[] sprites = new Sprite[] {universal, tween, engine, logo, powered, gdx}; for (Sprite sp : sprites) { sp.setSize(sp.getWidth() / PX_PER_METER, sp.getHeight() / PX_PER_METER); sp.setOrigin(sp.getWidth() / 2, sp.getHeight() / 2); } universal.setPosition(-0.325f, 0.028f); tween.setPosition(-0.320f, -0.066f); engine.setPosition(0.020f, -0.087f); logo.setPosition(0.238f, 0.022f); strip.setSize(wpw, wph); strip.setOrigin(wpw / 2, wph / 2); strip.setPosition(-wpw / 2, -wph / 2); powered.setPosition(-0.278f, -0.025f); gdx.setPosition(0.068f, -0.077f); veil.setSize(wpw, wph); veil.setPosition(-wpw / 2, -wph / 2); veil.setColor(1, 1, 1, 0); Timeline.createSequence() .push(Tween.set(tween, SpriteAccessor.POS_XY).targetRelative(-1, 0)) .push(Tween.set(engine, SpriteAccessor.POS_XY).targetRelative(1, 0)) .push(Tween.set(universal, SpriteAccessor.POS_XY).targetRelative(0, 0.5f)) .push(Tween.set(logo, SpriteAccessor.SCALE_XY).target(7, 7)) .push(Tween.set(logo, SpriteAccessor.OPACITY).target(0)) .push(Tween.set(strip, SpriteAccessor.SCALE_XY).target(1, 0)) .push(Tween.set(powered, SpriteAccessor.OPACITY).target(0)) .push(Tween.set(gdx, SpriteAccessor.OPACITY).target(0)) .pushPause(0.5f) .push(Tween.to(strip, SpriteAccessor.SCALE_XY, 0.8f).target(1, 0.6f).ease(Back.OUT)) .push(Tween.to(tween, SpriteAccessor.POS_XY, 0.5f).targetRelative(1, 0).ease(Quart.OUT)) .push(Tween.to(engine, SpriteAccessor.POS_XY, 0.5f).targetRelative(-1, 0).ease(Quart.OUT)) .push( Tween.to(universal, SpriteAccessor.POS_XY, 0.6f) .targetRelative(0, -0.5f) .ease(Quint.OUT)) .pushPause(-0.3f) .beginParallel() .push(Tween.set(logo, SpriteAccessor.OPACITY).target(1)) .push(Tween.to(logo, SpriteAccessor.SCALE_XY, 0.5f).target(1, 1).ease(Back.OUT)) .end() .push(Tween.to(strip, SpriteAccessor.SCALE_XY, 0.5f).target(1, 1).ease(Back.IN)) .pushPause(0.3f) .beginParallel() .push(Tween.to(tween, SpriteAccessor.POS_XY, 0.5f).targetRelative(1, 0).ease(Back.IN)) .push(Tween.to(engine, SpriteAccessor.POS_XY, 0.5f).targetRelative(1, 0).ease(Back.IN)) .push(Tween.to(universal, SpriteAccessor.POS_XY, 0.5f).targetRelative(1, 0).ease(Back.IN)) .push(Tween.to(logo, SpriteAccessor.POS_XY, 0.5f).targetRelative(1, 0).ease(Back.IN)) .end() .pushPause(-0.3f) .push(Tween.to(powered, SpriteAccessor.OPACITY, 0.3f).target(1)) .beginParallel() .push(Tween.to(gdx, SpriteAccessor.OPACITY, 1.5f).target(1).ease(Cubic.IN)) .push(Tween.to(gdx, SpriteAccessor.ROTATION, 2.0f).target(360 * 15).ease(Quad.OUT)) .end() .pushPause(0.3f) .push( Tween.to(gdx, SpriteAccessor.SCALE_XY, 0.6f) .waypoint(1.6f, 0.4f) .target(1.2f, 1.2f) .ease(Cubic.OUT)) .pushPause(0.3f) .beginParallel() .push(Tween.to(powered, SpriteAccessor.POS_XY, 0.5f).targetRelative(1, 0).ease(Back.IN)) .push(Tween.to(gdx, SpriteAccessor.POS_XY, 0.5f).targetRelative(1, 0).ease(Back.IN)) .end() .pushPause(0.3f) .setCallback(callback) .start(tweenManager); }
/** 异步加载资源 */ public static void update() { if (assetManager.update()) { textureAtlas_planes = assetManager.get("data/shoot.pack", TextureAtlas.class); // 背景,用来滚动显示 backgroud = textureAtlas_background.createSprite("background"); // 版权背景 copyright = textureAtlas_background.createSprite("shoot_copyright"); // 字体 font = assetManager.get("data/ui/font.fnt", BitmapFont.class); font.setColor(Color.BLACK); // 返回按钮 btn_goback = new TextureRegion(textureAtlas_background.createSprite("btn_finish")); // 玩家飞机 player = new TextureRegion[2]; player[0] = textureAtlas_planes.createSprite("hero1"); player[1] = textureAtlas_planes.createSprite("hero2"); animation_player = new Animation(0.3f, player); player_down = new TextureRegion[4]; player_down[0] = textureAtlas_planes.createSprite("hero_blowup_n1"); player_down[1] = textureAtlas_planes.createSprite("hero_blowup_n2"); player_down[2] = textureAtlas_planes.createSprite("hero_blowup_n3"); player_down[3] = textureAtlas_planes.createSprite("hero_blowup_n4"); animation_player_down = new Animation(0.3f, player_down); // 敌方飞机 enemy1 = new TextureRegion[1]; enemy2 = new TextureRegion[1]; enemy3 = new TextureRegion[2]; enemy1[0] = textureAtlas_planes.createSprite("enemy1"); enemy2[0] = textureAtlas_planes.createSprite("enemy2"); enemy3[0] = textureAtlas_planes.createSprite("enemy3_n1"); enemy3[1] = textureAtlas_planes.createSprite("enemy3_n2"); animation_enemy = new Animation[3]; animation_enemy[0] = new Animation(0.3f, enemy1); animation_enemy[1] = new Animation(0.3f, enemy2); animation_enemy[2] = new Animation(0.3f, enemy3); // 敌方飞机被击中动画 enemy2_hit = textureAtlas_planes.createSprite("enemy2_hit"); enemy3_hit = textureAtlas_planes.createSprite("enemy3_hit"); animation_enemy_hit = new Animation[3]; animation_enemy_hit[0] = new Animation(0.3f, enemy1); animation_enemy_hit[1] = new Animation(0.3f, enemy2[0], enemy2_hit); animation_enemy_hit[2] = new Animation(0.3f, enemy3[0], enemy3[1], enemy3_hit); // 敌方飞机爆炸动画 enemy1_down = new TextureRegion[4]; enemy2_down = new TextureRegion[4]; enemy3_down = new TextureRegion[6]; enemy1_down[0] = textureAtlas_planes.createSprite("enemy1_down1"); enemy1_down[1] = textureAtlas_planes.createSprite("enemy1_down2"); enemy1_down[2] = textureAtlas_planes.createSprite("enemy1_down3"); enemy1_down[3] = textureAtlas_planes.createSprite("enemy1_down4"); enemy2_down[0] = textureAtlas_planes.createSprite("enemy2_down1"); enemy2_down[1] = textureAtlas_planes.createSprite("enemy2_down2"); enemy2_down[2] = textureAtlas_planes.createSprite("enemy2_down3"); enemy2_down[3] = textureAtlas_planes.createSprite("enemy2_down4"); enemy3_down[0] = textureAtlas_planes.createSprite("enemy3_down1"); enemy3_down[1] = textureAtlas_planes.createSprite("enemy3_down2"); enemy3_down[2] = textureAtlas_planes.createSprite("enemy3_down3"); enemy3_down[3] = textureAtlas_planes.createSprite("enemy3_down4"); enemy3_down[4] = textureAtlas_planes.createSprite("enemy3_down5"); enemy3_down[5] = textureAtlas_planes.createSprite("enemy3_down6"); animation_enemy_down = new Animation[3]; animation_enemy_down[0] = new Animation(0.1f, enemy1_down); animation_enemy_down[1] = new Animation(0.1f, enemy2_down); animation_enemy_down[2] = new Animation(0.1f, enemy3_down); // 暂停按钮 gamePause = textureAtlas_planes.createSprite("game_pause_nor"); gamePausePressed = textureAtlas_planes.createSprite("game_pause_pressed"); // 炸弹 bomb = textureAtlas_planes.createSprite("bomb"); // 子弹 bullet_red = textureAtlas_planes.createSprite("bullet1"); bullet_bule = textureAtlas_planes.createSprite("bullet2"); // UFO UFO_BULLET = textureAtlas_planes.createSprite("ufo1"); UFO_BOMB = textureAtlas_planes.createSprite("ufo2"); isLoaded = true; } }