console
LSystem.screen(0.6);
function doScroll() {if(window.pageYOffset === 0)window.scrollTo(0, 1);}
window.onorientationchange = function(){setTimeout(doScroll, 100);};
window.onresize = function(){setTimeout(doScroll, 100);};
window.onload = function() {
setTimeout(doScroll, 100);
init(40,"mylegend",800,450,main,LEvent.INIT);
};
var loadingLayer;
var baseLayer;
var backLayer;
var charaLayer;
var imglist = {};
var imgData = new Array(
{name:"player_stand",path:"http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/stand.png"},
{name:"player_move",path:"http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/move.png"},
{name:"player_run",path:"http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/run.png"},
{name:"player_jump",path:"http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/jump.png"},
{name:"player_attack",path:"http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/attack.png"},
{name:"player_big_attack",path:"http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/big_attack.png"},
{name:"player_jump_attack",path:"http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/jump_attack.png"},
{name:"player_hit",path:"http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/hit.png"},
{name:"player_skill",path:"http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/skill.png"},
{name:"player_big_skill",path:"http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/big_skill.png"},
{name:"back",path:"http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/back.png"}
);
var hero = null;
var keylock = false;
var KEY = {LEFT:65,RIGHT:68,UP:87,DOWN:83,ATTACK:74,JUMP:75};
var ACTION = {STAND:0,MOVE:1,RUN:2,JUMP:3,ATTACK:4,BIG_ATTACK:5,JUMP_ATTACK:6,HIT:7,SKILL:8,BIG_SKILL:9};
var DIRECTION = {RIGHT:"right",LEFT:"left"};
var MOVE_STEP = 6;
var keyCtrl = new Array();
function main(){
LGlobal.setDebug(true);
loadingLayer = new LoadingSample3();
addChild(loadingLayer);
LLoadManage.load(
imgData,
function(progress){
loadingLayer.setProgress(progress);
},
gameInit
);
}
function gameInit(result){
imglist = result;
removeChild(loadingLayer);
loadingLayer = null;
baseLayer = new LSprite();
addChild(baseLayer);
backLayer = new LSprite();
baseLayer.addChild(backLayer);
var background = new LBitmap(new LBitmapData(imglist["back"],0,0,LGlobal.width,LGlobal.height));
backLayer.addChild(background);
charaLayer = new LSprite();
baseLayer.addChild(charaLayer);
addHero();
baseLayer.addEventListener(LEvent.ENTER_FRAME,onframe);
LEvent.addEventListener(LGlobal.window,LKeyboardEvent.KEY_DOWN,onkeydown);
LEvent.addEventListener(LGlobal.window,LKeyboardEvent.KEY_UP,onkeyup);
}
function addHero(){
var heroData = CharacterList.huangzhong();
hero = new Player(heroData[0],heroData[1],heroData[2]);
hero.x = 200;
hero.y = 250;
charaLayer.addChild(hero);
}
function onframe(){
var key = null;
for(key in charaLayer.childList){
charaLayer.childList[key].onframe();
}
}
var lefttime = 0, righttime = 0;
var keyList = [{keyCode:0,time:0},{keyCode:0,time:0},{keyCode:0,time:0}];
function onkeydown(e){
if(keylock || keyCtrl[e.keyCode])return;
var keyThis = {keyCode:e.keyCode,time:(new Date()).getTime()};
var keyLast01 = keyList[0];
var keyLast02 = keyList[1];
keyCtrl[e.keyCode] = true;
keyList.unshift(keyThis);
keyList.pop();
switch(e.keyCode){
case KEY.LEFT:
if(keyLast01.keyCode == KEY.LEFT && keyThis.time - keyLast01.time < 200){
hero.setAction(ACTION.RUN,DIRECTION.LEFT);
}else{
hero.setAction(ACTION.MOVE,DIRECTION.LEFT);
}
break;
case KEY.RIGHT:
if(keyLast01.keyCode == KEY.RIGHT && keyThis.time - keyLast01.time < 200){
hero.setAction(ACTION.RUN,DIRECTION.RIGHT);
}else{
hero.setAction(ACTION.MOVE,DIRECTION.RIGHT);
}
break;
case KEY.UP:
hero.setAction(ACTION.MOVE,hero.direction);
break;
case KEY.DOWN:
hero.setAction(ACTION.MOVE,hero.direction);
break;
case KEY.ATTACK:
if(keyLast01.keyCode == KEY.ATTACK && keyLast02.keyCode == KEY.ATTACK && keyThis.time - keyLast02.time < 1000){
keyList = [{keyCode:0,time:0},{keyCode:0,time:0},{keyCode:0,time:0}];
keylock = true;
hero.setAction(ACTION.BIG_ATTACK,hero.direction);
}else if(keyLast01.keyCode == KEY.JUMP && keyThis.time - keyLast01.time < 50){
keylock = true;
hero.setAction(ACTION.BIG_SKILL,hero.direction);
}else if(hero.action == ACTION.JUMP){
hero.setAction(ACTION.JUMP_ATTACK,hero.direction);
}else if(keyLast01.keyCode == KEY.UP && keyLast02.keyCode == KEY.DOWN && keyThis.time - keyLast02.time < 300){
keylock = true;
hero.setAction(ACTION.SKILL,hero.direction);
}else{
setTimeout("keylock = true;",50);
hero.setAction(ACTION.ATTACK,hero.direction);
}
break;
case KEY.JUMP:
if(keyLast01.keyCode == KEY.ATTACK && keyThis.time - keyLast01.time < 50){
keylock = true;
hero.setAction(ACTION.BIG_SKILL,hero.direction);
}else if(keyCtrl[KEY.DOWN]){
hero.setAction(ACTION.HIT,hero.direction);
}else{
hero.setAction(ACTION.JUMP,hero.direction);
}
break;
}
}
function onkeyup(e){
keyCtrl[e.keyCode] = false;
if(hero.action == ACTION.MOVE || hero.action == ACTION.RUN)
hero.setAction(ACTION.STAND,hero.direction);
}
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/lufylegend-1.5.2.js"></script>
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/lufylegend-1.5.2.js"></script>
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/Character.js"></script>
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/CharacterList.js"></script>
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/lufylegend-1.5.2.min.js"></script>
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/41/bfmp6hpg/Player.js"></script>
</head>
<body>
<h2>
该应用非原创,作者网站请猛戳
<a href="http://blog.csdn.net/lufy_Legend">这里</a>
</h2>
<div id="mylegend">loading……</div>