Skip to content
Browse files

Director boilerplate

  • Loading branch information...
1 parent 04b65ba commit 9aad95ed9b4408a32b37a522555812187a702163 @lqc lqc committed Apr 14, 2012
Showing with 70 additions and 15 deletions.
  1. +14 −0 client/src/intro_screen.js
  2. +55 −14 client/src/main.js
  3. +1 −1 client/statics/index.html
View
14 client/src/intro_screen.js
@@ -0,0 +1,14 @@
+var gamejs = require("gamejs");
+
+var StartScene = exports.StartScene = function(director) {
+ // pass
+ this.startPicture = gamejs.image.load('./statics/images/logo.png');
+};
+
+StartScene.prototype.handleEvent = function handleEvent(event) {
+ console.log("EVENT");
+};
+
+StartScene.prototype.draw = function(display) {
+ display.blit(this.startPicture);
+};
View
69 client/src/main.js
@@ -1,19 +1,60 @@
-var gamejs = require('gamejs');
+var gamejs = require('gamejs'), StartScene = require("intro_screen").StartScene;
-// gamejs.preload([]);
+gamejs.preload(["./statics/images/logo.png"]);
+//
gamejs.ready(function() {
+ function Director(width, height) {
+ this.onAir = false;
+ this.activeScene = null;
+ this.display = gamejs.display.setMode([ width, height ]);
+ gamejs.time.fpsCallback(this.tick, this, 30);
+ }
- var display = gamejs.display.setMode([1000, 550]);
- display.blit(
- (new gamejs.font.Font('30px Sans-serif')).render('Hello World')
- );
-
- /**
- function tick(msDuration) {
- // game loop
- return;
- };
- gamejs.time.fpsCallback(tick, this, 26);
- **/
+ Director.prototype.tick = function tick(msDuration) {
+ if (!this.onAir)
+ return;
+
+ if (this.activeScene.handleEvent) {
+ gamejs.event.get().forEach(this.activeScene.handleEvent);
+ } else {
+ // throw all events away
+ gamejs.event.get();
+ }
+ if (this.activeScene.update) {
+ this.activeScene.update(msDuration);
+ }
+ if (this.activeScene.draw) {
+ this.activeScene.draw(this.display);
+ }
+ return;
+ };
+
+ Director.prototype.start = function(scene) {
+ this.onAir = true;
+ this.replaceScene(scene);
+ return;
+ };
+
+ Director.prototype.replaceScene = function(scene) {
+ this.activeScene = scene;
+ };
+
+ Director.prototype.getScene = function() {
+ return this.activeScene;
+ };
+
+
+
+ var director = new Director(1000, 550);
+ director.start(new StartScene());
+
+ // display.blit(
+ // (new gamejs.font.Font('30px Sans-serif')).render('Hello World')
+ // );
+
+ /**
+ * function tick(msDuration) { // game loop return; };
+ * gamejs.time.fpsCallback(tick, this, 26);
+ */
});
View
2 client/statics/index.html
@@ -13,7 +13,7 @@
</script>
</head>
<body>
- <div id="logo"><img id="logo_img" src="/statics/images/logo.png" alt=""></div>
+ <!-- <div id="logo"><img id="logo_img" src="/statics/images/logo.png" alt=""></div> -->
<div id="container">
<div id="gjs-loader">Loading...</div>

0 comments on commit 9aad95e

Please sign in to comment.
Something went wrong with that request. Please try again.