*   >> Lectura Educación Artículos >> science >> programación

Hacer un clon de Space Invaders con PushButton - Bullets

gún daño. Por ahora la escucha de una colisión y elimina la entidad a la que pertenece desde el juego

 public class DamageOnContactConponent extiende EntityComponent {daños var pública:. Int = 0; función pública DamageOnContactConponent () {super (); } Función protegida anulación onAdd (): void {super.onAdd (); owner.eventDispatcher.addEventListener (CollisionEvent.COLLISION_EVENT, OnCollision); } Protegida anulación función onRemove (): void {super.onRemove (); owner.eventDispatcher.removeEventListener (CollisionEvent.

COLLISION_EVENT, OnCollision); } Function OnCollision privada (event: CollisionEvent): void {owner.destroy (); }

El componente DestroyIfOffScreenComponent comprueba la posición de la entidad cada cuadro y elimina la entidad a la que pertenece desde el juego si se ha movido fuera de la pantalla.

 public class DestroyIfOffScreenComponent extiende TickedComponent {[TypeHint (tipo = "flash.geom.

Point")] positionReference public var: PropertyReference; screenWidth public var: int = 480; screenHeight public var: int = 384; sideBuffer public var: int = 32; función DestroyIfOffScreenComponent público () {super (); } Function public override onTick (tickrate: Number): void {super.onTick (tickrate); posición var: Point = owner.getProperty (positionReference); si (posición == null) return; si (position.x> screenWidth + sideBuffer || position.x screenHeight + sideBuffer || position.y

La función PlayerControllerComponent onTick se ha modificado para que pueda disparar las balas.

En primer lugar tenemos la cuenta atrás de un temporizador denominado timeToNextShot que es incrementado cada vez que una bala se dispara

 función de anulación pública onTick (tickrate: Number):. void {//... timeToNextShot - = tickrate; timeToNextShot = timeToNextShot 

Si la barra de espacio ha sido presionado y el timeToNextShot es igual a cero que restablecer el contador timeToNextShot y creamos una nueva instancia de la plantilla PlayerBullet. La posición de las balas y la velocidad se establecen para que aparezca en la pantalla en la posición de los jugadores.


 si (InputManager.isKeyDown ( InputKey.SPACE) && timeToNextShot == 0) {timeToNextShot = timeBetweenShots; bala var: IEntity = TemplateManager.instance.instantiateEntity (bulletEntityName), si (bala = null) {var espacial: Box2DSpatialComponent = bullet.lookupComponentByType (Box2DSpatialComponent) como Box2DSpatialComponent ; spatial.position = new Point (position.x, pos

Page   <<  [1] [2] [3] >>
Copyright © 2008 - 2016 Lectura Educación Artículos,https://lectura.nmjjxx.com All rights reserved.