Created
June 24, 2016 00:29
-
-
Save djfumberger/de79d01feb8c0900fa783df2f5da905c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l = new BackgroundLayer | |
racerScale = 1.5 | |
class SpeedLayer extends Layer | |
constructor:(args) -> | |
super args | |
@.direction = args.direction | |
@.yOffset = args.yOffset | |
@.preventCopy = true | |
class SpeedDancer extends Layer | |
constructor:(args) -> | |
super args | |
@.backgroundColor = "null" | |
if args.dancerOne | |
@.dancer = new Layer | |
width: 52 / racerScale | |
height: 80 / racerScale | |
superLayer: @ | |
image: "images/dancer.png" | |
else if args.dancerTwo | |
@.dancer = new Layer | |
width: 82 / racerScale | |
height: 84 / racerScale | |
superLayer: @ | |
image: "images/double-dancer.png" | |
@.increment = 0 | |
@.preventCopy = true | |
setInterval((=> @.alternate()), 175) | |
alternate:() -> | |
@.increment++ | |
if @.increment == 0 | |
@.flip() | |
else if @.increment == 1 | |
@.restore() | |
else if @.increment == 2 | |
@.flip() | |
else if @.increment == 3 | |
@.flip() | |
if @.increment > 4 | |
@.increment = 0 | |
flip:() -> | |
@.dancer.rotationY = 180 | |
restore:() -> | |
@.dancer.rotationY = 0 | |
class SpeedWalker extends Layer | |
constructor:(args) -> | |
super args | |
@.backgroundColor = null | |
@.preventCopy = true | |
@.walker = new Layer | |
width: 38 / racerScale | |
height: 78 / racerScale | |
visible: false | |
superLayer: @ | |
image: "images/walker.png" | |
@.runner = new Layer | |
width: 62 / racerScale | |
height: 76 / racerScale | |
visible: true | |
x: -5 | |
y: 2 | |
superLayer: @ | |
image: "images/runner.png" | |
@.show = true | |
setInterval((=> @.alternate()), 200) | |
setup:() -> | |
@.walker.visible = false | |
@.runner.visible = true | |
@.show = false | |
alternate:() -> | |
@.show = [email protected] | |
if @.show | |
@.walker.visible = false | |
@.runner.visible = true | |
else | |
@.walker.visible = true | |
@.runner.visible = false | |
class SpeedRacerCyclist extends Layer | |
constructor:(args) -> | |
super args | |
@.backgroundColor = null | |
@.width = 84 / racerScale | |
@.height = 80 / racerScale | |
@.image = "images/racer.png" | |
@.puff() | |
puff:() -> | |
@.smoke = new Layer | |
width: 76 | |
height: 52 | |
x: -30 | |
y: 14 | |
superLayer: @ | |
scale: 0.0 | |
image: "images/cloud.png" | |
@.smoke.animate | |
time: 1.0 | |
properties: | |
scale: 0.6 | |
@.smoke.animate | |
time: 4.0 | |
properties: | |
x: -160 | |
y: 0 | |
opacity: 0.0 | |
class SpeedRacerBackground extends Layer | |
constructor:(options) -> | |
super options | |
@.backgroundColor = null | |
@.items = options.items | |
@.speed = options.speed | |
@.time = options.time | |
@.cycle = options.cycle | |
@.direction = options.direction | |
@.randomTime = options.randomTime | |
@.index = 0 | |
for i in @.items | |
i.superLayer = @ | |
i.visible = false | |
#setTimeout((=> @.newItem()), (@.time + Utils.randomNumber(@.randomTime)) * 1000) | |
newItem:() -> | |
l = Utils.randomChoice(@.items) | |
if @.cycle | |
l = @.items[@.index] | |
@.index++ | |
@.index = 0 if @.index >= @.items.length | |
if not l.preventCopy | |
l = l.copy(true) | |
l.x = @.width | |
l.y = (@.height - l.height) | |
if l.yOffset | |
l.y += l.yOffset | |
l.visible = true | |
l.superLayer = @ | |
toX = -(l.width + 20) | |
if @.direction == 1 || l.direction == 1 | |
l.x = -l.width | |
toX = @.width + 20 | |
a = new Animation | |
layer: l | |
curve: "linear" | |
time: @.speed | |
properties: | |
x: toX | |
a.start() | |
l.on Events.AnimationEnd, (animation, layer) -> | |
if not layer.preventCopy | |
layer.destroy() | |
setTimeout((=> @.newItem()), (@.time + Utils.randomNumber(@.randomTime)) * 1000) | |
class module.exports extends Layer | |
constructor:(options) -> | |
super options | |
@.backgroundColor = null | |
sceneWidth = Screen.width | |
@.background = new SpeedRacerBackground | |
x: (Screen.width - sceneWidth) / 2.0 | |
y: -45 | |
width: sceneWidth | |
clip: true | |
height: 80 | |
speed: 5.0 | |
time: 1.0 | |
superLayer: @ | |
randomTime: 3.0 | |
items: [new Layer | |
width: 76 / racerScale | |
height: 76 / racerScale | |
image: "images/building-1.png", | |
new Layer | |
width: 76 / racerScale | |
height: 76 / racerScale | |
image: "images/building-2.png" | |
new Layer | |
width: 76 / racerScale | |
height: 66 / racerScale | |
image: "images/building-3.png" | |
new Layer | |
width: 76 / racerScale | |
height: 80 / racerScale | |
image: "images/building-4.png" | |
new Layer | |
width: 76 / racerScale | |
height: 76 / racerScale | |
image: "images/building-5.png" | |
new Layer | |
width: 76 / racerScale | |
height: 76 / racerScale | |
image: "images/building-6.png" | |
new Layer | |
width: 76 / racerScale | |
height: 76 / racerScale | |
image: "images/building-7.png" | |
new Layer | |
width: 76 / racerScale | |
height: 76 / racerScale | |
image: "images/building-8.png" | |
new Layer | |
width: 80 / racerScale | |
height: 78 / racerScale | |
image: "images/building-9.png" | |
new Layer | |
width: 76 / racerScale | |
height: 76 / racerScale | |
image: "images/building-10.png" | |
new Layer | |
width: 60 / racerScale | |
height: 66 / racerScale | |
image: "images/building-11.png" | |
new Layer | |
width: 84 / racerScale | |
height: 84 / racerScale | |
image: "images/building-12.png" | |
new Layer | |
width: 76 / racerScale | |
height: 80 / racerScale | |
image: "images/building-13.png" | |
new Layer | |
width: 84 / racerScale | |
height: 68 / racerScale | |
image: "images/building-14.png"] | |
superLayer: @ | |
@.cyclist = new SpeedRacerCyclist | |
width: 84 | |
height: 80 | |
y: 10 | |
superLayer: @ | |
@.runner = new SpeedRacerBackground | |
x: (Screen.width - sceneWidth) / 2.0 | |
y: 20 | |
width: sceneWidth | |
clip: true | |
height: 90 | |
speed: 20.0 | |
time: 25.0 | |
direction: 0 | |
randomTime: 0.5 | |
cycle: true | |
items: [new SpeedWalker | |
width: 38 | |
height:78, | |
new SpeedDancer | |
dancerOne: true | |
width: 38 | |
height: 90, | |
new SpeedDancer | |
dancerTwo: true | |
width: 38 | |
height: 90, | |
new SpeedLayer | |
width: 84 / 1.25 | |
height: 74 / 1.25 | |
yOffset: -26 | |
direction: 1 | |
image: "images/horse.png", | |
new SpeedLayer | |
width: 84 | |
height: 74 | |
image: "images/boat.png" | |
yOffset: -25 | |
direction: 1 | |
] | |
superLayer: @ | |
@.foreground = new SpeedRacerBackground | |
x: (Screen.width - sceneWidth) / 2.0 | |
y: 0 | |
width: sceneWidth | |
clip: true | |
height: 100 | |
speed: 3.5 | |
time: 3.0 | |
randomTime: 0.5 | |
items: [new Layer | |
width: 78 | |
height: 78 | |
image: "images/tree-1.png" | |
new Layer | |
width: 74 | |
height: 82 | |
image: "images/tree-2.png" | |
new Layer | |
width: 64 | |
height: 84 | |
image: "images/tree-3.png" | |
new Layer | |
width: 68 | |
height: 80 | |
image: "images/tree-4.png" | |
] | |
superLayer: @ | |
willAppear:() -> | |
setTimeout((=> @.background.newItem()), 1000) | |
setTimeout((=> @.foreground.newItem()), 2500) | |
setTimeout((=> @.runner.newItem()), 6500) | |
setInterval((=> @.foreground.bringToFront()), 500) | |
@.cyclist.animate | |
time: 6.0 | |
properties: | |
x: Screen.width / 2.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment