From: Ricardo Cruz Date: Thu, 27 May 2004 14:18:00 +0000 (+0000) Subject: Draw enemies upside down when falling. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=835fe9710c67ec76af43e74ec601955693924c2a;p=supertux.git Draw enemies upside down when falling. The drawing code in texture.cpp is just a hack. Not sure how we can flip surfaces in SDL. The OpenGL should be easily done, I will take care of it later. SVN-Revision: 1338 --- diff --git a/src/badguy.cpp b/src/badguy.cpp index db8468343..19542fd47 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -978,7 +978,10 @@ BadGuy::draw(Camera& viewport, int) } Sprite* sprite = (dir == LEFT) ? sprite_left : sprite_right; - sprite->draw(viewport.world2screen(Vector(base.x, base.y))); + if(dying == DYING_FALLING) + sprite->draw(viewport.world2screen(Vector(base.x, base.y)), SD_VERTICAL_FLIP); + else + sprite->draw(viewport.world2screen(Vector(base.x, base.y))); if (debug_mode) fillrect(base.x - scroll_x, base.y - scroll_y, base.width, base.height, 75,0,75, 150); diff --git a/src/sprite.cpp b/src/sprite.cpp index bb31251a8..f5f1f6570 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp @@ -73,13 +73,20 @@ Sprite::update(float /*delta*/) } void -Sprite::draw(float x, float y) +Sprite::draw(float x, float y, int special_drawing) { time = SDL_GetTicks(); unsigned int frame = get_current_frame(); if (frame < surfaces.size()) - surfaces[frame]->draw(x - x_hotspot, y - y_hotspot); + { + if(special_drawing == SD_SEMI_TRANSPARENT) + surfaces[frame]->draw(x - x_hotspot, y - y_hotspot, 128); + if(special_drawing == SD_VERTICAL_FLIP) + surfaces[frame]->draw(x - x_hotspot, y - y_hotspot, 255, true); + else + surfaces[frame]->draw(x - x_hotspot, y - y_hotspot); + } } void diff --git a/src/sprite.h b/src/sprite.h index 0671e270c..b85cedda8 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -26,6 +26,8 @@ #include "texture.h" #include "vector.h" +enum SpecialDrawing { SD_NONE, SD_VERTICAL_FLIP, SD_SEMI_TRANSPARENT }; + class Sprite { private: @@ -56,12 +58,12 @@ class Sprite /** Update the sprite and process to the next frame */ void update(float delta); - void draw(float x, float y); + void draw(float x, float y, int special_drawing = SD_NONE); void draw_part(float sx, float sy, float x, float y, float w, float h); int get_current_frame() const; - void draw(const Vector& pos) - { draw(pos.x, pos.y); } + void draw(const Vector& pos, int special_drawing = SD_NONE) + { draw(pos.x, pos.y, special_drawing); } std::string get_name() const { return name; } int get_width() const; diff --git a/src/texture.cpp b/src/texture.cpp index f9ed75a49..4efdf6899 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -207,11 +207,15 @@ Surface::debug_check() } void -Surface::draw(float x, float y, Uint8 alpha, bool update) +Surface::draw(float x, float y, Uint8 alpha, bool upside_down, bool update) { if (impl) { - if (impl->draw(x, y, alpha, update) == -2) + if(upside_down) // FIXME: this should be done by the SDL and OpenGL draw() + for(float sy = 0; sy < h; sy++) + impl->draw_part(0, sy, x, y+(h-sy), w, 1, alpha, update); + + else if (impl->draw(x, y, alpha, update) == -2) reload(); } } diff --git a/src/texture.h b/src/texture.h index 00ad954b8..da4c8dc06 100644 --- a/src/texture.h +++ b/src/texture.h @@ -88,7 +88,7 @@ public: /** Reload the surface, which is necesarry in case of a mode swich */ void reload(); - void draw(float x, float y, Uint8 alpha = 255, bool update = false); + void draw(float x, float y, Uint8 alpha = 255, bool upside_down = false, bool update = false); void draw_bg(Uint8 alpha = 255, bool update = false); void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false); void draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update = false);