Skip to content

Instantly share code, notes, and snippets.

@jonbro
Forked from anonymous/readme.txt
Last active August 29, 2015 14:12
Show Gist options
  • Save jonbro/b067916b72951ddfa6e3 to your computer and use it in GitHub Desktop.
Save jonbro/b067916b72951ddfa6e3 to your computer and use it in GitHub Desktop.
Play this game by pasting the script in http://www.???.com/editor.html
Config.title = ['SNUGGLE', 'SHIP']
# Config.isDebuggingMode = true
Config.captureArgs = [0.5, 3, 0.05]
window.initialize = ->
Sound.setSeed 1041
@drums = []
# 'setDrum' and 'setDrumPattern' functions create
# a random drum voice and pattern when no arg is provided
@drums.push Game.newSound().setDrum().setDrumPattern() for i in [1..8]
window.begin = ->
drum.playPattern() for drum in @drums
Game.stage = 0
new Ship
# 'Game.newFiber' function creates a fiber assigned to this game
new Star for i in [1..30]
Game.newFiber()
.doOnce ->
Game.stage++
# 'Game.getDifficulty' function returns the number
# represents the difficulty increasing with the time passed
# 1 (game starts) -> 2 (about 3 minutes passed) ->
ev = (0.004.rr 0.008) * Game.getDifficulty()
for y in [1..9]
new Enemy -y * 0.1, ev
# repeat until '@next' function is called
.doRepeat ->
# 'Actor.s' function returns all actors of
# the class specifiled at the argument
@next() if (Actor.s Enemy).length == 0
window.update = ->
Actor.scroll Star, 0, 0.002, 0, 0, 0, 1
if G.ib && G.t == 0
G.nt '[ARROWS] MOVE'
.xy .1, .1
.d 250
.al
.so
if G.ib && G.t == 250
G.nt 'CATCH GREENS WITH GREEN'
.xy .1, .1
.d 250
.al
.so
class Enemy extends Actor
begin: (y, vy) ->
@drawing
.setColor Color.green
.addRects 0.02, 0.02
.addRects 0.02, 0.02
# 'A.rr B' creates a random number from A to B
@pos.setXy (0.1.rr 0.7), y
@vel.y = vy
@way = 0
update: ->
@way += 7
@remove() if @pos.y > 1
class Star extends Actor
# 'initialize' function is called only once when
# the first actor is created
initialize: ->
# the actor has the lower display priority number is
# displayed below actors have the higher number
# 0 (particle) -> 1 (default number for an actor) -> 2 (text)
@setDisplayPriority 0.5
begin: ->
@drawing
# 'addRect' add a square when the second argument is skipped
.addRect 0.01
@pos.setXy (0.rr 1), (0.rr 1)
class E2 extends A
begin: (x, y) ->
@drawing
.setColor Color.red
.addRect 0.02, 0.02, 0,0
@vel.y = -0.01
@pos.xy x,y
update: ->
@vel.y += 0.0001
@remove() if @pos.y > 1
# the bits of the ship that destroy the ship when they are touched
class ShipSides extends Actor
begin: (parent, offset) ->
@minsize = 0.02
@currentSize = 1
@drawing
.setColor Color.red
.addRect 0.02, 0.03, 0, 0
@parent = parent
@offset = offset
grow: ->
@currentSize*=1.1
@drawing.sc @currentSize, 1
new E2 @p.x, @p.y-0.05
shrink: ->
@newParticle()
.setXy @pos.x, @pos.y
.setColor Color.red
# set the number of particles emitted
.setNumber 3
# 'setWay' args:
# center angle (degree, clockwise), scattering angle
.setWay 0, 30
.setSpeed 0.03
# set the duration until the particle disappears
.setDuration 3
@currentSize *= 0.9
@currentSize = max 1, @currentSize
@drawing.sc @currentSize, 1
update: ->
if @onCollision E2, ((e) -> e.remove())
@shrink()
if @onCollision Enemy
@parent.destroy
# move to the parent position + the offset provided
@p.xy @parent.p.x + @offset.x, @parent.p.y + @offset.y
if @onCollision Enemy
@parent.destroy()
# characters in the game is called actor
# class of actor should be extended from 'Actor' class
class Ship extends Actor
# 'begin' function is called once when the actor is created
begin: ->
# 'addRect' to '@drawing' for creating the actor's shape
@drawing
.setColor Color.green
# 'addRect' args: width, height, offsetX, offsetY
.addRect 0.05, 0.05, 0, -0.01
.setColor Color.red
@p.xy .5, .9
Ship.destroySe = @newSound().setVolume(3).setDrum()
Ship.shotSe = @newSound().setDrum(10)
offset = 0.06
@sideL = new ShipSides this, new Vector().xy offset, 0
@sideR = new ShipSides this, new Vector().xy -offset, 0
destroy: ->
@newParticle()
.setColor Color.red
.setSize 0.1
.setNumber 20
.setSpeed 0.05
Ship.destroySe.playNow()
@remove()
Game.end();
@sideL.remove()
@sideR.remove()
# 'update' function is called every frame
update: ->
# get score for catching an enemy
if @onCollision E2
@destroy()
if Game.isBeginning && @onCollision Enemy, ((enemy) -> enemy.remove())
Ship.shotSe.playNow()
score = Game.stage
@newText "+#{score}"
.setVelocity 0, -0.05
.setDuration 20
Game.score += score
@sideL.grow()
@sideR.grow()
@newParticle()
.setXy @pos.x, @pos.y
.setColor Color.green
# set the number of particles emitted
.setNumber 3
# 'setWay' args:
# center angle (degree, clockwise), scattering angle
.setWay 0, 30
.setSpeed 0.03
# set the duration until the particle disappears
.setDuration 3
# '@pos' represents the position of the actor
# 'Mouse.pos' is the position of the mouse cursor
ma = 0.007
if Key.ip[37]
@p.x += -ma
if Key.ip[39]
@p.x += ma
if Key.ip[38]
@p.y += -ma
if Key.ip[40]
@p.y += ma
# velocity based movement
###
if Key.ip[37]
@vel.x = -0.009
else if Key.ip[39]
@vel.x = 0.009
else
@vel.x *= 0.7
if Key.ip[38]
@vel.y = -0.009
else if Key.ip[40]
@vel.y = 0.009
else
@vel.y *= 0.7
###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment