////////////////////////////////////////////////////////////////////////////////////////////////// // Draw functions ////////////////////////////////////////////////////////////////////////////////////////////////// void cEdiPaint::DrawTile( int idx, int x, int y, const iRect & map, dword color, int flip, int frame, Blend blend, float scale ) { Tile* tile = TileGet(idx); if(tile==NULL) return; int w = tile->GetWidth(); int h = tile->GetHeight(); if(frame<0) frame=0; frame = frame % tile->frames; int fx = tile->GetFx(frame); int fy = tile->GetFy(frame); fRect src = map; src.Offset(fV2(fx * w, fy *h)); R9_SetBlend(blend); R9_DrawSprite( fV2(x, y), src, tile->tex, color, flip, (float)scale ); }
namespace draw { /// FUNCTIONS // set draw mode void use2D(); void use3D(); // draw primitives void rectangle(fRect rect, Colour c = Colour()); void line(fV2 start, fV2 end, Colour c = Colour(), float thickness = 1.0f); void line(fV3 start, fV3 end, Colour c = Colour(), float thickness = 1.0f); void line_loop(fV2 points[], unsigned int n_pts, Colour c = Colour(), float thickness = 1.0f); void height_line(float height[], unsigned int n_pts, float x_spacing, fV2 base = fV2(0.0f, 0.0f), unsigned int start_i = 0, Colour c = Colour(), float thickness = 1.0f); void height_fill(float height[], unsigned int n_pts, float x_spacing, fV2 base = fV2(0.0f, 0.0f), unsigned int start_i = 0, Colour c = Colour()); void circle(fV2 position, double radius, Colour c = Colour(), bool fill = false); };
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/>. */ #include "NavCell.hpp" //! ---------------------------------------------------------------------------- //! CONSTANTS //! ---------------------------------------------------------------------------- const fV2 NavCell::SIZE = fV2(CELL_W, CELL_H); const float NavCell::floor_z = CELL_Z; const float NavCell::wall_h = CELL_WALL_H; //! ---------------------------------------------------------------------------- //! CONSTRUCTORS, DESTRUCTORS //! ---------------------------------------------------------------------------- NavCell::NavCell(uV2 grid_position_) : grid_position(grid_position_), vertex_position((fV2)grid_position_ * SIZE) { } NavCell::~NavCell() {
void cEdiPaint::DrawBrushAt( Brush* brush, int x, int y, float zoom, BOOL anim ) { if(brush==NULL) return; int idx = TileFind(brush->tile); // if(idx==-1) return; iRect map = brush->map; int mw = static_cast<int>(brush->mapWith()); int mh = static_cast<int>(brush->mapHeight()); float ms = brush->mapScale(); if( mw==0 || mh==0 ) return; fRect oldclip = R9_GetClipping(); fRect newclip( (float)x, (float)y, (float)x+zoom*brush->size.x, (float)y+zoom*brush->size.y ); R9_AddClipping(newclip); if(!R9_IsClipping()) { R9_SetClipping(oldclip); return; } // fully clipped if(idx==-1) // no tile { dword color = brush->color & 0xffff40ff; R9_DrawLine( fV2(newclip.p1.x,newclip.p1.y), fV2(newclip.p2.x-1,newclip.p1.y), color ); R9_DrawLine( fV2(newclip.p2.x-1,newclip.p1.y), fV2(newclip.p2.x-1,newclip.p2.y-1), color ); R9_DrawLine( fV2(newclip.p2.x-1,newclip.p2.y-1), fV2(newclip.p1.x,newclip.p2.y-1), color ); R9_DrawLine( fV2(newclip.p1.x,newclip.p2.y-1), fV2(newclip.p1.x,newclip.p1.y), color ); R9_DrawLine( fV2(newclip.p1.x,newclip.p1.y), fV2(newclip.p2.x-1,newclip.p2.y-1), color ); R9_DrawLine( fV2(newclip.p2.x-1,newclip.p1.y), fV2(newclip.p1.x,newclip.p2.y-1), color ); R9_SetClipping(oldclip); return; } int cx = (brush->size.x+mw-1) / mw; int cy = (brush->size.y+mh-1) / mh; int xt=x; for(int i=0;i<cy;i++) { x = xt; for(int j=0;j<cx;j++) { DrawTile( idx, x, y, map, brush->color, brush->flip, brush->frame, brush->shader, zoom*ms ); x+=(int)(zoom*mw); } y+=(int)(zoom*mh); } if(m_brushrect) { dword color = 0xa04040ff; R9_DrawLine( fV2(newclip.p1.x,newclip.p1.y), fV2(newclip.p2.x-1,newclip.p1.y), color ); R9_DrawLine( fV2(newclip.p2.x-1,newclip.p1.y), fV2(newclip.p2.x-1,newclip.p2.y-1), color ); R9_DrawLine( fV2(newclip.p2.x-1,newclip.p2.y-1), fV2(newclip.p1.x,newclip.p2.y-1), color ); R9_DrawLine( fV2(newclip.p1.x,newclip.p2.y-1), fV2(newclip.p1.x,newclip.p1.y), color ); } R9_SetClipping(oldclip); }
#define MAX_FPS 30 #define WINDOW_TITLE "Disquiet" //!----------------------------------------------------------------------------- //! FUNCTION INTERFACES //!----------------------------------------------------------------------------- int treatEvents(sf::Window &window); unsigned long getDelta(); int update(unsigned long delta_time); void renderTo(sf::RenderTarget &target); //!----------------------------------------------------------------------------- //!----------------------------------------------------------------------------- //! GLOBAL VARIABLES //!----------------------------------------------------------------------------- LevelNode n1(fV2(120, 30)), n2(fV2(70, 200)), n3(fV2(350, 120)); Player p(&n1); //!----------------------------------------------------------------------------- //! MAIN //!----------------------------------------------------------------------------- int main(int argc, char** argv, char** envp) { // open window sf::RenderWindow window(sf::VideoMode(WINDOW_W, WINDOW_H), WINDOW_TITLE); window.setFramerateLimit(MAX_FPS); // create game objects n1.neighbours[0] = &n2; n1.neighbours[1] = &n3; n2.neighbours[2] = &n3;