# HG changeset patch # User fred@reichbier.de # Date 1216313575 -7200 # Node ID a2d653eb9e99f54a287bc14e4d7f6525549c6332 first working version. diff -r 000000000000 -r a2d653eb9e99 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Thu Jul 17 18:52:55 2008 +0200 @@ -0,0 +1,5 @@ +syntax: regexp +^dsss_objs + +syntax: glob +bin/test diff -r 000000000000 -r a2d653eb9e99 bin/gfx/grass-stone-water-east.png Binary file bin/gfx/grass-stone-water-east.png has changed diff -r 000000000000 -r a2d653eb9e99 bin/gfx/grass-stone-water-l.png Binary file bin/gfx/grass-stone-water-l.png has changed diff -r 000000000000 -r a2d653eb9e99 bin/gfx/grass-stone-water-north.png Binary file bin/gfx/grass-stone-water-north.png has changed diff -r 000000000000 -r a2d653eb9e99 bin/gfx/grass.png Binary file bin/gfx/grass.png has changed diff -r 000000000000 -r a2d653eb9e99 dsss.conf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dsss.conf Thu Jul 17 18:52:55 2008 +0200 @@ -0,0 +1,4 @@ +[src/test.d] +target = bin/test +buildflags += -Isrc -I/usr/include/d/ -S/usr/lib -L-ldsfml-graphics -L-ldsfml-window -L-ldsfml-system + diff -r 000000000000 -r a2d653eb9e99 src/consumer.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/consumer.d Thu Jul 17 18:52:55 2008 +0200 @@ -0,0 +1,20 @@ +module consumer; + +import dsfml.window.all; +import dsfml.system.all; +import dsfml.graphics.all; + +import renderer; + +class Consumer { + protected RenderWindow app; + + this(Renderer renderer) { + this.app = renderer.app; + } + + void draw() { + Shape shape = Shape.circle(300, 300, 100, Color.WHITE); + this.app.draw(shape); + } +} diff -r 000000000000 -r a2d653eb9e99 src/imagecache.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/imagecache.d Thu Jul 17 18:52:55 2008 +0200 @@ -0,0 +1,28 @@ +module imagecache; + +import dsfml.window.all; +import dsfml.system.all; +import dsfml.graphics.all; + +import tango.io.vfs.FileFolder; + +class Cache { + private FileFolder filefolder; + private Image[char[]] images; + + this(char[] folder) { + this.filefolder = new FileFolder(folder, false); + } + + void load(char[] real_filename, char[] seen_filename) { + this.images[seen_filename] = new Image(); + this.images[seen_filename].loadFromFile(real_filename); + } + + Image get_image(char[] filename) { + if (!(filename in this.images)) { + this.load(this.filefolder.file(filename).toString(), filename); + } + return this.images[filename]; + } +} diff -r 000000000000 -r a2d653eb9e99 src/renderer.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/renderer.d Thu Jul 17 18:52:55 2008 +0200 @@ -0,0 +1,45 @@ +module renderer; + +import dsfml.window.all; +import dsfml.system.all; +import dsfml.graphics.all; + +import consumer; +import imagecache; + +class Renderer { + public RenderWindow app; + public Cache cache; + private Consumer[] consumers; + + this(char[] title, int width, int height, int depth=32) { + this.app = new RenderWindow(VideoMode(width, height, depth), title); + this.app.setFramerateLimit(40); + + this.cache = new Cache("."); // TODO + } + + void add_consumer(Consumer consumer) { + this.consumers ~= consumer; + } + + /* start the mainloop */ + void mainloop() { + Event evt; + + while(this.app.isOpened()) { + // handle all events + while(this.app.getEvent(evt)) { + if (evt.Type == Event.EventType.CLOSED) { + this.app.close(); + } + } + // draw all + foreach(Consumer consumer; this.consumers) { + consumer.draw(); + } + // display all + this.app.display(); + } + } +} diff -r 000000000000 -r a2d653eb9e99 src/test.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test.d Thu Jul 17 18:52:55 2008 +0200 @@ -0,0 +1,29 @@ +module test; + +import dsfml.window.all; +import dsfml.system.all; +import dsfml.graphics.all; + +import tileconsumer; +import renderer; +import consumer; +import imagecache; +import tilemap; +import tileset; + +int main(char[][] args) { + Cache cache = new Cache("gfx"); + Tileset tileset = new Tileset(cache); + Tilemap map = new Tilemap(tileset, 5, 5, 32, 32); + tileset.add_tile(0, "grass.png"); + for(int x=0; x < 5; x++) { + map.map[x][x] = 0; + } + + Renderer render = new Renderer("Blubb", 600, 480, 32); + TileConsumer consumer = new TileConsumer(render, map); + render.add_consumer(consumer); + + render.mainloop(); + return 0; +} diff -r 000000000000 -r a2d653eb9e99 src/tileconsumer.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/tileconsumer.d Thu Jul 17 18:52:55 2008 +0200 @@ -0,0 +1,25 @@ +module tileconsumer; + +import dsfml.window.all; +import dsfml.system.all; +import dsfml.graphics.all; + +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.app.draw(sprite); + } + } +} diff -r 000000000000 -r a2d653eb9e99 src/tilemap.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/tilemap.d Thu Jul 17 18:52:55 2008 +0200 @@ -0,0 +1,56 @@ +module tilemap; + +import tango.math.Math; + +import dsfml.window.all; +import dsfml.system.all; +import dsfml.graphics.all; + +import tileset; + +typedef Sprite[] SpriteArray; + +class Tilemap { + public int[int][int] map; + private Tileset tileset; + public int width, height, tilewidth, tileheight; + + this(Tileset tileset, int width, int height, int tilewidth, int tileheight) { + this.tileset = tileset; + this.width = width; + this.height = height; + this.tilewidth = tilewidth; + this.tileheight = tileheight; + } + + void real_to_tile(int real_x, int real_y, inout int tile_x, inout int tile_y) { + tile_x = rndint(floor(real_x / this.tilewidth)); + tile_y = rndint(floor(real_y / this.tileheight)); + } + + void tile_to_real(int tile_x, int tile_y, inout int real_x, inout int real_y) { + real_x = tile_x*this.tilewidth; + real_y = tile_y*this.tileheight; + } + + SpriteArray get_sprites() { + SpriteArray sprites; + Sprite sprite; + int real_x, real_y; + for(int x=0; x