view import/myrrdin/tileconsumer.d @ 5:f4b89014ad39

added moving figure stuff + animated sprites. not usable atm.
author fred@reichbier.de
date Sat, 19 Jul 2008 14:33:08 +0200
parents src/tileconsumer.d@292df259cc85
children 510541745cd1
line wrap: on
line source

/*
    This file is part of myrrdin.

    myrrdin is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as 
    published by the Free Software Foundation, either version 3 of 
    the License, or (at your option) any later version.

    myrrdin is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public 
    License along with myrrdin. If not, see <http://www.gnu.org/licenses/>.
*/

module tileconsumer;

import dsfml.window.all;
import dsfml.system.all;
import dsfml.graphics.all;
import tango.io.Stdout;

import consumer;
import renderer;
import tileset;
import tilemap;

class TileConsumer : Consumer {
    public Tilemap map;

    this(Renderer renderer, Tilemap map) {
	super(renderer);
	this.map = map;
    }

    void draw() {
	 foreach(Sprite sprite; this.map.get_sprites()) {
	    this.renderer.draw(sprite);
	 }
    }

    bool handle_event(Event evt) {
	if (evt.Type == Event.EventType.MOUSEBUTTONPRESSED) {
	    Input input = this.renderer.app.getInput();
	    Vector2i tile = this.map.real_to_tile(0, input.getMouseX(), input.getMouseY());
	    if(this.map.has_tile(0, tile.x, tile.y)) {
		Stdout.formatln("You clicked on the tile {}, {}", tile.x, tile.y);
	    }
	    return true;
	}	    
	return false;
    }
}