From: Wolfgang Becker Date: Fri, 11 Aug 2006 21:50:58 +0000 (+0000) Subject: Magic Blocks. (DrawingContext::get_light is not working yet.) X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ab9eab4c870195c2b60ce76b77044c35b31e8806;p=supertux.git Magic Blocks. (DrawingContext::get_light is not working yet.) SVN-Revision: 4163 --- diff --git a/data/images/objects/magicblock/magicblock-solid.png b/data/images/objects/magicblock/magicblock-solid.png new file mode 100644 index 000000000..d0e147005 Binary files /dev/null and b/data/images/objects/magicblock/magicblock-solid.png differ diff --git a/data/images/objects/magicblock/magicblock.png b/data/images/objects/magicblock/magicblock.png new file mode 100644 index 000000000..f9c7774bf Binary files /dev/null and b/data/images/objects/magicblock/magicblock.png differ diff --git a/data/images/objects/magicblock/magicblock.sprite b/data/images/objects/magicblock/magicblock.sprite new file mode 100644 index 000000000..1b8071955 --- /dev/null +++ b/data/images/objects/magicblock/magicblock.sprite @@ -0,0 +1,8 @@ +(supertux-sprite + (action + (name "normal") + (images "magicblock.png")) + (action + (name "solid") + (images "magicblock-solid.png")) +) diff --git a/data/levels/test/magicblocks.stl b/data/levels/test/magicblocks.stl new file mode 100644 index 000000000..cd3eeb27a --- /dev/null +++ b/data/levels/test/magicblocks.stl @@ -0,0 +1,104 @@ +(supertux-level + (version 2) + (name (_ "Unnamed")) + (author "wolfgang") + (sector + (name "main") + (ambient-light 0.1451591 0.1451591 0.1451591) + (camera + (mode "normal") + ) + (spawnpoint + (name "main") + (x 96) + (y 96) + ) + (spotlight + (angle 90) + (color 1 0 1) + (x 256) + (y 160) + ) + (spotlight + (angle 0) + (color 1 1 1) + (x 608) + (y 192) + ) + (magicblock + (x 192) + (y 288) + (color 1 1 1) + ) + (magicblock + (x 288) + (y 288) + (color 1 0 0) + ) + (magicblock + (x 384) + (y 288) + (color 0 1 0) + ) + (magicblock + (x 480) + (y 288) + (color 0 0 1) + ) + (magicblock + (x 576) + (y 288) + (color 1 1 0) + ) + (magicblock + (x 640) + (y 288) + (color 1 0 1) + ) + (magicblock + (x 736) + (y 288) + (color 0 1 1) + ) + (magicblock + (x 832) + (y 288) + (color 0 0 0) + ) + (magicblock + (x 288) + (y 288) + (color 1 0 0) + ) + (tilemap + (z-pos -100) + (solid #f) + (speed 1) + (width 50) + (height 20) + (tiles 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) + ) + (background + (speed 0.5) + (image-top "images/background/arctis_top.jpg") + (image "images/background/arctis.jpg") + (image-bottom "images/background/arctis_bottom.jpg") + ) + ) +) diff --git a/src/object/magicblock.cpp b/src/object/magicblock.cpp new file mode 100644 index 000000000..ef8d5b346 --- /dev/null +++ b/src/object/magicblock.cpp @@ -0,0 +1,102 @@ +// $Id:$ +// +// SuperTux - MagicBlock +// +// Magic Blocks are tile-like game objects that are sensitive to +// lighting conditions. They are rendered in a color and +// will only be solid as long as light of the same color shines +// on the block. +// +// Copyright (C) 2006 Wolfgang Becker +// +// 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 2 +// 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, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include +#include + +#include "magicblock.hpp" +#include "object_factory.hpp" +#include "sprite/sprite_manager.hpp" + +namespace { + const float MIN_INTENSITY = 0.8; + const float ALPHA_SOLID = 0.7; + const float ALPHA_NONSOLID = 0.3; +} + +MagicBlock::MagicBlock(const lisp::Lisp& lisp) + : MovingSprite(lisp, "images/objects/magicblock/magicblock.sprite"), + is_solid(false), light(1.0f,1.0f,1.0f) +{ + set_group(COLGROUP_STATIC); + //get color from lisp + std::vector vColor; + lisp.get_vector("color", vColor ); + color = Color( vColor ); + + //all alpha to make the sprite still visible + color.alpha = ALPHA_SOLID; + + //set trigger + trigger_red = (color.red == 1.0f ? MIN_INTENSITY : 0); + trigger_green = (color.green == 1.0f ? MIN_INTENSITY : 0); + trigger_blue = (color.blue == 1.0f ? MIN_INTENSITY : 0); + + center = Vector((get_bbox().p1.x+get_bbox().p2.x)/2, + (get_bbox().p1.y+get_bbox().p2.y)/2); +} + +void +MagicBlock::update(float /*elapsed_time*/) +{ + if(light.red >= trigger_red && light.green >= trigger_green + && light.blue >= trigger_blue) { + is_solid = true; + } else { + is_solid = false; + } + + //Update Sprite. + if(is_solid) { + color.alpha = ALPHA_SOLID; + sprite->set_action("solid"); + } else { + color.alpha = ALPHA_NONSOLID; + sprite->set_action("normal"); + } +} + +void +MagicBlock::draw(DrawingContext& context){ + //Ask for update about lightmap at center of this block + context.get_light( center, &light ); + + //Draw the Sprite. + MovingSprite::draw(context); + //Add the color. + context.draw_filled_rect( get_bbox(), color, layer); +} + +HitResponse +MagicBlock::collision(GameObject& /*other*/, const CollisionHit& /*hit*/) +{ + if(is_solid) { + return SOLID; + } else { + return PASSTHROUGH; + } +} + +IMPLEMENT_FACTORY(MagicBlock, "magicblock"); diff --git a/src/object/magicblock.hpp b/src/object/magicblock.hpp new file mode 100644 index 000000000..a0592b919 --- /dev/null +++ b/src/object/magicblock.hpp @@ -0,0 +1,51 @@ +// $Id$ +// +// SuperTux - MagicBlock +// +// Magic Blocks are tile-like game objects that are sensitive to +// lighting conditions. They are rendered in a color and +// will only be solid as long as light of the same color shines +// on the block. +// +// Copyright (C) 2006 Wolfgang Becker +// +// 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 2 +// 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, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef SUPERTUX_TRAMPOLINE_H +#define SUPERTUX_TRAMPOLINE_H + +#include "moving_sprite.hpp" +#include "lisp/lisp.hpp" + +class MagicBlock: public MovingSprite +{ +public: + MagicBlock(const lisp::Lisp& reader); + + HitResponse collision(GameObject& other, const CollisionHit& hit); + void update(float elapsed_time); + void draw(DrawingContext& context); + +private: + bool is_solid; + float trigger_red; + float trigger_green; + float trigger_blue; + Color color; + Color light; + Vector center; +}; + +#endif diff --git a/src/object/trampoline.cpp b/src/object/trampoline.cpp index c7c993934..c467dfc31 100644 --- a/src/object/trampoline.cpp +++ b/src/object/trampoline.cpp @@ -1,4 +1,4 @@ -// $Id$ +// $Id:$ // // SuperTux - Trampoline // Copyright (C) 2006 Wolfgang Becker @@ -34,7 +34,7 @@ namespace { } Trampoline::Trampoline(const lisp::Lisp& lisp) - : MovingSprite(lisp, "images/objects/trampoline/trampoline.sprite" ) + : MovingSprite(lisp, "images/objects/trampoline/trampoline.sprite") { set_group(COLGROUP_MOVING_STATIC); sound_manager->preload(TRAMPOLINE_SOUND); @@ -66,7 +66,7 @@ Trampoline::update(float elapsed_time) } HitResponse -Trampoline::collision(GameObject& other, const CollisionHit& hit ) +Trampoline::collision(GameObject& other, const CollisionHit& hit) { //Tramponine has to be on ground to work. if(!on_ground) { @@ -115,7 +115,7 @@ Trampoline::grab(MovingObject&, const Vector& pos, Direction) { } void -Trampoline::ungrab(MovingObject& , Direction ) { +Trampoline::ungrab(MovingObject& , Direction) { set_group(COLGROUP_MOVING_STATIC); on_ground = false; physic.set_velocity(0, 0); diff --git a/src/object/trampoline.hpp b/src/object/trampoline.hpp index df751d8ff..c534f54c6 100644 --- a/src/object/trampoline.hpp +++ b/src/object/trampoline.hpp @@ -37,8 +37,8 @@ public: void collision_solid(const CollisionHit& hit); void update(float elapsed_time); - void grab( MovingObject&, const Vector& pos, Direction ); - void ungrab(MovingObject& , Direction ); + void grab(MovingObject&, const Vector& pos, Direction); + void ungrab(MovingObject&, Direction); bool is_portable() const; private: diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index 6f570d018..e8887a645 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -33,7 +33,6 @@ #include "glutil.hpp" #include "texture.hpp" #include "texture_manager.hpp" - #define LIGHTMAP_DIV 4 static inline int next_po2(int val) @@ -239,6 +238,42 @@ DrawingContext::draw_filled_rect(const Rect& rect, const Color& color, } void +DrawingContext::get_light(const Vector& position, Color* color) +{ + if( ambient_color.red == 1.0f && ambient_color.green == 1.0f + && ambient_color.blue == 1.0f ) { + *color = Color( 1.0f, 1.0f, 1.0f); + return; + } + DrawingRequest request; + request.type = GETLIGHT; + request.pos = transform.apply(position); + request.layer = LAYER_GUI; //make sure all get_light requests are handled last. + + GetLightRequest* getlightrequest = new GetLightRequest; + getlightrequest->color_ptr = color; + request.request_data = getlightrequest; + lightmap_requests.push_back(request); +} + +void +DrawingContext::get_light(DrawingRequest& request) +{ + GetLightRequest* getlightrequest = (GetLightRequest*) request.request_data; + + float pixels[3]; + for( int i = 0; i<3; i++) + pixels[i] = 0.0f; //set to black + + //TODO: not working as i thought. this only returns ambient_color. Why? + glReadPixels((GLint) request.pos.x, (GLint)request.pos.y, 1, 1, GL_RGB, GL_FLOAT, pixels); + *(getlightrequest->color_ptr) = Color( pixels[0], pixels[1], pixels[2]); + //printf("get_light %f/%f r%f g%f b%f\n", request.pos.x, request.pos.y, pixels[0], pixels[1], pixels[2]); + + delete getlightrequest; +} + +void DrawingContext::draw_surface_part(DrawingRequest& request) { SurfacePartRequest* surfacepartrequest @@ -426,6 +461,9 @@ DrawingContext::handle_drawing_requests(DrawingRequests& requests) case LIGHTMAPREQUEST: draw_lightmap(*i); break; + case GETLIGHT: + get_light(*i); + break; } } } diff --git a/src/video/drawing_context.hpp b/src/video/drawing_context.hpp index fee498186..ee5d6ddc8 100644 --- a/src/video/drawing_context.hpp +++ b/src/video/drawing_context.hpp @@ -125,6 +125,9 @@ public: /// return currently set alpha float get_alpha() const; + /// on next update, set color to lightmap's color at position + void get_light(const Vector& position, Color* color ); + enum Target { NORMAL, LIGHTMAP }; @@ -162,7 +165,7 @@ private: enum RequestType { - SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, LIGHTMAPREQUEST + SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, LIGHTMAPREQUEST, GETLIGHT }; struct SurfacePartRequest @@ -215,6 +218,11 @@ private: } }; + struct GetLightRequest + { + Color* color_ptr; + }; + typedef std::vector DrawingRequests; void handle_drawing_requests(DrawingRequests& requests); @@ -224,6 +232,7 @@ private: void draw_gradient(DrawingRequest& request); void draw_filled_rect(DrawingRequest& request); void draw_lightmap(DrawingRequest& request); + void get_light(DrawingRequest& request); DrawingRequests drawing_requests; DrawingRequests lightmap_requests;