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 dukeman;

import java.util.Hashtable;
import javafx.scene.image.*;

//@author Pavel Porvatov

public def ANIMATION_TIME = 0.04s;

public def IS_MOBILE = FX.getProperty("javafx.me.profiles") != null;

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

public def SCREEN_WIDTH = bind if (IS_MOBILE) 240 else 480;
public def SCREEN_HEIGHT = bind if (IS_MOBILE) 320 else 640;

public def CELL_SIZE = bind if (IS_MOBILE) 8 else 16;
public def DUKE_SPEED = bind if (IS_MOBILE) 2 else 4;

public def BOTTOM_AREA_HEIGHT = bind CELL_SIZE * 3;
public def GAME_FIELD_WIDTH = bind LevelData.WIDTH * CELL_SIZE;
public def GAME_FIELD_HEIGHT = bind LevelData.HEIGHT * CELL_SIZE;
public def GAME_FIELD_X = bind (SCREEN_WIDTH - GAME_FIELD_WIDTH) / 2;
public def GAME_FIELD_Y = bind SCREEN_HEIGHT - GAME_FIELD_HEIGHT -
    BOTTOM_AREA_HEIGHT;

public function initialize() {
    for (s in IMAGES_NAMES) {
        var image = Image {
            url: "{IMAGE_DIR}/{s}"
        }

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

        insert image into images;
    }

    for (s in WALL_IMAGE_NAMES) {
        var image = Image {
            url: "{IMAGE_DIR}/wall/{s}.png"
        }

        if (image.error) {
            println("Image {image.url} not found");
        } else if (wallImages.size() > 0 and
                (image.width != CELL_SIZE or image.height != CELL_SIZE)) {
            // Check size of images only for last ones
            println("Image {image.url} has invalid size")
        }

        wallImages.put(s, image);
    }
}

public def IMAGE_SMALLDOT = 0;
public def IMAGE_DOT0 = 1;
public def IMAGE_DOT1 = 2;
public def IMAGE_DUKE0 = 3;
public def IMAGE_DUKE1 = 4;
public def IMAGE_DUKE2 = 5;
public def IMAGE_DUKE3 = 6;
public def IMAGE_FRONTDUKE0 = 7;
public def IMAGE_FRONTDUKE1 = 8;
public def IMAGE_FRONTDUKE2 = 9;
public def IMAGE_NORMAL_ENEMY0 = 10;
public def IMAGE_NORMAL_ENEMY1 = 11;
public def IMAGE_NORMAL_ENEMY2 = 12;
public def IMAGE_NORMAL_ENEMY3 = 13;
public def IMAGE_SAFE_ENEMY0 = 14;
public def IMAGE_SAFE_ENEMY1 = 15;
public def IMAGE_SAFE_ENEMY2 = 16;
public def IMAGE_SAFE_ENEMY3 = 17;
public def IMAGE_DEFEAT_ENEMY0 = 18;
public def IMAGE_DEFEAT_ENEMY1 = 19;
public def IMAGE_DEFEAT_ENEMY2 = 20;
public def IMAGE_DEFEAT_ENEMY3 = 21;
public def IMAGE_BONUS_200 = 22;
public def IMAGE_BONUS_400 = 23;
public def IMAGE_BONUS_800 = 24;
public def IMAGE_BONUS_1600 = 25;
public def IMAGE_DUKE_LIVES = 26;
public def IMAGE_GAME_OVER = 27;
public def IMAGE_GET_READY = 28;
public def IMAGE_BACKGROUND0 = 29;
public def IMAGE_BACKGROUND1 = 30;
public def IMAGE_BACKGROUND2 = 31;
public def IMAGE_SPLASH_BACKGROUND = 32;
public def IMAGE_SPLASH_DUKE0 = 33;
public def IMAGE_SPLASH_DUKE1 = 34;
public def IMAGE_SPLASH_DUKE2 = 35;

def IMAGES_NAMES = [
    "dots/smalldot.png",
    "dots/dot0.png",
    "dots/dot1.png",
    "duke/duke0.png",
    "duke/duke1.png",
    "duke/duke2.png",
    "duke/duke3.png",
    "duke/frontduke0.png",
    "duke/frontduke1.png",
    "duke/frontduke2.png",
    "enemy/normal/enemy0.png",
    "enemy/normal/enemy1.png",
    "enemy/normal/enemy2.png",
    "enemy/normal/enemy3.png",
    "enemy/safe/enemy0.png",
    "enemy/safe/enemy1.png",
    "enemy/safe/enemy2.png",
    "enemy/safe/enemy3.png",
    "enemy/defeat/enemy0.png",
    "enemy/defeat/enemy1.png",
    "enemy/defeat/enemy2.png",
    "enemy/defeat/enemy3.png",
    "bonuses/200.png",
    "bonuses/400.png",
    "bonuses/800.png",
    "bonuses/1600.png",
    "dukelives.png",
    "gameover.png",
    "getready.png",
    "backgrounds/background0.png",
    "backgrounds/background1.png",
    "backgrounds/background2.png",
    "splash/background.png",
    "splash/duke0.png",
    "splash/duke1.png",
    "splash/duke2.png",
];

public var images: Image[] = [];

public function getWall(type: String): Image {
    wallImages.get(type) as Image;
}

// Four digits correspondent to near cell:
//   <top-left><top-right><bottom-right><bottom-left>
def WALL_IMAGE_NAMES = [
    "enemyhome",
    "wall0001",
    "wall0010",
    "wall0011",
    "wall0100",
    "wall0110",
    "wall0111",
    "wall1000",
    "wall1001",
    "wall1011",
    "wall1100",
    "wall1101",
    "wall1110",
    "wall1111",
    "edgehor0",
    "edgehor1",
    "edgehor2",
    "edgehor3",
    "edgevert0",
    "edgevert1",
    "edgevert2",
    "edgevert3",
];

def wallImages: Hashtable = new Hashtable();