Better randomized orders. Better styled code.

This commit is contained in:
SHIYING 2014-01-12 12:59:51 -05:00
parent 524b2318f8
commit b6c499db72
2 changed files with 3 additions and 10 deletions

View file

@ -34,12 +34,6 @@ class Rand
# return an array of numbers from 0 to n-1, shuffled
randArray: (n) =>
array = ( i for i in [0..(n-1)] )
for i in [0..(n-1)]
r = @rand n
[ array[i], array[r] ] = [ array[r], array[i] ]
array
_.shuffle [0...n]
module.exports = Rand

View file

@ -5,7 +5,7 @@ Rand = require './rand'
module.exports = class Thang
@className: "Thang"
@random = new Rand 0
@random = new Rand
# Random ordering for each sprite name
@ordering: (spriteName) ->
@ -14,7 +14,7 @@ module.exports = class Thang
if names
len = names.length
array = Thang.orders[spriteName]
if not array?
unless array?
array = @random.randArray len
Thang.orders[spriteName] = array
else
@ -29,7 +29,6 @@ module.exports = class Thang
lastIDNum = Thang.lastIDNums[spriteName]
idNum = (if lastIDNum? then lastIDNum + 1 else 0)
Thang.lastIDNums[spriteName] = idNum
console.log order
id = names[order[idNum % names.length]]
if idNum >= names.length
id += Math.floor(idNum / names.length) + 1