X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=blobdiff_plain;f=src%2FentityCreator.cpp;h=28d6979f182830b692a2b449d6a8e4ef616b5144;hb=9ae1c0798cff2d1ed816bccb0723bd5a4ca97194;hp=0247f04d6b95079e6d9b8dac464adb698d72e276;hpb=617dcc71d9a71663f63fb56ffac2505b45bf91b9;p=physics.git diff --git a/src/entityCreator.cpp b/src/entityCreator.cpp index 0247f04..28d6979 100644 --- a/src/entityCreator.cpp +++ b/src/entityCreator.cpp @@ -1,97 +1,144 @@ +/* + * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com. + * + * 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 . + */ + #include "entityCreator.h" #include #include "entityManager.h" +#include "input/inputManager.h" + #include "Entities/Ball.h" #include "graphics/colors.h" + /// ***** Private Variables ***** typedef std::queue queBall; -queBall Balls; + +queBall startBalls; +queBall mouseBalls; + +/// ***** Private Method Headers ***** + +Ball* addBall(const Vector2& pos, + float radius, + const float* color, + queBall& que); + +void removeBall(queBall& que); +void removeAllBalls(queBall& que); /// ***** Initializers/Cleaners ***** void creator::init() { Ball* ball; + float startMass = 5; - ball = new Ball(Vector2(50, 50), 20, cWhite); + ball = addBall(Vector2(50, 50), 20, cWhite, startBalls); + ball->mass = startMass; - ball->applyImpulse(Vector2(0.25,0.05)), - Balls.push(ball); - manager::add(ball); + ball = addBall(Vector2(150, 50), 20, cGrey, startBalls); + ball->mass = startMass; - ball = new Ball(Vector2(100, 50), 20, cBlack); + ball = addBall(Vector2(50, 100), 20, cRed, startBalls); + ball->mass = startMass; - ball->applyImpulse(Vector2(-0.15,-0.05)), - Balls.push(ball); - manager::add(ball); + ball = addBall(Vector2(100, 100), 20, cGreen, startBalls); + ball->mass = startMass; - ball = new Ball(Vector2(150, 50), 20, cGrey); + ball = addBall(Vector2(150, 100), 20, cBlue, startBalls); + ball->mass = startMass; - ball->applyImpulse(Vector2(0.25,0.15)), - Balls.push(ball); - manager::add(ball); + ball = addBall(Vector2(50, 150), 20, cYellow, startBalls); + ball->mass = startMass; - ball = new Ball(Vector2(50, 100), 20, cRed); + ball = addBall(Vector2(100, 150), 20, cMagenta, startBalls); + ball->mass = startMass; - ball->applyImpulse(Vector2(0.35,-0.15)), - Balls.push(ball); - manager::add(ball); + ball = addBall(Vector2(150, 150), 20, cCyan, startBalls); + ball->mass = startMass; - ball = new Ball(Vector2(100, 100), 20, cGreen); + for( int i = 0; i<100; i++) + { + addBall(Vector2(200+i*2, 200+i*2), 10, cCyan); + } +} +void creator::clean() +{ + removeAllBalls(startBalls); + removeAllBalls(mouseBalls); +} - ball->applyImpulse(Vector2(-0.15,0.55)), - Balls.push(ball); - manager::add(ball); +/// ***** Public Methods ***** - ball = new Ball(Vector2(150, 100), 20, cBlue); +void creator::addBall(const Vector2& pos, float radius, const float* color) +{ + addBall(pos, radius, color, mouseBalls); +} +void creator::removeBall() +{ + removeBall(mouseBalls); +} +void creator::removeAllBalls() +{ + removeAllBalls(mouseBalls); +} - ball->applyImpulse(Vector2(0.25,0.15)), - Balls.push(ball); - manager::add(ball); +void creator::handleInput() +{ + if(input::mouseLeft()) + addBall(input::mousePosition(), 10, cCyan); - ball = new Ball(Vector2(50, 150), 20, cYellow); + if(input::mouseRight() && ! mouseBalls.empty()) + removeBall(); +} - ball->applyImpulse(Vector2(0.25,-0.05)), - Balls.push(ball); - manager::add(ball); +/// ***** Private Methods ***** - ball = new Ball(Vector2(100, 150), 20, cMagenta); +Ball* addBall(const Vector2& pos, + float radius, + const float* color, + queBall& que) +{ + Ball* ball = new Ball(pos, radius, color); - ball->applyImpulse(Vector2(-0.15,-0.05)), - Balls.push(ball); + que.push(ball); manager::add(ball); - ball = new Ball(Vector2(150, 150), 20, cCyan); - - ball->applyImpulse(Vector2(-0.15,0.05)), - Balls.push(ball); - manager::add(ball); + return ball; } -void creator::clean() + +void removeBall(queBall& que) { - removeAllBalls(); -} + Ball* ball = que.front(); -/// ***** Public Methods ***** + manager::remove(ball); + que.pop(); -void creator::addBall() -{ - //TODO + delete ball; } -void creator::removeBall() -{ - //TODO -} -void creator::removeAllBalls() +void removeAllBalls(queBall& que) { - while(! Balls.empty() ) + while(! que.empty() ) { - Ball* ball = Balls.front(); - Balls.pop(); + Ball* ball = que.front(); + que.pop(); manager::remove(ball); delete ball;