void MapLayer::draw(Graphics *graphics, int startX, int startY, int endX, int endY, int scrollX, int scrollY, const Sprites &sprites) const { startX -= mX; startY -= mY; endX -= mX; endY -= mY; if (startX < 0) startX = 0; if (startY < 0) startY = 0; if (endX > mWidth) endX = mWidth; if (endY > mHeight) endY = mHeight; Sprites::const_iterator si = sprites.begin(); graphics->pushClipArea(gcn::Rectangle(0, 0, graphics->getWidth(), graphics->getHeight())); for (int y = startY; y < endY; y++) { // If drawing the fringe layer, make sure all sprites above this row of // tiles have been drawn if (mIsFringeLayer) { while (si != sprites.end() && (*si)->getPixelY() <= y * 32 - 32) { (*si)->draw(graphics, -scrollX, -scrollY); si++; } } for (int x = startX; x < endX; x++) { Image *img = getTile(x, y); if (img) { const int px = (x + mX) * 32 - scrollX; const int py = (y + mY) * 32 - scrollY + 32 - img->getHeight(); graphics->drawImage(img, px, py); } } } // Draw any remaining sprites if (mIsFringeLayer) { while (si != sprites.end()) { if (-scrollX >= 0 && -scrollX <= graphics->getWidth() && -scrollY >= 0 && -scrollY <= graphics->getHeight()) { (*si)->draw(graphics, -scrollX, -scrollY); } si++; } } graphics->popClipArea(); }
void Floor::load(InputStream *stream, int notebook_version, NaturalLanguage language) { if (stream->get() != FLOOR_MARKER) { say_error(IDS_BAD_FLOOR_IN_CITY_FILE,TRUE); return; }; Sprites *floor_items = load_items(stream,notebook_version,language); if (floor_items != NULL) { // add_items(floor_items); Sprites *remaining = floor_items; while (remaining != NULL) { // new on 101099 if priority of item is fixed then don't reset it // so Marty, for example, loads in with correct priority add_item(remaining->first(),FALSE); // FALSE replaced !remaining->first()->priority_fixed() above on 211199 since priority is now saved correctly remaining = remaining->rest(); }; floor_items->recursively_propagate_changes(); floor_items->activate(); floor_items->remove_all(); delete floor_items; }; if (notebook_version >= first_version_to_save_number_colors) { stream->read((string) ¤t_priority, sizeof(current_priority)); // new on 150100 }; };
void Floor::need_new_main_cubby() { Sprites *remaining = alternative_body_cubbies; while (remaining != NULL) { Cubby *cubby = (Cubby *) (remaining->first()); if (cubby->vacuum_if_left_on_floor(NULL,0)) { // args are ignored record_event(NEW_MAIN_CUBBY,tt_programmer->pointer_to_appearance(),this,cubby); }; remaining = remaining->rest(); }; };
void Room::set_wall_decoration(Sprites *sprites, boolean give_priority, boolean subpicture) { initialize_wall_decoration(); if (sprites == NULL) { wall_decoration->set_visible(FALSE); } else { // wall_decoration->set_visible(TRUE); Sprites *remaining = sprites; while (remaining != NULL) { add_decoration(remaining->first(),give_priority,subpicture); // wall_decoration->add_follower(sprite,TRUE,FALSE); // is completely inside but want insertion by priority // sprite->recursively_activate_pictures(); remaining->set_first(NULL); // since about to destroy list remaining = remaining->rest(); }; delete sprites; // just the list not the contents }; };
Sprites parseSprite(const std::string& image, const std::string& json) { using namespace rapidjson; Sprites sprites; // Parse the sprite image. const util::Image raster(image); if (!raster) { Log::Warning(Event::Sprite, "Could not parse sprite image"); return sprites; } Document doc; doc.Parse<0>(json.c_str()); if (doc.HasParseError()) { Log::Warning(Event::Sprite, std::string{ "Failed to parse JSON: " } + doc.GetParseError() + " at offset " + std::to_string(doc.GetErrorOffset())); return sprites; } else if (!doc.IsObject()) { Log::Warning(Event::Sprite, "Sprite JSON root must be an object"); return sprites; } else { for (Value::ConstMemberIterator itr = doc.MemberBegin(); itr != doc.MemberEnd(); ++itr) { const std::string name = { itr->name.GetString(), itr->name.GetStringLength() }; const Value& value = itr->value; if (value.IsObject()) { const uint16_t x = getUInt16(value, "x", 0); const uint16_t y = getUInt16(value, "y", 0); const uint16_t width = getUInt16(value, "width", 0); const uint16_t height = getUInt16(value, "height", 0); const double pixelRatio = getDouble(value, "pixelRatio", 1); const bool sdf = getBoolean(value, "sdf", false); auto sprite = createSpriteImage(raster, x, y, width, height, pixelRatio, sdf); if (sprite) { sprites.emplace(name, sprite); } } } } return sprites; }
SpriteParseResult parseSprite(const std::string& image, const std::string& json) { Sprites sprites; PremultipliedImage raster; try { raster = decodeImage(image); } catch (...) { return std::current_exception(); } JSDocument doc; doc.Parse<0>(json.c_str()); if (doc.HasParseError()) { std::stringstream message; message << "Failed to parse JSON: " << rapidjson::GetParseError_En(doc.GetParseError()) << " at offset " << doc.GetErrorOffset(); return std::make_exception_ptr(std::runtime_error(message.str())); } else if (!doc.IsObject()) { return std::make_exception_ptr(std::runtime_error("Sprite JSON root must be an object")); } else { for (JSValue::ConstMemberIterator itr = doc.MemberBegin(); itr != doc.MemberEnd(); ++itr) { const std::string name = { itr->name.GetString(), itr->name.GetStringLength() }; const JSValue& value = itr->value; if (value.IsObject()) { const uint16_t x = getUInt16(value, "x", 0); const uint16_t y = getUInt16(value, "y", 0); const uint16_t width = getUInt16(value, "width", 0); const uint16_t height = getUInt16(value, "height", 0); const double pixelRatio = getDouble(value, "pixelRatio", 1); const bool sdf = getBoolean(value, "sdf", false); auto sprite = createSpriteImage(raster, x, y, width, height, pixelRatio, sdf); if (sprite) { sprites.emplace(name, sprite); } } } } return sprites; }
void Thought_Bubble::xml(xml_element *element, xml_document *document) { //#if TT_DEBUG_ON // if (!geometry_worth_saving()) { // log("debug this"); // }; //#endif // taken care of below now -- uncommented out on 280803 since if saving a city just after giving an untrained robot a box then cubby isn't yet a follower if (cubby != NULL && followers == NULL) { cubby->xml_create_and_append_element(element,document)->Release(); }; // what about robot?? -- apparently not needed since is only a back pointer and robot will do the work Sprites *remaining = followers; // new on 130703 -- needed if saving while expanding thought bubble to enter training while (remaining != NULL) { Sprite *sprite = remaining->first(); // if (sprite != cubby) { // if not already dealt with above sprite->xml_create_and_append_element(element,document)->Release(); // shouldn't be any more cubbies - right? otherwise confusion // }; remaining = remaining->rest(); }; Sprite::xml(element,document); // return(create_xml_element(L"ThoughtBubble",document,cubby,TRUE)); // last arg was FALSE prior to 120603 but can be shared if is current selection when city is saved - everything is like this };
AnimatedBoardView::AnimatedBoardView(Sprites sprites, SpritePtr selectionMarker, GridPtr grid, BoardAnimatorPtr animator) : sprites(sprites.begin(), sprites.end()), selectionMarker(selectionMarker), grid(grid), animator(animator) { }
void StartGame() { //players last shoot time float lastShootPlayer = 0; //map struct tileMap myMap; Sprites mySprites; mySprites.InitImages(); vector<Chest> chests; vector<Enemy> enemies; InitEnemies(enemies, mySprites); //create player Player player(mySprites.heroTexture, PLAYER_POSITION_X, PLAYER_POSITION_Y, PLAYER_WIDTH, PLAYER_HEIGHT, "Hero", 6); RenderWindow window(VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Game"); view.reset(FloatRect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)); //clock Clock clock; Clock gameTimer; //last player hit time float hitTimer = 0; //game time float gameTime; //current level int level = 1; while (window.isOpen()) { level = InitializeLevel(player); //time float time = clock.getElapsedTime().asMicroseconds(); clock.restart(); time = time / 500; //game time if (player.health > 0) { gameTime = gameTimer.getElapsedTime().asSeconds(); } //event ProcessEvents(window); player.Update(time, gameTime, lastShootPlayer, mySprites.wallBackgroundSprite, view); UpdateEnemies(enemies, time, gameTime, window, level); AddChest(level, chests, enemies); CheckEnemyCollidesPlayer(gameTime, hitTimer, player, enemies); //view window.setView(view); ///////////////////////////// window.clear(); DrawBackground(window, mySprites.wallBackgroundSprite, mySprites.floorBackgroundSprite); DrawPlayersHealth(player.health, window, view); DrawEnemies(window, level, enemies); myMap.drawMap(window, IsLevelCleared(level, enemies)); UpdateChests(chests, window, player); UpdateBullets(player, enemies, gameTime, bullets, time, window, mySprites); DrawPlayer(player, window); window.display(); ///////////////////////////// } }
int main(int argc, const char* argv[]) { al_init(); al_init_font_addon(); al_init_ttf_addon(); al_init_image_addon(); al_init_primitives_addon(); ALLEGRO_DISPLAY *display; al_set_new_display_flags(ALLEGRO_WINDOWED); display = al_create_display(800, 600); al_install_keyboard(); al_install_mouse(); ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue(); al_register_event_source(event_queue, (ALLEGRO_EVENT_SOURCE *)display); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_mouse_event_source()); ALLEGRO_FONT* font = al_load_ttf_font("data/times.ttf", 12, 0); Vector2 camera(-400, -300); Platforms platforms; Bitmaps bitmaps; Sprites sprites; File* file = new File(font); file->platforms = &platforms; file->bitmaps = &bitmaps; file->sprites = &sprites; Menu menu; menu.Add_entry(new Create_platform(platforms, camera, font)); menu.Add_entry(new Edit_platform(platforms, camera, font)); menu.Add_entry(file); menu.Add_entry(new Create_sprite(bitmaps, sprites, camera, font)); menu.Add_entry(new Edit_sprite(sprites, camera, font)); if(argc==2) file->Load(argv[1]); while(1) { ALLEGRO_EVENT event; if (al_get_next_event(event_queue, &event)) { if (ALLEGRO_EVENT_DISPLAY_CLOSE == event.type || ALLEGRO_EVENT_KEY_DOWN == event.type && ALLEGRO_KEY_ESCAPE == event.keyboard.keycode) { break; } if(ALLEGRO_EVENT_MOUSE_AXES) { ALLEGRO_MOUSE_STATE mstate; al_get_mouse_state(&mstate); if(al_mouse_button_down(&mstate, 3)) { camera.x -= event.mouse.dx; camera.y -= event.mouse.dy; } } menu.Event(event); } for(Sprites::iterator i = sprites.begin(); i != sprites.end(); ++i) { (*i)->Draw(camera); } for(Platforms::iterator i = platforms.begin(); i != platforms.end(); ++i) { (*i)->Draw(camera, al_map_rgb_f(0, 1, 0)); } al_draw_line(0, -camera.y, 800, -camera.y, al_map_rgba_f(0, 1, 0, 0.5), 0); al_draw_line(-camera.x, 0, -camera.x, 600, al_map_rgba_f(0, 0, 1, 0.5), 0); menu.Draw(); al_flip_display(); al_clear_to_color(al_map_rgb(0, 0, 0)); al_rest(0.001); } al_destroy_event_queue(event_queue); al_destroy_display(display); }