diff options
| -rw-r--r-- | game.html.coffee | 153 |
1 files changed, 92 insertions, 61 deletions
diff --git a/game.html.coffee b/game.html.coffee index 7b99de9..26a9f1c 100644 --- a/game.html.coffee +++ b/game.html.coffee @@ -78,6 +78,7 @@ genPage = -> @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" + @jsFile "lib/Evolving/evolving.js" @coffeeScript -> do -> # reportErrors = (x)-> @@ -109,24 +110,53 @@ genPage = -> sharpen = sharpener 86 jaws.onload = -> - class Demo - keyCodes: { left: leftKey, right: rightKey, up: upKey, down: downKey, space: spaceKey } = jaws.keyCodes - Sprite: Sprite = class extends jaws.Sprite + Evolving::Evolving = Evolving + Basic = Evolving::evolve -> + @Evolving = Evolving + @setConstructor = (c)@> + @constructor = c + c.prototype = @ + @importClass = (c)@> + Basic <. @ + @ .> evolve + evolve.call c::, -> + @ .< evolve + Basic.evolution.call @ + @ + @brew = (name, base, evolution)@> + @[name] = base::namedEvolve(name, evolution) + @method = (name, f)@> + @[name] = @[ name + @className ] = f + @ + @evolveEvolving = @evolve + @namedEvolve = (name, evolution = (-> @))@> + p = @ + @className = name + @[name] = @constructor + @[name] = c = @evolve -> evolution.call(@,p) + @ + Basic::Basic = Basic + Demo = Basic::evolve -> + @keyCodes = { left: leftKey, right: rightKey, up: upKey, down: downKey, space: spaceKey } = jaws.keyCodes + @brew 'Sprite', @importClass(jaws.Sprite), -> # caller needs to set lr for flip center - constructor: -> - super + @JSprite = jaws.Sprite + @setConstructor @> + @JSprite image: @image x: 0 y: 0 scale: 2 - draw: -> + return + @drawJSprite = @JSprite::draw + @method 'draw', @> @flipped = @lr >= 0 - @x = (screen_x1 + @px + @lr) * 2 - @y = (screen_y1 + @py - @tb) * 2 - super() - cr: 4 - sqrt: Math.sqrt - collide: (o)@> + @x = (@@screen_x1 + @px + @lr) * 2 + @y = (@@screen_y1 + @py - @tb) * 2 + @drawJSprite() + @cr = 4 + @sqrt = Math.sqrt + @collide = (o)@> { px, py, cr } = o opx = o.px; opy = o.py; ocr = o.cr dx = px - opx @@ -158,9 +188,9 @@ genPage = -> # px = opx + dx * d # @px = px | 0 # @py = py | 0 - - Bubble: Bubble = Sprite - HappyBubble: HappyBubble = class extends Bubble + @ + @Bubble = Bubble = @Sprite + @HappyBubble = HappyBubble = class extends Bubble image: happybubble0 constructor: -> @lr = 4 @@ -175,7 +205,7 @@ genPage = -> return if @dead # if dx * dx * 2 > qd @dead = true - GrumpyBubble: GrumpyBubble = class extends Bubble + @GrumpyBubble = GrumpyBubble = class extends Bubble image: grumpybubble0 constructor: -> @lr = 7 @@ -196,7 +226,7 @@ genPage = -> 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 + @EvilBubble = EvilBubble = class extends Bubble image: evilbubble0 constructor: -> @lr = 15 @@ -231,13 +261,13 @@ genPage = -> o.px = @px o.py = @py + @vy_ @dead = true unless @life > 0 - slowBubbles: @> + @slowBubbles = @> return if @slowedBubbles @slowedBubbles = true - quitSlowBubbles: @> + @quitSlowBubbles = @> return unless @slowedBubbles @slowedBubbles = false - Stilla: Stilla = class extends Bubble + @Stilla = Stilla = class extends Bubble image: stilla0 Bubble: @Bubble constructor: -> @@ -321,7 +351,7 @@ genPage = -> goodnight: (game)@> game.quitSlowBubbles() bumpedInto: (o)@> o.dead = true - oxygenation: oxygenation = + @oxygenation = oxygenation = create: @> oxygen: 0.7; __proto__: @ addFrom: (o)@> (o = o.oxygen)? then @@ -332,7 +362,7 @@ genPage = -> @oxygen = oxygen consume: @> @oxygen *= 0.99999 - Vaquita: Vaquita = class extends Sprite + @Vaquita = Vaquita = class extends @Sprite twist: [ pixyvaquita_twist_l, pixyvaquita_twist_r ] constructor: -> @lr = 16 @@ -347,7 +377,7 @@ genPage = -> @lr = 18 super() bumpedInto: (x)@> @oxygen.addFrom(x) - AiVaquita: AiVaquita = class extends Vaquita + @AiVaquita = AiVaquita = class extends Vaquita constructor: -> @image = pixyvaquita @time = 0 @@ -371,7 +401,7 @@ genPage = -> else if vx * vx + vy * vy > 2 @image = @twist[ @beat_lr++ & 1 ] super() - Vilma: Vilma = class extends Vaquita + @Vilma = Vilma = class extends Vaquita constructor: (@game)-> @image = pixyvaquita @time = 0 @@ -480,7 +510,7 @@ genPage = -> @oxygen.addFrom(x) score <. x @score += score if score? - addVaquita: -> + @addVaquita = -> # n = v.cloneNode() # n.setAttribute "opacity", "0.5" # n.href.baseVal = "#_v105" if Math.random(0) > 0.5 @@ -495,13 +525,13 @@ genPage = -> # v.draw() # vaquita.update() @vaquitas.push v - addStilla: (x, y)@> + @addStilla = (x, y)@> return if @stilla? v = new @Stilla v.px = x v.py = y @stilla = v - addInto: (n, v, x, y)@> + @addInto = (n, v, x, y)@> v.vx = 0 v.vy = 0 v.px = x @@ -512,8 +542,8 @@ genPage = -> else b.push v # v.draw() - constructor: (@vaquitas = [], @cameos = [], @stilla = null)-> - encounters: + @setConstructor (@vaquitas = [], @cameos = [], @stilla = null)-> + @encounters = __proto__: encounter: encounter = add: (game, x, y)@> game.addInto('cameos', new @creature(), x, y) @@ -603,7 +633,7 @@ genPage = -> __proto__: encounter p: (depth)@> depth < 0.01 then 1 else (1-depth)/100000 add: (game, x, y)@> game.addStilla(x, y) - touchInput: + @touchInput = ax: 0 ay: 0 tx: 0 @@ -661,7 +691,7 @@ genPage = -> event.stopPropagation() touchInput[name](event,this) catch err alert err.toString() - ColorPlane: ColorPlane = do-> + @ColorPlane = ColorPlane = do-> document: document init: @> color <. @ @@ -676,7 +706,7 @@ genPage = -> t.fillStyle = @color t.fillRect 0,0,1024,1024 # t.restore() - GenericPlane: GenericPlane = + @GenericPlane = GenericPlane = document: document init: @> document <. @ @@ -685,7 +715,7 @@ genPage = -> e.height = @h @ctx = e.getContext '2d' - ScaledImg: ScaledImg = + @ScaledImg = ScaledImg = document: document zoom: 2 init: @> @@ -712,7 +742,7 @@ genPage = -> retroScaling(ctx) @ctx = ctx.drawImage c0, 0, 0, w, height, 0, 0, w, h - ParallaxPlane: ParallaxPlane = + @ParallaxPlane = ParallaxPlane = __proto__: GenericPlane ParallaxPlaneSuper: GenericPlane lower: null @@ -757,7 +787,7 @@ genPage = -> l.logzoom? then l.abslogzoom ?= @logzoom + l.logzoom l.init(options) @ParallaxPlaneSuper.init.call @, options - BoundParallaxPlane: BoundParallaxPlane = + @BoundParallaxPlane = BoundParallaxPlane = __proto__: ParallaxPlane BoundParallaxPlaneProto: ParallaxPlane pmul: 1 @@ -806,7 +836,7 @@ genPage = -> t.drawImage canvas, -nx, -ny # t.drawImage canvas, 0, 0, w, h, -nx, -ny, w*pmul, h*pmul - SeaFloor: SeaFloor = do-> + @SeaFloor = SeaFloor = do-> __proto__: BoundParallaxPlane SeaFloorProto: BoundParallaxPlane # terror: CuteluTerror = @@ -837,7 +867,7 @@ genPage = -> ctx.fillRect 0, h - 1, w, 1 ctx.fillRect w - 1, 0, 1, h - SeamlessPlane: SeamlessPlane = + @SeamlessPlane = SeamlessPlane = withRect: (rx,ry,rw,rh,cb)@> { w, h } = @ if (ex = rx + rw) > w @@ -857,7 +887,7 @@ genPage = -> cb rx, ry, rw, rh, 0, 0 __proto__: ParallaxPlane - WaterPlane: WaterPlane = do-> + @WaterPlane = WaterPlane = do-> waterscapeSuper: waterscapeSuper = SeamlessPlane __proto__: waterscapeSuper random: Math.random @@ -897,7 +927,7 @@ genPage = -> @waterscapeSuperFrame.apply @, arguments t.restore() logzoom: 0 - textRenderer: textRenderer = + @textRenderer = textRenderer = glyphs: fontglyphs charMap: {"0":{"w":5,"o":509},"1":{"w":3,"o":518},"2":{"w":4,"o":525},"3":{"w":4,"o":533},"4":{"w":4,"o":541},"5":{"w":4,"o":549},"6":{"w":4,"o":557},"7":{"w":3,"o":565},"8":{"w":4,"o":572},"9":{"w":4,"o":580}," ":{"w":2,"o":0},"a":{"w":4,"o":6},"b":{"w":4,"o":14},"c":{"w":4,"o":22},"d":{"w":4,"o":30},"e":{"w":4,"o":38},"f":{"w":2,"o":46},"g":{"w":4,"o":52},"h":{"w":4,"o":60},"i":{"w":2,"o":68},"j":{"w":2,"o":74},"k":{"w":4,"o":80},"l":{"w":2,"o":88},"m":{"w":6,"o":94},"n":{"w":4,"o":104},"o":{"w":4,"o":112},"p":{"w":4,"o":120},"q":{"w":4,"o":128},"r":{"w":3,"o":136},"s":{"w":3,"o":143},"t":{"w":3,"o":150},"u":{"w":4,"o":157},"v":{"w":4,"o":165},"w":{"w":5,"o":173},"x":{"w":3,"o":182},"y":{"w":4,"o":189},"z":{"w":3,"o":197},"ñ":{"w":4,"o":204},"ç":{"w":4,"o":212},"A":{"w":5,"o":220},"B":{"w":4,"o":229},"C":{"w":6,"o":237},"D":{"w":6,"o":247},"E":{"w":4,"o":257},"F":{"w":4,"o":265},"G":{"w":6,"o":273},"H":{"w":6,"o":283},"I":{"w":2,"o":293},"J":{"w":2,"o":299},"K":{"w":5,"o":305},"L":{"w":4,"o":314},"M":{"w":7,"o":322},"N":{"w":6,"o":333},"O":{"w":6,"o":343},"P":{"w":4,"o":353},"Q":{"w":6,"o":361},"R":{"w":5,"o":371},"S":{"w":4,"o":380},"T":{"w":5,"o":388},"U":{"w":6,"o":397},"V":{"w":5,"o":407},"W":{"w":7,"o":416},"X":{"w":5,"o":427},"Y":{"w":5,"o":436},"Z":{"w":5,"o":445},"!":{"w":2,"o":454},"?":{"w":3,"o":460},",":{"w":2,"o":467},".":{"w":2,"o":473},"@":{"w":6,"o":479},"/":{"w":4,"o":489},":":{"w":2,"o":497},";":{"w":2,"o":503},"á":{"w":4,"o":588},"é":{"w":4,"o":596},"í":{"w":2,"o":604},"ó":{"w":4,"o":610},"ú":{"w":4,"o":618},"à":{"w":4,"o":626},"è":{"w":4,"o":634},"ì":{"w":2,"o":642},"ò":{"w":4,"o":648},"ù":{"w":4,"o":656}} lineHeight: 12 @@ -930,7 +960,7 @@ genPage = -> @ctx.drawImage glyphs, o, 0, w + 4, lineHeight, x, y * scale, (w + 4) * scale, lineHeight * scale x += (w + 1) * scale - narrator: do-> + @narrator = do-> first: null last: null say: (t)@> @@ -990,7 +1020,7 @@ genPage = -> first = first.next @first = first if x <= -w __proto__: textRenderer - scoreBox: + @scoreBox = textRenderer: textRenderer score: 0 draw: @> @@ -1012,7 +1042,7 @@ genPage = -> hide: @> { game } = @ delete game.other.scoreBox - waves: + @waves = intro: @> @@ -1067,12 +1097,12 @@ genPage = -> # @waterscapeSuperFrame.apply @, arguments # # t.restore() # logzoom: 0 - seafloor: seafloorPlane = __proto__: SeaFloor - getDepth: @> + @seafloor = seafloorPlane = __proto__: SeaFloor + @getDepth = @> r = @seafloor.fy / @seafloor.mfy r < 0 then 0 else r - resetDepth: @> @seafloor.fy = 0 - waterscape: waterscape = do-> + @resetDepth = @> @seafloor.fy = 0 + @waterscape = waterscape = do-> __proto__: WaterPlane # color: "cyan" # logzoom: 0 @@ -1090,7 +1120,7 @@ genPage = -> # abslogzoom: 2 logzoom: 2 lower: seafloorPlane - bluescape: + @bluescape = __proto__: SeamlessPlane bluescapeSuper: SeamlessPlane lower: waterscape @@ -1144,7 +1174,7 @@ genPage = -> # ctx.fillStyle = "#0099dd" # ctx.fillRect 0, 0, @w, @h - setup: -> + @setup = -> { time, bluescape, radx, rady } = @ @textRenderer.ctx = jaws.context @@ -1204,10 +1234,10 @@ genPage = -> ]) @collisions.setup(radx, rady) - radx: screen_x1 - rady: screen_y1 - rad: screen_x1 * screen_x1 + screen_y1 * screen_y1 - collisions: + @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 @@ -1245,7 +1275,7 @@ genPage = -> clear: @> @b = new @Array(@b.length) # Discrete board for detecting collisions @l = [ ] # List of collisions targets - getPlayTimeText: (dec)@> + @getPlayTimeText = (dec)@> { playTime } = @time s = playTime % 60 playTime = (playTime / 60) | 0 @@ -1254,7 +1284,7 @@ genPage = -> m = m.toString().replace(/^[0-9]$/, ((x)-> "0" + x)) s = s.toFixed(dec).replace(/^[0-9][.]/, ((x)-> "0" + x)) "#{playTime}:#{m}:#{s}".replace(/:([0-9][:.])/g, ((x, y)-> ":0" + y)) - time: + @time = playTime: 0 current: 0 advance: @> @@ -1275,8 +1305,8 @@ genPage = -> p = e @future = events[0] future: null - other: { } - draw: @> + @other = { } + @draw = @> { jaws, radx, rady, vilma, vaquitas, cameos, stilla, rad, collisions } = @ # @addVaquita() if (!(@gameloop.ticks & 0x7f) and vaquitas.length < 1) or jaws.pressed[spaceKey] @@ -1353,11 +1383,11 @@ genPage = -> if (@gameloop.ticks & 0xff) is 0xff fps.innerHTML = "#{@gameloop.fps} fps" - jaws: jaws - window: window - spaceKey: spaceKey - fps: 24 - setupJaws: (Demo)@> + @jaws = jaws + @window = window + @spaceKey = spaceKey + @fps = 24 + @setupJaws = (Demo)@> { jaws, window, fps } = @ if true jaws.init() @@ -1367,6 +1397,7 @@ genPage = -> (game.gameloop = gameloop).start() # else # jaws.start Demo, fps:25 + @ Demo::setupJaws(Demo) # gameFrame = -> reportErrors -> |
