License text

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER 
 * Copyright  2008, 2010 Oracle and/or its affiliates.  All rights reserved. 
 * Use is subject to license terms.
 * 
 * This file is available and licensed under the following license:
 * 
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met: 
 * 
 *   * Redistributions of source code must retain the above copyright notice, 
 *     this list of conditions and the following disclaimer. 
 *
 *   * Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *
 *   * Neither the name of Oracle Corporation nor the names of its contributors 
 *     may be used to endorse or promote products derived from this software 
 *     without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

    

package brickbreaker;

import javafx.scene.image.*;
import javafx.stage.*;
/**
 * @author Pavel Porvatov
 */

public var isMobile: Boolean = false;
public var isTV: Boolean = false;

public function initialize(currentProfile: String) {
    if(currentProfile == "mobile") {
	isMobile = true;
    }
    else if(currentProfile == "tv") {
	isTV = true;
    }

    for (imageName in IMAGES_NAMES) {
        var image = Image {
            url: "{IMAGE_DIR}/{imageName}"
        };
        if (image.error) {
            println("Image {imageName} not found");
        }

        insert image into images;
    }

    for (imageName in BRICKS_IMAGES) {
        var image = Image {
            url: "{IMAGE_DIR}/brick/{imageName}"
        };
        if (image.error) {
            println("Image {image.url} not found");
        }

        insert image into bricksImages;
    }
    var BONUS_IMAGES_DIR = "{__DIR__}images/desktop";
    for (imageName in BONUSES_IMAGES) {
        if (Config.screenHeight < 500) 
        BONUS_IMAGES_DIR = "{__DIR__}images/mobile";
        var image = Image {
            url: "{BONUS_IMAGES_DIR}/bonus/{imageName}"
        };

        if (image.error) {
            println("Image {image.url} not found");
        }
        insert image into bonusesImages;
    }
}

public def ANIMATION_TIME = 0.04s;

// Screen info
public def FIELD_BRICK_IN_ROW = 15;

public def IMAGE_DIR = bind if(isMobile) "{__DIR__}images/mobile" else "{__DIR__}images/desktop";

public def scale: Number = bind if (isMobile) Screen.primary.visualBounds.maxX * 1.43/1000 else 1.0;

public def screenWidth: Integer = bind if (isMobile) Screen.primary.visualBounds.maxX as Integer else if(isTV) 1200 else 960;
public def screenHeight: Integer = bind if (isMobile) Screen.primary.visualBounds.maxY as Integer else if(isTV) 720 else 720;

public def infoTextSpace: Integer = bind 10 * scale as Integer;

// Game field info
public def brickWidth: Integer = bind 48 * scale as Integer;
public def brickHeight: Integer = bind 24 * scale as Integer;
public def shadowWidth: Integer = bind 10 * scale as Integer;
public def shadowHeight: Integer = bind 16 * scale as Integer;

public def ballMinSpeed: Number = bind 6 * scale;
public def ballMaxSpeed: Number = bind brickHeight;
public def ballMinCoordSpeed: Number = bind 2 * scale;
public def ballSpeedInc: Number = bind 0.5 * scale;

public def batY: Integer = bind screenHeight - 40 * scale as Integer;
public def batSpeed = bind 8 * scale as Integer;

public def bonusSpeed: Integer = bind 3 * scale as Integer;

public def fieldWidth: Integer = bind if (isMobile) screenWidth else FIELD_BRICK_IN_ROW * brickWidth;
public def fieldHeight: Integer = bind fieldWidth;
public def fieldY: Integer = bind screenHeight - fieldHeight;

// ################
// Ui
// ################
def BRICKS_IMAGES = [
    "blue.png",
    "broken1.png",
    "broken2.png",
    "brown.png",
    "cyan.png",
    "green.png",
    "grey.png",
    "magenta.png",
    "orange.png",
    "red.png",
    "violet.png",
    "white.png",
    "yellow.png",
];

public var bricksImages: Image[] = [];

def BONUSES_IMAGES = [
    "ballslow.png",
    "ballfast.png",
    "catch.png",
    "batgrow.png",
    "batreduce.png",
    "ballgrow.png",
    "ballreduce.png",
    "strike.png",
    "extralife.png",
];

public var bonusesImages: Image[] = [];

public def IMAGE_BACKGROUND = 0;
public def IMAGE_BAT_LEFT = 1;
public def IMAGE_BAT_CENTER = 2;
public def IMAGE_BAT_RIGHT = 3;
public def IMAGE_BALL_0 = 4;
public def IMAGE_BALL_1 = 5;
public def IMAGE_BALL_2 = 6;
public def IMAGE_BALL_3 = 7;
public def IMAGE_BALL_4 = 8;
public def IMAGE_BALL_5 = 9;
public def IMAGE_LOGO = 10;
public def IMAGE_SPLASH_BRICK = 11;
public def IMAGE_SPLASH_BRICKSHADOW = 12;
public def IMAGE_SPLASH_BREAKER = 13;
public def IMAGE_SPLASH_BREAKERSHADOW = 14;
public def IMAGE_SPLASH_PRESSANYKEY = 15;
public def IMAGE_SPLASH_PRESSANYKEYSHADOW = 16;
public def IMAGE_SPLASH_STRIKE = 17;
public def IMAGE_SPLASH_STRIKESHADOW = 18;
public def IMAGE_SPLASH_SUN = 19;
public def IMAGE_READY = 20;
public def IMAGE_GAMEOVER = 21;

def IMAGES_NAMES = [
    "background.png",
    "bat/left.png",
    "bat/center.png",
    "bat/right.png",
    "ball/ball0.png",
    "ball/ball1.png",
    "ball/ball2.png",
    "ball/ball3.png",
    "ball/ball4.png",
    "ball/ball5.png",
    "logo.png",
    "splash/brick.png",
    "splash/brickshadow.png",
    "splash/breaker.png",
    "splash/breakershadow.png",
    "splash/pressanykey.png",
    "splash/pressanykeyshadow.png",
    "splash/strike.png",
    "splash/strikeshadow.png",
    "splash/sun.png",
    "ready.png",
    "gameover.png",
];

public var images: Image[] = [];

public function scaleFont(size: Number): Integer {
    (size - 2) * scale + 2 as Integer
}