Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by dungeonmaster

Hello,

I'm working on a top-view RTS. I'd like to implement a starcraft1 style minimap. I want to show each entity based on its player color in the minimap.

What do you think the best (fast) approach would look like?

1 decade ago by dungeonmaster

Well, I guess the question was too vague. Anyway I worked out a solution and it seems pretty fast

In the main.js (in tothe ig.Game.extent block)
    showMinimap : function () {
        var drones = this.getEntitiesByType(EntityDrone);
        var ctx = ig.system.context;
        var s = ig.system.scale;
        var x,y,size;
        ctx.save();
        ctx.fillStyle = "#000000";
        ctx.fillRect(this.minimap.x,
                     this.minimap.y,
                     this.minimap.x+this.minimap.size,
                     this.minimap.y+this.minimap.size);
        for (i=0;i<drones.length;i++) {
            x = drones[i].pos.x * s / this.minimap.s +this.minimap.x;
            y = drones[i].pos.y * s / this.minimap.s +this.minimap.y;
            size = drones[i].size.x * s / this.minimap.s;
            ctx.fillStyle = drones[i].color;
            ctx.fillRect(x,y,size,size);
        }
        ctx.restore();
    }

also in main.js
    minimap : {
        size : 128, //128x128px on the screen
        c : 16, // Compression factor, for a square map of 16x128pixel .
        //Absolute positions on the screen
        x: 0, 
        y: 480 - 128
    },

Note: My canvas is 640x480. Out of lazyness, I hardcoded it here.

Screenshot:
http://tinypic.com/r/213rgw7/6
[IMG]http://i48.tinypic.com/213rgw7.jpg[/IMG]

1 decade ago by city41

I did pretty much the same thing. I was about to post very similar code :)

Your game looks pretty cool, any website or demo for it?
Page 1 of 1
« first « previous next › last »