Game Development Reference
In-Depth Information
if (_keyRightPressed) {
s horizontal movement is applied as
a force (scaled by the amount of time that has passed) to the
In readKeyInput , the player
s physics object.
protected function playerJump():void {
if (_player.isJumping || _player.isFalling) return;
_player.isJumping = true;
var jump:Vector3D = _config.playerJump.clone();
When the user presses the jump key, it triggers the playerJump
method. If the player is already jumping or is falling through the
air, the jump command is ignored. The jump is applied directly
one time, rather than being scaled over time; gravity will, even-
tually, overcome the force of the jump.
protected function applyForces():void {
var gravity:Vector3D = _config.gravity.clone();
if (_player.isJumping) {
_player.netForce.x *= _config.drag;
} else {
_player.netForce.x *= _config.friction;
protected function movePlayer():void {
_player.tempX = _player.x + _player.netForce.x;
_player.tempY = _player.y + _player.netForce.y;
Next, the forces of gravity, drag, and friction are all applied to
the player
s position is updated to
its tempX and tempY properties based on the current amount of
force being applied. Before checking for collisions, however, we
need to update the positions of all enemies in the game.
s force object. Then the player
protected function moveEnemies():void {
for each (var enemy:IEnemy in _enemies) {
var motion:Vector3D = enemy.motion.clone();
enemy.tempX = enemy.x + motion.x;
enemy.tempY = enemy.y + motion.y;
Search Nedrilad ::

Custom Search