| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | #include "..\e2daction.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-24 00:58:16 +08:00
										 |  |  | #include "..\e2dnode.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-28 20:06:27 +08:00
										 |  |  | e2d::JumpBy::JumpBy(float duration, const Vector2 & vec, float height, int jumps) | 
					
						
							| 
									
										
										
										
											2018-05-22 22:29:42 +08:00
										 |  |  | 	: FiniteTimeAction(duration) | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 	, _deltaPos(vec) | 
					
						
							|  |  |  | 	, _height(height) | 
					
						
							|  |  |  | 	, _jumps(jumps) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::JumpBy * e2d::JumpBy::clone() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-06 12:59:32 +08:00
										 |  |  | 	return new (e2d::autorelease) JumpBy(_duration, _deltaPos, _height, _jumps); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::JumpBy * e2d::JumpBy::reverse() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-06 12:59:32 +08:00
										 |  |  | 	return new (e2d::autorelease) JumpBy(_duration, -_deltaPos, _height, _jumps); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::JumpBy::_init() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-22 22:29:42 +08:00
										 |  |  | 	FiniteTimeAction::_init(); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (_target) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		_prevPos = _startPos = _target->getPos(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::JumpBy::_update() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-22 22:29:42 +08:00
										 |  |  | 	FiniteTimeAction::_update(); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (_target) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-28 20:06:27 +08:00
										 |  |  | 		float frac = fmod(_delta * _jumps, 1.f); | 
					
						
							|  |  |  | 		float x = _deltaPos.x * _delta; | 
					
						
							|  |  |  | 		float y = _height * 4 * frac * (1 - frac); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 		y += _deltaPos.y * _delta; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Point currentPos = _target->getPos(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-02 23:13:49 +08:00
										 |  |  | 		Vector2 diff = currentPos - _prevPos; | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 		_startPos = diff + _startPos; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-02 23:13:49 +08:00
										 |  |  | 		Point newPos = _startPos + Vector2(x, y); | 
					
						
							| 
									
										
										
										
											2018-05-10 14:03:54 +08:00
										 |  |  | 		_target->setPos(newPos); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		_prevPos = newPos; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |