mirror of
https://github.com/Cola-Echo/memory-manager-concurrent.git
synced 2026-06-07 11:45:53 +00:00
Update memory-manager-concurrent
This commit is contained in:
45
games/mario/ball/index.html
Normal file
45
games/mario/ball/index.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<!doctype html>
|
||||
<html style="touch-action: none;">
|
||||
<head>
|
||||
<title>Mario - Backbone Game Engine</title>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<link href="../favicon.ico" rel="shortcut icon" type="image/x-icon" />
|
||||
<link href="../apple_touch_icon.png" rel="apple-touch-icon" />
|
||||
|
||||
<meta name="viewport" content="width=960, user-scalable=no"/>
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
|
||||
|
||||
<script src="../3rd/underscore.js" type="text/javascript"></script>
|
||||
<script src="../3rd/backbone.native.js" type="text/javascript"></script>
|
||||
<script src="../3rd/backbone.js" type="text/javascript"></script>
|
||||
|
||||
<script src="../src/adjust-viewport.js" type="text/javascript"></script>
|
||||
<script src="../src/shapes.js" type="text/javascript"></script>
|
||||
<script src="../src/core.js" type="text/javascript"></script>
|
||||
|
||||
<script src="main.js" type="text/javascript"></script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
background-color: #000;
|
||||
}
|
||||
canvas {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<canvas id="foreground" width="960" height="700">
|
||||
Your browser does not support canvas element.
|
||||
</canvas>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
107
games/mario/ball/main.js
Normal file
107
games/mario/ball/main.js
Normal file
@@ -0,0 +1,107 @@
|
||||
$(window).on("load", function() {
|
||||
|
||||
/**
|
||||
*
|
||||
* Backbone Game Engine - An elementary HTML5 canvas game engine using Backbone.
|
||||
*
|
||||
* Copyright (c) 2014 Martin Drapeau
|
||||
* https://github.com/martindrapeau/backbone-game-engine
|
||||
*
|
||||
*/
|
||||
|
||||
// Bouncing ball.
|
||||
|
||||
Backbone.Ball = Backbone.Sprite.extend({
|
||||
defaults: _.extend(Backbone.Sprite.prototype.defaults, {
|
||||
x: 400,
|
||||
y: 400,
|
||||
radius: 20,
|
||||
color: "red",
|
||||
velocity: 400,
|
||||
yVelocity: 400
|
||||
}),
|
||||
update: function(dt) {
|
||||
if (!this.engine) return false;
|
||||
|
||||
var x = this.get("x"),
|
||||
y = this.get("y"),
|
||||
radius = this.get("radius"),
|
||||
velocity = this.get("velocity") - radius,
|
||||
yVelocity = this.get("yVelocity") - radius,
|
||||
maxX = this.engine.canvas.width - radius,
|
||||
maxY = this.engine.canvas.height - radius,
|
||||
attrs = {oldX: x, oldY: y};
|
||||
|
||||
x += velocity * (dt/1000);
|
||||
y += yVelocity * (dt/1000);
|
||||
|
||||
if (x <= 0) {
|
||||
x = 0;
|
||||
attrs.velocity = velocity * -1;
|
||||
}
|
||||
if (x >= maxX) {
|
||||
x = maxX;
|
||||
attrs.velocity = velocity * -1;
|
||||
}
|
||||
|
||||
if (y <= 0) {
|
||||
y = 0;
|
||||
attrs.yVelocity = yVelocity * -1;
|
||||
}
|
||||
if (y >= maxY) {
|
||||
y = maxY;
|
||||
attrs.yVelocity = yVelocity * -1;
|
||||
}
|
||||
attrs.x = x;
|
||||
attrs.y = y;
|
||||
|
||||
this.set(attrs);
|
||||
return true;
|
||||
},
|
||||
draw: function(context) {
|
||||
var x = this.get("x"),
|
||||
y = this.get("y"),
|
||||
oldX = this.get("oldX"),
|
||||
oldY = this.get("oldY"),
|
||||
radius = this.get("radius"),
|
||||
color = this.get("color");
|
||||
|
||||
if (oldX || oldY)
|
||||
context.clearRect(oldX, oldY, radius, radius);
|
||||
|
||||
drawCircle(context, x+radius/2, y+radius/2, radius, color);
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
var canvas = document.getElementById("foreground");
|
||||
|
||||
var debugPanel = new Backbone.DebugPanel();
|
||||
|
||||
var ball = new Backbone.Ball({
|
||||
x: 100,
|
||||
y: 100,
|
||||
color: "blue"
|
||||
});
|
||||
|
||||
var engine = new Backbone.Engine({
|
||||
clearOnDraw: true
|
||||
}, {
|
||||
canvas: canvas,
|
||||
debugPanel: debugPanel
|
||||
});
|
||||
engine.add([
|
||||
ball,
|
||||
debugPanel
|
||||
]);
|
||||
|
||||
// Expose things as globals - easier to debug
|
||||
_.extend(window, {
|
||||
canvas: canvas,
|
||||
engine: engine
|
||||
});
|
||||
|
||||
adjustViewport(canvas);
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user