Search in sources :

Example 1 with RedButton

use of com.watabou.pixeldungeon.ui.RedButton in project pixel-dungeon by watabou.

the class SurfaceScene method create.

@Override
public void create() {
    super.create();
    Music.INSTANCE.play(Assets.HAPPY, true);
    Music.INSTANCE.volume(1f);
    uiCamera.visible = false;
    int w = Camera.main.width;
    int h = Camera.main.height;
    Archs archs = new Archs();
    archs.reversed = true;
    archs.setSize(w, h);
    add(archs);
    float vx = align((w - SKY_WIDTH) / 2);
    float vy = align((h - SKY_HEIGHT - BUTTON_HEIGHT) / 2);
    Point s = Camera.main.cameraToScreen(vx, vy);
    viewport = new Camera(s.x, s.y, SKY_WIDTH, SKY_HEIGHT, defaultZoom);
    Camera.add(viewport);
    Group window = new Group();
    window.camera = viewport;
    add(window);
    boolean dayTime = !Dungeon.nightMode;
    Sky sky = new Sky(dayTime);
    sky.scale.set(SKY_WIDTH, SKY_HEIGHT);
    window.add(sky);
    if (!dayTime) {
        for (int i = 0; i < NSTARS; i++) {
            float size = Random.Float();
            ColorBlock star = new ColorBlock(size, size, 0xFFFFFFFF);
            star.x = Random.Float(SKY_WIDTH) - size / 2;
            star.y = Random.Float(SKY_HEIGHT) - size / 2;
            star.am = size * (1 - star.y / SKY_HEIGHT);
            window.add(star);
        }
    }
    float range = SKY_HEIGHT * 2 / 3;
    for (int i = 0; i < NCLOUDS; i++) {
        Cloud cloud = new Cloud((NCLOUDS - 1 - i) * (range / NCLOUDS) + Random.Float(range / NCLOUDS), dayTime);
        window.add(cloud);
    }
    int nPatches = (int) (sky.width() / GrassPatch.WIDTH + 1);
    for (int i = 0; i < nPatches * 4; i++) {
        GrassPatch patch = new GrassPatch((i - 0.75f) * GrassPatch.WIDTH / 4, SKY_HEIGHT + 1, dayTime);
        patch.brightness(dayTime ? 0.7f : 0.4f);
        window.add(patch);
    }
    Avatar a = new Avatar(Dungeon.hero.heroClass);
    a.x = PixelScene.align((SKY_WIDTH - a.width) / 2);
    a.y = SKY_HEIGHT - a.height;
    window.add(a);
    final Pet pet = new Pet();
    pet.rm = pet.gm = pet.bm = 1.2f;
    pet.x = SKY_WIDTH / 2 + 2;
    pet.y = SKY_HEIGHT - pet.height;
    window.add(pet);
    window.add(new TouchArea(sky) {

        protected void onClick(Touch touch) {
            pet.jump();
        }

        ;
    });
    for (int i = 0; i < nPatches; i++) {
        GrassPatch patch = new GrassPatch((i - 0.5f) * GrassPatch.WIDTH, SKY_HEIGHT, dayTime);
        patch.brightness(dayTime ? 1.0f : 0.8f);
        window.add(patch);
    }
    Image frame = new Image(Assets.SURFACE);
    frame.frame(0, 0, FRAME_WIDTH, FRAME_HEIGHT);
    frame.x = vx - FRAME_MARGIN_X;
    frame.y = vy - FRAME_MARGIN_TOP;
    add(frame);
    if (dayTime) {
        a.brightness(1.2f);
        pet.brightness(1.2f);
    } else {
        frame.hardlight(0xDDEEFF);
    }
    RedButton gameOver = new RedButton("Game Over") {

        protected void onClick() {
            Game.switchScene(TitleScene.class);
        }
    };
    gameOver.setSize(SKY_WIDTH - FRAME_MARGIN_X * 2, BUTTON_HEIGHT);
    gameOver.setPos(frame.x + FRAME_MARGIN_X * 2, frame.y + frame.height + 4);
    add(gameOver);
    Badges.validateHappyEnd();
    fadeIn();
}
Also used : Group(com.watabou.noosa.Group) Point(com.watabou.utils.Point) Touch(com.watabou.input.Touchscreen.Touch) Image(com.watabou.noosa.Image) Point(com.watabou.utils.Point) Archs(com.watabou.pixeldungeon.ui.Archs) TouchArea(com.watabou.noosa.TouchArea) Camera(com.watabou.noosa.Camera) RedButton(com.watabou.pixeldungeon.ui.RedButton) ColorBlock(com.watabou.noosa.ColorBlock)

Example 2 with RedButton

use of com.watabou.pixeldungeon.ui.RedButton in project pixel-dungeon by watabou.

the class AmuletScene method create.

@Override
public void create() {
    super.create();
    BitmapTextMultiline text = null;
    if (!noText) {
        text = createMultiline(TXT, 8);
        text.maxWidth = WIDTH;
        text.measure();
        add(text);
    }
    amulet = new Image(Assets.AMULET);
    add(amulet);
    RedButton btnExit = new RedButton(TXT_EXIT) {

        @Override
        protected void onClick() {
            Dungeon.win(ResultDescriptions.WIN);
            Dungeon.deleteGame(Dungeon.hero.heroClass, true);
            Game.switchScene(noText ? TitleScene.class : RankingsScene.class);
        }
    };
    btnExit.setSize(WIDTH, BTN_HEIGHT);
    add(btnExit);
    RedButton btnStay = new RedButton(TXT_STAY) {

        @Override
        protected void onClick() {
            onBackPressed();
        }
    };
    btnStay.setSize(WIDTH, BTN_HEIGHT);
    add(btnStay);
    float height;
    if (noText) {
        height = amulet.height + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
        amulet.x = align((Camera.main.width - amulet.width) / 2);
        amulet.y = align((Camera.main.height - height) / 2);
        btnExit.setPos((Camera.main.width - btnExit.width()) / 2, amulet.y + amulet.height + LARGE_GAP);
        btnStay.setPos(btnExit.left(), btnExit.bottom() + SMALL_GAP);
    } else {
        height = amulet.height + LARGE_GAP + text.height() + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
        amulet.x = align((Camera.main.width - amulet.width) / 2);
        amulet.y = align((Camera.main.height - height) / 2);
        text.x = align((Camera.main.width - text.width()) / 2);
        text.y = amulet.y + amulet.height + LARGE_GAP;
        btnExit.setPos((Camera.main.width - btnExit.width()) / 2, text.y + text.height() + LARGE_GAP);
        btnStay.setPos(btnExit.left(), btnExit.bottom() + SMALL_GAP);
    }
    new Flare(8, 48).color(0xFFDDBB, true).show(amulet, 0).angularSpeed = +30;
    fadeIn();
}
Also used : Flare(com.watabou.pixeldungeon.effects.Flare) RedButton(com.watabou.pixeldungeon.ui.RedButton) Image(com.watabou.noosa.Image) BitmapTextMultiline(com.watabou.noosa.BitmapTextMultiline)

Aggregations

Image (com.watabou.noosa.Image)2 RedButton (com.watabou.pixeldungeon.ui.RedButton)2 Touch (com.watabou.input.Touchscreen.Touch)1 BitmapTextMultiline (com.watabou.noosa.BitmapTextMultiline)1 Camera (com.watabou.noosa.Camera)1 ColorBlock (com.watabou.noosa.ColorBlock)1 Group (com.watabou.noosa.Group)1 TouchArea (com.watabou.noosa.TouchArea)1 Flare (com.watabou.pixeldungeon.effects.Flare)1 Archs (com.watabou.pixeldungeon.ui.Archs)1 Point (com.watabou.utils.Point)1