Package demo.tilemap

Source Code of demo.tilemap.IsometricScene2

package demo.tilemap;

import java.awt.Point;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.ShapeFill;
import org.newdawn.slick.fills.GradientFill;
import org.newdawn.slick.geom.Shape;

import kku.cs.fgl.Color;
import kku.cs.fgl.IsometricViewPort;
import kku.cs.fgl.Scene;
import kku.cs.fgl.SpriteCell;
import kku.cs.fgl.SpriteManager;
import kku.cs.fgl.actor.LabelActor;

public class IsometricScene2 extends Scene {
  IsometricViewPort v;
  Point selected = null;
  LabelActor label = new LabelActor(300, 20, "");

  public IsometricScene2(int id) {
    super(id);
  }

  @Override
  public void enter() {
    // TODO Auto-generated method stub

  }

  Color scolor = new Color(0, 200, 0);
    SpriteManager sman = new SpriteManager();
  @Override
  public void init() {
    sman.load("sample.sheet");
    v = new IsometricViewPort(2, this, 0, 0) {
      @Override
      public void paintCell(Graphics g, int tx, int ty, Shape r, SpriteCell cell) {
        if (selected != null && tx == selected.x && ty == selected.y) {
          g.setColor(scolor);
          g.fill(r);
        }
        Point p = getTileLocation(tx, ty);
        g.drawString(tx + "," + ty, p.x + 15, p.y - 10);
        super.paintCell(g, tx, ty, r,cell);
      }
    };
    v.loadMap("sample.map");   
    //v.setTileWidth(60);
    v.setDrawGrid(true);
    v.setSheet(sman.getSheet("1"));
    add(label);
  }

  @Override
  public void leave() {
    // TODO Auto-generated method stub

  }

  @Override
  public void mouseMoved(int oldx, int oldy, int newx, int newy) {
    if (oldx != newx || oldy != newy) {
      selected = v.getCellFromScreenXY(newx, newy);
      label.setText("x=" + selected.x + " y=" + selected.y);
    }
  }

  @Override
  public void update(int delta) {
    super.update(delta);
    Input p = screen.getInput();
    int mx = p.getMouseX();
    int my = p.getMouseY();
    if (mx >= 780) {
      v.move(5, 0);
    }
    if (mx < 10) {
      v.move(-5, 0);
    }
  }
}
TOP

Related Classes of demo.tilemap.IsometricScene2

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.