Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace App:Model:
- class AbstractModel
- constructor: (left, top, width, height) ->
- @position = # Координаты игрока x, y
- left: left
- top: top
- @size = # Размеры объекта
- width: width
- height: height
- @padding = # Отступы сцены
- h: @size.width
- v: @size.height
- @rotate = # Поворот
- angle: 0 # угол
- top: 0 # точка поворота Y
- left: 0 # точка поворота X
- @delta =
- left: 0 # Дельта слева (при повороте)
- top: 0 # Дельта сверху
- @scene = new Boo.Scene(
- @size.width + @padding.h * 2,
- @size.height + @padding.v * 2
- )
- draw: (ctx) ->
- @scene.redraw()
- ctx.drawImage @scene.view, @position.left - @padding.h, @position.top - @padding.v
- add: (cb) ->
- @scene.add (ctx) =>
- #ctx.style color: '#eee'
- #ctx.fillRect 0, 0, @size.width + @padding.h * 2, @size.height + @padding.v * 2
- ctx.translate(
- @padding.h + @rotate.left,
- @padding.v + @rotate.top
- )
- ctx.rotate(@degree(@rotate.angle))
- x = -@rotate.left
- y = -@rotate.top
- cb(ctx, x, y)
- degree: (rad) ->
- rad * Math.PI / 180
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement