Advertisement
Serafim

Untitled

Oct 30th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace App:Model:
  2.   class AbstractModel
  3.     constructor: (left, top, width, height) ->
  4.       @position = # Координаты игрока x, y
  5.         left:   left
  6.         top:    top
  7.       @size =     # Размеры объекта
  8.         width:  width
  9.         height: height
  10.       @padding =  # Отступы сцены
  11.         h:      @size.width
  12.         v:      @size.height
  13.       @rotate =   # Поворот
  14.         angle:  0 # угол
  15.         top:    0 # точка поворота Y
  16.         left:   0 # точка поворота X
  17.       @delta =
  18.         left:   0 # Дельта слева (при повороте)
  19.         top:    0 # Дельта сверху
  20.  
  21.       @scene = new Boo.Scene(
  22.         @size.width + @padding.h * 2,
  23.         @size.height + @padding.v * 2
  24.       )
  25.  
  26.     draw: (ctx) ->
  27.       @scene.redraw()
  28.       ctx.drawImage @scene.view, @position.left - @padding.h, @position.top - @padding.v
  29.  
  30.  
  31.     add: (cb) ->
  32.       @scene.add (ctx) =>
  33.         #ctx.style color: '#eee'
  34.         #ctx.fillRect 0, 0, @size.width + @padding.h * 2, @size.height + @padding.v * 2
  35.  
  36.         ctx.translate(
  37.           @padding.h + @rotate.left,
  38.           @padding.v + @rotate.top
  39.         )
  40.         ctx.rotate(@degree(@rotate.angle))
  41.         x = -@rotate.left
  42.         y = -@rotate.top
  43.         cb(ctx, x, y)
  44.  
  45.     degree: (rad) ->
  46.       rad * Math.PI / 180
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement