| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | #include "..\e2daction.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-24 00:58:16 +08:00
										 |  |  | #include "..\e2dnode.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-02 23:13:49 +08:00
										 |  |  | e2d::MoveBy::MoveBy(double duration, Vector2 vector) | 
					
						
							| 
									
										
										
										
											2018-05-22 22:29:42 +08:00
										 |  |  | 	: FiniteTimeAction(duration) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	_deltaPos = vector; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::MoveBy::_init() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-22 22:29:42 +08:00
										 |  |  | 	FiniteTimeAction::_init(); | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | 	if (_target) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-29 22:12:01 +08:00
										 |  |  | 		_prevPos = _startPos = _target->getPos(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::MoveBy::_update() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-22 22:29:42 +08:00
										 |  |  | 	FiniteTimeAction::_update(); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  | 	if (_target) | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-29 22:12:01 +08:00
										 |  |  | 		Point currentPos = _target->getPos(); | 
					
						
							| 
									
										
										
										
											2018-07-02 23:13:49 +08:00
										 |  |  | 		Vector2 diff = currentPos - _prevPos; | 
					
						
							| 
									
										
										
										
											2018-05-29 22:12:01 +08:00
										 |  |  | 		_startPos = _startPos + diff; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Point newPos = _startPos + (_deltaPos * _delta); | 
					
						
							|  |  |  | 		_target->setPos(newPos); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		_prevPos = newPos; | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::MoveBy * e2d::MoveBy::clone() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-06 00:47:50 +08:00
										 |  |  | 	return new (std::nothrow) MoveBy(_duration, _deltaPos); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::MoveBy * e2d::MoveBy::reverse() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-06 00:47:50 +08:00
										 |  |  | 	return new (std::nothrow) MoveBy(_duration, -_deltaPos); | 
					
						
							| 
									
										
										
										
											2018-05-08 20:03:29 +08:00
										 |  |  | } |