Permalink
Browse files

Add beginning of level1 boss

  • Loading branch information...
1 parent c4cbb5b commit e1a1ef81e4b2319c72635a88ef38989d85f123e5 Daniel Mark Schwartz committed Nov 25, 2012
Showing with 39 additions and 2 deletions.
  1. BIN buddha1.png
  2. +39 −2 game.coffee
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1,3 +1,6 @@
+Number.prototype.clamp = (min, max) ->
+ Math.min (Math.max this, min), max
+
randInRange = (l, h) ->
l + Math.random() * (h - l)
@@ -38,8 +41,10 @@ shipImage2.src = 'monk_2.png'
enemyImage = new Image
enemyImage.src = 'enemy.gif'
-#Photo credit: Christopher Chan / Foter / CC BY-NC-ND
+#buddha1 = http://www.flickr.com/photos/27234114@N03/3200712567/sizes/o/
+#title_monk = Photo credit: Christopher Chan / Foter / CC BY-NC-ND
imgs =
+ buddha1: 'buddha1.png'
wheel: 'wheel.png'
eye: 'eye.png'
title_monk: 'title_monk.png'
@@ -273,6 +278,30 @@ moveStraightGravity = (dx=0, dy=50, g=200) ->
dy += dt*g
[x + dx * dt, y + dy * dt]
+moveRandom = () ->
+ t = 0
+ dx = randInRange -50, 50
+ dy = randInRange -50, 50
+ dur =randInRange .2, 2
+ (x, y, dt) ->
+ t += dt
+ if t > dur
+ dx = randInRange -50, 50
+ dy = randInRange -50, 50
+ dur =randInRange .2, 2
+ t = 0
+
+ [x,y] = [x + dx * dt, y + dy * dt]
+ if not (50 < x < atom.width-50)
+ x.clamp 50, atom.width-50
+ dx = -dx
+
+ if not (50 < y < atom.height-100)
+ y.clamp 50, atom.height-100
+ dy = -dy
+
+ [x,y]
+
bulletStraight = (dx=0, dy=100) ->
{image: bulletImage, move: moveStraight dx, dy}
@@ -330,6 +359,13 @@ enemy =
bullet: [(dt, s, e) -> bulletDirect s, e]
animate: new Animation enemyImage
health: 1250
+
+ buddha1: () ->
+ move: moveRandom()
+ fire: fireEvery 1
+ bullet: [(dt, s, e) -> bulletDirect s, e]
+ animate: new Animation atom.images.buddha1
+ health: 100000
class Enemy
@@ -682,7 +718,8 @@ level1 = [
{wait: .5},
{from: 200, to: 100, step: -20, wait: .75, do: (s, x) -> s.spawnEnemy x, 10, (enemy.fan 50)},
{waitUntil: (s) -> s.enemies.length <= 0},
- {wait: 1},
+ {wait: 5},
+ {do: (s) -> s.spawnEnemy atom.width/2, 150, enemy.buddha1()},
#{changeScene: true}
]

0 comments on commit e1a1ef8

Please sign in to comment.