all repos — uStrat @ main

simple turn-based strategy game inspired by uCity, Super Robot Wars, C&C, Fire Emblem

MiniMap.js (raw)

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
82
83
84
85
86
87
88
89
90
91
92
93
// MiniMap.js & uStrat (c) Derek Stevens <nilix@nilfm.cc>
// this file contains the mini-map data, listening, and drawing procedure

window.minimap = {};
minimap.gfx = {};
minimap.gfx.bg = new Image();
minimap.gfx.bg.src = "assets/mapbg/miniMap/miniMapBG.png"
minimap.gfx.cam = new Image();
minimap.gfx.cam.src = "assets/mapbg/miniMap/cameraOverlay.png"

minimap.gfx.ruins = new Image();
minimap.gfx.ruins.src = "assets/mapbg/miniMap/ruins.png"
minimap.gfx.city = new Image();
minimap.gfx.city.src = "assets/mapbg/miniMap/city.png"
minimap.gfx.forest = new Image();
minimap.gfx.forest.src = "assets/mapbg/miniMap/forest.png"
minimap.gfx.mountain = new Image();
minimap.gfx.mountain.src = "assets/mapbg/miniMap/mountain.png"
minimap.gfx.plain = new Image();
minimap.gfx.plain.src = "assets/mapbg/miniMap/plain.png"
minimap.gfx.ocean = new Image();
minimap.gfx.ocean.src = "assets/mapbg/miniMap/ocean.png"
minimap.gfx.p1 = new Image();
minimap.gfx.p1.src = "assets/mapbg/miniMap/p1.png"
minimap.gfx.cpu = new Image();
minimap.gfx.cpu.src = "assets/mapbg/miniMap/cpu.png"
minimap.gfx.p1u = new Image();
minimap.gfx.p1u.src = "assets/mapbg/miniMap/p1u.png"
minimap.gfx.cpuu = new Image();
minimap.gfx.cpuu.src = "assets/mapbg/miniMap/cpuu.png"

minimap.draw = function()
{
  let i, j, sprite;
  screen.drawImage(minimap.gfx.bg, 0, 0);
  for (i = 0; i < map.sz; i++)
  {
    for (j = 0; j < map.sz; j++)
    {
      switch (map.data[i][j].type)
      {
        case "ruins":
          sprite = this.gfx.ruins;
          break;
        case "plain":
          sprite = this.gfx.plain;
          break;
        case "water":
          sprite = this.gfx.ocean;
          break;
        case "mountain":
          sprite = this.gfx.mountain;
          break;
        case "city":
          sprite = this.gfx.city;
          break;
        case "forest":
          sprite = this.gfx.forest;
          break;
      }
      screen.drawImage(sprite, 320/2 - map.sz + 2*i, 180/2 - map.sz + 2*j);
      if (!isEmptyObject(map.data[i][j].structure))
      {
        if (map.data[i][j].structure.name.startsWith("p1"))
        {
          screen.drawImage(this.gfx.p1, 320/2  - map.sz + 2*i, 180/2  - map.sz + 2*j);
        }
        else { screen.drawImage(this.gfx.cpu, 320/2  - map.sz + 2*i, 180/2  - map.sz + 2*j) ; }
      }
      if (!isEmptyObject(map.data[i][j].unit))
      {
        if (map.data[i][j].unit.name.startsWith("p1"))
        {
          screen.drawImage(this.gfx.p1u, 320/2  - map.sz + 2*i, 180/2  - map.sz + 2*j);
        }
        else { screen.drawImage(this.gfx.cpuu, 320/2  - map.sz + 2*i, 180/2  - map.sz + 2*j); }
      }
      if (i >= camera.x && i < camera.x + 20 && j >= camera.y && j < camera.y + 12)
      {
        screen.drawImage(this.gfx.cam, 320/2  - map.sz + 2*i, 180/2  - map.sz + 2*j);
      }
    }
  }
}

minimap.listen = function()
{
  if (controller.start || controller.y || controller.x)
  {
    controller.start = controller.y = controller.x = false;
    gameState.flow = "freeLook";
  }
}