All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.siemens.mp.game.TiledBackground Maven / Gradle / Ivy

The newest version!
/*
 *  Siemens API for MicroEmulator
 *  Copyright (C) 2003 Markus Heberling 
 *
 *  It is licensed under the following two licenses as alternatives:
 *    1. GNU Lesser General Public License (the "LGPL") version 2.1 or any newer version
 *    2. Apache License (the "AL") Version 2.0
 *
 *  You may not use this file except in compliance with at least one of
 *  the above two licenses.
 *
 *  You may obtain a copy of the LGPL at
 *      http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
 *
 *  You may obtain a copy of the AL at
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the LGPL or the AL for the specific language governing permissions and
 *  limitations.
 */
package com.siemens.mp.game;

import javax.microedition.lcdui.*;
import org.microemu.device.DeviceFactory;

/**
 *
 * @author  markus
 * @version
 */
public class TiledBackground extends GraphicObject{
    Image pixels[];
    byte map[];
    int widthInTiles;
    int heightInTiles;
    int posx;
    int posy;
    
    public TiledBackground(byte[] tilePixels, byte[] tileMask, byte[] map, int widthInTiles, int heightInTiles) {
        //        System.out.println("public TiledBackground(byte[] tilePixels, byte[] tileMask, byte[] map, int "+widthInTiles+", int "+heightInTiles+")");
        this(
        com.siemens.mp.ui.Image.createImageFromBitmap(tilePixels,8,tilePixels.length),
        com.siemens.mp.ui.Image.createImageFromBitmap(tileMask,8,tilePixels.length),
        map,
        widthInTiles,
        heightInTiles
        );
    }
    
    public TiledBackground(ExtendedImage tilePixels, ExtendedImage tileMask, byte[] map, int widthInTiles, int heightInTiles) {
        //System.out.println("public TiledBackground(ExtendedImage tilePixels, ExtendedImage tileMask, byte[] map, int widthInTiles, int heightInTiles)");
        this(tilePixels.getImage(), tileMask.getImage(), map, widthInTiles, heightInTiles);
    }
    
    public TiledBackground(Image tilePixels, Image tileMask, byte[] map, int widthInTiles, int heightInTiles) {
        System.out.println("public TiledBackground(Image tilePixels, Image tileMask, byte[] map, int "+widthInTiles+", int "+heightInTiles+")");
        
        this.map=map;
        this.heightInTiles=heightInTiles;
        this.widthInTiles=widthInTiles;
        
        pixels=new Image[tilePixels.getHeight()/8+3];
        pixels[0]=Image.createImage(8,8);
        pixels[1]=Image.createImage(8,8);
        pixels[2]=Image.createImage(8,8);
        pixels[2].getGraphics().fillRect(0,0,8,8);
        
        for (int i=0;iDeviceFactory.getDevice().getDeviceDisplay().getWidth()) break;
                g.drawImage(pixels[map[y*widthInTiles+x]], -posx+x*8,-posy+y*8,0);
            }
            if (-posy+y*8>DeviceFactory.getDevice().getDeviceDisplay().getHeight()) break;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy