Загрузка страницы

Mover Símbolo con Teclas y Colisiones

Descarga Recursos(Enlace actualizado)
https://drive.google.com/file/d/0B4wQ-bfpZOVVMHJKUm91MmVob00/view?usp=sharing&resourcekey=0-vsx17Eq2l9ft2MpnJ0zUlQ

Codigo:

import flash.events.*;
import flash.ui.Keyboard;

//posicion inicial del carro
icarro.x=stage.stageWidth/2;
icarro.y=380;
//variables para teclas cuando se preionar o se sueltan
var moverderecha:Boolean=false;
var moverizquierda:Boolean=false;
var moverarriba:Boolean=false;
var moverabajo:Boolean=false;
//variable de la velocidad al presionar las teclas
var velocidad:Number=5;
//crear las eventlistener con las funciones
stage.addEventListener(Event.ENTER_FRAME, mover);
stage.addEventListener(KeyboardEvent.KEY_DOWN, presionar);
stage.addEventListener(KeyboardEvent.KEY_UP, soltar);

//crear las funciones
function mover(event:Event):void{
//verificar colisiona el carro
if(icarro.hitTestObject(ihit1)){
icarro.x=stage.stageWidth/2;
icarro.y=380;
}

if(icarro.hitTestObject(ihit2)){
icarro.x=stage.stageWidth/2;
icarro.y=380;
}

if(icarro.hitTestObject(ihit3)){
icarro.x=stage.stageWidth/2;
icarro.y=380;
}
if(icarro.hitTestObject(ihit4)){
icarro.x=stage.stageWidth/2;
icarro.y=380;
}
if(icarro.hitTestObject(ihit5)){
icarro.x=stage.stageWidth/2;
icarro.y=380;
}
if(icarro.hitTestObject(ihit6)){
icarro.x=stage.stageWidth/2;
icarro.y=380;
}
//verificando las teclas para molvimiento
if(moverderecha==true){
icarro.x+=velocidad;
}
if(moverizquierda==true){
icarro.x-=velocidad;
}
if(moverabajo==true){
icarro.y+=velocidad;
}
if(moverarriba==true){
icarro.y-=velocidad;
}
}

function presionar(event:KeyboardEvent){
if(event.keyCode==39){
moverderecha=true;
}
if(event.keyCode==37){
moverizquierda=true;
}
if(event.keyCode==38){
moverarriba=true;
}
if(event.keyCode==40){
moverabajo=true;
}
}

function soltar(event:KeyboardEvent):void{
if(event.keyCode==39){
moverderecha=false;
}
if(event.keyCode==37){
moverizquierda=false;
}
if(event.keyCode==38){
moverarriba=false;
}
if(event.keyCode==40){
moverabajo=false;
}
}

Видео Mover Símbolo con Teclas y Colisiones канала rolandostudios
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
9 мая 2017 г. 12:40:42
00:28:48
Яндекс.Метрика