1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//---------------------카메라.js
forEachVisible function(callback, extra) {
    var extra = extra || 0;
 
    for(var y = this.gridY - extra; y < this.gridY + this.gridH + (extra * 2); ++y) {
        for(var x = this.gridX - extra; x < this.gridX + this.gridW + (extra * 2); ++x) {
            callback(x, y);
        }
    }
},
//--------------------------게임.js
forEachVisibleTileIndex: function(callback, extra) {
    var m = this.map;
 
    this.camera.forEachVisiblePosition(function(x, y) {
        if(!m.isOutOfBounds(x, y)) {
            callback(m.gridPositionToTileIndex(x, y) -1);
        }
    }, extra);
},
 
forEachVisibleTile: function(callback, extra) {
    var self = this;
    var m = this.map;
 
    if(m.isLoaded) {
        this.forEachVisibleTileIndex(function(tileIndex) {
            if(_.isArray(m.data[tileIndex])) {
                _.each(m.data[tileIndex], function(id) {
                    callback(id -1, tileIndex);
                });
            } else {
                if(!_.isNaN(m.data[tileIndex] -1)) {
                    callback(m.data[tileIndex] -1, tileIndex);
                }
            }
 
        }, extra);
    }
},
 
// -------------------------------------렌더러.js
drawTerrain: function() {
    var self = this;
    var m = this.game.map;
    var tilesetwidth = this.tileset.width / m.tilesize;
 
    this.game.forEachVisibleTile((function(id, index) {
        if(!m.isHighTile(id) && !m.isAnimatedTile(id)) {
            self.drawTile(
                self.background,
                id,            // 타일 아이디 0 ~
                self.tileset,
                tilesetwidth,  // 타일 한 개당 넓이 / 맵 넓이 => 32 / 640 => 20
                m.width,      // 맵 넓이 => (640px)
                index          // 캔버스 타일 인덱스 1 ~
            );
        }
    }),1);
},
 
 
//--------------------------------------------애니메이션.js
initAnimatedTiles: function() {
    var self = this;
    var m = this.map;
 
    this.animatedTiles = [];
    this.forEachVisibleTile(function(id, index) {
        if(m.isAnimatedTile(id)) {
            var tile
             = new AnimatedTile(id, m.getTileAnimationLength(id), m.getTileAnimationDelay(id), index);
            var pos = m.tileIndexToGridPosition(tile.index);
 
            tile.x = pos.x;
            tile.y = pos.y;
            self.animatedTiles.push(tile);
        }
    }, 1);
},
 
cs

하루지나면 까먹음