x1 = bbox.p2.x + 1;
x2 = bbox.p2.x + 1;
}
- return Sector::current()->is_free_of_statics(Rect(x1, y1, x2, y2));
+ return Sector::current()->is_free_of_statics(Rectf(x1, y1, x2, y2));
}
Player*
x1 = bbox.p2.x + 1;
x2 = bbox.p2.x + width;
}
- return ((!Sector::current()->is_free_of_statics(Rect(x1, y1a, x2, y2a))) && (Sector::current()->is_free_of_statics(Rect(x1, y1b, x2, y2b))));
+ return ((!Sector::current()->is_free_of_statics(Rectf(x1, y1a, x2, y2a))) &&
+ (Sector::current()->is_free_of_statics(Rectf(x1, y1b, x2, y2b))));
}
void
bool
Igel::can_see(const MovingObject& o)
{
- Rect mb = get_bbox();
- Rect ob = o.get_bbox();
+ Rectf mb = get_bbox();
+ Rectf ob = o.get_bbox();
bool inReach_left = ((ob.p2.x < mb.p1.x) && (ob.p2.x >= mb.p1.x-((dir == LEFT) ? RANGE_OF_VISION : 0)));
bool inReach_right = ((ob.p1.x > mb.p2.x) && (ob.p1.x <= mb.p2.x+((dir == RIGHT) ? RANGE_OF_VISION : 0)));
}
// spawn PoisonIvy
- Vector leaf1_pos = Vector(stumpy_pos.x - POISONIVY_WIDTH - 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
- Rect leaf1_bbox = Rect(leaf1_pos.x, leaf1_pos.y, leaf1_pos.x + POISONIVY_WIDTH, leaf1_pos.y + POISONIVY_HEIGHT);
+ Vector leaf1_pos(stumpy_pos.x - POISONIVY_WIDTH - 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
+ Rectf leaf1_bbox(leaf1_pos.x, leaf1_pos.y, leaf1_pos.x + POISONIVY_WIDTH, leaf1_pos.y + POISONIVY_HEIGHT);
if (Sector::current()->is_free_of_movingstatics(leaf1_bbox, this)) {
PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1, LEFT);
leaf1 = leaf1;
}
// spawn PoisonIvy
- Vector leaf2_pos = Vector(stumpy_pos.x + sprite->get_current_hitbox_width() + 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
- Rect leaf2_bbox = Rect(leaf2_pos.x, leaf2_pos.y, leaf2_pos.x + POISONIVY_WIDTH, leaf2_pos.y + POISONIVY_HEIGHT);
+ Vector leaf2_pos(stumpy_pos.x + sprite->get_current_hitbox_width() + 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
+ Rectf leaf2_bbox(leaf2_pos.x, leaf2_pos.y, leaf2_pos.x + POISONIVY_WIDTH, leaf2_pos.y + POISONIVY_HEIGHT);
if (Sector::current()->is_free_of_movingstatics(leaf2_bbox, this)) {
PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1, RIGHT);
leaf2 = leaf2;
Player* player = this->get_nearest_player();
if (player) {
- Rect mb = this->get_bbox();
- Rect pb = player->get_bbox();
+ Rectf mb = this->get_bbox();
+ Rectf pb = player->get_bbox();
bool inReach_left = (pb.p2.x >= mb.p2.x-((dir == LEFT) ? 256 : 0));
bool inReach_right = (pb.p1.x <= mb.p1.x+((dir == RIGHT) ? 256 : 0));
Player* player = this->get_nearest_player();
if (player) {
- Rect mb = this->get_bbox();
- Rect pb = player->get_bbox();
+ Rectf mb = this->get_bbox();
+ Rectf pb = player->get_bbox();
bool inReach_left = (pb.p2.x >= mb.p2.x-((dir == LEFT) ? 256 : 0));
bool inReach_right = (pb.p1.x <= mb.p1.x+((dir == RIGHT) ? 256 : 0));
if(active_item == index)
{
float blink = (sinf(real_time * M_PI * 1.0f)/2.0f + 0.5f) * 0.5f + 0.25f;
- context.draw_filled_rect(Rect(Vector(pos_x - menu_width/2 + 10 - 2, y_pos - 12 - 2),
- Vector(pos_x + menu_width/2 - 10 + 2, y_pos + 12 + 2)),
+ context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2 + 10 - 2, y_pos - 12 - 2),
+ Vector(pos_x + menu_width/2 - 10 + 2, y_pos + 12 + 2)),
Color(1.0f, 1.0f, 1.0f, blink),
14.0f,
LAYER_GUI-10);
- context.draw_filled_rect(Rect(Vector(pos_x - menu_width/2 + 10, y_pos - 12),
- Vector(pos_x + menu_width/2 - 10, y_pos + 12)),
+ context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2 + 10, y_pos - 12),
+ Vector(pos_x + menu_width/2 - 10, y_pos + 12)),
Color(1.0f, 1.0f, 1.0f, 0.5f),
12.0f,
LAYER_GUI-10);
}
/* Draw a transparent background */
- context.draw_filled_rect(Rect(Vector(pos_x - menu_width/2-4, pos_y - menu_height/2 - 10-4),
- Vector(pos_x + menu_width/2+4, pos_y - menu_height/2 + 10 + menu_height+4)),
+ context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2-4, pos_y - menu_height/2 - 10-4),
+ Vector(pos_x + menu_width/2+4, pos_y - menu_height/2 + 10 + menu_height+4)),
Color(0.2f, 0.3f, 0.4f, 0.8f),
20.0f,
LAYER_GUI-10);
- context.draw_filled_rect(Rect(Vector(pos_x - menu_width/2, pos_y - menu_height/2 - 10),
- Vector(pos_x + menu_width/2, pos_y - menu_height/2 + 10 + menu_height)),
+ context.draw_filled_rect(Rectf(Vector(pos_x - menu_width/2, pos_y - menu_height/2 - 10),
+ Vector(pos_x + menu_width/2, pos_y - menu_height/2 + 10 + menu_height)),
Color(0.6f, 0.7f, 0.8f, 0.5f),
16.0f,
LAYER_GUI-10);
int text_width = (int) Resources::normal_font->get_text_width(items[active_item]->help);
int text_height = (int) Resources::normal_font->get_text_height(items[active_item]->help);
- Rect text_rect(pos_x - text_width/2 - 8,
+ Rectf text_rect(pos_x - text_width/2 - 8,
SCREEN_HEIGHT - 48 - text_height/2 - 4,
pos_x + text_width/2 + 8,
SCREEN_HEIGHT - 48 + text_height/2 + 4);
- context.draw_filled_rect(Rect(text_rect.p1 - Vector(4,4),
- text_rect.p2 + Vector(4,4)),
+ context.draw_filled_rect(Rectf(text_rect.p1 - Vector(4,4),
+ text_rect.p2 + Vector(4,4)),
Color(0.2f, 0.3f, 0.4f, 0.8f),
16.0f,
LAYER_GUI-10);
+++ /dev/null
-// SuperTux
-// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_SUPERTUX_MATH_RECT_HPP
-#define HEADER_SUPERTUX_MATH_RECT_HPP
-
-#include <assert.h>
-
-#include "math/vector.hpp"
-
-/** This class represents a rectangle.
- * (Implementation Note) We're using upper left and lower right point instead of
- * upper left and width/height here, because that makes the collision detection
- * a little bit more efficient.
- */
-class Rect
-{
-public:
- Rect() :
- p1(),
- p2()
- { }
-
- Rect(const Vector& np1, const Vector& np2)
- : p1(np1), p2(np2)
- {
- }
-
- Rect(float x1, float y1, float x2, float y2)
- : p1(x1, y1), p2(x2, y2)
- {
- assert(p1.x <= p2.x && p1.y <= p2.y);
- }
-
- float get_left() const
- { return p1.x; }
-
- float get_right() const
- { return p2.x; }
-
- float get_top() const
- { return p1.y; }
-
- float get_bottom() const
- { return p2.y; }
-
- float get_width() const
- { return p2.x - p1.x; }
-
- float get_height() const
- { return p2.y - p1.y; }
-
- Vector get_middle() const
- { return Vector((p1.x+p2.x)/2, (p1.y+p2.y)/2); }
-
- void set_pos(const Vector& v)
- {
- move(v-p1);
- }
-
- void set_height(float height)
- {
- p2.y = p1.y + height;
- }
- void set_width(float width)
- {
- p2.x = p1.x + width;
- }
- void set_size(float width, float height)
- {
- set_width(width);
- set_height(height);
- }
- Vector get_size()
- {
- return Vector(get_width(), get_height());
- }
-
- void move(const Vector& v)
- {
- p1 += v;
- p2 += v;
- }
-
- bool contains(const Vector& v) const
- {
- return v.x >= p1.x && v.y >= p1.y && v.x < p2.x && v.y < p2.y;
- }
- bool contains(const Rect& other) const
- {
- if(p1.x >= other.p2.x || other.p1.x >= p2.x)
- return false;
- if(p1.y >= other.p2.y || other.p1.y >= p2.y)
- return false;
-
- return true;
- }
-
- // leave these two public to save the headaches of set/get functions for such
- // simple things :)
-
- /// upper left edge
- Vector p1;
- /// lower right edge
- Vector p2;
-};
-
-#endif
-
-/* EOF */
--- /dev/null
+// SuperTux
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_MATH_RECTF_HPP
+#define HEADER_SUPERTUX_MATH_RECTF_HPP
+
+#include <assert.h>
+
+#include "math/vector.hpp"
+
+/** This class represents a rectangle.
+ * (Implementation Note) We're using upper left and lower right point instead of
+ * upper left and width/height here, because that makes the collision detection
+ * a little bit more efficient.
+ */
+class Rectf
+{
+public:
+ Rectf() :
+ p1(),
+ p2()
+ { }
+
+ Rectf(const Vector& np1, const Vector& np2)
+ : p1(np1), p2(np2)
+ {
+ }
+
+ Rectf(float x1, float y1, float x2, float y2)
+ : p1(x1, y1), p2(x2, y2)
+ {
+ assert(p1.x <= p2.x && p1.y <= p2.y);
+ }
+
+ float get_left() const
+ { return p1.x; }
+
+ float get_right() const
+ { return p2.x; }
+
+ float get_top() const
+ { return p1.y; }
+
+ float get_bottom() const
+ { return p2.y; }
+
+ float get_width() const
+ { return p2.x - p1.x; }
+
+ float get_height() const
+ { return p2.y - p1.y; }
+
+ Vector get_middle() const
+ { return Vector((p1.x+p2.x)/2, (p1.y+p2.y)/2); }
+
+ void set_pos(const Vector& v)
+ {
+ move(v-p1);
+ }
+
+ void set_height(float height)
+ {
+ p2.y = p1.y + height;
+ }
+ void set_width(float width)
+ {
+ p2.x = p1.x + width;
+ }
+ void set_size(float width, float height)
+ {
+ set_width(width);
+ set_height(height);
+ }
+ Vector get_size()
+ {
+ return Vector(get_width(), get_height());
+ }
+
+ void move(const Vector& v)
+ {
+ p1 += v;
+ p2 += v;
+ }
+
+ bool contains(const Vector& v) const
+ {
+ return v.x >= p1.x && v.y >= p1.y && v.x < p2.x && v.y < p2.y;
+ }
+ bool contains(const Rectf& other) const
+ {
+ if(p1.x >= other.p2.x || other.p1.x >= p2.x)
+ return false;
+ if(p1.y >= other.p2.y || other.p1.y >= p2.y)
+ return false;
+
+ return true;
+ }
+
+ // leave these two public to save the headaches of set/get functions for such
+ // simple things :)
+
+ /// upper left edge
+ Vector p1;
+ /// lower right edge
+ Vector p2;
+};
+
+#endif
+
+/* EOF */
#include <stdexcept>
#include <sstream>
-#include "math/rect.hpp"
+#include "math/rectf.hpp"
#include "util/log.hpp"
std::string anchor_point_to_string(AnchorPoint point)
throw std::runtime_error(msg.str());
}
-Vector get_anchor_pos(const Rect& rect, AnchorPoint point)
+Vector get_anchor_pos(const Rectf& rect, AnchorPoint point)
{
Vector result;
return result;
}
-Vector get_anchor_pos(const Rect& destrect, float width, float height,
+Vector get_anchor_pos(const Rectf& destrect, float width, float height,
AnchorPoint point)
{
Vector result;
#include "math/vector.hpp"
-class Rect;
+class Rectf;
enum AnchorPoint {
ANCHOR_H_MASK = 0x00f0,
std::string anchor_point_to_string(AnchorPoint point);
AnchorPoint string_to_anchor_point(const std::string& str);
-Vector get_anchor_pos(const Rect& rect, AnchorPoint point);
-Vector get_anchor_pos(const Rect& destrect, float width, float height,
+Vector get_anchor_pos(const Rectf& rect, AnchorPoint point);
+Vector get_anchor_pos(const Rectf& destrect, float width, float height,
AnchorPoint point);
#endif
return;
}
- Vector spos = pos + get_anchor_pos(Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
+ Vector spos = pos + get_anchor_pos(Rectf(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
sprite->get_width(), sprite->get_height(), anchor);
sprite->draw(context, spos, layer);
Player* player = this->get_nearest_player();
if (!player) return false;
- const Rect& pr = player->get_bbox();
- const Rect& br = get_bbox();
+ const Rectf& pr = player->get_bbox();
+ const Rectf& br = get_bbox();
if ((pr.p2.x > br.p1.x) && (pr.p1.x < br.p2.x) && (pr.p1.y >= br.p2.y)) {
return true;
}
break;
}
- lines[i]->draw(context, Rect(x1, y, x2, y), LAYER_GUI-50+1);
+ lines[i]->draw(context, Rectf(x1, y, x2, y), LAYER_GUI-50+1);
y += lines[i]->get_height();
}
}
bool
-Ispy::intersects_line(Rect r, Vector line_start, Vector line_end)
+Ispy::intersects_line(Rectf r, Vector line_start, Vector line_end)
{
Vector p1 = r.p1;
Vector p2 = Vector(r.p2.x, r.p1.y);
private:
bool line_intersects_line(Vector line1_start, Vector line1_end, Vector line2_start, Vector line2_end);
- bool intersects_line(Rect r, Vector line_start, Vector line_end);
+ bool intersects_line(Rectf r, Vector line_start, Vector line_end);
bool free_line_of_sight(Vector p1, Vector p2, const MovingObject* ignore_object);
enum IspyState {
void
MovingSprite::set_action(const std::string& action, int loops, AnchorPoint anchorPoint)
{
- Rect old_bbox = bbox;
+ Rectf old_bbox = bbox;
sprite->set_action(action, loops);
float w = sprite->get_current_hitbox_width();
float h = sprite->get_current_hitbox_height();
int max_x = int(x2+1);
int max_y = int(y2+1);
- Rect dest = Rect(x1, y1, x2, y2);
+ Rectf dest(x1, y1, x2, y2);
dest.move(movement);
Constraints constraints;
water = true;
}
} else { // normal rectangular tile
- Rect rect(x*32, y*32, (x+1)*32, (y+1)*32);
+ Rectf rect(x*32, y*32, (x+1)*32, (y+1)*32);
if(intersects(dest, rect)) {
if(tile->getAttributes() & Tile::WATER)
water = true;
bool
Player::adjust_height(float new_height)
{
- Rect bbox2 = bbox;
+ Rectf bbox2 = bbox;
bbox2.move(Vector(0, bbox.get_height() - new_height));
bbox2.set_height(new_height);
if(new_height > bbox.get_height()) {
- Rect additional_space = bbox2;
+ Rectf additional_space = bbox2;
additional_space.set_height(new_height - bbox.get_height());
if(!Sector::current()->is_free_of_statics(additional_space, this, true))
return false;
Vector pos = get_pos() +
Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
bbox.get_height()*0.66666 - 32);
- Rect dest(pos, pos + Vector(32, 32));
+ Rectf dest(pos, pos + Vector(32, 32));
if(Sector::current()->is_free_of_movingstatics(dest)) {
MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
if(moving_object) {
float width = 500;
float height = 70;
- Vector spos = pos + get_anchor_pos(Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
+ Vector spos = pos + get_anchor_pos(Rectf(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
width, height, anchor);
context.draw_filled_rect(spos, Vector(width, height),
return action->hitbox_h;
}
-Rect
+Rectf
Sprite::get_current_hitbox() const
{
- return Rect(action->x_offset, action->y_offset, action->x_offset + action->hitbox_w, action->y_offset + action->hitbox_h);
+ return Rectf(action->x_offset, action->y_offset, action->x_offset + action->hitbox_w, action->y_offset + action->hitbox_h);
}
void
/** return height of current action's hitbox */
float get_current_hitbox_height() const;
/** return current action's hitbox, relative to 0,0 */
- Rect get_current_hitbox() const;
+ Rectf get_current_hitbox() const;
/** Set the angle of the sprite rotation in degree */
void set_angle(float angle);
#include <algorithm>
#include "math/aatriangle.hpp"
-#include "math/rect.hpp"
+#include "math/rectf.hpp"
namespace collision {
-bool intersects(const Rect& r1, const Rect& r2)
+bool intersects(const Rectf& r1, const Rectf& r2)
{
if(r1.p2.x < r2.p1.x || r1.p1.x > r2.p2.x)
return false;
}
-bool rectangle_aatriangle(Constraints* constraints, const Rect& rect,
+bool rectangle_aatriangle(Constraints* constraints, const Rectf& rect,
const AATriangle& triangle, const Vector& addl_ground_movement)
{
- if(!intersects(rect, (const Rect&) triangle))
+ if(!intersects(rect, (const Rectf&) triangle))
return false;
Vector normal;
float c;
Vector p1;
- Rect area;
+ Rectf area;
switch(triangle.dir & AATriangle::DEFORM_MASK) {
case 0:
area.p1 = triangle.p1;
}
void set_rectangle_rectangle_constraints(Constraints* constraints,
- const Rect& r1, const Rect& r2, const Vector& addl_ground_movement)
+ const Rectf& r1, const Rectf& r2, const Vector& addl_ground_movement)
{
float itop = r1.get_bottom() - r2.get_top();
float ibottom = r2.get_bottom() - r1.get_top();
#include <limits>
class Vector;
-class Rect;
+class Rectf;
class AATriangle;
namespace collision {
};
/** checks if 2 rectangle intersect each other */
-bool intersects(const Rect& r1, const Rect& r2);
+bool intersects(const Rectf& r1, const Rectf& r2);
/** does collision detection between a rectangle and an axis aligned triangle
* Returns true in case of a collision and fills in the hit structure then.
*/
-bool rectangle_aatriangle(Constraints* constraints, const Rect& rect,
+bool rectangle_aatriangle(Constraints* constraints, const Rectf& rect,
const AATriangle& triangle, const Vector& addl_ground_movement = Vector(0,0));
void set_rectangle_rectangle_constraints(Constraints* constraints,
- const Rect& r1, const Rect& r2, const Vector& addl_ground_movement = Vector(0,0));
+ const Rectf& r1, const Rectf& r2, const Vector& addl_ground_movement = Vector(0,0));
} // namespace collision
break;
}
- lines[i]->draw(context, Rect(x1, y, x1+width, y), LAYER_GUI);
+ lines[i]->draw(context, Rectf(x1, y, x1+width, y), LAYER_GUI);
y += lines[i]->get_height();
}
}
void
-InfoBoxLine::draw(DrawingContext& context, const Rect& bbox, int layer)
+InfoBoxLine::draw(DrawingContext& context, const Rectf& bbox, int layer)
{
Vector position = bbox.p1;
switch (lineType) {
class DrawingContext;
class Font;
-class Rect;
+class Rectf;
class Surface;
/**
InfoBoxLine(char format_char, const std::string& text);
~InfoBoxLine();
- void draw(DrawingContext& context, const Rect& bbox, int layer);
+ void draw(DrawingContext& context, const Rectf& bbox, int layer);
float get_height();
static const std::vector<InfoBoxLine*> split(const std::string& text, float width);
#include <stdint.h>
-#include "math/rect.hpp"
+#include "math/rectf.hpp"
#include "supertux/collision_hit.hpp"
#include "supertux/game_object.hpp"
}
/** returns the bounding box of the Object */
- const Rect& get_bbox() const
+ const Rectf& get_bbox() const
{
return bbox;
}
/** The bounding box of the object (as used for collision detection,
this isn't necessarily the bounding box for graphics) */
- Rect bbox;
+ Rectf bbox;
/** The movement that will happen till next frame */
Vector movement;
This field holds the currently anticipated destination of the object
during collision detection */
- Rect dest;
+ Rectf dest;
};
#endif
_current = NULL;
}
-Rect
+Rectf
Sector::get_active_region()
{
- return Rect(
+ return Rectf(
camera->get_translation() - Vector(1600, 1200),
camera->get_translation() + Vector(1600, 1200) + Vector(SCREEN_WIDTH,SCREEN_HEIGHT));
}
for(MovingObjects::iterator i = moving_objects.begin();
i != moving_objects.end(); ++i) {
MovingObject* object = *i;
- const Rect& rect = object->get_bbox();
+ const Rectf& rect = object->get_bbox();
context.draw_filled_rect(rect, col, LAYER_FOREGROUND1 + 10);
}
/** r1 is supposed to be moving, r2 a solid object */
void check_collisions(collision::Constraints* constraints,
- const Vector& movement, const Rect& r1, const Rect& r2,
+ const Vector& movement, const Rectf& r1, const Rectf& r2,
GameObject* object = NULL, MovingObject* other = NULL, const Vector& addl_ground_movement = Vector(0,0))
{
if(!collision::intersects(r1, r2))
void
Sector::collision_tilemap(collision::Constraints* constraints,
- const Vector& movement, const Rect& dest) const
+ const Vector& movement, const Rectf& dest) const
{
// calculate rectangle where the object will move
float x1 = dest.get_left();
collision::rectangle_aatriangle(constraints, dest, triangle, solids->get_movement());
} else { // normal rectangular tile
- Rect rect(x*32 + solids->get_x_offset(), y*32 + solids->get_y_offset(), (x+1)*32 + solids->get_x_offset(), (y+1)*32 + solids->get_y_offset());
+ Rectf rect(x*32 + solids->get_x_offset(), y*32 + solids->get_y_offset(), (x+1)*32 + solids->get_x_offset(), (y+1)*32 + solids->get_y_offset());
check_collisions(constraints, movement, dest, rect, NULL, NULL, solids->get_movement());
}
}
}
uint32_t
-Sector::collision_tile_attributes(const Rect& dest) const
+Sector::collision_tile_attributes(const Rectf& dest) const
{
float x1 = dest.p1.x;
float y1 = dest.p1.y;
}
/** fills in CollisionHit and Normal vector of 2 intersecting rectangle */
-static void get_hit_normal(const Rect& r1, const Rect& r2, CollisionHit& hit,
+static void get_hit_normal(const Rectf& r1, const Rectf& r2, CollisionHit& hit,
Vector& normal)
{
float itop = r1.get_bottom() - r2.get_top();
{
using namespace collision;
- const Rect& r1 = object1->dest;
- const Rect& r2 = object2->dest;
+ const Rectf& r1 = object1->dest;
+ const Rectf& r2 = object2->dest;
CollisionHit hit;
if(intersects(object1->dest, object2->dest)) {
void
Sector::collision_static(collision::Constraints* constraints,
- const Vector& movement, const Rect& dest,
+ const Vector& movement, const Rectf& dest,
GameObject& object)
{
collision_tilemap(constraints, movement, dest);
Constraints constraints;
Vector movement = object.get_movement();
- Rect& dest = object.dest;
+ Rectf& dest = object.dest;
float owidth = object.get_bbox().get_width();
float oheight = object.get_bbox().get_height();
}
bool
-Sector::is_free_of_tiles(const Rect& rect, const bool ignoreUnisolid) const
+Sector::is_free_of_tiles(const Rectf& rect, const bool ignoreUnisolid) const
{
using namespace collision;
}
bool
-Sector::is_free_of_statics(const Rect& rect, const MovingObject* ignore_object, const bool ignoreUnisolid) const
+Sector::is_free_of_statics(const Rectf& rect, const MovingObject* ignore_object, const bool ignoreUnisolid) const
{
using namespace collision;
}
bool
-Sector::is_free_of_movingstatics(const Rect& rect, const MovingObject* ignore_object) const
+Sector::is_free_of_movingstatics(const Rectf& rect, const MovingObject* ignore_object) const
{
using namespace collision;
}
bool
-Sector::inside(const Rect& rect) const
+Sector::inside(const Rectf& rect) const
{
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
TileMap* solids = *i;
}
class Vector;
-class Rect;
+class Rectf;
class Sprite;
class GameObject;
class Player;
* tests if a given rectangle is inside the sector
* (a rectangle that is on top of the sector is considered inside)
*/
- bool inside(const Rect& rectangle) const;
+ bool inside(const Rectf& rectangle) const;
void play_music(MusicType musictype);
MusicType get_music_type();
}
void collision_tilemap(collision::Constraints* constraints,
- const Vector& movement, const Rect& dest) const;
+ const Vector& movement, const Rectf& dest) const;
/**
* Checks if the specified rectangle is free of (solid) tiles.
* Note that this does not include static objects, e.g. bonus blocks.
*/
- bool is_free_of_tiles(const Rect& rect, const bool ignoreUnisolid = false) const;
+ bool is_free_of_tiles(const Rectf& rect, const bool ignoreUnisolid = false) const;
/**
* Checks if the specified rectangle is free of both
* 1.) solid tiles and
* 2.) MovingObjects in COLGROUP_STATIC.
* Note that this does not include badguys or players.
*/
- bool is_free_of_statics(const Rect& rect, const MovingObject* ignore_object = 0, const bool ignoreUnisolid = false) const;
+ bool is_free_of_statics(const Rectf& rect, const MovingObject* ignore_object = 0, const bool ignoreUnisolid = false) const;
/**
* Checks if the specified rectangle is free of both
* 1.) solid tiles and
* 2.) MovingObjects in COLGROUP_STATIC, COLGROUP_MOVINGSTATIC or COLGROUP_MOVING.
* This includes badguys and players.
*/
- bool is_free_of_movingstatics(const Rect& rect, const MovingObject* ignore_object = 0) const;
+ bool is_free_of_movingstatics(const Rectf& rect, const MovingObject* ignore_object = 0) const;
/**
* returns a list of players currently in the sector
return std::vector<Player*>(1, this->player);
}
- Rect get_active_region();
+ Rectf get_active_region();
/**
* returns the width (in px) of a sector)
float get_gravity() const;
private:
- uint32_t collision_tile_attributes(const Rect& dest) const;
+ uint32_t collision_tile_attributes(const Rectf& dest) const;
void before_object_remove(GameObject* object);
bool before_object_add(GameObject* object);
* (because of ABORT_MOVE in the collision response or no collisions)
*/
void collision_static(collision::Constraints* constraints,
- const Vector& movement, const Rect& dest, GameObject& object);
+ const Vector& movement, const Rectf& dest, GameObject& object);
void collision_static_constrains(MovingObject& object);
float y = SCREEN_HEIGHT - scroll;
for(size_t i = 0; i < lines.size(); i++) {
if (y + lines[i]->get_height() >= 0 && SCREEN_HEIGHT - y >= 0) {
- lines[i]->draw(context, Rect(LEFT_BORDER, y, SCREEN_WIDTH - 2*LEFT_BORDER, y), LAYER_GUI);
+ lines[i]->draw(context, Rectf(LEFT_BORDER, y, SCREEN_WIDTH - 2*LEFT_BORDER, y), LAYER_GUI);
}
y += lines[i]->get_height();
#include <vector>
#include <stdint.h>
-#include "math/rect.hpp"
+#include "math/rectf.hpp"
#include "video/surface.hpp"
#include "util/reader_fwd.hpp"
};
struct ImageSpec {
- ImageSpec(const std::string& newfile, const Rect& newrect)
+ ImageSpec(const std::string& newfile, const Rectf& newrect)
: file(newfile), rect(newrect)
{ }
std::string file;
- Rect rect;
+ Rectf rect;
};
private:
{
std::string file;
cur->get(file);
- imagespecs.push_back(Tile::ImageSpec(m_tiles_path + file, Rect(0, 0, 0, 0)));
+ imagespecs.push_back(Tile::ImageSpec(m_tiles_path + file, Rectf(0, 0, 0, 0)));
}
else if(cur->get_type() == lisp::Lisp::TYPE_CONS &&
cur->get_car()->get_type() == lisp::Lisp::TYPE_SYMBOL &&
ptr->get_car()->get(y); ptr = ptr->get_cdr();
ptr->get_car()->get(w); ptr = ptr->get_cdr();
ptr->get_car()->get(h);
- imagespecs.push_back(Tile::ImageSpec(m_tiles_path + file, Rect(x, y, x+w, y+h)));
+ imagespecs.push_back(Tile::ImageSpec(m_tiles_path + file, Rectf(x, y, x+w, y+h)));
}
else
{
std::vector<Tile::ImageSpec> imagespecs;
for(std::vector<std::string>::const_iterator j = images.begin(); j != images.end(); ++j)
{
- imagespecs.push_back(Tile::ImageSpec(m_tiles_path + *j, Rect(x, y, x + 32, y + 32)));
+ imagespecs.push_back(Tile::ImageSpec(m_tiles_path + *j, Rectf(x, y, x + 32, y + 32)));
}
std::auto_ptr<Tile> tile(new Tile(m_tileset, imagespecs,
controller->press(Controller::RIGHT);
// Check if we should press the jump button
- Rect lookahead = tux->get_bbox();
+ Rectf lookahead = tux->get_bbox();
lookahead.p2.x += 96;
bool pathBlocked = !sector->is_free_of_statics(lookahead);
if ((pathBlocked && jumpWasReleased) || !tux->on_ground()) {
bbox.set_size(w, h);
}
-Climbable::Climbable(const Rect& area) :
+Climbable::Climbable(const Rectf& area) :
climbed_by(0),
activate_try_timer()
{
static Color text_color;
public:
Climbable(const Reader& reader);
- Climbable(const Rect& area);
+ Climbable(const Rectf& area);
~Climbable();
void event(Player& player, EventType type);
message_displayed = false;
}
-SecretAreaTrigger::SecretAreaTrigger(const Rect& area, std::string fade_tilemap) :
+SecretAreaTrigger::SecretAreaTrigger(const Rectf& area, std::string fade_tilemap) :
message_timer(),
message_displayed(),
fade_tilemap(fade_tilemap)
static Color text_color;
public:
SecretAreaTrigger(const Reader& reader);
- SecretAreaTrigger(const Rect& area, std::string fade_tilemap = "");
+ SecretAreaTrigger(const Rectf& area, std::string fade_tilemap = "");
~SecretAreaTrigger();
void event(Player& player, EventType type);
#include "util/log.hpp"
-#include "math/rect.hpp"
+#include "math/rectf.hpp"
#include "supertux/console.hpp"
#ifndef NDEBUG
return out;
}
-std::ostream& operator<<(std::ostream& out, const Rect& rect)
+std::ostream& operator<<(std::ostream& out, const Rectf& rect)
{
out << "[" << rect.get_left() << "," << rect.get_top() << " "
<< rect.get_right() << "," << rect.get_bottom() << "]";
class Vector;
std::ostream& operator<< (std::ostream& str, const Vector& vector);
-class Rect;
-std::ostream& operator<< (std::ostream& str, const Rect& rect);
+class Rectf;
+std::ostream& operator<< (std::ostream& str, const Rectf& rect);
#endif
}
void
-DrawingContext::draw_filled_rect(const Rect& rect, const Color& color,
+DrawingContext::draw_filled_rect(const Rectf& rect, const Color& color,
int layer)
{
draw_filled_rect(rect, color, 0.0f, layer);
}
void
-DrawingContext::draw_filled_rect(const Rect& rect, const Color& color, float radius, int layer)
+DrawingContext::draw_filled_rect(const Rectf& rect, const Color& color, float radius, int layer)
{
DrawingRequest* request = new(obst) DrawingRequest();
#include <stdint.h>
#include <obstack.h>
-#include "math/rect.hpp"
+#include "math/rectf.hpp"
#include "math/vector.hpp"
#include "video/color.hpp"
#include "video/drawing_request.hpp"
/// Fills a rectangle.
void draw_filled_rect(const Vector& topleft, const Vector& size,
const Color& color, int layer);
- void draw_filled_rect(const Rect& rect, const Color& color, int layer);
- void draw_filled_rect(const Rect& rect, const Color& color, float radius, int layer);
+ void draw_filled_rect(const Rectf& rect, const Color& color, int layer);
+ void draw_filled_rect(const Rectf& rect, const Color& color, float radius, int layer);
void draw_inverse_ellipse(const Vector& pos, const Vector& size, const Color& color, int layer);
glyph.surface_idx = surface_idx;
if( glyph_width == FIXED ) {
- glyph.rect = Rect(x, y, x + char_width, y + char_height);
+ glyph.rect = Rectf(x, y, x + char_width, y + char_height);
glyph.offset = Vector(0, 0);
glyph.advance = char_width;
}
right -= 1;
if (left <= right)
- glyph.rect = Rect(left, y, right+1, y + char_height);
+ glyph.rect = Rectf(left, y, right+1, y + char_height);
else // glyph is completely transparent
- glyph.rect = Rect(x, y, x + char_width, y + char_height);
+ glyph.rect = Rectf(x, y, x + char_width, y + char_height);
glyph.offset = Vector(0, 0);
glyph.advance = glyph.rect.get_width() + 1; // FIXME: might be useful to make spacing configurable
#include <stdint.h>
#include <string>
-#include "math/rect.hpp"
+#include "math/rectf.hpp"
#include "math/vector.hpp"
#include "video/color.hpp"
#include "video/surface.hpp"
int surface_idx;
/** Position of the glyph inside the surface */
- Rect rect;
+ Rectf rect;
Glyph() :
advance(),
fillrectrequest->size.y/2));
// inner rectangle
- Rect irect(request.pos.x + radius,
+ Rectf irect(request.pos.x + radius,
request.pos.y + radius,
request.pos.x + fillrectrequest->size.x - radius,
request.pos.y + fillrectrequest->size.y - radius);
#include <string>
#include <vector>
-#include "math/rect.hpp"
+#include "math/rectf.hpp"
#include "math/vector.hpp"
#include "video/color.hpp"
#include "video/drawing_request.hpp"
#include <stdint.h>
#include <obstack.h>
-#include "math/rect.hpp"
+#include "math/rectf.hpp"
#include "math/vector.hpp"
#include "video/color.hpp"
#include "video/font.hpp"