Package demo.tilemap

Source Code of demo.tilemap.IsometricScene1

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.actor.LabelActor;

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

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

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

  }

  Color scolor = new Color(0, 200, 0);

  @Override
  public void init() {
    v = new IsometricViewPort(2, this, 0, 0) {
      GradientFill gr = new GradientFill(0, 0, Color.red, 60, 60,
          Color.blue);

      @Override
      public void paintCell(Graphics g, int tx, int ty, Shape r,
          SpriteCell cell) {
        super.paintCell(g, tx, ty, r, 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);
      }
    };
    v.setMapSize(20, 20);
    v.setTileWidth(60);
    v.setDrawGrid(true);
    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.IsometricScene1

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.