Permalink
Browse files

draw works for ent, but no masks yet. Made bouncy balls use draw

  • Loading branch information...
1 parent 4918d00 commit 835d23ffdd12edc38fcccfd453cee7423454fc0b @vonkow committed Apr 14, 2011
Showing with 63 additions and 66 deletions.
  1. +53 −60 examples/bouncy_balls/game.js
  2. +10 −6 rosewood.js
@@ -32,7 +32,7 @@ var wall=function(type,x,y) {
var ball = function(name, ty, dirX, dirY) {
this.spdMod = 10*Math.random()
- this.base = new rw.Ent(name, ty, 40, 40)
+ this.base = new rw.Ent(name, 'draw', 40, 40)
this.dirX = dirX
this.dirY = dirY
this.hit = false
@@ -41,13 +41,12 @@ var ball = function(name, ty, dirX, dirY) {
;(this.dirX=='r') ? this.base.move(this.spdMod,0) : this.base.move(-this.spdMod,0)
;(this.dirY=='d') ? this.base.move(0,this.spdMod) : this.base.move(0,-this.spdMod)
}
- if (ty=='ball') {
- this.hitMap=[['ball',['rWall','lWall','tWall','bWall','tri','ball'],20,20,20]]
- } else if (ty=='tri') {
- this.hitMap=[['ball',['rWall','lWall','tWall','bWall','tri','ball'],0.001,40,40,40,20,0.001]]
- } else if (ty=='box') {
- this.hitMap=[['ball',['rWall','lWall','tWall','bWall','tri','ball'],0,0,40,40]]
+ this.draw = function(c) {
+ c.beginPath()
+ c.arc(this.base.posX+this.base.width/2,this.base.posY+this.base.height/2,this.base.width/2,0,Math.PI*2,true)
+ c.fill()
}
+ this.hitMap=[['ball',['rWall','lWall','tWall','bWall','tri','ball'],20,20,20]]
this.gotHit = function(by) {
if (this.hit==false) {
switch (by) {
@@ -75,58 +74,52 @@ var ball = function(name, ty, dirX, dirY) {
}
}
function startGame() {
- rw.loadSprites({
- ball: ['sprites/ball.png', 40, 40, 0, 0],
- box: ['sprites/box.png', 40, 40, 0, 0],
- tri: ['sprites/tri.png', 40, 40, 0, 0]
- }, function() {
- rw.init('playarea', {
- x:600,
- y:600,
- FPS:60,
- sequence:['ajax','ents','cols','blit'],
- keys:false,
- mouse:false
- })
- .newEnt(new lagTimer()).base.display(0,16,0).end()
- .newEnt(new wall('tWall',600,10))
- .base.display(0, -10, 0).end()
- .newEnt(new wall('rWall',10,600))
- .base.display(600, 0, 0).end()
- .newEnt(new wall('lWall',10,600))
- .base.display(-10, 0, 0).end()
- .newEnt(new wall('bWall',600,10))
- .base.display(0, 600, 0).end()
- .newEnt(new ball('ball_1', 'ball', 'r', 'd'))
- .base.display(392, 426, 50).end()
- .newEnt(new ball('ball_2', 'ball', 'l', 'd'))
- .base.display(347, 32, 50).end()
- .newEnt(new ball('ball_3', 'ball', 'r', 'u'))
- .base.display(209, 433, 50).end()
- .newEnt(new ball('ball_4', 'box', 'l', 'u'))
- .base.display(65, 145, 50).end()
- .newEnt(new ball('ball_5', 'box', 'r', 'd'))
- .base.display(413, 221, 50).end()
- .newEnt(new ball('ball_6', 'box', 'l', 'd'))
- .base.display(165, 370, 50).end()
- .newEnt(new ball('ball_7', 'tri', 'r', 'u'))
- .base.display(160, 245, 50).end()
- .newEnt(new ball('ball_8', 'tri', 'l', 'u'))
- .base.display(473, 399, 50).end()
- .newEnt(new ball('ball_9', 'tri', 'l', 'u'))
- .base.display(102, 45, 50).end()
- .newEnt(new ball('ball_10', 'ball', 'r', 'd'))
- .base.display(263, 264, 50).end()
- .newEnt(new ball('ball_11', 'ball', 'r', 'd'))
- .base.display(54, 201, 50).end()
- .newEnt(new ball('ball_12', 'ball', 'l', 'd'))
- .base.display(437, 23, 50).end()
- .newEnt(new ball('ball_13', 'box', 'l', 'u'))
- .base.display(56, 451, 50).end()
- .newEnt(new ball('ball_14', 'box', 'r', 'd'))
- .base.display(314, 122, 50).end()
- .newEnt(new ball('ball_15', 'tri', 'r', 'u'))
- .base.display(112, 392, 50).end()
- .start()
+ rw.init('playarea', {
+ x:600,
+ y:600,
+ FPS:60,
+ sequence:['ajax','ents','cols','blit'],
+ keys:false,
+ mouse:false
})
+ .newEnt(new lagTimer()).base.display(0,16,0).end()
+ .newEnt(new wall('tWall',600,10))
+ .base.display(0, -10, 0).end()
+ .newEnt(new wall('rWall',10,600))
+ .base.display(600, 0, 0).end()
+ .newEnt(new wall('lWall',10,600))
+ .base.display(-10, 0, 0).end()
+ .newEnt(new wall('bWall',600,10))
+ .base.display(0, 600, 0).end()
+ .newEnt(new ball('ball_1', 'ball', 'r', 'd'))
+ .base.display(392, 426, 50).end()
+ .newEnt(new ball('ball_2', 'ball', 'l', 'd'))
+ .base.display(347, 32, 50).end()
+ .newEnt(new ball('ball_3', 'ball', 'r', 'u'))
+ .base.display(209, 433, 50).end()
+ .newEnt(new ball('ball_4', 'box', 'l', 'u'))
+ .base.display(65, 145, 50).end()
+ .newEnt(new ball('ball_5', 'box', 'r', 'd'))
+ .base.display(413, 221, 50).end()
+ .newEnt(new ball('ball_6', 'box', 'l', 'd'))
+ .base.display(165, 370, 50).end()
+ .newEnt(new ball('ball_7', 'tri', 'r', 'u'))
+ .base.display(160, 245, 50).end()
+ .newEnt(new ball('ball_8', 'tri', 'l', 'u'))
+ .base.display(473, 399, 50).end()
+ .newEnt(new ball('ball_9', 'tri', 'l', 'u'))
+ .base.display(102, 45, 50).end()
+ .newEnt(new ball('ball_10', 'ball', 'r', 'd'))
+ .base.display(263, 264, 50).end()
+ .newEnt(new ball('ball_11', 'ball', 'r', 'd'))
+ .base.display(54, 201, 50).end()
+ .newEnt(new ball('ball_12', 'ball', 'l', 'd'))
+ .base.display(437, 23, 50).end()
+ .newEnt(new ball('ball_13', 'box', 'l', 'u'))
+ .base.display(56, 451, 50).end()
+ .newEnt(new ball('ball_14', 'box', 'r', 'd'))
+ .base.display(314, 122, 50).end()
+ .newEnt(new ball('ball_15', 'tri', 'r', 'u'))
+ .base.display(112, 392, 50).end()
+ .start()
}
View
@@ -977,13 +977,17 @@
}
} else if (curEnt.sprite=='draw') {
// Add drawing stuff
- board.beginPath()
- board.rect(curEnt.posX, curEnt.posY, curEnt.width, curEnt.height)
- board.clip()
+ //board.beginPath()
+ //board.rect(
+ //curEnt.posX,curEnt.posY,
+ //curEnt.posX+curEnt.width,
+ //curEnt.posY+curEnt.height
+ //)
+ //board.clip()
curEnt.ent.draw(board)
- board.beginPath()
- board.rect(0,0,X,Y)
- board.clip()
+ //board.beginPath()
+ //board.rect(0,0,X,Y)
+ //board.clip()
} else if (curEnt.sprite!='') {
// GET THIS OUT OF THE LOOP!!!!!!!!! PRECALC THAT SHIT!!!
if (curEnt.sprite.indexOf('.')!=-1) {

0 comments on commit 835d23f

Please sign in to comment.