-
-
Save miebach/5125292 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- BiwaScheme 0.6.1 --> | |
<html> | |
<head> | |
<title>enchant.js sample in BiwaScheme</title> | |
</head> | |
<body> | |
<div id="enchant-stage" /> | |
<script src="./enchant.js"></script> | |
<script src="./biwascheme.js"> | |
(js-call (js-eval "enchant")) | |
(js-set! (js-eval "window") "onload" (js-closure (lambda () | |
(let ((game (js-new "Game" 320 320))) | |
(js-set! game "fps" 24) | |
(js-invoke game "preload" "bear.png") | |
;; the images used in the game should be preloaded | |
(js-set! game "onload" (js-closure (lambda () | |
(let ((bear (js-new "Sprite" 32 32))) | |
(js-set! bear "x" 8) | |
(js-set! bear "y" 8) | |
(js-set! bear "image" (js-ref (js-ref game "assets") "bear.png")) | |
(js-invoke bear "addEventListener" "enterframe" (js-closure (lambda (e) | |
;; check input from key on every frame | |
(if (js-ref (js-ref game "input") "right") | |
(js-set! bear "x" (+ (js-ref bear "x") 2))) | |
(if (js-ref (js-ref game "input") "left") | |
(js-set! bear "x" (- (js-ref bear "x") 2))) | |
(if (js-ref (js-ref game "input") "up") | |
(js-set! bear "y" (- (js-ref bear "y") 2))) | |
(if (js-ref (js-ref game "input") "down") | |
(js-set! bear "y" (+ (js-ref bear "y") 2)))))) | |
;; add bear to rootScene (default scene) | |
(js-invoke (js-ref game "rootScene") "addChild" bear)) | |
(js-set! (js-ref game "rootScene") "backgroundColor" #xffffff)))) | |
(js-invoke game "start"))))) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment