Skip to content

Commit

Permalink
shrunk killzone, reduced physics to 32ms from 16ms
Browse files Browse the repository at this point in the history
  • Loading branch information
Zolmeister committed Feb 16, 2014
1 parent fb30f1d commit 0ed0e7a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 22 deletions.
3 changes: 2 additions & 1 deletion cache.appcache
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
CACHE MANIFEST
#build 1.0.7
#build 1.0.7.1

CACHE:
#NETWORK:
index.html
libs/stats.js
assets/logo.png
Expand Down
4 changes: 2 additions & 2 deletions fish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function Fish(AI, x, y, size, dir, frame) {
this.dir = dir || 0 // radians
this.AI = AI || false
this.targetDir = dir
this.arcSpeed = 0.07
this.arcSpeed = 0.14
this.canv = document.createElement('canvas')
this.circles = Array.apply([], new Array(6)).map(function(cir, i){
return {
Expand Down Expand Up @@ -42,7 +42,7 @@ function Fish(AI, x, y, size, dir, frame) {

this.velocity = [0, 0]
this.accel = [0, 0]
this.maxSpeed = this.AI ? 1 : 3
this.maxSpeed = this.AI ? 2 : 6

}
Fish.prototype.draw = function(outputCtx) {
Expand Down
2 changes: 1 addition & 1 deletion levelballs.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ LevelBalls.prototype.physics = function() {
return cnt === 10
}
LevelBalls.prototype.toParticles = function(target) {
return particalize.call(this, target, this.y, 4, 0.08)
return particalize.call(this, target, this.y, 8, 0.16)
}
LevelBalls.prototype.shift = function() {
this.x += this.width/13 + this.ballRadius
Expand Down
2 changes: 1 addition & 1 deletion levelbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ LevelBar.prototype.resize = function(width, height) {
this.targetX = this.x
}
LevelBar.prototype.toParticles = function(target) {
return particalize.call(this, target, 0, 10, 0.6)
return particalize.call(this, target, 0, 20, 1.2)
}
LevelBar.prototype.addColor = function() {
var color = randColor(this.colors[this.colors.length-1])
Expand Down
63 changes: 48 additions & 15 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,70 @@
"use strict";

function setGlobals() {
$canv = document.createElement('canvas')
window.$canv = document.createElement('canvas')
$canv.width = window.innerWidth
$canv.height = window.innerHeight
document.body.appendChild($canv)
ctx = $canv.getContext('2d')
window.ctx = $canv.getContext('2d')
ctx.lineJoin = 'round'
debug = false // true
window.debug = false // true

// this probably shouldnt be a global...
usingSmallLogo = false
window.usingSmallLogo = false

// window.ext is set by cocoonjs
isMobile = !!window.ext
window.isMobile = !!window.ext
// color pallet // blue l blue l green orange d orange
pallet = [[105,210,231], [167,219,216], [224,228,204], [243,134,48], [250,105,0]]
lastColor = new Color()
GAME = {
window.pallet = [[105,210,231], [167,219,216], [224,228,204], [243,134,48], [250,105,0]]
window.lastColor = new Color()
window.GAME = {
MENU: {
opacity: 1
},
state: 'menu',
firstLoop : true,
bufferLoop: true
}
ASSETS = {loaded: false}
window.ASSETS = {loaded: false}

if(debug){
stats = new Stats()
window.stats = new Stats()
document.body.appendChild(stats.domElement)
}
// game loop
MS_PER_UPDATE = 16
previousTime = 0.0
lag = 0.0
quality = 10
window.MS_PER_UPDATE = 32
window.previousTime = 0.0
window.lag = 0.0
window.quality = 10

// object pool
var poolCnt = 1000
window.objectPool = (function() {
var objects = []
var available = []
var i = poolCnt
while (i-- > 0) {
objects.push({})
available.push(objects.length - 1)
}
return {
create: function() {
if(available.length === 0) {
var i = poolCnt
while (i-- > 0) {
objects.push({})
available.push(objects.length - 1)
}
}

return objects[available.pop()]
},
free: function(object) {
available.push(objects.indexOf(object))
}
}
})()

}

setGlobals()
Expand Down Expand Up @@ -136,6 +167,8 @@ function draw(time) {
ctx.translate(-player.x + $canv.width/2, -player.y + $canv.height/2)
paintEndGameParticles()
paintFish()

if(debug) spawner.debug()
ctx.restore()

drawSoundControl()
Expand Down Expand Up @@ -245,7 +278,7 @@ function draw(time) {
}

// if far enough away from player, remove
if(distance(fish, player) > Math.max($canv.width, $canv.height) * 1.2) {
if(distance(fish, player) > Math.max($canv.width, $canv.height)) {
fish.dead = true
}

Expand Down
4 changes: 2 additions & 2 deletions particle.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ function Particle(x, y, color, targetFish, dir, r, speed, arcSpeed) {
this.target = targetFish
this.dir = dir || 0
this.r = r || 2
this.speed = speed || 4
this.arcSpeed = arcSpeed || 0.2
this.speed = speed || 8
this.arcSpeed = arcSpeed || 0.4
}
Particle.prototype.draw = function(ctx) {
ctx.lineWidth = 2
Expand Down

0 comments on commit 0ed0e7a

Please sign in to comment.