4 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include "lispreader.h"
29 #include "screen/drawing_context.h"
31 /** Dirty little helper to create a surface from a snipped of lisp:
34 * (region "filename" x y w h)
37 Surface* create_surface(lisp_object_t* cur)
39 if (lisp_string_p(cur))
41 return new Surface(datadir + "/images/tilesets/" + lisp_string(cur),
44 else if (lisp_cons_p(cur) && lisp_symbol_p(lisp_car(cur)))
46 lisp_object_t* sym = lisp_car(cur);
47 lisp_object_t* data = lisp_cdr(cur);
49 if (strcmp(lisp_symbol(sym), "region") == 0)
51 if (lisp_list_length(data) == 5) // (image-region filename x y w h)
53 return new Surface(datadir + "/images/tilesets/" + lisp_string(lisp_car(data)),
54 lisp_integer(lisp_list_nth(data, 1)),
55 lisp_integer(lisp_list_nth(data, 2)),
56 lisp_integer(lisp_list_nth(data, 3)),
57 lisp_integer(lisp_list_nth(data, 4)),
62 std::cout << "Tile: Type mispatch, should be '(region \"somestring\" x y w h)'" << std::endl;
68 std::cout << "Tile: Unhandled tag: " << lisp_symbol(sym) << std::endl;
73 std::cout << "Tile: unhandled element" << std::endl;
77 /** Create a vector of surfaces (aka Sprite) from a piece of lisp:
78 ((image "bla.png") (image-region "bla.png") ...)
81 std::vector<Surface*> create_surfaces(lisp_object_t* cur)
83 std::vector<Surface*> surfs;
87 Surface* surface = create_surface(lisp_car(cur));
89 surfs.push_back(surface);
91 std::cout << "Tile: Couldn't create image" << std::endl;
100 : id(-1), attributes(0), data(0), next_tile(0), anim_speed(25)
106 for(std::vector<Surface*>::iterator i = images.begin(); i != images.end();
110 for(std::vector<Surface*>::iterator i = editor_images.begin();
111 i != editor_images.end(); ++i) {
117 Tile::read(LispReader& reader)
119 if(!reader.read_int("id", id)) {
120 std::cerr << "Missing tile-id.\n";
125 if(reader.read_bool("solid", value) && value)
127 if(reader.read_bool("unisolid", value) && value)
129 if(reader.read_bool("brick", value) && value)
131 if(reader.read_bool("ice", value) && value)
133 if(reader.read_bool("water", value) && value)
135 if(reader.read_bool("spike", value) && value)
137 if(reader.read_bool("fullbox", value) && value)
138 attributes |= FULLBOX;
139 if(reader.read_bool("distro", value) && value)
141 if(reader.read_bool("coin", value) && value)
143 if(reader.read_bool("goal", value) && value)
146 reader.read_int("data", data);
147 reader.read_int("anim-speed", anim_speed);
148 reader.read_int("next-tile", next_tile);
151 reader.read_float("slope-angle", slope_angle);
153 { // convert angle to radians from degrees:
154 slope_angle = (slope_angle * M_PI) / 180;
158 // FIXME: make images and editor_images a sprite
159 images = create_surfaces(reader.read_lisp("images"));
160 editor_images = create_surfaces(reader.read_lisp("editor-images"));