From ad5b4e6d85e7b6c9f5c009f12c17c27659043816 Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Wed, 24 Dec 2014 13:22:27 +0100 Subject: Pruned unused files diff --git a/Evil-bubble.png b/Evil-bubble.png deleted file mode 100644 index e56b72c..0000000 Binary files a/Evil-bubble.png and /dev/null differ diff --git a/Grumpy-bubble.png b/Grumpy-bubble.png deleted file mode 100644 index 2053221..0000000 Binary files a/Grumpy-bubble.png and /dev/null differ diff --git a/Happy-oxygen-bubble-v2.png b/Happy-oxygen-bubble-v2.png deleted file mode 100644 index 7190965..0000000 Binary files a/Happy-oxygen-bubble-v2.png and /dev/null differ diff --git a/Happy-oxygen-bubble.png b/Happy-oxygen-bubble.png deleted file mode 100644 index 7529157..0000000 Binary files a/Happy-oxygen-bubble.png and /dev/null differ diff --git a/Stilla-the-starfish.png b/Stilla-the-starfish.png deleted file mode 100644 index 7d1dae5..0000000 Binary files a/Stilla-the-starfish.png and /dev/null differ diff --git a/SunkenMoon.appcache b/SunkenMoon.appcache deleted file mode 100644 index d2e3191..0000000 --- a/SunkenMoon.appcache +++ /dev/null @@ -1,904 +0,0 @@ -CACHE MANIFEST - -CACHE: -SunkenMoon.html - -NETWORK: -/ -/remote/* -* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SunkenMoon.html b/SunkenMoon.html deleted file mode 100644 index e16f73d..0000000 --- a/SunkenMoon.html +++ /dev/null @@ -1,1395 +0,0 @@ - -Vilma, the happy Vaquita - Sunken Moon
Vilma, the happy Vaquita - Sunken Moon v0.2.249 - Save Vaqitas
\ No newline at end of file diff --git a/SunkenMoon.html.coffee b/SunkenMoon.html.coffee deleted file mode 100644 index c9d8efb..0000000 --- a/SunkenMoon.html.coffee +++ /dev/null @@ -1,1117 +0,0 @@ -# Copyright (c) 2013, 2014 Michele Bini - -# A game featuring a Vaquita, the smallest, most endagered marine cetacean - -# This program is available under the terms of the MIT License - -version = "0.2.249" - -{ htmlcup } = require 'htmlcup' - -htmlcup[x] = htmlcup.compileTag x for x in [ "svg", "rect", "g", "ellipse", "polygon", "line", "image", "defs", "linearGradient", "stop", "use" ] - -title = "Vilma, the happy Vaquita - Sunken Moon" - -fs = require 'fs' - -datauri = (t,x)-> "data:#{t};base64,#{new Buffer(fs.readFileSync(x)).toString("base64")}" -datauripng = (x)-> datauri "image/png", x -dataurijpeg = (x)-> datauri "image/jpeg", x -datauriicon = (x)-> datauri "image/x-icon", x - -icon = datauriicon "vaquita.ico" -pixyvaquita = datauripng "vilma.png" - -frames = - _: pixyvaquita - twist_l: datauripng "vilma_twist_l.png" - twist_r: datauripng "vilma_twist_r.png" - happybubble0: datauripng "Happy-oxygen-bubble.png" - grumpybubble0: datauripng "Grumpy-bubble.png" - evilbubble0: datauripng "Evil-bubble.png" - stilla0: datauripng "Stilla-the-starfish.png" - # cuteluterror: datauripng 'cutelu-terror-v3.png' - seafloor: dataurijpeg "seafloor.png" - -gameName = "#{title} v#{version}" - -htmlcup.jsFile = (f)-> @script type:"text/javascript", (fs.readFileSync(f).toString()) - -gameAreaSize = [ 240, 360 ] - -genPage = -> - htmlcup.printHtml "\n" - htmlcup.html lang:"en", manifest:"SunkenMoon.appcache", style:"height:100%", -> - @head -> - @meta charset:"utf-8" - @meta name:"viewport", content:"width=480, user-scalable=no" - @meta name:"apple-mobile-web-app-capable", content:"yes" - @meta name:"mobile-web-app-capable", content:"yes" - # Improve support: http://www.html5rocks.com/en/mobile/fullscreen/ - # Homescreen installed webapp on Android Chrome has weird name! (Web App) - @link rel:"shortcut icon", href:icon - @title title - @body style:"margin:0;border:0;padding:0;height:100%;width:100%;background:black", -> - @div style:"visibility:hidden;position:absolute", -> - @img id:"pixyvaquita", src:pixyvaquita - @img id:"pixyvaquita_twist_l", src:frames.twist_l - @img id:"pixyvaquita_twist_r", src:frames.twist_r - @img id:"happybubble0", src:frames.happybubble0 - @img id:"grumpybubble0", src:frames.grumpybubble0 - @img id:"evilbubble0", src:frames.evilbubble0 - @img id:"stilla0", src:frames.stilla0 - # @img id:"cuteluterror", src:frames.cuteluterror - @img id:"seafloor", src:frames.seafloor - @div style:"display:table;width:100%;max-width:100%;height:100%;margin:0;border:0;padding:0", -> - @div style:"display:table-cell;vertical-align:middle;width:100%;margin:0;border:0;padding:0;text-align:center", -> - @div style:"position:relative;display:inline-block", width:"#{gameAreaSize[0]*2}", height:"#{gameAreaSize[1]*2}", -> - @canvas width:"#{gameAreaSize[0]*2}", height:"#{gameAreaSize[1]*2}" - @header style:"position:absolute;top:0;left:0;font-size:14px;width:100%;color:black", -> - @span gameName - @span " - " - @a target:"_blank", href:"index.html", "Save Vaqitas" - @div style:"text-align:right", id:"fps" - gameObjects = null - @script type:"text/javascript", "gameObjects=#{JSON.stringify(gameObjects)};" - @script type:"text/javascript", "__hasProp = {}.hasOwnProperty; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };" - @jsFile "jaws/jaws-min.js" - # @jsFile "jaws-assets-named.js" - @coffeeScript -> do -> - - # reportErrors = (x)-> - # try - # x() - # catch error - # try - # alert error.toString() - # catch error2 - # alert error - - screen_x1 = 120 - screen_y1 = 180 - { sqrt } = Math - - ### - # an ad-hoc redux of hammer.js - hammerLet = do(window, navigator)@> - mobile_regex: mobile_regex = /mobile|tablet|ip(ad|hone|od)|android/i - support_touch: support_touch = ('ontouchstart' in window) - prefixed: prefixed = - global: window - get: (sym)@> - { global } = @g - for v in @vendors - return r if (r = global[v + sym])? - undefined - vendors: [ 'webkit', 'moz', 'MS', 'ms', 'o' ] - PointerEvent: PointerEvent ? prefixed.run(window, 'PointerEvent')? - suppourt_touch_only: support_touch && mobile_regex.test(navigator.userAgent) - ### - jaws.onload = -> - class Demo - keyCodes: { left: leftKey, right: rightKey, up: upKey, down: downKey, space: spaceKey } = jaws.keyCodes - Sprite: Sprite = class extends jaws.Sprite - # caller needs to set lr for flip center - constructor: -> - super - image: @image - x: 0 - y: 0 - scale: 2 - draw: -> - @flipped = @lr >= 0 - @x = (screen_x1 + @px + @lr) * 2 - @y = (screen_y1 + @py - @tb) * 2 - super() - cr: 4 - sqrt: Math.sqrt - collide: (o)@> - { px, py, cr } = o - opx = o.px; opy = o.py; ocr = o.cr - dx = px - opx - dy = py - opy - dc = cr + ocr - if (qd = dx * dx + dy * dy) <= dc * dc - @bumpedInto?(o, qd, dx, dy) - o.bumpedInto?(@, qd, -dx, -dy) - # if true - # @lr = - @lr - # o.lr = - o.lr - # @px = opx - # @py = opy - # return - # @py = py - 1 - # return - # { sqrt } = @ - # if false - # py = opy - # px = opx - dc - # else - # d = sqrt d - # if d < 0.1 - # dy = -1 - # d = dx * dx + dy * dy - # d = sqrt d - # d = 3 * dc / sqrt(d) - # py = opy + dy * d - # px = opx + dx * d - # @px = px | 0 - # @py = py | 0 - - Bubble: Bubble = Sprite - HappyBubble: HappyBubble = class extends Bubble - image: happybubble0 - constructor: -> - @lr = 4 - @tb = 4 - super() - draw: -> - @py-- - super() - bumpedInto: (o, qd, dx, dy)@> - return if @dead - # if dx * dx * 2 > qd - @dead = true - GrumpyBubble: GrumpyBubble = class extends Bubble - image: grumpybubble0 - constructor: -> - @lr = 7 - @tb = 7 - @cr = 8 - @life = 60 - super() - draw: (collisions, game)-> - if game?.slowedBubbles - @py -= 2 - else - @py -= 3 - super() - bumpedInto: (o, qd, dx, dy)@> - return if @dead - # if dx * dx * 2 > qd - # @dead = true - ovy = o.vy - o.py -= 3 + (ovy > 0 then @life -= ovy; ovy * 2 else 0) - @dead = true unless @life > 0 - EvilBubble: EvilBubble = class extends Bubble - image: evilbubble0 - constructor: -> - @lr = 15 - @tb = 15 - @cr = 8 - @vy_ = -7 - @life = 2200 - super() - draw: (collisions, game)-> - l = 0 - if game.slowedBubbles - @py -= 3 - else - @py += @vy_ - if (life = @life) < 2200 - l = 2200 - @life - # l -= 1100 - # l = -l if l < 0 - # l = (l / 20)|0 - l = 2200 - l if l > 1100 - l /= 55 - @vy_ = - 8 - l - super() - bumpedInto: (o, qd, dx, dy)@> - return if @dead - # if dx * dx * 2 > qd - # @dead = true - ovx = o.vx - ovy = o.vy - @life -= ovx * ovx + ovy * ovy - @life -= 10 - o.px = @px - o.py = @py + @vy_ - @dead = true unless @life > 0 - slowBubbles: @> - return if @slowedBubbles - @slowedBubbles = true - quitSlowBubbles: @> - return unless @slowedBubbles - @slowedBubbles = false - Stilla: Stilla = class extends Bubble - image: stilla0 - Bubble: @Bubble - constructor: -> - @lr = 16 - @tb = 20 - @patience = 490 - super() - # Math: Math - sqrt: Math.sqrt - pow: Math.pow - sin: Math.sin - draw: (collisions, game)-> - { px, py, lr } = @ - (spin = @spin) then - { pow, sin } = @ - d = pow(px * px + py * py, 0.42) - r = 5 / (d + 1) - if r < 1 - ir = 1 - else - d = sin(d / 8000) - d = d * d * 8000 - ir = sqrt(1 - r * r) * pow(d, 0.01) - @px = px * ir + py * (r * spin) - @py = py * ir - px * (r * spin) - (d = px * px + py * py) > 40000 then - @spin = null - if @patience < 0 - @dead = 1 - # @patience += 10 - # @spinFrame = - else !(d >= 0) then - @px = 0 - @py = 1 - throw "ir #{ir}" - - else - closest = null - closestDist = null - consider = (v)-> - return unless v? - dx = px - v.px - dy = py - v.py - d = dx * dx + dy * dy - if !closest? or d < closestDist - return unless d >= 0 - closest = v - closestDist = d - game.quitSlowBubbles() - { vilma } = game - consider vilma - if game.vaquitas? - consider v for v in game.vaquitas - slowBubbles = false - if closest? - if closestDist < 7000 - slowBubbles = true - if closestDist < 4000 - @patience-- - if @patience < 0 or (closestDist < 1000 and closest is vilma) - dx = px - closest.px - @spin = (lr > 0 then +1 else -1) # Start spinning - @patience -= 100 - else - dx = px - closest.px - dy = py - closest.py - # fpx = @fpx += dx / 100 - # fpy = @fpy += dy / 100 - # @px = fpx | 0 - # @py = fpy | 0 - @px += (dx > +2 then +1 else dx < -2 then -1 else 0) - @py += (dy > +2 then +1 else dy < -2 then -1 else 0) - # @px += 1 - - # @px += 1 - if slowBubbles - game.slowBubbles() - else - game.quitSlowBubbles() - @lr = -lr if px * lr > 0 - super() - goodnight: (game)@> game.quitSlowBubbles() - bumpedInto: (o)@> - o.dead = true - Vaquita: Vaquita = class extends Sprite - twist: [ pixyvaquita_twist_l, pixyvaquita_twist_r ] - constructor: -> - @lr = 16 - @tb = 16 - super() - draw: -> - if @vx < 0 - @lr = - 18 - else if @vx > 0 - @lr = 18 - super() - AiVaquita: AiVaquita = class extends Vaquita - constructor: -> - @image = pixyvaquita - @time = 0 - super() - beat_lr: 0 - draw: -> - vx = @vx + Math.floor(Math.random()*3) - 1 - vy = @vy + Math.floor(Math.random()*3) - 1 - x = @px - y = @py - rx = 0.5 * x / screen_x1 - ry = 0.5 * y / screen_y1 - if (s = vx * vx + vy * vy * 2) > 6 - vx = Math.round(vx * 0.8 - rx) - vy = Math.round(vy * 0.8 - ry) - @px += @vx = vx - @py += @vy = vy - if (@time++ % 3) is 0 - if @image isnt pixyvaquita - @image = pixyvaquita - else if vx * vx + vy * vy > 2 - @image = @twist[ @beat_lr++ & 1 ] - super() - Vilma: Vilma = class extends Vaquita - constructor: (@game)-> - @image = pixyvaquita - @time = 0 - super() - @fpx = @px ? 0 - @fpy = @py ? 0 - @touch = @game.touchInput - beat_lr: 0 - move: -> - { touch } = @ - { tx, ty } = touch - itx = (tx >= 2 then 2 else tx <= -2 then -2 else 0) - ity = (ty >= 2 then 2 else ty <= -2 then -2 else 0) - touch.tx = tx * 0.9 - itx - touch.ty = ty * 0.9 - ity - ax = (if jaws.pressed[leftKey] then -1 else 0) + (if jaws.pressed[rightKey] then 1 else 0) - itx / 2 - ay = (if jaws.pressed[upKey] then -1 else 0) + (if jaws.pressed[downKey] then 1 else 0) - ity / 2 - if (aq = ax * ax + ay * ay) > 1 - aq = sqrt(aq) - ax /= aq - ay /= aq - ax *= 0.618 - ay *= 0.618 - vx = @vx - vy = @vy - if ax * vx < 0 - vx = 0 - else - vx += ax - vx *= 0.9 - if ay * vy < 0 - vy = 0 - else - vy += ay - vy *= 0.9 - @vx = vx - @vy = vy - @px = (@fpx += @vx) - @py = (@fpy += @vy) - draw: -> - { vx, vy } = @ - if (@time++ % 3) is 0 - if @image isnt pixyvaquita - @image = pixyvaquita - else if vx * vx + (vy * vy / 4) > 1 - @image = @twist[@beat_lr++ & 1] - super() - addVaquita: -> - # n = v.cloneNode() - # n.setAttribute "opacity", "0.5" - # n.href.baseVal = "#_v105" if Math.random(0) > 0.5 - # n.setAttribute "transform", "" - # sea.appendChild n - angle = Math.random() * 6.28 - v = new AiVaquita - v.vx = 0 - v.vy = 0 - v.px = Math.floor(Math.sin(angle) * 300) - v.py = Math.floor(Math.cos(angle) * 300) - # v.draw() - # vaquita.update() - @vaquitas.push v - addStilla: (x, y)@> - return if @stilla? - v = new @Stilla - v.px = x - v.py = y - @stilla = v - addInto: (n, v, x, y)@> - v.vx = 0 - v.vy = 0 - v.px = x - v.py = y - b = @[n] - if (i = b.indexOf(null)) >= 0 - b[i] = v - else - b.push v - # v.draw() - constructor: (@vaquitas = [], @cameos = [], @stilla = null)-> - encounters: - __proto__: - encounter: encounter = - add: (game, x, y)@> game.addInto('cameos', new @creature(), x, y) - vy: 0 - random: Math.random - log: Math.log - exp: Math.exp - pow: Math.pow - poissonSample: (m)@> - { exp, random } = @ - pgen = (m)-> - x = 0 - p = exp(-m) - s = p - u = random() - while u > s - x++ - p = p * m / x - s += p - x - s = 0 - while m > 50 - s += pgen 50 - m -= 50 - s + pgen m - generate: (game,left,top,width,height,vx,vvy)@> - { probability, random } = @ - depth = game.getDepth() - genRect = (m,left,top,width,height)=> - c = m.p(depth) * width * height - # c = 0 - c = @poissonSample(c) - if c is 1 - m.add?( game, left + ((random() * width)|0), top + ((random() * height)|0) ) - else - # c = 0 # if c > 1000 - # c-- if random() > 0.15 - while c-- > 0 - m.add?( game, left + ((random() * width)|0), top + ((random() * height)|0) ) - 1 - if vx * vx >= width * width - for k,v of @catalogue - genRect(v, left, top, width, height) - else for k,v of @catalogue - vy = vvy - v.vy - if vy * vy >= height * height - genRect(v, left, top, width, height) - else if vx > 0 - if vy > 0 - genRect(v, left, top + height - vy, width, vy) - genRect(v, left + width - vx, top, vx, height - vy) - else if vy < 0 - genRect(v, left, top, width, -vy) - genRect(v, left + width - vx, top - vy, vx, height + vy) - else - genRect(v, left + width, top, vx, height) - else if vx < 0 - if vy > 0 - genRect(v, left, top + height - vy, width, vy) - genRect(v, left, top, -vx, height - vy) - else if vy < 0 - genRect(v, left, top, width, -vy) - genRect(v, left, top - vy, -vx, height + vy) - else - genRect(v, left, top, -vx, height) - else if vy > 0 - genRect(v, left, top + height - vy, width, vy) - else if vy < 0 - genRect(v, left, top, width, -vy) - catalogue: - happybubble: - __proto__: encounter - p: (depth)@> 0.0001 * (1.5 - depth) - creature: HappyBubble - vy: -1 - grumpybubble: - __proto__: encounter - p: (depth)@> depth < 0.08 then 0 else (depth - 0.08) * 0.00015 - creature: GrumpyBubble - vy: -3 - evilbubble: - __proto__: encounter - p: (depth)@> depth < 0.35 then 0 else (depth - 0.35) * 0.00005 - creature: EvilBubble - vy: -8 - stilla: - __proto__: encounter - p: (depth)@> depth < 0.01 then 1 else (1-depth)/100000 - add: (game, x, y)@> game.addStilla(x, y) - touchInput: - tx: 0 - ty: 0 - ongoing: { } - __proto__: - eval: eval - start: (ev,el)@> - { ongoing } = @ - for t in ev.changedTouches - { identifier, pageX, pageY } = t - ongoing[identifier] = - px: pageX - py: pageY - move: (ev,el)@> - { ongoing } = @ - { tx, ty } = @ - for t in ev.changedTouches - { identifier, pageX, pageY } = t - o = ongoing[identifier] - dx = (pageX - o.px) * 4 - dy = (pageY - o.py) * 4 - dx *= 3 if dx * tx < 0 - dy *= 3 if dy * ty < 0 - tx += dx - ty += dy - # tx * dx > 0 then tx += dx else tx = dx * 2 - # ty * dy > 0 then ty += dy else ty = dy * 2 - o.px = pageX - o.py = pageY - @tx = tx - @ty = ty - end: (ev,el)@> - { ongoing } = @ - for t in ev.changedTouches - { identifier } = t - delete ongoing[identifier] - handle: (name)-> - touchInput = @ - (event)-> - event.preventDefault() - event.stopPropagation() - touchInput[name](event,this) catch err - alert err.toString() - ColorPlane: ColorPlane = do-> - document: document - init: @> - { color } = @ - if color and typeof color is 'string' - e = @document.createElement "canvas" - e.width = @w - e.height = @h - ctx = e.getContext '2d' - @color = ctx.fillStyle = color - frame: (t)@> - # t.save() - t.fillStyle = @color - t.fillRect 0,0,1024,1024 - # t.restore() - GenericPlane: GenericPlane = - document: document - init: @> - { document } = @ - e = document.createElement "canvas" - e.width = @w - e.height = @h - @ctx = e.getContext '2d' - - ScaledImg: ScaledImg = - document: document - zoom: 2 - init: @> - retroScaling = (c)-> - c.imageSmoothingEnabled = false; - c.webkitImageSmoothingEnabled = false; - c.mozImageSmoothingEnabled = false; - - { zoom } = @ - { width, height } = @img - @w = w = width * zoom - @h = h = height * zoom - c0 = e = @document.createElement "canvas" - retroScaling(c0) - e.width = w - e.height = height - ctx0 = e.getContext '2d' - retroScaling(ctx0) - ctx0.drawImage @img, 0, 0, width, height, 0, 0, w, height - @canvas = e = @document.createElement "canvas" - e.width = w - e.height = h - ctx = e.getContext '2d' - retroScaling(ctx) - @ctx = ctx.drawImage c0, 0, 0, w, height, 0, 0, w, h - - ParallaxPlane: ParallaxPlane = - __proto__: GenericPlane - ParallaxPlaneSuper: GenericPlane - lower: null - x: 0 - y: 0 - fx: 0 - fy: 0 - logzoom: 2 - frame: (t,dx,dy)@> - { fx, fy, x, y, abslogzoom, w, h, ctx } = @ - nfx = fx + dx - nfy = fy + dy - nx = nfx >> abslogzoom - ny = nfy >> abslogzoom - if nx isnt x - if nx >= w - nx -= w - nfx -= w << abslogzoom - else if nx < 0 - nx += w - nfx += w << abslogzoom - @x = nx - if ny isnt y - if ny >= h - ny -= h - nfy -= h << abslogzoom - else if ny < 0 - ny += h - nfy += h << abslogzoom - @y = ny - @fx = nfx - @fy = nfy - @lower?.frame t, dx, dy - { canvas } = ctx - t.drawImage canvas, nx, ny - t.drawImage canvas, nx - w, ny - t.drawImage canvas, nx, ny - h - t.drawImage canvas, nx - w, ny - h - init: (options)@> - @abslogzoom ?= @logzoom - (l = @lower)? then - l.logzoom? then l.abslogzoom ?= @logzoom + l.logzoom - l.init(options) - @ParallaxPlaneSuper.init.call @, options - BoundParallaxPlane: BoundParallaxPlane = - __proto__: ParallaxPlane - BoundParallaxPlaneProto: ParallaxPlane - pmul: 1 - alert: alert - init: (options)@> - { screenw, screenh } = options - @BoundParallaxPlaneProto.init.call @ - { logzoom, abslogzoom, w, h, pmul } = @ - @mx = ((w << abslogzoom) * pmul - screenw * 8) >> abslogzoom - @my = ((h << abslogzoom) * pmul - screenh * 8) >> abslogzoom - # { alert } = @; alert screenw - if false - @fx = (@x = @mx) << abslogzoom - @fy = (@y = @my) << abslogzoom - @fx = @fy = 0 - @mfy = @my << abslogzoom - frame: (t, dx, dy)@> - { fx, fy, x, y, abslogzoom, w, h, ctx } = @ - nfx = fx - dx - nfy = fy - dy - nx = nfx >> abslogzoom - ny = nfy >> abslogzoom - if nx isnt x - { mx } = @ - if nx >= mx - nx = mx - nfx = mx << abslogzoom - else if nx < 0 - nx = 0 - nfx = 0 - @x = nx - if ny isnt y - { my } = @ - if ny >= my - ny = my - nfy = my << abslogzoom - else if ny < 0 - ny = 0 - nfy = 0 - @y = ny - @fx = nfx - @fy = nfy - # @lower?.frame t, dx >> abslogzoom, dy >> abslogzoom - { canvas } = ctx - # @mny = 100 - t.drawImage canvas, -nx, -ny - # t.drawImage canvas, 0, 0, w, h, -nx, -ny, w*pmul, h*pmul - - SeaFloor: SeaFloor = do-> - __proto__: BoundParallaxPlane - SeaFloorProto: BoundParallaxPlane - # terror: CuteluTerror = - # img: cuteluterror - # zoom: 6 - # __proto__: ScaledImg - # color: "#051555" - seafloorImg: seafloor - init: (options)@> - { seafloorImg } = @ - # @terror.init(options) - w = seafloorImg.width - h = seafloorImg.height - @w = w - @h = h - @SeaFloorProto.init.call @, options - # { color, w, h } = @ - # e = @document.createElement "canvas" - # e.width = w - # e.height = h - # @ctx = ctx = e.getContext '2d' - { ctx, w, h } = @ - ctx.drawImage seafloorImg, 0, 0 - if false - ctx.fillStyle = "magenta" - ctx.fillRect 0, 0, w, 1 - ctx.fillRect 0, 0, 1, h - ctx.fillRect 0, h - 1, w, 1 - ctx.fillRect w - 1, 0, 1, h - - SeamlessPlane: SeamlessPlane = - withRect: (rx,ry,rw,rh,cb)@> - { w, h } = @ - if (ex = rx + rw) > w - if (ey = ry + rh) > h - cb rx, ry, w - rx, h - ry, 0, 0 - cb 0, ry, ex - w, h - ry, w - rx, 0 - cb rx, 0, w - rx, ey - h, 0, h - ry - cb 0, 0, ex - w, ey - h, w - rx, h - ry - else - cb rx, ry, w - rx, rh, 0, 0 - cb 0, ry, ex - w, rh, w - rx, 0 - else - if (ey = ry + rh) > h - cb rx, ry, rw, h - ry, 0, 0 - cb rx, 0, rw, ey - h, 0, h - ry - else - cb rx, ry, rw, rh, 0, 0 - __proto__: ParallaxPlane - - WaterPlane: WaterPlane = do-> - waterscapeSuper: waterscapeSuper = SeamlessPlane - __proto__: waterscapeSuper - random: Math.random - sqrt: Math.sqrt - colors: [ "cyan", "blue" ] - randomStuff: @> - { random, sqrt, ctx } = @ - s = sqrt(15000 / (random() * 50 + 1)) | 0 - @withRect (random() * @w | 0), (random() * @h | 0), s, s >> 2, (x,y,w,h)-> - ctx.fillRect x,y,w,h - @ - init: (options)@> - { lower, w, h, moltf, colors } = @ - if lower? - lower.w ?= w - lower.h ?= h - lower.moltf ?= moltf >> lower.logzoom if moltf? - @waterscapeSuper.init.call @, options - { ctx } = @ - for k,v of colors - ctx.fillStyle = v - colors[k] = ctx.fillStyle - ctx.globalAlpha = 0.16 - if true - x = 200 - while x-- > 0 - @randomStuff() - waterscapeSuperFrame: waterscapeSuper.frame - frame: (t)@> - { ctx, moltf, random } = @ - - ctx.fillStyle = @colors[ random() * 1.2 | 0 ] - @randomStuff() while moltf-- > 0 - - t.save() - t.globalAlpha = @alpha - @waterscapeSuperFrame.apply @, arguments - t.restore() - logzoom: 0 - - # PinkWaveletPlane: PinkWaveletPlane = do-> - # waterscapeSuper: waterscapeSuper = SeamlessPlane - # __proto__: waterscapeSuper - # random: Math.random - # sqrt: Math.sqrt - # sprites: [ "cyan", "blue" ] - # wlets: null - # randmix: @> - # { random, sqrt, ctx } = @ - # s = sqrt(15000 / (random() * 100 + 1)) | 0 - # @withRect (random() * @w | 0), (random() * @h | 0), s, s >> 2, (x,y,w,h)-> - # ctx.fillRect x,y,w,h - # @ - # init: @> - # { lower, w, h, moltf, colors } = @ - # if lower? - # lower.w ?= w - # lower.h ?= h - # lower.moltf ?= moltf >> lower.logzoom if moltf? - # @waterscapeSuper.init.call @ - # { ctx } = @ - # for k,v of colors - # ctx.fillStyle = v - # colors[k] = ctx.fillStyle - # ctx.globalAlpha = 0.06 - # if true - # x = 300 - # while x-- > 0 - # @randomStuff() - # waterscapeSuperFrame: waterscapeSuper.frame - # frame: (t)@> - # { ctx, moltf, random } = @ - - # ctx.fillStyle = @colors[ random() * 1.2 | 0 ] - # @randomStuff() while moltf-- > 0 - - # { alpha } = @ - # # t.save() - # t.globalAlpha = alpha if alpha? - # @waterscapeSuperFrame.apply @, arguments - # # t.restore() - # logzoom: 0 - seafloor: seafloorPlane = __proto__: SeaFloor - getDepth: @> @seafloor.fy / @seafloor.mfy - waterscape: waterscape = do-> - __proto__: WaterPlane - # color: "cyan" - # logzoom: 0 - moltf: 12 - colors: [ "#051555", "#33ddff" ] - alpha: 0.2 - logzoom: 0 - lower: - # __proto__: ColorPlane - # logzoom: 2 - __proto__: WaterPlane - # color: "blue" - colors: [ "#000033", "#001155" ] - alpha: 0.3 - # abslogzoom: 2 - logzoom: 2 - lower: seafloorPlane - bluescape: - __proto__: SeamlessPlane - bluescapeSuper: SeamlessPlane - lower: waterscape - logzoom: 0 - frame: (t,sx,sy)@> - { ctx, random, w, h } = @ - - x = @x + sx - x = (x + w) % w - y = (y + h) % h - @x = x - y = @y + sy - y += h while y < 0 - y -= h while y >= h - @y = y - # i = ctx.getImageData(0,0,@w,@h) - - ctx.save() - @lower.frame ctx, sx, sy - ctx.restore() - # t.save() - # t.globalCompositeOperation = 'copy' - - t.drawImage ctx.canvas, 0,0,w,h, 0,0,w*4,h*4 - - # t.drawImage ctx.canvas, 0,0,w>>2,h>>2, 0,0,w*2,h*2 - - # t.drawImage ctx.canvas, 0,0,w>>2,h>>2, 0,0,w*2,h>>2 - # t.drawImage t.canvas, 0,0,w*2,h>>2, 0,0,w*2,h*2 - - # t.restore() - # @withRect x, y, rx*2, ry*2, (x,y,w,h,ox,oy)-> t.drawImage c, x,y,w,h, ox*2,oy*2,w*2,h*2 - # t.drawImage c, 0, 0, - # t.fillColor = if random() > 0.5 then "#104080" else "#155590" - # t.fillRect 0, 0, 100, 100 - # t.clearRect 0, 0, 100, 100 - # t.drawImage t, 0, 0, 100, 100, 50, 50, 100, 100 - init: (options)@> - { w, h, lower } = @ - - @w = w - @h = h - - lower.w = (w >> 2) * 5 - lower.h = (h >> 2) * 5 - - @bluescapeSuper.init.call @, options - - { ctx } = @ - - # ctx.fillStyle = "#0099dd" - # ctx.fillRect 0, 0, @w, @h - - setup: -> - { bluescape, radx, rady } = @ - - bluescape.w = radx - bluescape.h = rady - bluescape.init( { screenw: radx * 2, screenh: rady * 2 } ) - - v = new Vilma(@) # jaws.Sprite x:screen_x1*2, y:screen_y1*2, zoom:2, image:pixyvaquita - v.px = 0 - v.py = 0 - v.vx = 0 - v.vy = 0 - @vilma = v - - @encounters.generate(@,-radx, -rady, radx * 2, rady * 2, radx * 2, 0) - - { touchInput } = @ - touchInput.game = @ - x = document.body - x.addEventListener "touchmove", touchInput.handle('move'), true - x.addEventListener "touchstart", touchInput.handle('start'), true - tend = touchInput.handle 'end' - x.addEventListener "touchend", tend, true - x.addEventListener "touchleave", tend, true - x.addEventListener "touchcancel", tend, true - - @collisions.setup(radx, rady) - radx: screen_x1 - rady: screen_y1 - rad: screen_x1 * screen_x1 + screen_y1 * screen_y1 - collisions: - Array: Array - setup: (radx, rady)@> - # Setup the collision detection subsystem - # Assumes: - # - radx and rady are multiples of 8 - w = @w = (radx >> 2) - h = @h = (rady >> 2) - @b = new @Array(w * h) - @o = (w >> 1) * h + (h >> 1) + 1 - @l = [ ] - a: (o)@> - # Add a collision subject - # Assumes: - # - all the corners of the object's collision area are in the viewing area - # - the object's collision radius is <= 8 - { l, b, w } = @ - i = @o + (o.py >> 3) * @w + (o.px >> 3) - @b[i-1] = @b[i+1] = @b[i] = o - i -= w - @b[i-1] = @b[i+1] = @b[i] = o - i += w << 1 - @b[i-1] = @b[i+1] = @b[i] = o - @l.push o - - # o.crad - q: (o)@> - # Quick collision test - # Test collisions of object against previously added collision subjects - # For this to work correctly: - # - the object should have a collision radius <= 4, - # - have a center in the viewing area - @b[@o + (o.py >> 3) * @w + (o.px >> 3)]?.collide(o) - # t2: (o)@> - # Like above but for objects with a collision radius <= 8 - clear: @> - @b = new @Array(@b.length) # Discrete board for detecting collisions - @l = [ ] # List of collisions targets - draw: @> - { jaws, spaceKey, radx, rady, vilma, vaquitas, cameos, stilla, rad, collisions } = @ - - @addVaquita() if (!(@gameloop.ticks & 0x7f) and vaquitas.length < 1) or jaws.pressed[spaceKey] - - vilma.fpx += vilma.px - vilma.fpy += vilma.py - vilma.move() - - if true - { px, py, fpx, fpy } = vilma - - vilma.fpx -= px - vilma.fpy -= py - vilma.px = 0 - vilma.py = 0 - - px = px | 0 - py = py | 0 - - @bluescape.frame jaws.context, -fpx, -fpy - else - { px, py } = vilma - - vilma.fpx = 0 - vilma.fpy = 0 - vilma.px = 0 - vilma.py = 0 - - px = px | 0 - py = py | 0 - - @bluescape.frame jaws.context, -px, -py - - collisions.a vilma - - for v in vaquitas - x = v.px -= px - y = v.py -= py - v.draw() - if (x >= -radx) and (x < radx) and (y >= -rady) and (y < rady) - collisions.a v - - vilma.draw() - - if stilla? - x = stilla.px -= px - y = stilla.py -= py - if stilla.dead or x * x + y * y > rad * 16 - stilla.goodnight(@) - @stilla = null - else - stilla.draw(collisions, @) - if (x >= -radx) and (x < radx) and (y >= -rady) and (y < rady) - collisions.a stilla - - for k,v of cameos - continue unless v? - x = v.px -= px - y = v.py -= py - if v.dead or (x < -radx) or (x >= radx) or (y < -rady) or (y >= rady) - cameos[k] = null - else - v.draw(collisions, @) - collisions.q v - - @encounters.generate(@,-radx, -rady, radx * 2, rady * 2, px, py) - - collisions.clear() - - if (@gameloop.ticks & 0xff) is 0xff - fps.innerHTML = "#{@gameloop.fps} fps" - - jaws: jaws - spaceKey: spaceKey - if true - jaws.init() - jaws.setupInput(); - window.game = game = new Demo - gameloop = new jaws.GameLoop(game, { fps:24 }) - (game.gameloop = gameloop).start() - else - jaws.start Demo, fps:25 - - # gameFrame = -> reportErrors -> - # if (time & 0xff) is 0x00 and vaquitas.length < 4 - # addVaquita() - # # s += 0.001 - # x -= vx = pressedKeys[leftKey] - pressedKeys[rightKey] - # y -= pressedKeys[upKey] - pressedKeys[downKey] - # if vx > 0 - # zoomX = 1 - # else if vx < 0 - # zoomX = -1 - # v.setAttribute("transform", "translate(#{x}, #{y}) zoom(#{zoomX}, #{zoomY})") - # # transform = v.transform.baseVal.getItem(0) - # # transformMatrix.a = zoomX - # # transformMatrix.e = x - # # transformMatrix.f = y - # if (time % 3) is 0 - # if currentFrame.baseVal is "#twistleft" - # currentFrame .baseVal = "#_" - # else if vx isnt 0 - # currentFrame.baseVal = "#twistleft" - # # transformList.initialize(transform) - # vq.update() for vq in vaquitas - # time++ - - # # setInterval gameFrame, 40 - # window.location.reload(true) - window.addEventListener('load', ((e)-> - if (window.applicationCache) - window.applicationCache.addEventListener('updateready', ((e)-> - # if (window.applicationCache.status == window.applicationCache.UPDATEREADY) - # Browser downloaded a new app cache. - # Swap it in and reload the page to get the new hotness. - window.applicationCache.swapCache() - if (confirm('A new version of this site is available. Load it?')) - window.location.reload() - # else - # Manifest didn't changed. Nothing new to server. - ), false) - ), false) - -genPage() diff --git a/attic/game-debug.html b/attic/game-debug.html deleted file mode 100644 index 52935f8..0000000 --- a/attic/game-debug.html +++ /dev/null @@ -1,269 +0,0 @@ - -Vilma the Vaquita
\ No newline at end of file diff --git a/attic/game-debug.html.coffee b/attic/game-debug.html.coffee deleted file mode 100644 index 3877da7..0000000 --- a/attic/game-debug.html.coffee +++ /dev/null @@ -1,311 +0,0 @@ -# Copyright (c) 2013, 2014 Michele Bini - -# A game featuring a Vaquita, the smallest, most endagered marine cetacean - -# This program is available under the terms of the MIT License - -version = "0.0.11" - -{ htmlcup } = require 'htmlcup' - -htmlcup[x] = htmlcup.compileTag x for x in [ "svg", "rect", "g", "ellipse", "polygon", "line", "image", "defs", "linearGradient", "stop", "use" ] - -title = "Vilma the Vaquita" - -fs = require 'fs' - -datauri = (t, x)-> "data:#{t};base64,#{new Buffer(fs.readFileSync(x)).toString("base64")}" -datauripng = (x)-> datauri "image/png", x -datauriicon = (x)-> datauri "image/x-icon", x - -icon = datauriicon "vaquita.ico" -pixyvaquita = datauripng "pixyvaquita_v2.png" -pixyvaquita_v105 = datauripng "pixyvaquita_v105_v.png" -frames = - _: pixyvaquita - _v105: pixyvaquita_v105 - twistleft: datauripng "pixyvaquita_v2_twistleft.png" - -useSvg = true - -genPage = -> - htmlcup.html5Page -> - @head -> - @meta charset:"utf-8" - @link rel:"shortcut icon", href:icon - @title title - @style type: "text/css", - """ - body { - /* background:pink; */ - /* background: #69B2FF; */ - /* background: #21AFF8; */ - /* background: #0286E8; */ - /* background: #1096EE; */ - background:black; - text-align: center; - font-size: 22px; - font-family: Helvetica; - } - .banner { - border: 5px solid white; - border: 5px solid white rgba(255,255,255,0.9); - box-shadow: 0 2px 4px blue; - margin: 1em; - } - p { - color:white; - color:rgba(255,255,255,0.9); - margin-top:0.418em; - margin-bottom:0.418em; - margin-left:auto; - margin-right:auto; - width:22em; - max-width:100%; - text-shadow: 0 1px 1px blue; - } - a { - /* - color:rgb(200,255,255); - color:rgba(200,255,255,0.9); - */ - color:white; - color:rgba(255,255,255,0.9); - text-decoration:none; - display: inline-block; - border: 1px solid white; - padding: 0 0.2em; - border-radius: 0.2em; - -moz-border-radius: 0.2em; - -webkit-border-radius: 0.2em; - -ie-border-radius: 0.2em; - } - a:hover { - background-color:rgba(20,70,180,1.0); - } - .petition { - margin:0.418em; - padding:0.618em; - } - .petition a { - font-size:127.2%; - box-shadow: 0 2px 4px blue; - margin:0.3em; - } - .page { - width: 100%; - height: 100%; - margin: 0; - border: 0; - } - .centering { - display: table; - padding: 0; - } - .centered { - display: table-cell; - vertical-align: middle; - text-align: center; - } - .inline-block { - display: inline-block; - } - .dynamic-section { - display: inline-block; - vertical-align:middle; - max-width:100%; - } - .flip-lr { - -moz-transform: scaleX(-1); - -o-transform: scaleX(-1); - -webkit-transform: scaleX(-1); - transform: scaleX(-1); - filter: FlipH; - -ms-filter: "FlipH"; - } - image, .pixelart { - image-rendering:optimizeSpeed; /* Legal fallback */ - image-rendering:-moz-crisp-edges; /* Firefox */ - image-rendering:-o-crisp-edges; /* Opera */ - image-rendering:-webkit-optimize-contrast; /* Safari */ - image-rendering:optimize-contrast; /* CSS3 Proposed */ - image-rendering:crisp-edges; /* CSS4 Proposed */ - image-rendering:pixelated; /* CSS4 Proposed */ - -ms-interpolation-mode:nearest-neighbor; /* IE8+ */ - } - /* - .pixelart { - image-rendering: -moz-crisp-edges; - -ms-interpolation-mode: nearest-neighbor; - image-rendering: pixelated; - image-rendering: crisp-edges; - } - */ - g.flipped { - transform:scale(-1,1); - } - .dimmed { - opacity: 0.2; - } - .dimmed:hover { - opacity: 1; - } - """ - @body -> - @div class:"centering page", -> - @div class:"centered", -> - @div -> @a class:"dimmed", "Vilma the Vaquita - v#{version}" - if useSvg - @svg id:"sea-svgroot", width:"960", height:"720", -> - @defs -> - @linearGradient id:"grad1", x1:"0%", y1:"0%", x2:"0%", y2:"100%", -> - @stop offset:"0%", style:"stop-color:rgb(255,255,255);stop-opacity:1" - @stop offset:"25%", style:"stop-color:rgb(100,200,250);stop-opacity:1" - @stop offset:"50%", style:"stop-color:rgb(0,80,240);stop-opacity:1" - @stop offset:"75%", style:"stop-color:rgb(0,0,180);stop-opacity:1" - @stop offset:"100%", style:"stop-color:rgb(0,0,0);stop-opacity:1" - for k,v of frames - @g id:k, -> - @g transform:"translate(-18,-15)", -> - @image width:"50", height:"30", "xlink:href":v - @rect x:"0", y:"0", width:"960", height:"720", fill:"url(#grad1)" - @g transform:"scale(2)", -> - @g id:"sea", transform:"translate(240,180)", -> - @use "xlink:href":"#_" - else - @canvas width:"960", height:"720", -> - @div -> @a class:"dimmed", target:"_blank", href:"index.html", "Learn about Vaquitas" - gameObjects = null - @script type:"text/javascript", "gameObjects=#{JSON.stringify(gameObjects)};" - @coffeeScript -> - svgroot = document.getElementById("sea-svgroot") - - reportErrors = (x)-> - try - x() - catch error - try - alert error.toString() - catch error2 - alert error - - screen_x1 = 240 - screen_y1 = 180 - vaquitas = [ ] - vaquitaObj = - update: (x, y)-> - if !window.abcd - window.abcd = 1 - vx = @vx + Math.floor(Math.random()*3) - 1 - vy = @vy + Math.floor(Math.random()*3) - 1 - x = @x - y = @y - rx = 0.5 * x / screen_x1 - ry = 0.5 * y / screen_y1 - if (s = vx * vx + vy * vy * 2) > 6 - vx = Math.round(vx * 0.9 + rx) - vy = Math.round(vy * 0.9 + ry) - @x = x -= @vx = vx - @y = y -= @vy = vy - if vx > 0 - @scaleX = 1 - else if vx < 0 - @scaleX = -1 - @e.setAttribute "transform", "translate(#{x}, #{y}) scale(#{@scaleX}, 1)" - m = @m; m.e = x; m.f = y; m.a = @scaleX - # @e.transform.baseVal.consolidate() - # @e.transform.baseVal.initialize(@e.transform.baseVal.matrix) - sea = document.getElementById "sea" - v = sea.firstChild - - getTransformMatrix = (el)-> - transformListXX = el.transform.baseVal - transformMatrixXX = svgroot.createSVGMatrix() - transformXX = svgroot.createSVGTransform() - transformXX.setMatrix(transformMatrixXX) - transformListXX.initialize(transformXX) - transformXX.matrix - - addVaquita = -> - n = v.cloneNode() - n.setAttribute "opacity", "0.5" - n.href.baseVal = "#_v105" if Math.random(0) > 0.5 - # n.setAttribute "transform", "" - sea.appendChild n - angle = Math.random() * 6.28 - vaquita = - e: n - m: getTransformMatrix(n) - x: Math.sin(angle) * 300 - y: Math.cos(angle) * 300 - vx: 0 - vy: 0 - scaleX: 1 - __proto__: vaquitaObj - vaquita.update() - vaquitas.push vaquita - - leftKey = 37 - upKey = 38 - rightKey = 39 - downKey = 40 - usedKeys = [ leftKey, upKey, rightKey, downKey ] - - keyDownActions = - 32: addVaquita - - pressedKeys = { } - pressedKeys[k] = 0 for k in usedKeys - - window.addEventListener 'keydown', (event)-> - code = event.keyCode - keyDownActions[ code ]?(event) - pressedKeys[ code ] = 1 - window.addEventListener 'keyup', (event)-> - pressedKeys[ event.keyCode ] = 0 - - do (x = 0, y = 0)-> reportErrors -> - time = 0 - vx = 0 - vy = 0 - ax = 0 - ay = 0 - # s = 1 - # x = 0 - # y = 0 - scaleX = 1 - scaleY = 1 - - window.cf = currentFrame = v.href - transformMatrix = getTransformMatrix(v) - transformMatrix.a = scaleX - transformMatrix.e = x - transformMatrix.f = y - - gameFrame = -> reportErrors -> - if (time & 0xff) is 0x00 and vaquitas.length < 4 - addVaquita() - # s += 0.001 - x -= vx = pressedKeys[leftKey] - pressedKeys[rightKey] - y -= pressedKeys[upKey] - pressedKeys[downKey] - if vx > 0 - scaleX = 1 - else if vx < 0 - scaleX = -1 - v.setAttribute("transform", "translate(#{x}, #{y}) scale(#{scaleX}, #{scaleY})") - # transform = v.transform.baseVal.getItem(0) - # transformMatrix.a = scaleX - # transformMatrix.e = x - # transformMatrix.f = y - if (time % 3) is 0 - if currentFrame.baseVal is "#twistleft" - currentFrame .baseVal = "#_" - else if vx isnt 0 - currentFrame.baseVal = "#twistleft" - # transformList.initialize(transform) - vq.update() for vq in vaquitas - time++ - - setInterval gameFrame, 40 - -genPage() diff --git a/cloaky.png b/cloaky.png deleted file mode 100644 index 1f796ef..0000000 Binary files a/cloaky.png and /dev/null differ diff --git a/game.html b/game.html deleted file mode 100644 index 6642a17..0000000 --- a/game.html +++ /dev/null @@ -1,310 +0,0 @@ - -Vilma the Vaquita Demo
\ No newline at end of file diff --git a/game.html.coffee b/game.html.coffee deleted file mode 100644 index 30dc1a4..0000000 --- a/game.html.coffee +++ /dev/null @@ -1,330 +0,0 @@ -# Copyright (c) 2013, 2014 Michele Bini - -# A game featuring a Vaquita, the smallest, most endagered marine cetacean - -# This program is available under the terms of the MIT License - -version = "0.1.63" - -{ htmlcup } = require 'htmlcup' - -htmlcup[x] = htmlcup.compileTag x for x in [ "svg", "rect", "g", "ellipse", "polygon", "line", "image", "defs", "linearGradient", "stop", "use" ] - -title = "Vilma the Vaquita Demo" - -fs = require 'fs' - -datauri = (t, x)-> "data:#{t};base64,#{new Buffer(fs.readFileSync(x)).toString("base64")}" -datauripng = (x)-> datauri "image/png", x -datauriicon = (x)-> datauri "image/x-icon", x - -icon = datauriicon "vaquita.ico" -pixyvaquita = datauripng "vilma.png" -pixyvaquita_v105 = datauripng "pixyvaquita_v105_v.png" -frames = - _: pixyvaquita - _v105: pixyvaquita_v105 - twist_l: datauripng "vilma_twist_l.png" - twist_r: datauripng "vilma_twist_r.png" - -gameName = "#{title} v#{version}" - -htmlcup.jsFile = (f)-> @script type:"text/javascript", (fs.readFileSync(f).toString()) - -genPage = -> - htmlcup.html5Page -> - @head -> - @meta charset:"utf-8" - @link rel:"shortcut icon", href:icon - @title title - @style type: "text/css", - """ - body { - /* background:pink; */ - /* background: #69B2FF; */ - /* background: #21AFF8; */ - /* background: #0286E8; */ - /* background: #1096EE; */ - background:black; - text-align: center; - font-size: 22px; - font-family: Helvetica; - color:white; - color:rgba(255,255,255,0.9); - margin:0; - } - .banner { - border: 5px solid white; - border: 5px solid white rgba(255,255,255,0.9); - box-shadow: 0 2px 4px blue; - margin: 1em; - } - footer, p { - margin-top:0.418em; - margin-bottom:0.418em; - margin-left:auto; - margin-right:auto; - text-shadow: 0 1px 1px blue; - } - p { - width:22em; - max-width:100%; - } - a { - /* - color:rgb(200,255,255); - color:rgba(200,255,255,0.9); - */ - color:white; - color:rgba(255,255,255,0.9); - text-decoration:none; - display: inline-block; - border: 1px solid white; - padding: 0 0.2em; - border-radius: 0.2em; - -moz-border-radius: 0.2em; - -webkit-border-radius: 0.2em; - -ie-border-radius: 0.2em; - } - a:hover { - background-color:rgba(20,70,180,1.0); - } - .petition { - margin:0.418em; - padding:0.618em; - } - .petition a { - font-size:127.2%; - box-shadow: 0 2px 4px blue; - margin:0.3em; - } - .page { - width: 100%; - height: 100%; - margin: 0; - border: 0; - } - .centering { - display: table; - padding: 0; - } - .centered { - display: table-cell; - vertical-align: middle; - text-align: center; - } - .inline-block { - display: inline-block; - } - .dynamic-section { - display: inline-block; - vertical-align:middle; - max-width:100%; - } - .flip-lr { - -moz-transform: scaleX(-1); - -o-transform: scaleX(-1); - -webkit-transform: scaleX(-1); - transform: scaleX(-1); - filter: FlipH; - -ms-filter: "FlipH"; - } - image, .pixelart { - image-rendering:optimizeSpeed; /* Legal fallback */ - image-rendering:-moz-crisp-edges; /* Firefox */ - image-rendering:-o-crisp-edges; /* Opera */ - image-rendering:-webkit-optimize-contrast; /* Safari */ - image-rendering:optimize-contrast; /* CSS3 Proposed */ - image-rendering:crisp-edges; /* CSS4 Proposed */ - image-rendering:pixelated; /* CSS4 Proposed */ - -ms-interpolation-mode:nearest-neighbor; /* IE8+ */ - } - /* - .pixelart { - image-rendering: -moz-crisp-edges; - -ms-interpolation-mode: nearest-neighbor; - image-rendering: pixelated; - image-rendering: crisp-edges; - } - */ - g.flipped { - transform:scale(-1,1); - } - .dim { - opacity: 0.2; - } - .dim:hover { - opacity: 1; - } - """ - @body -> - @div class:"centering page", -> - @div class:"centered", -> - @div style:"visibility:hidden;position:absolute", -> - @img id:"pixyvaquita", src:pixyvaquita - @img id:"pixyvaquita_105", src:frames._v105 - @img id:"pixyvaquita_twist_l", src:frames.twist_l - @img id:"pixyvaquita_twist_r", src:frames.twist_r - @div style:"position:relative", -> - @svg id:"sea-svgroot", width:"960", height:"720", style:"position:absolute;opacity:0.9;z-index:-1000", -> - @defs -> - @linearGradient id:"grad1", x1:"0%", y1:"0%", x2:"0%", y2:"100%", -> - @stop offset:"0%", style:"stop-color:rgb(255,255,255);stop-opacity:1" - @stop offset:"25%", style:"stop-color:rgb(100,200,250);stop-opacity:1" - @stop offset:"50%", style:"stop-color:rgb(0,80,240);stop-opacity:1" - @stop offset:"75%", style:"stop-color:rgb(0,0,180);stop-opacity:1" - @stop offset:"100%", style:"stop-color:rgb(0,0,0);stop-opacity:1" - @rect x:"0", y:"0", width:"960", height:"720", fill:"url(#grad1)" - @canvas width:"960", height:"720", -> - @footer class:"dim", -> - @span gameName - @span " - " - @a target:"_blank", href:"index.html", "Learn about Vaquitas" - @span id:"fps" - gameObjects = null - @script type:"text/javascript", "gameObjects=#{JSON.stringify(gameObjects)};" - @script type:"text/javascript", "__hasProp = {}.hasOwnProperty; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };" - @jsFile "jaws/jaws-min.js" - # @jsFile "jaws-assets-named.js" - @coffeeScript -> do -> - # svgroot = document.getElementById("sea-svgroot") - - # reportErrors = (x)-> - # try - # x() - # catch error - # try - # alert error.toString() - # catch error2 - # alert error - - screen_x1 = 240 - screen_y1 = 180 - - jaws.onload = -> - class Demo - { left: leftKey, right: rightKey, up: upKey, down: downKey, space: spaceKey } = jaws.keyCodes - Sprite = class extends jaws.Sprite - # caller needs to set lr for flip center - constructor: -> - super - image: @image - x: 0 - y: 0 - scale: 2 - FlippableSprite = class extends Sprite - draw: -> - @flipped = @lr >= 0 - @x = (screen_x1 + @px + @lr) * 2 - @y = (screen_y1 + @py - 5) * 2 - super() - Vaquita = class extends FlippableSprite - constructor: -> - @lr = 18 - super() - draw: -> - if @vx < 0 - @lr = - 18 - else if @vx > 0 - @lr = 18 - super() - AiVaquita = class extends Vaquita - constructor: -> - @image = if Math.random() > 0.5 then pixyvaquita_105 else pixyvaquita - super() - draw: -> - vx = @vx + Math.floor(Math.random()*3) - 1 - vy = @vy + Math.floor(Math.random()*3) - 1 - x = @px - y = @py - rx = 0.5 * x / screen_x1 - ry = 0.5 * y / screen_y1 - if (s = vx * vx + vy * vy * 2) > 6 - vx = Math.round(vx * 0.9 - rx) - vy = Math.round(vy * 0.9 - ry) - @px += @vx = vx - @py += @vy = vy - super() - HeroVaquita = class extends Vaquita - twist = [ pixyvaquita_twist_l, pixyvaquita_twist_r ] - constructor: -> - @image = pixyvaquita - @time = 0 - super() - beat_lr: 0 - draw: -> - @vx = (if jaws.pressed[leftKey] then -1 else 0) + (if jaws.pressed[rightKey] then 1 else 0) - @vy = (if jaws.pressed[upKey] then -1 else 0) + (if jaws.pressed[downKey] then 1 else 0) - @px += @vx - @py += @vy - if (@time++ % 3) is 0 - if @image isnt pixyvaquita - @image = pixyvaquita - else if @vx isnt 0 - @image = twist[@beat_lr++ & 1] - super() - addVaquita: -> - # n = v.cloneNode() - # n.setAttribute "opacity", "0.5" - # n.href.baseVal = "#_v105" if Math.random(0) > 0.5 - # n.setAttribute "transform", "" - # sea.appendChild n - angle = Math.random() * 6.28 - v = new AiVaquita - v.vx = 0 - v.vy = 0 - v.px = Math.floor(Math.sin(angle) * 300) - v.py = Math.floor(Math.cos(angle) * 300) - v.draw() - # vaquita.update() - @vaquitas.push v - constructor: (@vaquitas = [])-> - setup: -> - v = new HeroVaquita # jaws.Sprite x:screen_x1*2, y:screen_y1*2, scale:2, image:pixyvaquita - v.px = 0 - v.py = 0 - v.vx = 0 - v.vy = 0 - @vaquitas.push v - draw: -> - jaws.clear() - @addVaquita() if (!(@gameloop.ticks & 0x7f) and @vaquitas.length < 7) or jaws.pressed[spaceKey] - v.draw() for v in @vaquitas - if (@gameloop.ticks & 0xff) is 0xff - fps.innerHTML = " - #{@gameloop.fps} fps" - if true - jaws.init() - jaws.setupInput(); - game = new Demo - gameloop = new jaws.GameLoop(game, { fps:24 }) - (game.gameloop = gameloop).start() - else - jaws.start Demo, fps:25 - - # gameFrame = -> reportErrors -> - # if (time & 0xff) is 0x00 and vaquitas.length < 4 - # addVaquita() - # # s += 0.001 - # x -= vx = pressedKeys[leftKey] - pressedKeys[rightKey] - # y -= pressedKeys[upKey] - pressedKeys[downKey] - # if vx > 0 - # scaleX = 1 - # else if vx < 0 - # scaleX = -1 - # v.setAttribute("transform", "translate(#{x}, #{y}) scale(#{scaleX}, #{scaleY})") - # # transform = v.transform.baseVal.getItem(0) - # # transformMatrix.a = scaleX - # # transformMatrix.e = x - # # transformMatrix.f = y - # if (time % 3) is 0 - # if currentFrame.baseVal is "#twistleft" - # currentFrame .baseVal = "#_" - # else if vx isnt 0 - # currentFrame.baseVal = "#twistleft" - # # transformList.initialize(transform) - # vq.update() for vq in vaquitas - # time++ - - # # setInterval gameFrame, 40 - -genPage() diff --git a/jaws-assets-named.coffee b/jaws-assets-named.coffee deleted file mode 100644 index 4a7a5df..0000000 --- a/jaws-assets-named.coffee +++ /dev/null @@ -1,456 +0,0 @@ -# LGPL-licensed, please consult jawsjs.com -# conversion to coffeescript modification of src_assets.js from 'jawsjs.com' by Michele Bini - -# this supports named assets: like named:ImageName:image.png" - -jaws = ((jaws) -> - - ###* - @fileOverview jaws.assets properties and functions - - Loads and processes image, sound, video, and json assets - (Used internally by JawsJS to create jaws.assets) - - @class Jaws.Assets - @constructor - @property {boolean} bust_cache Add a random argument-string to assets-urls when loading to bypass any cache - @property {boolean} fuchia_to_transparent Convert the color fuchia to transparent when loading .bmp-files - @property {boolean} image_to_canvas Convert all image assets to canvas internally - @property {string} root Rootdir from where all assets are loaded - @property {array} file_type Listing of file postfixes and their associated types - @property {array} can_play Listing of postfixes and (during runtime) populated booleans - ### - - ###* - Returns the length of the resource list - @public - @returns {number} The length of the resource list - ### - - ###* - Set root prefix-path to all assets - - @example - jaws.assets.setRoot("music/").add(["music.mp3", "music.ogg"]).loadAll() - - @public - @param {string} path-prefix for all following assets - @returns {object} self - ### - - ###* - Get one or more resources from their URLs. Supports simple wildcard (you can end a string with "*"). - - @example - jaws.assets.add(["song.mp3", "song.ogg"]) - jaws.assets.get("song.*") // -> Will return song.ogg in firefox and song.mp3 in IE - - @public - @param {string|array} src The resource(s) to retrieve - @returns {array|object} Array or single resource if found in cache. Undefined otherwise. - ### - - # Wildcard? song.*, match against asset-srcs, make sure it's loaded and return content of first match. - - # TODO: self.loaded[src] is false for supported files for some odd reason. - - ###* - Returns if specified resource is currently loading or not - @public - @param {string} src Resource URL - @return {boolean|undefined} If resource is currently loading. Otherwise, undefined. - ### - - ###* - Returns if specified resource is loaded or not - @param src Source URL - @return {boolean|undefined} If specified resource is loaded or not. Otherwise, undefined. - ### - - ###* - Returns lowercase postfix of specified resource - @public - @param {string} src Resource URL - @returns {string} Lowercase postfix of resource - ### - - ###* - Determine type of file (Image, Audio, or Video) from its postfix - @private - @param {string} src Resource URL - @returns {string} Matching type {Image, Audio, Video} or the postfix itself - ### - - ###* - Add URL(s) to asset listing for later loading - @public - @param {string|array|arguments} src The resource URL(s) to add to the asset listing - @example - jaws.assets.add("player.png") - jaws.assets.add(["media/bullet1.png", "media/bullet2.png"]) - jaws.assets.add("foo.png", "bar.png") - jaws.assets.loadAll({onload: start_game}) - ### - - ###* - Iterate through the list of resource URL(s) and load each in turn. - @public - @param {Object} options Object-literal of callback functions - @config {function} [options.onprogress] The function to be called on progress (when one assets of many is loaded) - @config {function} [options.onerror] The function to be called if an error occurs - @config {function} [options.onload] The function to be called when finished - ### - - ###* - Loads a single resource from its given URL - Will attempt to match a resource to known MIME types. - If unknown, loads the file as a blob-object. - - @public - @param {string} src Resource URL - @param {Object} options Object-literal of callback functions - @config {function} [options.onload] Function to be called when assets has loaded - @config {function} [options.onerror] Function to be called if an error occurs - @example - jaws.load("media/foo.png") - jaws.load("http://place.tld/foo.png") - ### - # NOTE: assetLoaded can be called several times during loading. - - #Load everything else as raw blobs... - - # ... But don't load un-supported audio-files. - - # Initial loading callback for all assets for parsing specific filetypes or - # optionally converting images to canvas-objects. - # @private - # @param {EventObject} event The EventObject populated by the calling event - # @see processCallbacks() - - # - # * Only increment load_count ONCE per unique asset. - # * This is needed cause assetLoaded-callback can in certain cases be called several for a single asset... - # * ..and not only Once when it's loaded. - # - - # Called when jaws asset-handler decides that an asset shouldn't be loaded - # For example, an unsupported audio-format won't be loaded. - - # @private - - # Increases the error count and calls processCallbacks with false flag set - # @see processCallbacks() - # @private - # @param {EventObject} event The EventObject populated by the calling event - - # Processes (if set) the callbacks per resource - # @private - # @param {object} asset The asset to be processed - # @param {boolean} ok If an error has occured with the asset loading - # @param {EventObject} event The EventObject populated by the calling event - # @see jaws.start() in core.js - - # Displays the progress of asset handling as an overall percentage of all loading - # (Can be overridden as jaws.assets.displayProgress = function(percent_done) {}) - # @public - # @param {number} percent_done The overall percentage done across all resource handling - - # Make Fuchia (0xFF00FF) transparent (BMPs ONLY) - # @private - # @param {HTMLImageElement} image The Bitmap Image to convert - # @returns {CanvasElement} canvas The translated CanvasElement - - fuchiaToTransparent = (image) -> - return unless jaws.isDrawable(image) - canvas = (if jaws.isImage(image) then jaws.imageToCanvas(image) else image) - context = canvas.getContext("2d") - img_data = context.getImageData(0, 0, canvas.width, canvas.height) - pixels = img_data.data - i = 0 - - while i < pixels.length - # Color: Fuchia - pixels[i + 3] = 0 if pixels[i] is 255 and pixels[i + 1] is 0 and pixels[i + 2] is 255 # Set total see-through transparency - i += 4 - context.putImageData img_data, 0, 0 - canvas - jaws.Assets = Assets = -> - getType = (src) -> - if jaws.isString(src) - postfix = self.getPostfix(src) - (if self.file_type[postfix] then self.file_type[postfix] else postfix) - else - jaws.log.error "jaws.assets.getType: Argument not a String with " + src - return - assetLoaded = (event) -> - asset = @asset - src = asset.src - filetype = getType(asset.src) - try - if filetype is "json" - return if @readyState isnt 4 - self.data[asset.src] = JSON.parse(@responseText) - else if filetype is "image" - new_image = (if self.image_to_canvas then jaws.imageToCanvas(asset.image) else asset.image) - new_image = fuchiaToTransparent(new_image) if self.fuchia_to_transparent and self.getPostfix(asset.src) is "bmp" - self.data[asset.src] = new_image - else if filetype is "audio" and self.can_play[self.getPostfix(asset.src)] - self.data[asset.src] = asset.audio - else if filetype is "video" and self.can_play[self.getPostfix(asset.src)] - self.data[asset.src] = asset.video - else - self.data[asset.src] = @response - catch e - jaws.log.error "Cannot process " + src + " (Message: " + e.message + ", Name: " + e.name + ")" - self.data[asset.src] = null - self.load_count++ unless self.loaded[src] - self.loaded[src] = true - self.loading[src] = false - processCallbacks asset, true, event - return - assetSkipped = (asset) -> - self.loaded[asset.src] = true - self.loading[asset.src] = false - self.load_count++ - processCallbacks asset, true - return - assetError = (event) -> - asset = @asset - self.error_count++ - processCallbacks asset, false, event - return - processCallbacks = (asset, ok, event) -> - percent = parseInt((self.load_count + self.error_count) / self.src_list.length * 100) - if ok - self.onprogress asset.src, percent if self.onprogress - asset.onprogress event if asset.onprogress and event isnt `undefined` - else - self.onerror asset.src, percent if self.onerror - asset.onerror event if asset.onerror and event isnt `undefined` - if percent is 100 - self.onload() if self.onload - self.onprogress = null - self.onerror = null - self.onload = null - return - return new arguments.callee() unless this instanceof arguments.callee - self = this - self.loaded = [] - self.loading = [] - self.src_list = [] - self.data = [] - self.bust_cache = false - self.image_to_canvas = true - self.fuchia_to_transparent = true - self.root = "" - self.file_type = {} - self.file_type["json"] = "json" - self.file_type["wav"] = "audio" - self.file_type["mp3"] = "audio" - self.file_type["ogg"] = "audio" - self.file_type["m4a"] = "audio" - self.file_type["weba"] = "audio" - self.file_type["aac"] = "audio" - self.file_type["mka"] = "audio" - self.file_type["flac"] = "audio" - self.file_type["png"] = "image" - self.file_type["jpg"] = "image" - self.file_type["jpeg"] = "image" - self.file_type["gif"] = "image" - self.file_type["bmp"] = "image" - self.file_type["tiff"] = "image" - self.file_type["mp4"] = "video" - self.file_type["webm"] = "video" - self.file_type["ogv"] = "video" - self.file_type["mkv"] = "video" - self.can_play = {} - try - audioTest = new Audio() - self.can_play["wav"] = !!audioTest.canPlayType("audio/wav; codecs=\"1\"").replace(/^no$/, "") - self.can_play["ogg"] = !!audioTest.canPlayType("audio/ogg; codecs=\"vorbis\"").replace(/^no$/, "") - self.can_play["mp3"] = !!audioTest.canPlayType("audio/mpeg;").replace(/^no$/, "") - self.can_play["m4a"] = !!(audioTest.canPlayType("audio/x-m4a;") or audioTest.canPlayType("audio/aac;")).replace(/^no$/, "") - self.can_play["weba"] = !!audioTest.canPlayType("audio/webm; codecs=\"vorbis\"").replace(/^no$/, "") - self.can_play["aac"] = !!audioTest.canPlayType("audio/aac;").replace(/^no$/, "") - self.can_play["mka"] = !!audioTest.canPlayType("audio/x-matroska;").replace(/^no$/, "") - self.can_play["flac"] = !!audioTest.canPlayType("audio/x-flac;").replace(/^no$/, "") - try - videoTest = document.createElement("video") - self.can_play["mp4"] = !!videoTest.canPlayType("video/mp4;").replace(/^no$/, "") - self.can_play["webm"] = !!videoTest.canPlayType("video/webm; codecs=\"vorbis\"").replace(/^no$/, "") - self.can_play["ogv"] = !!videoTest.canPlayType("video/ogg; codecs=\"vorbis\"").replace(/^no$/, "") - self.can_play["mkv"] = !!videoTest.canPlayType("video/x-matroska;").replace(/^no$/, "") - self.length = -> - self.src_list.length - - self.setRoot = (path) -> - self.root = path - self - - self.get = (src) -> - if jaws.isArray(src) - src.map (i) -> - self.data[i] - - else if jaws.isString(src) - if src[src.length - 1] is "*" - needle = src.replace("*", "") - i = 0 - - while i < self.src_list.length - return self.data[self.src_list[i]] if self.src_list[i].indexOf(needle) is 0 and self.data[self.src_list[i]] - i++ - if self.data[src] - self.data[src] - else - jaws.log.warn "No such asset: " + src, true - else - jaws.log.error "jaws.get: Neither String nor Array. Incorrect URL resource " + src - return - return - - self.isLoading = (src) -> - if jaws.isString(src) - self.loading[src] - else - jaws.log.error "jaws.isLoading: Argument not a String with " + src - return - - self.isLoaded = (src) -> - if jaws.isString(src) - self.loaded[src] - else - jaws.log.error "jaws.isLoaded: Argument not a String with " + src - return - - self.getPostfix = (src) -> - if jaws.isString(src) - src.toLowerCase().match(/.+\.([^?]+)(\?|$)/)[1] - else - jaws.log.error "jaws.assets.getPostfix: Argument not a String with " + src - return - - self.add = (src) -> - list = arguments - list = list[0] if list.length is 1 and jaws.isArray(list[0]) - i = 0 - - while i < list.length - if jaws.isArray(list[i]) - self.add list[i] - else - if jaws.isString(list[i]) - self.src_list.push list[i] - else - jaws.log.error "jaws.assets.add: Neither String nor Array. Incorrect URL resource " + src - i++ - self - - self.loadAll = (options) -> - self.load_count = 0 - self.error_count = 0 - self.onprogress = options.onprogress if options.onprogress and jaws.isFunction(options.onprogress) - self.onerror = options.onerror if options.onerror and jaws.isFunction(options.onerror) - self.onload = options.onload if options.onload and jaws.isFunction(options.onload) - self.src_list.forEach (item) -> - self.load item - return - - self - - self.load = (src, options) -> - options = {} unless options - unless jaws.isString(src) - jaws.log.error "jaws.assets.load: Argument not a String with " + src - return - asset = {} - resolved_src = "" - if parts =/^named:([^:]+):/.exec src - asset.name = parts[1] - src = src.substring parts[0].length - asset.src = src - asset.onload = options.onload - asset.onerror = options.onerror - self.loading[src] = true - parser = RegExp("^((f|ht)tp(s)?:)?//") - if /^[a-z][a-z0-9-]*:/.test(src) - resolved_src = asset.src - else - resolved_src = self.root + asset.src - resolved_src += "?" + parseInt(Math.random() * 10000000) if self.bust_cache - type = getType(asset.src) - if type is "image" - try - asset.image = new Image() - asset.image.asset = asset - asset.image.addEventListener "load", assetLoaded - asset.image.addEventListener "error", assetError - asset.image.src = resolved_src - catch e - jaws.log.error "Cannot load Image resource " + resolved_src + " (Message: " + e.message + ", Name: " + e.name + ")" - else if self.can_play[self.getPostfix(asset.src)] - if type is "audio" - try - asset.audio = new Audio() - asset.audio.asset = asset - asset.audio.addEventListener "error", assetError - asset.audio.addEventListener "canplay", assetLoaded - self.data[asset.src] = asset.audio - asset.audio.src = resolved_src - asset.audio.load() - catch e - jaws.log.error "Cannot load Audio resource " + resolved_src + " (Message: " + e.message + ", Name: " + e.name + ")" - else if type is "video" - try - asset.video = document.createElement("video") - asset.video.asset = asset - self.data[asset.src] = asset.video - asset.video.setAttribute "style", "display:none;" - asset.video.addEventListener "error", assetError - asset.video.addEventListener "canplay", assetLoaded - document.body.appendChild asset.video - asset.video.src = resolved_src - asset.video.load() - catch e - jaws.log.error "Cannot load Video resource " + resolved_src + " (Message: " + e.message + ", Name: " + e.name + ")" - else - if type is "audio" and not self.can_play[self.getPostfix(asset.src)] - assetSkipped asset - return self - try - req = new XMLHttpRequest() - req.asset = asset - req.onreadystatechange = assetLoaded - req.onerror = assetError - req.open "GET", resolved_src, true - req.responseType = "blob" if type isnt "json" - req.send null - catch e - jaws.log.error "Cannot load " + resolved_src + " (Message: " + e.message + ", Name: " + e.name + ")" - self - - self.displayProgress = (percent_done) -> - return unless jaws.isNumber(percent_done) - return unless jaws.context - jaws.context.save() - jaws.context.fillStyle = "black" - jaws.context.fillRect 0, 0, jaws.width, jaws.height - jaws.context.fillStyle = "white" - jaws.context.strokeStyle = "white" - jaws.context.textAlign = "center" - jaws.context.strokeRect 50 - 1, (jaws.height / 2) - 30 - 1, jaws.width - 100 + 2, 60 + 2 - jaws.context.fillRect 50, (jaws.height / 2) - 30, ((jaws.width - 100) / 100) * percent_done, 60 - jaws.context.font = "11px verdana" - jaws.context.fillText "Loading... " + percent_done + "%", jaws.width / 2, jaws.height / 2 - 35 - jaws.context.font = "11px verdana" - jaws.context.fillStyle = "#ccc" - jaws.context.textBaseline = "bottom" - jaws.context.fillText "powered by www.jawsjs.com", jaws.width / 2, jaws.height - 1 - jaws.context.restore() - return - - return - - jaws.assets = new jaws.Assets() - jaws -)(jaws or {}) diff --git a/jaws/LICENSE b/jaws/LICENSE deleted file mode 100644 index 65c5ca8..0000000 --- a/jaws/LICENSE +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/jaws/README.rdoc b/jaws/README.rdoc deleted file mode 100644 index 5a84523..0000000 --- a/jaws/README.rdoc +++ /dev/null @@ -1,276 +0,0 @@ -= Jaws - HTML5 Javascript web game development library -{Build Status}[https://travis-ci.org/ippa/jaws] - -Depends on JavaScript Edition 5. Works with Chrome 9+, Firefox 3.6+, Safari 5+ & IE9. - -Licensed under LGPL so you're free to use it for commercial projects. - -== Highlights -* Animation(), Sprite(), SpriteSheet(), TileMap(), Assets() and other useful constructors -* Easy and robust game state system to switch between menus, play, high score lists and settings -* JSDOC Documentation & commented examples - -Jaws also: -- Uses 2D canvas to draw stuff on the screen -- Does not depend on any other JavaScript library -- Suple-simple-to-use collision detection, bounding box and circles. -- Doesn't try to force a certain "JS class pattern" on you, just pure JavaScript as mother nature intended it -- Tries to make assets (images, music, json data) in webgames as easy as possible -- Often does object literals as arguments for readabillity (ie. new Sprite({image: "player.png", x: 100, y: 100}) -- Builds on lessons learned from years of developing http://github.com/ippa/chingu (Ruby game lib) - -== Local build / test - npm install - npm test - -== Learn more -- {http://jawsjs.com/docs/index.html}[http://jawsjs.com/docs/index.html] - Jaws documentation -- {http://jawsjs.com/}[http://jawsjs.com/] - Official Jaws homepage. Overview and design choices. -- {http://jawsjs.com/jawsjs/test/index.html}[http://jawsjs.com/jawsjs/test/index.html] - Jaws testsuite (QUnit) - -== Tutorials -- {http://videlais.com/2013/05/17/learning-jawsjs-part-1/}[http://videlais.com/2013/05/17/learning-jawsjs-part-1/] - Intro to sprites, collisions and game states by Dan Cox. -- {http://videlais.com/2013/05/23/learning-jawsjs-part-2/}[http://videlais.com/2013/05/23/learning-jawsjs-part-2/] - SpriteList, collideOneWithMany and more. -- {http://videlais.com/2013/06/01/learning-jawsjs-part-3/}[http://videlais.com/2013/06/01/learning-jawsjs-part-3/] - Viewport & assets. -- {http://videlais.com/2013/06/05/learning-jawsjs-part-4/}[http://videlais.com/2013/06/05/learning-jawsjs-part-4/] - SpriteSheet, Animation and game states. - -== What kind of games can you make with Jaws? -Jaws is well suited for "classic" side/top scrolling games (tile based or not) where you have a number of sprite-sheet-animated sprites. -Jaws comes with basic rect-vs-rect/circle-vs-circle collision detection that works well in most cases. If you have _tons_ of sprites (for example, a bullet hell schmup) you probably want to use a physicslib like Box2D or spatial -hashing like quad trees to speed things up. Jaws use of canvas makes pixel perfect collisions and worms-style terrain relatively easy to develop. If your game is very GUI-heavy you might want to base your game on pure HTML-elements instead of canvas-sprites. - -== Simple examples demonstrating certain features -Check out the sourcecode for comments and explanations: - -* http://jawsjs.com/jawsjs/examples/example0.html - get a Jaws-app working with as little code as possible -* http://jawsjs.com/jawsjs/examples/example1.html - basic example with manual setup of canvas -* http://jawsjs.com/jawsjs/examples/example2.html - jaws game states -* http://jawsjs.com/jawsjs/examples/example3.html - jaws.Animation -* http://jawsjs.com/jawsjs/examples/example4.html - jaws.Rect based collision detection -* http://jawsjs.com/jawsjs/examples/example5.html - the jaws.Sprite({anchor: "..."}) parameter -* http://jawsjs.com/jawsjs/examples/example6.html - jaws.Parallax -* http://jawsjs.com/jawsjs/examples/example7.html - simple DOM-based sprite (DEPRECATED) -* http://jawsjs.com/jawsjs/examples/example8.html - jaws.TileMap -* http://jawsjs.com/jawsjs/examples/example9.html - jaws.Viewport (The basics for a sidescrolling platformer right here) -* http://jawsjs.com/jawsjs/examples/example10.html - jaws.game_states.Edit, a simple map editor -* http://jawsjs.com/jawsjs/examples/example11.html - jaws.gfx.retroScaleImage and Literal Notion game state -* http://jawsjs.com/jawsjs/examples/example12.html - jaws.viewport.drawTileMap() - optimized tile map drawing - -== Games using Jaws -* {http://www.ludumdare.com/compo/ludum-dare-29/?action=preview&uid=21212}[http://www.ludumdare.com/compo/ludum-dare-29/?action=preview&uid=21212] - DrillFish: drill through the levels as a very odd fish - by mezka -* {http://recardona.github.io/BitBot/}[http://recardona.github.io/BitBot/] - BitBot: puzzle, enter commands to the robot to reach the goal -* {http://ld27.pauljoannon.com//}[http://ld27.pauljoannon.com/] - Castle Clocksworth: Steampunk-style puzzle adventure -* {http://ippa.se/webgames/the_adventures_of_10_seconds/}[http://ippa.se/webgames/the_adventures_of_10_seconds/] - Small worms-style terrain puzzle-adventure! -* {http://mcfunkypants.com/LD26/}[http://mcfunkypants.com/LD26/] - Colorful abstract platformer by McFunkypants -* {http://games.subdimension.co.uk/LD26/}[http://games.subdimension.co.uk/LD26/] - Unique painting mini-game by Malphas Wats -* {http://mcfunkypants.com/RubbaRabbit/}[http://mcfunkypants.com/RubbaRabbit/] - Fullscreen platformer by McFunkypants -* {http://mcfunkypants.com/Gwendolynn/}[http://mcfunkypants.com/Gwendolynn/] - Gwendolynn, platformer by McFunkypants -* {http://gamejolt.com/games/arcade/b-w-tennis/13883/}[http://gamejolt.com/games/arcade/b-w-tennis/13883/] - Pong-clone by devpoga -* {http://ricardonakamura.org/game/ld25/}[http://ricardonakamura.org/game/ld25/] - Sword of Truth by http://ricardonakamura.org/ -* {http://gamejolt.com/games/arcade/for-victory/14267/}[http://gamejolt.com/games/arcade/for-victory/14267/] - Minimalistic game by devpoga -* {http://www.castleriot.com/}[http://www.castleriot.com/] - Multiplayer game with guards and thieves. By team @ http://nodeknockout.com/teams/third-times-the-char -* {http://ippa.se/webgames/the_escape/index.html}[http://ippa.se/webgames/the_escape/index.html] - "The Escape" - My Ludum Dare #21 entry. Adventure/Puzzle. -* {http://ippa.se/webgames/unexpected_outcome/index.html}[http://ippa.se/webgames/unexpected_outcome/index.html] - A 10-minute adventure game with pixel-perfect collisions -* {http://ippa.se/webgames/unwaivering/index.html}[http://ippa.se/webgames/unwaivering/index.html] - A Jaws-game for http://www.ludumdare.com/compo/2011/01/25/minild-24/ -* {http://dl.dropbox.com/u/73425602/ld23/index.html}[http://dl.dropbox.com/u/73425602/ld23/index.html] - LD #23 game by Nibelung (http://www.ludumdare.com/compo/author/nibelung/) -* {http://www.twitchtetris.com/}[http://www.twitchtetris.com/] - A tetris game by http://twitchcode.blogspot.com/ -* {http://www.mcfunkypants.com/kart/magma/}[http://www.mcfunkypants.com/kart/magma/] - Another pixel perfect game from MC Funky Pants. Don't touch the rising lava! -* {http://dl.dropbox.com/u/15658925/LD22%20release/game.html}[http://dl.dropbox.com/u/15658925/LD22%20release/game.html] - LD#22 entry by "Char" (http://www.ludumdare.com/compo/ludum-dare-22/?action=preview&uid=3407) -* {http://h31p.com/save-atherton/}[http://h31p.com/save-atherton/] - A political satire mini-game from https://github.com/dalethatcher -* {http://www.mcfunkypants.com/LD22/}[http://www.mcfunkypants.com/LD22/] - a Ludum Dare #22 entry by Christer Kaitila -* {http://nibster.net/LD/}[http://nibster.net/LD/] - a Ludum Dare #22 entry by https://github.com/Nibster -* {http://memetika.com/iron_santa/}[http://memetika.com/iron_santa/] - a Ludum Dare #22 entry by https://github.com/dmitrizagidulin -* {http://markbennett.ca/JAWS-on-a-plane/}[http://markbennett.ca/JAWS-on-a-plane/] - A minigame by https://github.com/MarkBennett -* {http://davidgomes.github.com/paxlure/}[http://davidgomes.github.com/paxlure/] - Zombie blasting minigame by https://github.com/davidgomes -* {http://crystalpart.com/hp/}[http://crystalpart.com/hp/] - A mini game by by Ashan Fernando (http://crystalpart.com/wp/) -* {http://magigames.org/runestone_defense.html}[http://magigames.org/runestone_defense.html] - Runestone, a tower defense game by David Blood -* {http://www.tinycrate.com/ld48/vivere/}[http://www.tinycrate.com/ld48/vivere/] - TinyCrate - An experimental game about mixing DNA by http://www.thank-etc-ok.com/ -* {http://www.tinycrate.com/ld48/volo/}[http://www.tinycrate.com/ld48/volo/] - VOLO - A game by http://www.thank-etc-ok.com -* {http://www.philbgarner.com/vampire/}[http://www.philbgarner.com/vampire/] - Scion of Dracula - Play dracula in search for Van Helsing. By Phil Garner. -* {http://charitygamejam.com/?Parachute%20Champ}[http://charitygamejam.com/?Parachute%20Champ] - Parachute Champ - land your parachute safely. By Nicholas Wrenn. -* {https://www.facebook.com/appcenter/hopeofabug}[https://www.facebook.com/appcenter/hopeofabug] - Facebook minigame by Fahad Mahmood. -... missing your game here? Mail me about it (my email is on my github profilepage). Or create a new issue. - -== Libs using Jaws -* {http://mcfunkypants.com/tower/} - Tower Game Starter Kit -* {http://mcfunkypants.com/ludus/}[http://mcfunkypants.com/ludus/] - Platformer Game Starter Kit -* {https://github.com/deisdestiny/Jaws-TS}[https://github.com/deisdestiny/Jaws-TS] - Jaws TypeScript Definitions - -== Loading Jaws -* jaws.js - includes the whole framework in one easy-to-include file. -* jaws-min.js - same as jaws.js but minified with Googles closure compiler. This is probably what you want to include in your project. -* jaws-dynamic.js - dynamically loads all separate jaws files. Useful for debugging errors when patching jaws since you get exact file/line# of possible errors. Warning, jaws-dynamic.js loads all Jaws-files asynchronously, resulting in Jaws might not be fully loaded when the browser reaches your game.js. You can solve this by hooking into the jaws.onload callback and put your jaws.start() there. - -You can also link to invidual files in your HTML: - - - -NOTE: core.js is always needed but after that you can pick and choose depending on what you need. -A rule of thumb is that a file named "foo.js" will include a constructor named Foo(). - -NOTE #2: jaws.js and jaws-min.js does Not include files from src/extras-dir. -Examples of files that aren't included in the mainbundle are: tile_map_pathfinding.js, pixel_map.js and audio.js (jaws