From 8e02ba38e2a98f9ea7f092e333f8085520e6c22a Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Sun, 5 Dec 2004 17:04:57 +0000 Subject: [PATCH] forgot to add new files SVN-Revision: 2242 --- data/credits.txt | 112 ++---------------------------------------- src/badguy/flyingsnowball.cpp | 82 +++++++++++++++++++++++++++++++ src/badguy/flyingsnowball.h | 28 +++++++++++ src/collision_grid_iterator.h | 90 +++++++++++++++++++++++++++++++++ 4 files changed, 203 insertions(+), 109 deletions(-) create mode 100644 src/badguy/flyingsnowball.cpp create mode 100644 src/badguy/flyingsnowball.h create mode 100644 src/collision_grid_iterator.h diff --git a/data/credits.txt b/data/credits.txt index dac5c9843..a6c9b1abd 100644 --- a/data/credits.txt +++ b/data/credits.txt @@ -2,7 +2,7 @@ (supertux-text (background "oiltux.jpg") - (text "-- SuperTux - + (text (_ "-- SuperTux - Milestone 1 @@ -106,111 +106,5 @@ - See you soon in Milestone2!") - -; Portuguese (European) by Ricardo Cruz - (text-pt_PT "-- SuperTux - - Milestone 1 - - --Responsável pela Manutenção - - Tobias (tobgle) Glaesser - - --Originalmente desenvolvido por - - Bill Kendrick - - --Programadores - - Tobias (tobgle) Glaesser - - Ricardo (blacksheep) Cruz - - Ingo (grumbel) Ruhnke - - Matthias (MatzeB) Braun - - --Programadores que colaboraram - - Ryan (sik0fewl) Flegel - - Duong-Khang (neoneurone) NGUYEN - - --Gráficos - - Ingo (grumbel) Ruhnke - - Christopher A. (paroneayea) Webber - - Benjamin P. (litespeed) Jung - - --Design dos Níveis - - Marek (Wansti) Moeckel - - Ingo (grumbel) Ruhnke - - --História - - Christopher A. (paroneayea) Webber - - --Música - - Marek (Wansti) Moeckel - - Mystical - - Mortimer Twang - - --Sons - - Efeitos sonoros livres de custo - de CDROMs e sites FTP - - --Agradecimentos a - - Larry Ewing - Criador do Tux, o pinguim do Linux - - SDL e OpenGL - Por ter possibilitado esta excelente - experiência de jogo em Linux - - --Contactos - - Visita a nossa página em -*http://super-tux.sf.net - - Ou visita-nos directamente no IRC: -*#supertux em irc.freenode.net - - Comentários, ideias e sugestões - devem ir para a nossa lista de correio -*super-tux-devel@lists.sourceforge.net - - - - - - - - Obrigado por teres - jogado ao - --SuperTux - - - - Ver-nos-emos em breve na Milestone2!") - ) + See you soon in Milestone2!")) +) diff --git a/src/badguy/flyingsnowball.cpp b/src/badguy/flyingsnowball.cpp new file mode 100644 index 000000000..e07179a76 --- /dev/null +++ b/src/badguy/flyingsnowball.cpp @@ -0,0 +1,82 @@ +#include +#include + +#include "flyingsnowball.h" + +static const float FLYTIME = 1.0; +static const float FLYSPEED = 100.0; + +FlyingSnowBall::FlyingSnowBall(const lisp::Lisp& reader) +{ + reader.get("x", start_position.x); + reader.get("y", start_position.y); + bbox.set_size(31.8, 31.8); + sprite = sprite_manager->create("flyingsnowball"); + physic.enable_gravity(false); +} + +FlyingSnowBall::FlyingSnowBall(float pos_x, float pos_y) +{ + start_position.x = pos_x; + start_position.y = pos_y; + bbox.set_size(31.8, 31.8); + sprite = sprite_manager->create("flyingsnowball"); + physic.enable_gravity(false); +} + +void +FlyingSnowBall::write(lisp::Writer& writer) +{ + writer.start_list("flyingsnowball"); + + writer.write_float("x", start_position.x); + writer.write_float("y", start_position.y); + + writer.end_list("flyingsnowball"); +} + +void +FlyingSnowBall::activate() +{ + sprite->set_action(dir == LEFT ? "left" : "right"); + mode = FLY_UP; + physic.set_velocity_y(FLYSPEED); + timer.start(FLYTIME/2); +} + +bool +FlyingSnowBall::collision_squished(Player& player) +{ + sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); + kill_squished(player); + return true; +} + +HitResponse +FlyingSnowBall::collision_solid(GameObject& , const CollisionHit& hit) +{ + if(fabsf(hit.normal.y) > .5) { // hit floor or roof? + physic.set_velocity_y(0); + } + + return CONTINUE; +} + +void +FlyingSnowBall::active_action(float elapsed_time) +{ + if(timer.check()) { + if(mode == FLY_UP) { + mode = FLY_DOWN; + physic.set_velocity_y(-FLYSPEED); + } else if(mode == FLY_DOWN) { + mode = FLY_UP; + physic.set_velocity_y(FLYSPEED); + } + timer.start(FLYTIME); + } + movement=physic.get_movement(elapsed_time); + dir= Sector::current()->player->get_pos().x>get_pos().x?RIGHT:LEFT; + sprite->set_action(dir == LEFT ? "left" : "right"); +} + diff --git a/src/badguy/flyingsnowball.h b/src/badguy/flyingsnowball.h new file mode 100644 index 000000000..615156f43 --- /dev/null +++ b/src/badguy/flyingsnowball.h @@ -0,0 +1,28 @@ +#ifndef __FLYINGSNOWBALL_H__ +#define __FLYINGSNOWBALL_H__ + +#include "badguy.h" + +class FlyingSnowBall : public BadGuy +{ +public: + FlyingSnowBall(const lisp::Lisp& reader); + FlyingSnowBall(float pos_x, float pos_y); + + void activate(); + void write(lisp::Writer& writer); + void active_action(float elapsed_time); + HitResponse collision_solid(GameObject& other, const CollisionHit& hit); +protected: + enum FlyingSnowballMode { + FLY_UP, + FLY_DOWN + }; + FlyingSnowballMode mode; + bool collision_squished(Player& player); +private: + Timer2 timer; +}; + +#endif + diff --git a/src/collision_grid_iterator.h b/src/collision_grid_iterator.h new file mode 100644 index 000000000..9e22f629f --- /dev/null +++ b/src/collision_grid_iterator.h @@ -0,0 +1,90 @@ +#ifndef __COLLISION_GRID_ITERATOR_H__ +#define __COLLISION_GRID_ITERATOR_H__ + +#include "math/rectangle.h" + +using namespace SuperTux; + +class CollisionGrid; + +class CollisionGridIterator +{ +public: + CollisionGridIterator(CollisionGrid& newgrid, const Rectangle& bbox) + : grid(newgrid) + { + start_x = int(bbox.p1.x / grid.cell_width); + if(start_x < 0) + start_x = 0; + x = start_x; + + y = int(bbox.p1.y / grid.cell_height); + if(y < 0) + y = 0; + + end_x = int(bbox.p2.x / grid.cell_width) + 1; + if(end_x > (int) grid.cells_x) + end_x = grid.cells_x; + + end_y = int(bbox.p2.y / grid.cell_height) + 1; + if(end_y > (int) grid.cells_y) + end_y = grid.cells_y; + + if(start_x >= end_x) { + printf("bad region.\n"); + y = 0; + end_y = 0; + return; + } + + timestamp = grid.iterator_timestamp++; + entry = 0; + } + + MovingObject* next() + { + CollisionGrid::ObjectWrapper* wrapper = next_wrapper(); + if(wrapper == 0) + return 0; + + return wrapper->object; + } + +private: + friend class CollisionGrid; + + CollisionGrid::ObjectWrapper* next_wrapper() + { + CollisionGrid::ObjectWrapper* wrapper; + + do { + while(entry == 0) { + if(y >= end_y) + return 0; + + entry = grid.grid[y*grid.cells_x + x]; + x++; + if(x >= end_x) { + x = start_x; + y++; + } + } + + wrapper = entry->object_wrapper; + entry = entry->next; + } while(wrapper->timestamp == timestamp); + + wrapper->timestamp = timestamp; + + return wrapper; + } + + CollisionGrid& grid; + CollisionGrid::GridEntry* entry; + int x, y; + int start_x, end_x, end_y; + int timestamp; +}; + +#endif + -- 2.11.0