Commits

Laurens Rodriguez  committed 3c0acf4

Minecraft4k demo rendering correctly.

  • Participants
  • Parent commits ffd4153

Comments (0)

Files changed (4)

File bin/windows/game/conf.kia

 
 public function love.conf(t) {
     t.title = ""                // The title of the window the game is in (string)
-    t.author = "Laurens R. O."  // The author of the game (string)
+    t.author = "Laurens R."     // The author of the game (string)
     t.identity = "ex_demos"     // The name of the save directory (string)
     t.version = "0.8.0"         // The L0VE version this game was made for (number)
-    t.main = "main"             // The main script to load (without kia extension)
+    t.main = "minecraft4k"      // The main script to load (without kia extension)
     t.console = false           // Attach a console (boolean, Windows only)
     t.screen.width = 640        // The window width (number)
     t.screen.height = 480       // The window height (number)

File bin/windows/game/filelist.kia

 function love.draw() {
     love.graphics.print(filesString, 0, 0)
 }
+
+
+function love.keypressed(key, unicode) {
+    if (key == "escape") {
+        love.event.push("quit")
+    }
+}

File bin/windows/game/minecraft4k.kia

-
-var canvas;
-
-var w = 240 * 2;
-var h = 160 * 2;
-
-var map = [];
-var texmap = [];
-
-function init() {
-    for (var i = 1; i < 16; i += 1) {
-        var br = 255 - ((Math.random() * 96) | 0);
-        for (var y = 0; y < 16 * 3; y += 1) {
-            for (var x = 0; x < 16; x += 1) {
-                var color = 0x966C4A;
-                if (i == 4) {
-                    color = 0x7F7F7F;
-                }
-                if (i != 4 || ((Math.random() * 3) | 0) == 0) {
-                    br = 255 - ((Math.random() * 96) | 0);
-                }
-                if ((i == 1 && y < (((x * x * 3 + x * 81) >> 2) & 3) + 18)) {
-                    color = 0x6AAA40;
-                } else if ((i == 1 && y < (((x * x * 3 + x * 81) >> 2) & 3) + 19)) {
-                    br = br * 2 / 3;
-                }
-                if (i == 7) {
-                    color = 0x675231;
-                    if (x > 0 && x < 15 && ((y > 0 && y < 15) || (y > 32 && y < 47))) {
-                        color = 0xBC9862;
-                        var xd = (x - 7);
-                        var yd = ((y & 15) - 7);
-                        if (xd < 0) {
-                            xd = 1 - xd;
-                        }
-                        if (yd < 0) {
-                            yd = 1 - yd;
-                        }
-                        if (yd > xd) {
-                            xd = yd;
-                        }
-                        br = 196 - ((Math.random() * 32) | 0) + xd % 3 * 32;
-                    }
-                    else if (((Math.random() * 2) | 0) == 0) {
-                        br = br * (150 - (x & 1) * 100) / 100;
-                    }
-                }
-
-                if (i == 5) {
-                    color = 0xB53A15;
-                    if ((x + (y >> 2) * 4) % 8 == 0 || y % 4 == 0) {
-                        color = 0xBCAFA5;
-                    }
-                }
-                if (i == 9) {
-                    color = 0x4040ff;
-                }
-                var brr = br;
-                if (y >= 32) {
-                    brr /= 2;
-                }
-
-                if (i == 8) {
-                    color = 0x50D937;
-                    if (((Math.random() * 2) | 0) == 0) {
-                        color = 0;
-                        brr = 255;
-                    }
-                }
-
-                var col = (((color >> 16) & 0xff) * brr / 255) << 16
-                        | (((color >> 8) & 0xff) * brr / 255) << 8
-                        | (((color) & 0xff) * brr / 255);
-                texmap[x + y * 16 + i * 256 * 3] = col;
-            }
-        }
-    }
-
-    for (var x = 0; x < 64; x += 1) {
-        for (var y = 0; y < 64; y += 1) {
-            for (var z = 0; z < 64; z += 1) {
-                var i = z << 12 | y << 6 | x;
-                var yd = (y - 32.5) * 0.4;
-                var zd = (z - 32.5) * 0.4;
-                map[i] = (Math.random() * 16) | 0;
-                if (Math.random() > Math.sqrt(Math.sqrt(yd * yd + zd * zd)) - 0.8) {
-                    map[i] = 0;
-                }
-            }
-        }
-    }
-};
-
-var f = 0;
-function renderMinecraft() {
-    var dateNow = Math.floor(1000 * love.timer.getTime());
-    var xRot = Math.sin(dateNow % 10000 / 10000 * global.Math.pi * 2) * 0.1 + global.Math.pi / 2;
-    var yRot = Math.cos(dateNow % 10000 / 10000 * global.Math.pi * 2) * 0.1;
-    var yCos = Math.cos(yRot);
-    var ySin = Math.sin(yRot);
-    var xCos = Math.cos(xRot);
-    var xSin = Math.sin(xRot);
-
-    var ox = 32.5 + dateNow % 10000 / 10000 * 8;
-    var oy = 32.5;
-    var oz = 32.5;
-
-    f += 1;
-    for (var x = 0; x < w; x += 1) {
-        var ___xd = (x - w / 2) / h;
-        for (var y = 0; y < h; y += 1) {
-            var __yd = (y - h / 2) / h;
-            var __zd = 1;
-
-            var ___zd = __zd * yCos + __yd * ySin;
-            var _yd = __yd * yCos - __zd * ySin;
-
-            var _xd = ___xd * xCos + ___zd * xSin;
-            var _zd = ___zd * xCos - ___xd * xSin;
-
-            var col = 0;
-            var br = 255;
-            var ddist = 0;
-
-            var closest = 32;
-            for (var d = 0; d < 3; d += 1) {
-                var dimLength = _xd;
-                if (d == 1) {
-                    dimLength = _yd;
-                }
-                if (d == 2) {
-                    dimLength = _zd;
-                }
-
-                var ll = (1 / (dimLength < 0)? -dimLength : dimLength);
-                var xd = (_xd) * ll;
-                var yd = (_yd) * ll;
-                var zd = (_zd) * ll;
-
-                var initial = 0;
-                if (d == 1) {
-                    initial = 0;
-                }
-                if (d == 2) {
-                    initial = 0;
-                }
-                if (dimLength > 0) {
-                    initial = 1 - initial;
-                }
-
-                var dist = ll * initial;
-
-                var xp = ox + xd * initial;
-                var yp = oy + yd * initial;
-                var zp = oz + zd * initial;
-
-                if (dimLength < 0) {
-                    if (d == 0) {
-                        xp -= 1;
-                    }
-                    if (d == 1) {
-                        yp -= 1;
-                    }
-                    if (d == 2) {
-                        zp -= 1;
-                    }
-                }
-
-                while (dist < closest) {
-                    var tex = map[(zp & 63) << 12 | (yp & 63) << 6 | (xp & 63)];
-
-                    if (tex > 0) {
-                        var u = ((xp + zp) * 16) & 15;
-                        var v = ((yp * 16) & 15) + 16;
-                        if (d == 1) {
-                            u = (xp * 16) & 15;
-                            v = ((zp * 16) & 15);
-                            if (yd < 0) {
-                                v += 32;
-                            }
-                        }
-
-                        var cc = texmap[u + v * 16 + tex * 256 * 3];
-                        if (cc && cc > 0) {
-                            col = cc;
-                            ddist = 255 - ((dist / 32 * 255) | 0);
-                            br = 255 * (255 - ((d + 2) % 3) * 50) / 255;
-                            closest = dist;
-                        }
-                    }
-                    xp += xd;
-                    yp += yd;
-                    zp += zd;
-                    dist += ll;
-                }
-            }
-
-            var r = ((col >> 16) & 0xff) * br * ddist / (255 * 255);
-            var g = ((col >> 8) & 0xff) * br * ddist / (255 * 255);
-            var b = ((col) & 0xff) * br * ddist / (255 * 255);
-
-            love.graphics.setColor(r, g, b);
-            love.graphics.point(x, y);
-        }
-    }
-}
-
-function love.load() {
-    love.graphics.setCaption("Minecraft4k: " .. global._VERSION);
-    love.graphics.setPoint(1, "rough");
-    // Set window size
-    assert(love.graphics.setMode(w, h, false, true, 0),
-           "Could not set screen mode")
-    canvas = love.graphics.newCanvas(w, h);
-    init();
-}
-
-function love.draw() {
-    love.graphics.setCanvas(canvas);
-    renderMinecraft();
-    love.graphics.setCanvas();
-    love.graphics.setColor(255, 255, 255);
-    love.graphics.draw(canvas, 0, 0);
-}
-
-function love.keypressed(key, unicode) {
-    if (key == "escape") {
-        love.event.push("quit")
-    }
-}
-
+
+// Ported from Flash version: http://wonderfl.net/c/sqL5/read
+// Ported from Notch's JavaScript version: http://jsdo.it/notch/dB1E
+
+var canvas;
+var w = 200;
+var h = 200;
+
+//private var bmd:BitmapData = new BitmapData(w, h, false, 0);
+//private var bmp:Bitmap = new Bitmap(bmd);
+
+var map = []; //var map:Vector.<int> = new Vector.<int>(64 * 64 * 64, true);
+var texmap = []; //var texmap:Vector.<int> = new Vector.<int>(16 * 16 * 3 * 16, true);
+
+function init() {
+    // Init textmap
+    for (var i = 1; i < 16; i += 1) {
+        var br = 255 - ((Math.random() * 96) | 0);
+        for (var y = 0; y < 16 * 3; y += 1) {
+            for (var x = 0; x < 16; x += 1) {
+                var color = 0x966C4A;
+                if (i == 4) {
+                    color = 0x7F7F7F;
+                }
+                if (i != 4 || ((Math.random() * 3) | 0) == 0) {
+                    br = 255 - ((Math.random() * 96) | 0);
+                }
+                if ((i == 1 && y < (((x * x * 3 + x * 81) >> 2) & 3) + 18)) {
+                    color = 0x6AAA40;
+                }
+                else if ((i == 1 && y < (((x * x * 3 + x * 81) >> 2) & 3) + 19)) {
+                    br = Math.floor(br * 2 / 3);
+                }
+                if (i == 7) {
+                    color = 0x675231;
+                    if (x > 0 && x < 15 && ((y > 0 && y < 15) || (y > 32 && y < 47))) {
+                        color = 0xBC9862;
+                        var xd = (x - 7);
+                        var yd = ((y & 15) - 7);
+                        if (xd < 0) {
+                            xd = 1 - xd;
+                        }
+                        if (yd < 0) {
+                            yd = 1 - yd;
+                        }
+                        if (yd > xd) {
+                            xd = yd;
+                        }
+                        br = 196 - ((Math.random() * 32) | 0) + xd % 3 * 32;
+
+                    }
+                    else if (((Math.random() * 2) | 0) == 0) {
+                        br = br * (150 - (x & 1) * 100) / 100;
+                    }
+                }
+
+                if (i == 5) {
+                    color = 0xB53A15;
+                    if ((x + (y >> 2) * 4) % 8 == 0 || y % 4 == 0) {
+                        color = 0xBCAFA5;
+                    }
+                }
+                if (i == 9) {
+                    color = 0x4040ff;
+                }
+                var brr = br;
+                if (y >= 32) {
+                    brr = Math.floor(brr / 2);
+                }
+
+                if (i == 8) {
+                    color = 0x50D937;
+                    if (((Math.random() * 2) | 0) == 0) {
+                        color = 0;
+                        brr = 255;
+                    }
+                }
+
+                var col = (((color >> 16) & 0xff) * brr / 255) << 16
+                                | (((color >> 8) & 0xff) * brr / 255) << 8
+                                | (((color) & 0xff) * brr / 255);
+                texmap[x + y * 16 + i * 256 * 3] = col;
+            }
+        }
+    }
+
+    // Init map
+    for (var x = 0; x < 64; x += 1) {
+        for (var y = 0; y < 64; y += 1) {
+            for (var z = 0; z < 64; z += 1) {
+                var i = z << 12 | y << 6 | x;
+                var yd = (y - 32.5) * 0.4;
+                var zd = (z - 32.5) * 0.4;
+                map[i] = (Math.random() * 16) | 0;
+                if (Math.random() > Math.sqrt(Math.sqrt(yd * yd + zd * zd)) - 0.8) {
+                    map[i] = 0;
+                }
+            }
+        }
+    }
+}
+
+var f = 0;
+
+function renderMinecraft() {
+
+	var timeNow = 1000 * love.timer.getTime();
+
+    var xRot = Math.sin(timeNow % 10000 / 10000 * global.Math.PI * 2) * 0.4 + global.Math.PI / 2;
+    var yRot = Math.cos(timeNow % 10000 / 10000 * global.Math.PI * 2) * 0.4;
+    var yCos = Math.cos(yRot);
+    var ySin = Math.sin(yRot);
+    var xCos = Math.cos(xRot);
+    var xSin = Math.sin(xRot);
+
+    var ox = 32.5 + timeNow % 10000 / 10000 * 64;
+    var oy = 32.5;
+    var oz = 32.5;
+
+    f += 1;
+
+    for (var x = 0; x < w; x += 1) {
+        var ___xd = (x - w / 2) / h;
+        for (var y = 0; y < h; y += 1) {
+            var __yd = (y - h / 2) / h;
+            var __zd = 1;
+
+            var ___zd = __zd * yCos + __yd * ySin;
+            var _yd = __yd * yCos - __zd * ySin;
+
+            var _xd = ___xd * xCos + ___zd * xSin;
+            var _zd = ___zd * xCos - ___xd * xSin;
+
+            var col = 0;
+            var br = 255;
+            var ddist = 0;
+
+            var closest = 32;
+            for (var d = 0; d < 3; d += 1) {
+                var dimLength = _xd;
+                if (d == 1) {
+                    dimLength = _yd;
+                }
+                if (d == 2) {
+                    dimLength = _zd;
+                }
+
+                var ll = 1 / ((dimLength < 0)? -dimLength : dimLength);
+                var xd = (_xd) * ll;
+                var yd = (_yd) * ll;
+                var zd = (_zd) * ll;
+
+                var initial = ox - (ox | 0);
+                if (d == 1) {
+                    initial = oy - (oy | 0);
+                }
+                if (d == 2) {
+                    initial = oz - (oz | 0);
+                }
+                if (dimLength > 0) {
+                    initial = 1 - initial;
+                }
+
+                var dist = ll * initial;
+
+                var xp = ox + xd * initial;
+                var yp = oy + yd * initial;
+                var zp = oz + zd * initial;
+
+                if (dimLength < 0) {
+                    if (d == 0) {
+                        xp -= 1;
+                    }
+                    if (d == 1) {
+                        yp -= 1;
+                    }
+                    if (d == 2) {
+                        zp -= 1;
+                    }
+                }
+
+                while (dist < closest) {
+                    var tex = map[(zp & 63) << 12 | (yp & 63) << 6 | (xp & 63)];
+
+                    if (tex > 0) {
+                        var u = ((xp + zp) * 16) & 15;
+                        var v = ((yp * 16) & 15) + 16;
+                        if (d == 1) {
+                            u = (xp * 16) & 15;
+                            v = ((zp * 16) & 15);
+                            if (yd < 0) {
+                                v += 32;
+                            }
+                        }
+
+                        var cc = texmap[u + v * 16 + tex * 256 * 3];
+                        if (cc > 0) {
+                            col = cc;
+                            ddist = 255 - ((dist / 32 * 255) | 0);
+                            br = Math.floor(255 * (255 - ((d + 2) % 3) * 50) / 255);
+                            closest = dist;
+                        }
+                    }
+                    xp += xd;
+                    yp += yd;
+                    zp += zd;
+                    dist += ll;
+                }
+            }
+
+            var r = ((col >> 16) & 0xff) * br * ddist / 65025;
+            var g = ((col >> 8) & 0xff) * br * ddist / 65025;
+            var b = ((col) & 0xff) * br * ddist / 65025;
+
+//            bmd.setPixel(x, y, r << 16 | g << 8 | b);
+            love.graphics.setColor(r, g, b);
+            love.graphics.point(x, y);
+        }
+    }
+}
+
+function love.load() {
+    love.graphics.setCaption("Minecraft4k: " .. global._VERSION);
+    love.graphics.setPoint(1, "rough");
+    love.graphics.setMode(430, 430, false, true, 0)
+    canvas = love.graphics.newCanvas(w, h);
+	init();
+}
+
+function love.draw() {
+    love.graphics.setCanvas(canvas);
+    renderMinecraft();
+    love.graphics.setCanvas();
+    love.graphics.setColor(255, 255, 255);
+    love.graphics.draw(canvas, 15, 15, 0, 2, 2);
+}
+
+function love.keypressed(key, unicode)  {
+    if (key == "escape") {
+        love.event.push("quit");
+    }
+}

File bin/windows/game/physics.kia

 	world::update(dt * 0.5);
 	player.body::applyForce(230, 0)
 }
+
+function love.keypressed(key, unicode) {
+    if (key == "escape") {
+        love.event.push("quit")
+    }
+}
+