The useless warrior (it is said that no one can last for 37 seconds)

Welcome to the Program Courtyard

Good-for-nothing warrior

How to play: Click the left and right buttons at the bottom of the screen to kill monsters. The monsters will attack from the left and right directions at the same time. Click the buttons quickly to kill the monsters. See how many seconds you can hold on.
It is said that I haven’t been able to hold on for 37 seconds yet, so go and kill the monsters and challenge^^.

Start the gameicon-default.png?t=N7T8https://www.ormcc.com/play/gameStart/194

html

<canvas id="gameCanvas" width="480" height="800"></canvas>

css

h2.title{
  display: block;
  margin: 50px auto;
  text-align: center;
}

js

var heroLayer = null;
var monsterLayer = null;
var explosionLayer = null;

var isFirstPlay = true; //Whether this is the first time to play this game
var prepareMonsterArr = [];//Array of upcoming monsters
var monsterArray = [];//Monsters that have appeared
var monsterShadowArray = [];//Shadows of all monsters that have appeared
var delArray = [];//The monster that was hacked to death is ready to be deleted
var touchLocationX = null;//X coordinate position of touch
var positionY = null;//Y coordinates of monster and hero
var bgSprite = null; //Background image
var shadowBatchNode = null;
var heroSprite = null; //Protagonist
var heroShadow = null;//The shadow of the protagonist
var targetX = 0;//X coordinate where the monster wants to reach
var durationLabel = null;//time label
var duration = 0;//How long the game lasts
var hpMax = 3;
var hpLabel = null;//Health volume label
var hpProgress = null;
var hp = 0;//blood volume
var hpNode = null;
var scoreLabel = null;//score label
var score = 0;//score
var isGameOver = false;//Is the game over?
var coolDowan = 0;//cooling time
var skillProgress = null;//Skill cooling progress bar

var isSkillPeriod = false; //Whether it is during the release of skills
var attackDir = 0; //The direction of the hero's attack, 0 means no more attacking, 1 means attacking to the left, 2 means attacking to the right.
var response = null;
var responsefailedLabel;//The content displayed when the network request fails
var isSharelayer = false;//Whether it is a sharing interface

var BgLayer = cc.Layer.extend({
    ctor:function(){
        this._super();
        bgSprite = cc.Sprite.create(res.bg1_jpg);
        bgSprite.setPosition(cc.p(240,400));
        bgSprite.setScale(1.6);
        this.addChild(bgSprite);
    }
});
/**
 * Boot process during the first game
 */
guidePrecess:function(){
    var noticeNode = cc.Node.create();
    var noticeSprite = cc.Sprite.create(res.notice_board_png);
    noticeSprite.setPosition(cc.p(240,840));//The prompt window is initialized at the top of the screen
    noticeNode.addChild(noticeSprite);

    noticeSprite.runAction(cc.Sequence.create(cc.MoveTo.create(0.3,cc.p(240,400)),
        cc.MoveTo.create(0.05,cc.p(240,420)),
        cc.MoveTo.create(0.05,cc.p(240,400))));//Move the prompt window to the middle of the screen

    //Add a Lich Elf
    var lichSprite = cc.Sprite.create(res.monster6_1_png);
    lichSprite.setPosition(cc.p(-lichSprite.getContentSize().width/2,450));//The initial position is outside the middle left of the screen
    noticeNode.addChild(lichSprite);
    this.addChild(noticeNode,3);

    var lichMoveTo = cc.moveTo(0.2,cc.p(lichSprite.getContentSize().width/2,450));
    var lichAnim = cc.Animation.create();
    for(var i = 1; i <= 4; i + + ){
        var frame = "/default/game/fcys/res/monster6_" + i + ".png";
        lichAnim.addSpriteFrameWithFile(frame);
    }
    lichAnim.setDelayPerUnit(0.15);
    lichSprite.runAction(cc.RepeatForever.create(cc.Animate.create(lichAnim)));//Play frame animation
    lichSprite.runAction(cc.Sequence.create(cc.DelayTime.create(0.4),
    lichMoveTo,cc.CallFunc.create(noticeCallback)));//Move to the left side of the screen and call back the noticeCallback function
}
//Regular update function to update the game persistence time, cooling time, and monsters ready to appear
updateDuration:function(dt){
    duration + = dt;
    coolDowan + = dt;
    if(coolDowan <= 30){
        //var to = cc.ProgressTo.create(0.01, (30 - coolDowan) / 30 * 100);
        //skillProgress.runAction(to);
    }else{
        coolDowan = 30;
    }

    var tempArr = [];
    for(var i = 0; i < prepareMonsterArr.length; i + + ){
        if(prepareMonsterArr[i].time <= duration){
            tempArr.push(prepareMonsterArr[i]);//Add the attributes of the upcoming monster to the tempArr array
        }else{
            break;
        }
    }

    for(var i = 0; i < tempArr.length; i + + ){
        this.createMonster(tempArr[i]);//Create the upcoming monster
    }
    deleteChildFromArray(prepareMonsterArr,tempArr);//Delete the created monster from prepareMonsterArr
    if(duration >= 88){
        gameOver();
    }
}
/**
 *Create monsters
 * @param monsterData monster attributes
 */
createMonster:function(prepareMonsterData){
    var monsterSprite = cc.Sprite.create("/default/game/fcys/res/monster" +
    prepareMonsterData.type + "_1.png");//Select the corresponding image according to the type
    monsterSprite.setScale(1.0/0.8);
    monsterSprite.setAnchorPoint(cc.p(0.5, 0));
    var dir = Math.random();
    if(Math.random() < prepareMonsterData.direction){
        targetX = 180;
        monsterSprite.setPosition(cc.p(-30,positionY - 55));
    }else{
        targetX = 300;
        monsterSprite.setPosition(cc.p(510,positionY - 55));
        monsterSprite.setFlippedX(true);//The monster image that appears on the right is displayed
    }
    /*if(prepareMonsterData.direction == 0){//If the direction in which the monster appears is random, generate a random number of 1 or 2,
    1 means left, 2 means right
        prepareMonsterData.direction = Math.floor(Math.random() * 10 % 2 + 1);
    }
    if(prepareMonsterData.direction == 1){//Monster appearing from the left
        targetX = 180;
        monsterSprite.setPosition(cc.p(-30,positionY - 65));
    }else if(prepareMonsterData.direction == 2){//Monster appearing from the right
        targetX = 300;
        monsterSprite.setPosition(cc.p(510,positionY - 65));
        monsterSprite.setFlippedX(true);//The monster image that appears on the right is displayed
    }*/


    monsterArray.push(monsterSprite);//The monster that has appeared is added to the monsterArray array

    monsterLayer.getChildByTag(prepareMonsterData.type).addChild(monsterSprite,1,
    prepareMonsterData.type);//Add monsters to Layer, TAG is the type of monster
    //Different monster types initialize different blood volumes
    if(prepareMonsterData.type == 1 || prepareMonsterData.type ==3
        || prepareMonsterData.type == 4 || prepareMonsterData.type == 5){
        monsterSprite.setUserData(monsterUserData(1,1));
    }else{
        monsterSprite.setUserData(monsterUserData(2,2));
    }
    var walkLine = createMonsterWalkLine(prepareMonsterData.type,prepareMonsterData.rampageProb);

    //Set the monster's walking route and Action according to the monster type
    if(prepareMonsterData.type ==1 || prepareMonsterData.type == 2
        || prepareMonsterData.type == 5 || prepareMonsterData.type == 6){
        monsterSprite.runAction(createMonsterWalkAnimate(prepareMonsterData.type));
        monsterSprite.runAction(cc.Sequence.create(walkLine, cc.CallFunc.create(monsterAttackCallback)));
    }else if(prepareMonsterData.type ==3 || prepareMonsterData.type ==4){
        monsterSprite.runAction(walkLine);
    }
}

Source codeicon-default.png?t=N7T8https://www.ormcc.com/

If you need the source code, please follow and add friends ^ ^

Reprint: Welcome to this site, please indicate the source of the article when reprinting https://ormcc.com/