Home > Java, Slick2D > Scrollable Map menggunakan Slick 2D

Scrollable Map menggunakan Slick 2D


Sebuah peta pada game berjenis RTS atau Real Time Strategy biasanya pengguna dapat melakukan scroll,
berikut ini sebuah kelas sederhana untuk mengimplementasikan hal tersebut, ingat silahkan gunakan Slick 2Dsebagai library, berikut ini kelasnya

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testmap;

import java.util.ArrayList;
import java.util.List;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;

/**
 *
 * @author Ratno
 */
public class ScrollableMap extends TiledMap {

    private List<Human> humans;

    public ScrollableMap(String ref) throws SlickException {
        super(ref);
        humans = new ArrayList<Human>();

    }

    public boolean add(Human e, int X, int Y) {
        e.X = X;
        e.Y = Y;
        return humans.add(e);
    }

    public void update(int delta){
        for (Human human : humans) {
            human.update(delta);
        }
    }

    public void render() {
        render((Global.TILE_SIZE / 2), (Global.TILE_SIZE / 2),
                Global.X_CORNER, Global.Y_CORNER, Global.WIDTH_IN_TILES, Global.HEIGHT_IN_TILES,
                true);
    }

    @Override
    protected void renderedLine(int visualY, int mapY, int layer) {
        if (layer == 1) {
//            System.out.println(visualY + ";" + mapY + ";" + layer);
            for (Human human : humans) {
                if (human.Y == mapY) {
                    human.draw();
                }
            }
        }
        super.renderedLine(visualY, mapY, layer);
    }
}

Categories: Java, Slick2D Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: