From ef51dceca8a2a35d8784edb92908c55c06639ca7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tobias=20Gl=C3=A4=C3=9Fer?= Date: Sun, 28 Mar 2004 01:44:15 +0000 Subject: [PATCH] applied flame badguy patch from Matze Braun SVN-Revision: 400 --- src/badguy.cpp | 221 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/badguy.h | 9 ++- src/gameloop.cpp | 167 +---------------------------------------- 3 files changed, 230 insertions(+), 167 deletions(-) diff --git a/src/badguy.cpp b/src/badguy.cpp index 0c76659f2..71656a5ff 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -9,6 +9,7 @@ // Copyright: See COPYING file that comes with this distribution // // +#include #include "globals.h" #include "defines.h" @@ -34,6 +35,7 @@ texture_type img_mrbomb_left[4]; texture_type img_mrbomb_right[4]; texture_type img_stalactite; texture_type img_stalactite_broken; +texture_type img_flame[2]; BadGuyKind badguykind_from_string(const std::string& str) { @@ -47,6 +49,8 @@ BadGuyKind badguykind_from_string(const std::string& str) return BAD_MRBOMB; else if (str == "stalactite") return BAD_STALACTITE; + else if (str == "flame") + return BAD_FLAME; else { printf("Couldn't convert badguy: %s\n", str.c_str()); @@ -73,6 +77,9 @@ std::string badguykind_to_string(BadGuyKind kind) case BAD_STALACTITE: return "stalactite"; break; + case BAD_FLAME: + return "flame"; + break; default: return "bsod"; } @@ -101,6 +108,8 @@ BadGuy::init(float x, float y, BadGuyKind kind_) mode = BOMB_TICKING; // hack so that the bomb doesn't hurt until it expldes... dying = DYING_SQUISHED; + } else if(kind == BAD_FLAME) { + base.ym = 0; // we misuse base.ym as angle for the flame } } @@ -430,6 +439,17 @@ void BadGuy::action_stalactite() } void +BadGuy::action_flame() +{ + static const float radius = 100; + static const float speed = 0.02; + base.x = old_base.x + cos(base.ym) * radius; + base.y = old_base.y + sin(base.ym) * radius; + + base.ym = fmodf(base.ym + frame_ratio * speed, 2*M_PI); +} + +void BadGuy::action() { if (seen) @@ -460,6 +480,9 @@ BadGuy::action() action_stalactite(); break; + case BAD_FLAME: + action_flame(); + break; } } @@ -576,6 +599,15 @@ BadGuy::draw_stalactite() } void +BadGuy::draw_flame() +{ + size_t frame = (global_frame_counter / 10) % 2; + texture_type* texture = &img_flame[frame]; + + texture_draw(texture, base.x - scroll_x, base.y); +} + +void BadGuy::draw() { // Don't try to draw stuff that is outside of the screen @@ -607,6 +639,11 @@ BadGuy::draw() case BAD_STALACTITE: draw_stalactite(); break; + + case BAD_FLAME: + draw_flame(); + break; + } } } @@ -707,7 +744,7 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type) switch (c_object) { case CO_BULLET: - if(kind == BAD_BOMB || kind == BAD_STALACTITE) + if(kind == BAD_BOMB || kind == BAD_STALACTITE || kind == BAD_FLAME) return; dying = DYING_FALLING; @@ -757,4 +794,186 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type) } } +//--------------------------------------------------------------------------- + +void load_badguy_gfx() +{ + /* (BSOD) */ + texture_load(&img_bsod_left[0], datadir + + "/images/shared/bsod-left-0.png", + USE_ALPHA); + + texture_load(&img_bsod_left[1], datadir + + "/images/shared/bsod-left-1.png", + USE_ALPHA); + + texture_load(&img_bsod_left[2], datadir + + "/images/shared/bsod-left-2.png", + USE_ALPHA); + + texture_load(&img_bsod_left[3], datadir + + "/images/shared/bsod-left-3.png", + USE_ALPHA); + + texture_load(&img_bsod_right[0], datadir + + "/images/shared/bsod-right-0.png", + USE_ALPHA); + + texture_load(&img_bsod_right[1], datadir + + "/images/shared/bsod-right-1.png", + USE_ALPHA); + + texture_load(&img_bsod_right[2], datadir + + "/images/shared/bsod-right-2.png", + USE_ALPHA); + + texture_load(&img_bsod_right[3], datadir + + "/images/shared/bsod-right-3.png", + USE_ALPHA); + + texture_load(&img_bsod_squished_left, datadir + + "/images/shared/bsod-squished-left.png", + USE_ALPHA); + + texture_load(&img_bsod_squished_right, datadir + + "/images/shared/bsod-squished-right.png", + USE_ALPHA); + + texture_load(&img_bsod_falling_left, datadir + + "/images/shared/bsod-falling-left.png", + USE_ALPHA); + + texture_load(&img_bsod_falling_right, datadir + + "/images/shared/bsod-falling-right.png", + USE_ALPHA); + + + /* (Laptop) */ + + texture_load(&img_laptop_left[0], datadir + + "/images/shared/laptop-left-0.png", + USE_ALPHA); + + texture_load(&img_laptop_left[1], datadir + + "/images/shared/laptop-left-1.png", + USE_ALPHA); + + texture_load(&img_laptop_left[2], datadir + + "/images/shared/laptop-left-2.png", + USE_ALPHA); + + texture_load(&img_laptop_right[0], datadir + + "/images/shared/laptop-right-0.png", + USE_ALPHA); + + texture_load(&img_laptop_right[1], datadir + + "/images/shared/laptop-right-1.png", + USE_ALPHA); + + texture_load(&img_laptop_right[2], datadir + + "/images/shared/laptop-right-2.png", + USE_ALPHA); + + texture_load(&img_laptop_flat_left, datadir + + "/images/shared/laptop-flat-left.png", + USE_ALPHA); + + texture_load(&img_laptop_flat_right, datadir + + "/images/shared/laptop-flat-right.png", + USE_ALPHA); + + texture_load(&img_laptop_falling_left, datadir + + "/images/shared/laptop-falling-left.png", + USE_ALPHA); + + texture_load(&img_laptop_falling_right, datadir + + "/images/shared/laptop-falling-right.png", + USE_ALPHA); + + + /* (Money) */ + + texture_load(&img_money_left[0], datadir + + "/images/shared/bag-left-0.png", + USE_ALPHA); + + texture_load(&img_money_left[1], datadir + + "/images/shared/bag-left-1.png", + USE_ALPHA); + + texture_load(&img_money_right[0], datadir + + "/images/shared/bag-right-0.png", + USE_ALPHA); + + texture_load(&img_money_right[1], datadir + + "/images/shared/bag-right-1.png", + USE_ALPHA); + + /* Mr. Bomb */ + for(int i=0; i<4; ++i) { + char num[4]; + snprintf(num, 4, "%d", i); + texture_load(&img_mrbomb_left[i], + datadir + "/images/shared/mrbomb-left-" + num + ".png", USE_ALPHA); + texture_load(&img_mrbomb_right[i], + datadir + "/images/shared/mrbomb-right-" + num + ".png", USE_ALPHA); + } + + /* stalactite */ + texture_load(&img_stalactite, + datadir + "/images/shared/stalactite.png", USE_ALPHA); + texture_load(&img_stalactite_broken, + datadir + "/images/shared/stalactite-broken.png", USE_ALPHA); + + /* flame */ + texture_load(&img_flame[0], + datadir + "/images/shared/flame-0.png", USE_ALPHA); + texture_load(&img_flame[1], + datadir + "/images/shared/flame-1.png", USE_ALPHA); +} + +void free_badguy_gfx() +{ + for (int i = 0; i < 4; i++) + { + texture_free(&img_bsod_left[i]); + texture_free(&img_bsod_right[i]); + } + + texture_free(&img_bsod_squished_left); + texture_free(&img_bsod_squished_right); + + texture_free(&img_bsod_falling_left); + texture_free(&img_bsod_falling_right); + + for (int i = 0; i < 3; i++) + { + texture_free(&img_laptop_left[i]); + texture_free(&img_laptop_right[i]); + } + + texture_free(&img_laptop_flat_left); + texture_free(&img_laptop_flat_right); + + texture_free(&img_laptop_falling_left); + texture_free(&img_laptop_falling_right); + + for (int i = 0; i < 2; i++) + { + texture_free(&img_money_left[i]); + texture_free(&img_money_right[i]); + } + + for(int i = 0; i < 4; i++) { + texture_free(&img_mrbomb_left[i]); + texture_free(&img_mrbomb_right[i]); + } + + texture_free(&img_stalactite); + texture_free(&img_stalactite_broken); + + texture_free(&img_flame[0]); + texture_free(&img_flame[1]); +} + // EOF // diff --git a/src/badguy.h b/src/badguy.h index 76d25cca0..6d2fb5c51 100644 --- a/src/badguy.h +++ b/src/badguy.h @@ -53,6 +53,7 @@ extern texture_type img_mrbomb_left[4]; extern texture_type img_mrbomb_right[4]; extern texture_type img_stalactite; extern texture_type img_stalactite_broken; +extern texture_type img_flame[2]; /* Bad guy kinds: */ enum BadGuyKind { @@ -61,11 +62,14 @@ enum BadGuyKind { BAD_MONEY, BAD_MRBOMB, BAD_BOMB, - BAD_STALACTITE + BAD_STALACTITE, + BAD_FLAME }; BadGuyKind badguykind_from_string(const std::string& str); std::string badguykind_to_string(BadGuyKind kind); +void load_badguy_gfx(); +void free_badguy_gfx(); struct BadGuyData { @@ -127,6 +131,9 @@ class BadGuy void action_stalactite(); void draw_stalactite(); + void action_flame(); + void draw_flame(); + void make_player_jump(Player* player); void check_horizontal_bump(bool checkcliff = false); void bump(); diff --git a/src/gameloop.cpp b/src/gameloop.cpp index d59de79bf..630ef3d83 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -1020,134 +1020,7 @@ void loadshared(void) /* Bad guys: */ - - /* (BSOD) */ - - texture_load(&img_bsod_left[0], datadir + - "/images/shared/bsod-left-0.png", - USE_ALPHA); - - texture_load(&img_bsod_left[1], datadir + - "/images/shared/bsod-left-1.png", - USE_ALPHA); - - texture_load(&img_bsod_left[2], datadir + - "/images/shared/bsod-left-2.png", - USE_ALPHA); - - texture_load(&img_bsod_left[3], datadir + - "/images/shared/bsod-left-3.png", - USE_ALPHA); - - texture_load(&img_bsod_right[0], datadir + - "/images/shared/bsod-right-0.png", - USE_ALPHA); - - texture_load(&img_bsod_right[1], datadir + - "/images/shared/bsod-right-1.png", - USE_ALPHA); - - texture_load(&img_bsod_right[2], datadir + - "/images/shared/bsod-right-2.png", - USE_ALPHA); - - texture_load(&img_bsod_right[3], datadir + - "/images/shared/bsod-right-3.png", - USE_ALPHA); - - texture_load(&img_bsod_squished_left, datadir + - "/images/shared/bsod-squished-left.png", - USE_ALPHA); - - texture_load(&img_bsod_squished_right, datadir + - "/images/shared/bsod-squished-right.png", - USE_ALPHA); - - texture_load(&img_bsod_falling_left, datadir + - "/images/shared/bsod-falling-left.png", - USE_ALPHA); - - texture_load(&img_bsod_falling_right, datadir + - "/images/shared/bsod-falling-right.png", - USE_ALPHA); - - - /* (Laptop) */ - - texture_load(&img_laptop_left[0], datadir + - "/images/shared/laptop-left-0.png", - USE_ALPHA); - - texture_load(&img_laptop_left[1], datadir + - "/images/shared/laptop-left-1.png", - USE_ALPHA); - - texture_load(&img_laptop_left[2], datadir + - "/images/shared/laptop-left-2.png", - USE_ALPHA); - - texture_load(&img_laptop_right[0], datadir + - "/images/shared/laptop-right-0.png", - USE_ALPHA); - - texture_load(&img_laptop_right[1], datadir + - "/images/shared/laptop-right-1.png", - USE_ALPHA); - - texture_load(&img_laptop_right[2], datadir + - "/images/shared/laptop-right-2.png", - USE_ALPHA); - - texture_load(&img_laptop_flat_left, datadir + - "/images/shared/laptop-flat-left.png", - USE_ALPHA); - - texture_load(&img_laptop_flat_right, datadir + - "/images/shared/laptop-flat-right.png", - USE_ALPHA); - - texture_load(&img_laptop_falling_left, datadir + - "/images/shared/laptop-falling-left.png", - USE_ALPHA); - - texture_load(&img_laptop_falling_right, datadir + - "/images/shared/laptop-falling-right.png", - USE_ALPHA); - - - /* (Money) */ - - texture_load(&img_money_left[0], datadir + - "/images/shared/bag-left-0.png", - USE_ALPHA); - - texture_load(&img_money_left[1], datadir + - "/images/shared/bag-left-1.png", - USE_ALPHA); - - texture_load(&img_money_right[0], datadir + - "/images/shared/bag-right-0.png", - USE_ALPHA); - - texture_load(&img_money_right[1], datadir + - "/images/shared/bag-right-1.png", - USE_ALPHA); - - /* Mr. Bomb */ - for(int i=0; i<4; ++i) { - char num[4]; - snprintf(num, 4, "%d", i); - texture_load(&img_mrbomb_left[i], - datadir + "/images/shared/mrbomb-left-" + num + ".png", USE_ALPHA); - texture_load(&img_mrbomb_right[i], - datadir + "/images/shared/mrbomb-right-" + num + ".png", USE_ALPHA); - } - - /* stalactite */ - texture_load(&img_stalactite, - datadir + "/images/shared/stalactite.png", USE_ALPHA); - texture_load(&img_stalactite_broken, - datadir + "/images/shared/stalactite-broken.png", USE_ALPHA); + load_badguy_gfx(); /* Upgrades: */ @@ -1244,43 +1117,7 @@ void unloadshared(void) texture_free(&skidtux_left); texture_free(&skidtux_right); - for (i = 0; i < 4; i++) - { - texture_free(&img_bsod_left[i]); - texture_free(&img_bsod_right[i]); - } - - texture_free(&img_bsod_squished_left); - texture_free(&img_bsod_squished_right); - - texture_free(&img_bsod_falling_left); - texture_free(&img_bsod_falling_right); - - for (i = 0; i < 3; i++) - { - texture_free(&img_laptop_left[i]); - texture_free(&img_laptop_right[i]); - } - - texture_free(&img_laptop_flat_left); - texture_free(&img_laptop_flat_right); - - texture_free(&img_laptop_falling_left); - texture_free(&img_laptop_falling_right); - - for (i = 0; i < 2; i++) - { - texture_free(&img_money_left[i]); - texture_free(&img_money_right[i]); - } - - for(i = 0; i < 4; i++) { - texture_free(&img_mrbomb_left[i]); - texture_free(&img_mrbomb_right[i]); - } - - texture_free(&img_stalactite); - texture_free(&img_stalactite_broken); + free_badguy_gfx(); texture_free(&img_box_full); texture_free(&img_box_empty); -- 2.11.0