保卫战小游戏

欢迎来到程序小院

保卫战

玩法:当鬼子进入射击范围内点击鼠标左键射击,不要让鬼子越过炮台哦,快去杀鬼子去吧^^。

开始游戏icon-default.png?t=N7T8https://www.ormcc.com/play/gameStart/249

html

<div style="position: relative;" id="gameDiv"></div>

css

body {
  text-align: center;
  background: #fff;
  padding: 0;
  border: 0;
  margin: 0;
  height: 100%;
}

html {
  -ms-touch-action: none; /* Direct all pointer events to JavaScript code. */
}

#gameDiv, canvas {
  display: block;
  position: absolute;
  margin: 0 auto;
  padding: 0;
  border: 0;
}

js

var NullLocalStorage = (function () {
    function NullLocalStorage() {
        this.data = {};
    }
    NullLocalStorage.prototype.getItem = function (key) {
        return this.data[key];
    };
    NullLocalStorage.prototype.setItem = function (key, value) {
        this.data[key] = value;
    };
    NullLocalStorage.prototype.removeItem = function (key) {
        delete this.data[key];
    };
    NullLocalStorage.prototype.clear = function () {
        for (var key in this.data) {
            this.removeItem(key);
        }
    };
    return NullLocalStorage;
})();
var EgretLocalStorage = (function () {
    function EgretLocalStorage() {
        if (egret_webview.io.isFileExists(EgretLocalStorage.filePath)) {
            var str = egret_webview.io.readFile(EgretLocalStorage.filePath, null);
            this.data = JSON.parse(str);
        }
        else {
            this.data = {};
        }
    }
    EgretLocalStorage.prototype.getItem = function (key) {
        return this.data[key];
    };
    EgretLocalStorage.prototype.setItem = function (key, value) {
        this.data[key] = value;
        this.save();
    };
    EgretLocalStorage.prototype.removeItem = function (key) {
        delete this.data[key];
        this.save();
    };
    EgretLocalStorage.prototype.clear = function () {
        for (var key in this.data) {
            delete this.data[key];
        }
        this.save();
    };
    EgretLocalStorage.prototype.save = function () {
        egret_webview.io.writeFile(EgretLocalStorage.filePath, JSON.stringify(this.data), 
        null);
    };
    EgretLocalStorage.filePath = "LocalStorage.local";
    return EgretLocalStorage;
})();
function EgretRuntimeBridgeInit() {
    if (typeof(egret_webview) == "undefined") {
        if (typeof(window.____egret_webview) == "undefined") {
            //Runtime出错了!!
            //alert("_js : window.____egret_webview undefined");
        }
        else {
            egret_webview = {};
            egret_webview.obj = window.____egret_webview;
            console.log("_js : egret_webview =  " + egret_webview.obj);
            egret_webview.io = window.____egtIO;
            console.log("_js : egret_webview.io =  " + egret_webview.io);
            egret_webview.audio = window.____egtAudio;
            console.log("_js : egret_webview.audio =  " + egret_webview.audio);
        }
    }
    if (window.hasOwnProperty("egret_webview") && typeof(egret_webview) != "undefined") {
        egret_webview.onDestory = function () {
        };
        egret_webview.onPause = function () {
        };
        egret_webview.onResume = function () {
        };
        egret.localStorage = new EgretLocalStorage();
    }
    else if (window && window.localStorage && window.localStorage.getItem) {
        egret.localStorage = window.localStorage;
    }
    else {
        egret.localStorage = new NullLocalStorage();
    }
}
window.EgretRuntimeBridgeInit = EgretRuntimeBridgeInit;
egret_h5 = {};

egret_h5.prefix = "";

egret_h5.loadScript = function (list, callback) {
    var loaded = 0;
    var loadNext = function () {
        egret_h5.loadSingleScript(egret_h5.prefix + list[loaded], function () {
            loaded++;
            if (loaded >= list.length) {
                callback();
            }
            else {
                loadNext();
            }
        })
    };
    loadNext();
};
egret_h5.loadSingleScript = function (src, callback) {
    var s = document.createElement('script');
    if (s.hasOwnProperty("async")) {
        s.async = false;
    }
    s.src = src;
    s.addEventListener('load', function () {
        this.removeEventListener('load', arguments.callee, false);
        callback();
    }, false);
    document.body.appendChild(s);
};
egret_h5.preloadScript = function (list, prefix) {
    if (!egret_h5.preloadList) {
        egret_h5.preloadList = [];
    }
    egret_h5.preloadList = egret_h5.preloadList.concat(list.map(function (item) {
        return prefix + item;
    }))
};
egret_h5.startLoading = function () {
    var list = egret_h5.preloadList;
    egret_h5.loadScript(list, egret_h5.startGame);
};
egret_h5.startGame = function () {
 // updateShare(0,0);
    var  context = egret.MainContext.instance;
    context.touchContext = new egret.HTML5TouchContext();
    context.deviceContext = new egret.HTML5DeviceContext();
    context.netContext = new egret.HTML5NetContext();

    egret.StageDelegate.getInstance().setDesignSize(480, 800);
    context.stage = new egret.Stage();
    var scaleMode =  egret.MainContext.deviceType == egret.MainContext.DEVICE_MOBILE ? 
    egret.StageScaleMode.SHOW_ALL : egret.StageScaleMode.NO_SCALE;
    context.stage.scaleMode = scaleMode;

    //WebGL是egret的Beta特性,默认关闭
    var rendererType = 0;
    if (rendererType == 1) {// egret.WebGLUtils.checkCanUseWebGL()) {
        context.rendererContext = new egret.WebGLRenderer();
    }
    else {
        context.rendererContext = new egret.HTML5CanvasRenderer();
    }
    egret.MainContext.instance.rendererContext.texture_scale_factor = 1;
    context.run();

    var rootClass;
    if(document_class){
        rootClass = egret.getDefinitionByName(document_class);
    }
    if(rootClass) {
        var rootContainer = new rootClass();
        if(rootContainer instanceof egret.DisplayObjectContainer){
            context.stage.addChild(rootContainer);
        }
        else{
            throw new Error("文档类必须是egret.DisplayObjectContainer的子类!");
        }
    }
    else{
        throw new Error("找不到文档类!");
    }
    //处理屏幕大小改变
    var resizeTimer = null;
    var doResize = function () {
        context.stage.changeSize();
        resizeTimer = null;
    };
    window.onresize = function () {
        if (resizeTimer == null) {
            resizeTimer = setTimeout(doResize, 300);
        }
    };
};

源码

需要源码请关注添加好友哦^ ^

转载:欢迎来到本站,转载请注明文章出处https://ormcc.com/

  • 49
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值