From 9b1fb64e1640eb36c485102b499653ce48830e1b Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 25 Jul 2012 13:37:04 +0100 Subject: [PATCH] WIND tool --- src/game/GameController.cpp | 2 +- src/game/GameModel.cpp | 1 + src/game/Tool.cpp | 48 +++++++++++++++++++++++++++++++++---- src/game/Tool.h | 25 +++++++++++++------ 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 72c38c0e7..8fc1acaea 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -295,7 +295,7 @@ void GameController::DrawPoints(int toolSelection, queue & pointQueu pointQueue.pop(); if(!first) { - activeTool->DrawLine(sim, cBrush, fPoint, sPoint); + activeTool->DrawLine(sim, cBrush, sPoint, fPoint, true); } else { diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index f3ce1bc01..536ca4249 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -93,6 +93,7 @@ GameModel::GameModel(): //Add special sign and prop tools menuList[SC_TOOL]->AddTool(new SignTool()); menuList[SC_TOOL]->AddTool(new PropertyTool()); + menuList[SC_TOOL]->AddTool(new WindTool(0, "WIND", "Create air movement", 64, 64, 64)); //Build menu for simtools for(int i = 0; i < sim->tools.size(); i++) diff --git a/src/game/Tool.cpp b/src/game/Tool.cpp index 977896b5d..352587627 100644 --- a/src/game/Tool.cpp +++ b/src/game/Tool.cpp @@ -37,7 +37,7 @@ void Tool::Click(Simulation * sim, Brush * brush, ui::Point position) { } void Tool::Draw(Simulation * sim, Brush * brush, ui::Point position) { sim->ToolBrush(position.X, position.Y, toolID, brush); } -void Tool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { +void Tool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging) { sim->ToolLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush); } void Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { @@ -53,7 +53,7 @@ ElementTool::~ElementTool() {} void ElementTool::Draw(Simulation * sim, Brush * brush, ui::Point position){ sim->CreateParts(position.X, position.Y, toolID, brush); } -void ElementTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { +void ElementTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging) { sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, toolID, brush); } void ElementTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { @@ -72,7 +72,7 @@ WallTool::~WallTool() {} void WallTool::Draw(Simulation * sim, Brush * brush, ui::Point position){ sim->CreateWalls(position.X, position.Y, 1, 1, toolID, 0, brush); } -void WallTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { +void WallTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging) { sim->CreateWallLine(position1.X, position1.Y, position2.X, position2.Y, 1, 1, toolID, 0, brush); } void WallTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { @@ -91,7 +91,7 @@ GolTool::~GolTool() {} void GolTool::Draw(Simulation * sim, Brush * brush, ui::Point position){ sim->CreateParts(position.X, position.Y, PT_LIFE|(toolID<<8), brush); } -void GolTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { +void GolTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging) { sim->CreateLine(position1.X, position1.Y, position2.X, position2.Y, PT_LIFE|(toolID<<8), brush); } void GolTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { @@ -101,6 +101,46 @@ void GolTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) { sim->FloodParts(position.X, position.Y, PT_LIFE|(toolID<<8), -1, -1, 0); } +WindTool::WindTool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int)): + Tool(id, name, description, r, g, b, textureGen) +{ +} +WindTool::~WindTool() {} +void WindTool::Draw(Simulation * sim, Brush * brush, ui::Point position) +{ + +} +void WindTool::DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging) +{ + int radiusX, radiusY, sizeX, sizeY; + + float strength = dragging?0.01f:0.002f; + + radiusX = brush->GetRadius().X; + radiusY = brush->GetRadius().Y; + + sizeX = brush->GetSize().X; + sizeY = brush->GetSize().Y; + + unsigned char *bitmap = brush->GetBitmap(); + + for(int y = 0; y < sizeY; y++) + { + for(int x = 0; x < sizeX; x++) + { + if(bitmap[(y*sizeX)+x] && (position1.X+(x-radiusX) >= 0 && position1.Y+(y-radiusY) >= 0 && position1.X+(x-radiusX) < XRES && position1.Y+(y-radiusY) < YRES)) + { + sim->vx[(position1.Y+(y-radiusY))/CELL][(position1.X+(x-radiusX))/CELL] += (position2.X-position1.X)*strength; + sim->vy[(position1.Y+(y-radiusY))/CELL][(position1.X+(x-radiusX))/CELL] += (position2.Y-position1.Y)*strength; + } + } + } +} +void WindTool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) {} + +void WindTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {} + + void Element_LIGH_Tool::Draw(Simulation * sim, Brush * brush, ui::Point position) { int p = sim->create_part(-2, position.X, position.Y, toolID); diff --git a/src/game/Tool.h b/src/game/Tool.h index c7b7f587b..763968f37 100644 --- a/src/game/Tool.h +++ b/src/game/Tool.h @@ -33,7 +33,7 @@ public: virtual ~Tool(); virtual void Click(Simulation * sim, Brush * brush, ui::Point position); virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); - virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false); virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position); int colRed, colBlue, colGreen; @@ -50,7 +50,7 @@ public: virtual ~SignTool() {} virtual void Click(Simulation * sim, Brush * brush, ui::Point position); virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) { } - virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { } + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false) { } virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { } virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { } }; @@ -65,7 +65,7 @@ public: virtual ~PropertyTool() {} virtual void Click(Simulation * sim, Brush * brush, ui::Point position); virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) {}; - virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { } + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false) { } virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { } virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { } }; @@ -80,7 +80,7 @@ public: virtual ~Element_LIGH_Tool() {} virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); virtual void Click(Simulation * sim, Brush * brush, ui::Point position) { } - virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { } + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false) { } virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { } virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position) { } }; @@ -91,7 +91,7 @@ public: ElementTool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int) = NULL); virtual ~ElementTool(); virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); - virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false); virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position); }; @@ -102,7 +102,7 @@ public: WallTool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int) = NULL); virtual ~WallTool(); virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); - virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false); virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position); }; @@ -113,7 +113,18 @@ public: GolTool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int) = NULL); virtual ~GolTool(); virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); - virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false); + virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); + virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position); +}; + +class WindTool: public Tool +{ +public: + WindTool(int id, string name, string description, int r, int g, int b, VideoBuffer * (*textureGen)(int, int, int) = NULL); + virtual ~WindTool(); + virtual void Draw(Simulation * sim, Brush * brush, ui::Point position); + virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false); virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2); virtual void DrawFill(Simulation * sim, Brush * brush, ui::Point position); };