Giter Site home page Giter Site logo

doubleice / gameengine Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xiugangzhang/gameengine

0.0 3.0 0.0 152 KB

:trophy:使用原生js封装的一个比较完整的游戏引擎,实现了游戏引擎中的一些必需的模块,包括游戏循环模块、游戏状态切换模块、基于时间运动、资源加载(图像、音乐文件)、键盘事件处理、高分榜的维护等模块,并以这个小型的游戏引擎设计了一个简单的小球运动的测试案例。

JavaScript 88.05% CSS 5.81% HTML 6.14%

gameengine's Introduction

GameEngine

预览

V1.0: 引擎实现的基本模块思路

1.创建一个游戏引擎对象及精灵对象 2.将精灵对象添加到引擎中去,并实现播放动画效果以及需要用到的回调方法 3.启动引擎

V2.0: 实现游戏循环模块

1.如果游戏暂停了,就跳过以下各步骤,并在100毫秒后再次执行游戏循环 2.更新帧速率 3.设置游戏时间 4.清除屏幕内容 5.在播放动画前,调用startAnimate的方法(可以进行碰撞检测)

startAnimate()

6.绘制精灵背后的内容(绘制背景) 7.更新精灵 8.绘制精灵 9.绘制精灵前方的内容 10.动画播放完毕之后,调用endAnimate方法

endAnimate()

11.请求浏览器播放下一帧动画

V3.0: 实现在暂停状态与运行状态之间的切换togglePaused

togglePaused()

V4.0:实现基于时间的运动效果 :

pixelPerFrame
 计算公式:(pixels / second) * (second / frame) = pixeld / second【单位:每一秒移动的像素数】

V5.0: 实现加载图像的功能:

queueImage(imageUrl): 将图像放入到加载队列中去
loadImages(): 开发者需要持续调用该方法,知道返回100位置(方法的返回值表示图像加载完成的百分比)
getImage(imageUrl):返回图像对象, 只有咋loadImages()返回100之后,才可以调用该方法

V6.0:实现同时播放多个声音的功能

canPlay(): 用于查询浏览器是否能够播放某种特定格式的声音文件
playSound():用于播放声音

V7.0: 键盘事件的处理

addKeyListener(): 用于向游戏注册按键监听器

V8.0: 高分榜的维护:游戏的高分榜数组以json格式存档在本地

V9.0: 实现了一个比较完整的游戏引擎,开始使用这个简单的游戏引擎去制作一个小游戏

需求分析: 1.资源加载的画面 2.游戏资源的管理 3.声音的播放 4.具有视差动画的滚动背景 5.生命数量的显示 6.高分榜的维护 7.按键的监听与处理 8.暂停功能与自动暂停机制实现 9.游戏结束的流程处理

gameengine's People

Contributors

xiugangzhang avatar

Watchers

James Cloos avatar  avatar DoubleIcy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.