Sample of HTML 5 game development
来源:互联网 发布:mysql 数据库备份语句 编辑:程序博客网 时间:2024/05/18 03:53
Just a sample of HTML 5 game development.
<!DOCTYPE html><html><head><script type="text/javascript">var VehicleGame = function() {var ctx;var goRight = false, goLeft = false, pause = false;var vx = 0, vy = 0, dx = 4, dy = 4;var init = function(id) {var el = document.getElementById(id);if (el && el.getContext) {ctx = el.getContext("2d");this.run();this.addListener();}}init.prototype = {clear: function() {ctx.fillStyle = '#c2c2c2';ctx.fillRect(0, 0, 600, 400);ctx.strokeStyle = '#333';ctx.strokeRect(0, 0, 600, 400);},run: function() {var _this = this;this.interval = setInterval(function () {_this.drawVehicle();}, 16)},drawVehicle: function() {this.clear();var vehicle = new Image();vehicle.src = 'vehicle.png';ctx.drawImage(vehicle, vx, vy);if (pause) {this.showInfo("Paused!!!Press spacebar to cancel it!");}if (goLeft && !pause) {vx -= dy;}if (goRight && !pause) {vx += dx;}},showInfo: function(message) {ctx.fillStyle = '#333';ctx.font = '24px "Calibri"';ctx.fillText(message, 100, 180);},addListener: function() {document.addEventListener('keydown', function (e) {if (e.keyCode == 39) {goRight = true;} else if (e.keyCode == 37) {goLeft = true;}}, false);document.addEventListener('keyup', function (e) {if (e.keyCode == 39) {goRight = false;} else if (e.keyCode == 37) {goLeft = false;} else if (e.keyCode == 32) {pause = !pause ? true : false;}}, false);}}return init;}();window.onload = function() {new VehicleGame("canvas");}</script></head><body><canvas id="canvas" width="600" height="400">Your browser can not support canvas, please upgrade your browser!</canvas></body></html>
Result:
- Sample of HTML 5 game development
- The rapid development of the game server
- A list of game development resources
- game sample
- The Use of Design Patterns In Game Development
- Book Review of Dynamics of Software Development--Get their heads into the game
- 手机游戏软件开发的前景 The future of development of game software on mobiles
- MUD Game Programming (Game Development)
- J2ME Game Development
- Mobile Game Development Fundamental
- Open Source Game Development
- Free (game development) libraries
- AI Game Development
- Game Engine Toolset Development
- Game Development and Production
- Game Development Bibliography
- Free Game Development Libraries
- Game development - J2ME
- android 获取屏幕分辨率
- Hadoop集群安装详细步骤|Hadoop安装配置
- Qt collect2: ld returned 1 exit status问题
- QtNetwork: No such file or directory 问题的解决
- 手机打电话的通讯原理
- Sample of HTML 5 game development
- GTK+开发环境搭建(Centos+Netbeans)
- 技能提升
- Linux下常用简单命令
- 关于两个排列的思考
- java 的构造器是干什么用的,初始化对象,还是初始化数据,默认的无参构造器,和有参构造器的区别,找高手解答
- SQLsever分页存储过程(有返回总页数,传入表名与字段条件)
- oracle优化链接
- Hive安装配置详细