about summary refs log tree commit diff stats
path: root/html/rogue/js/world.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/rogue/js/world.js')
-rw-r--r--html/rogue/js/world.js567
1 files changed, 290 insertions, 277 deletions
diff --git a/html/rogue/js/world.js b/html/rogue/js/world.js
index c416c91..ec6b5e8 100644
--- a/html/rogue/js/world.js
+++ b/html/rogue/js/world.js
@@ -131,284 +131,297 @@ const GRASS_TYPES = {
 };
 
 // Create a world with platforms, trees, and rocks
-const createWorld = () => ({
-    groundHeight: 12,
-    // Separate arrays for different layers
-    backgroundTrees: [
-        // Far left trees
-        {
-            type: WORLD_OBJECTS.FIR_BACKGROUND,
-            x: -1500,
-            config: FIR_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.MAPLE_BACKGROUND,
-            x: -1200,
-            config: MAPLE_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.FIR_BACKGROUND,
-            x: -900,
-            config: FIR_TYPES.SMALL
-        },
-        // Existing trees
-        {
-            type: WORLD_OBJECTS.FIR_BACKGROUND,
-            x: -400,
-            config: FIR_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.MAPLE_BACKGROUND,
-            x: -250,
-            config: MAPLE_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.FIR_BACKGROUND,
-            x: 50,
-            config: FIR_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.MAPLE_BACKGROUND,
-            x: 250,
-            config: MAPLE_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.FIR_BACKGROUND,
-            x: 500,
-            config: FIR_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.MAPLE_BACKGROUND,
-            x: 650,
-            config: MAPLE_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.FIR_BACKGROUND,
-            x: 900,
-            config: FIR_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.MAPLE_BACKGROUND,
-            x: 1100,
-            config: MAPLE_TYPES.LARGE
-        },
-        // Far right trees
-        {
-            type: WORLD_OBJECTS.MAPLE_BACKGROUND,
-            x: 1400,
-            config: MAPLE_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.FIR_BACKGROUND,
-            x: 1700,
-            config: FIR_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.MAPLE_BACKGROUND,
-            x: 2000,
-            config: MAPLE_TYPES.LARGE
-        }
-    ],
-    backgroundRocks: [
-        // Far left rocks
-        {
-            type: WORLD_OBJECTS.ROCK_BACKGROUND,
-            x: -1300,
-            config: ROCK_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_BACKGROUND,
-            x: -1000,
-            config: ROCK_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_BACKGROUND,
-            x: -300,
-            config: ROCK_TYPES.MEDIUM
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_BACKGROUND,
-            x: -100,
-            config: ROCK_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_BACKGROUND,
-            x: 150,
-            config: ROCK_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_BACKGROUND,
-            x: 400,
-            config: ROCK_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_BACKGROUND,
-            x: 750,
-            config: ROCK_TYPES.MEDIUM
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_BACKGROUND,
-            x: 1000,
-            config: ROCK_TYPES.SMALL
-        },
-        // Far right rocks
-        {
-            type: WORLD_OBJECTS.ROCK_BACKGROUND,
-            x: 1600,
-            config: ROCK_TYPES.MEDIUM
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_BACKGROUND,
-            x: 1900,
-            config: ROCK_TYPES.SMALL
-        }
-    ],
-    platforms: [
-        {
-            type: WORLD_OBJECTS.PLATFORM,
-            x: 300,
-            y: 300,
-            width: 200,
-            height: 20,
-            color: '#484'
-        },
-        {
-            type: WORLD_OBJECTS.PLATFORM,
-            x: 600,
-            y: 200,
-            width: 200,
-            height: 20,
-            color: '#484'
-        },
-        {
-            type: WORLD_OBJECTS.PLATFORM,
-            x: -200,
-            y: 250,
-            width: 200,
-            height: 20,
-            color: '#484'
-        }
-    ],
-    foregroundTrees: [
-        // Far left trees
-        {
-            type: WORLD_OBJECTS.FIR_FOREGROUND,
-            x: -1400,
-            config: FIR_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.MAPLE_FOREGROUND,
-            x: -1100,
-            config: MAPLE_TYPES.SMALL
-        },
-        // Existing trees
-        {
-            type: WORLD_OBJECTS.MAPLE_FOREGROUND,
-            x: -150,
-            config: MAPLE_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.FIR_FOREGROUND,
-            x: 200,
-            config: FIR_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.MAPLE_FOREGROUND,
-            x: 450,
-            config: MAPLE_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.FIR_FOREGROUND,
-            x: 800,
-            config: FIR_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.MAPLE_FOREGROUND,
-            x: 1200,
-            config: MAPLE_TYPES.SMALL
-        },
-        // Far right trees
-        {
-            type: WORLD_OBJECTS.FIR_FOREGROUND,
-            x: 1500,
-            config: FIR_TYPES.LARGE
-        },
-        {
-            type: WORLD_OBJECTS.MAPLE_FOREGROUND,
-            x: 1800,
-            config: MAPLE_TYPES.SMALL
-        }
-    ],
-    foregroundRocks: [
-        // Far left rocks
-        {
-            type: WORLD_OBJECTS.ROCK_FOREGROUND,
-            x: -1000,
-            config: ROCK_TYPES.MEDIUM
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_FOREGROUND,
-            x: 0,
-            config: ROCK_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_FOREGROUND,
-            x: 300,
-            config: ROCK_TYPES.MEDIUM
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_FOREGROUND,
-            x: 700,
-            config: ROCK_TYPES.SMALL
-        },
-        {
-            type: WORLD_OBJECTS.ROCK_FOREGROUND,
-            x: 950,
-            config: ROCK_TYPES.LARGE
-        },
-        // Far right rocks
-        {
-            type: WORLD_OBJECTS.ROCK_FOREGROUND,
-            x: 1500,
-            config: ROCK_TYPES.LARGE
+const createWorld = () => {
+    const world = {
+        groundHeight: 12,
+        // Separate arrays for different layers
+        backgroundTrees: [
+            // Far left trees
+            {
+                type: WORLD_OBJECTS.FIR_BACKGROUND,
+                x: -1500,
+                config: FIR_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.MAPLE_BACKGROUND,
+                x: -1200,
+                config: MAPLE_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.FIR_BACKGROUND,
+                x: -900,
+                config: FIR_TYPES.SMALL
+            },
+            // Existing trees
+            {
+                type: WORLD_OBJECTS.FIR_BACKGROUND,
+                x: -400,
+                config: FIR_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.MAPLE_BACKGROUND,
+                x: -250,
+                config: MAPLE_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.FIR_BACKGROUND,
+                x: 50,
+                config: FIR_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.MAPLE_BACKGROUND,
+                x: 250,
+                config: MAPLE_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.FIR_BACKGROUND,
+                x: 500,
+                config: FIR_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.MAPLE_BACKGROUND,
+                x: 650,
+                config: MAPLE_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.FIR_BACKGROUND,
+                x: 900,
+                config: FIR_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.MAPLE_BACKGROUND,
+                x: 1100,
+                config: MAPLE_TYPES.LARGE
+            },
+            // Far right trees
+            {
+                type: WORLD_OBJECTS.MAPLE_BACKGROUND,
+                x: 1400,
+                config: MAPLE_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.FIR_BACKGROUND,
+                x: 1700,
+                config: FIR_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.MAPLE_BACKGROUND,
+                x: 2000,
+                config: MAPLE_TYPES.LARGE
+            }
+        ],
+        backgroundRocks: [
+            // Far left rocks
+            {
+                type: WORLD_OBJECTS.ROCK_BACKGROUND,
+                x: -1300,
+                config: ROCK_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_BACKGROUND,
+                x: -1000,
+                config: ROCK_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_BACKGROUND,
+                x: -300,
+                config: ROCK_TYPES.MEDIUM
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_BACKGROUND,
+                x: -100,
+                config: ROCK_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_BACKGROUND,
+                x: 150,
+                config: ROCK_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_BACKGROUND,
+                x: 400,
+                config: ROCK_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_BACKGROUND,
+                x: 750,
+                config: ROCK_TYPES.MEDIUM
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_BACKGROUND,
+                x: 1000,
+                config: ROCK_TYPES.SMALL
+            },
+            // Far right rocks
+            {
+                type: WORLD_OBJECTS.ROCK_BACKGROUND,
+                x: 1600,
+                config: ROCK_TYPES.MEDIUM
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_BACKGROUND,
+                x: 1900,
+                config: ROCK_TYPES.SMALL
+            }
+        ],
+        platforms: [
+            {
+                type: WORLD_OBJECTS.PLATFORM,
+                x: 300,
+                y: 300,
+                width: 200,
+                height: 20,
+                color: '#484'
+            },
+            {
+                type: WORLD_OBJECTS.PLATFORM,
+                x: 600,
+                y: 200,
+                width: 200,
+                height: 20,
+                color: '#484'
+            },
+            {
+                type: WORLD_OBJECTS.PLATFORM,
+                x: -200,
+                y: 250,
+                width: 200,
+                height: 20,
+                color: '#484'
+            }
+        ],
+        foregroundTrees: [
+            // Far left trees
+            {
+                type: WORLD_OBJECTS.FIR_FOREGROUND,
+                x: -1400,
+                config: FIR_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.MAPLE_FOREGROUND,
+                x: -1100,
+                config: MAPLE_TYPES.SMALL
+            },
+            // Existing trees
+            {
+                type: WORLD_OBJECTS.MAPLE_FOREGROUND,
+                x: -150,
+                config: MAPLE_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.FIR_FOREGROUND,
+                x: 200,
+                config: FIR_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.MAPLE_FOREGROUND,
+                x: 450,
+                config: MAPLE_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.FIR_FOREGROUND,
+                x: 800,
+                config: FIR_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.MAPLE_FOREGROUND,
+                x: 1200,
+                config: MAPLE_TYPES.SMALL
+            },
+            // Far right trees
+            {
+                type: WORLD_OBJECTS.FIR_FOREGROUND,
+                x: 1500,
+                config: FIR_TYPES.LARGE
+            },
+            {
+                type: WORLD_OBJECTS.MAPLE_FOREGROUND,
+                x: 1800,
+                config: MAPLE_TYPES.SMALL
+            }
+        ],
+        foregroundRocks: [
+            // Far left rocks
+            {
+                type: WORLD_OBJECTS.ROCK_FOREGROUND,
+                x: -1000,
+                config: ROCK_TYPES.MEDIUM
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_FOREGROUND,
+                x: 0,
+                config: ROCK_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_FOREGROUND,
+                x: 300,
+                config: ROCK_TYPES.MEDIUM
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_FOREGROUND,
+                x: 700,
+                config: ROCK_TYPES.SMALL
+            },
+            {
+                type: WORLD_OBJECTS.ROCK_FOREGROUND,
+                x: 950,
+                config: ROCK_TYPES.LARGE
+            },
+            // Far right rocks
+            {
+                type: WORLD_OBJECTS.ROCK_FOREGROUND,
+                x: 1500,
+                config: ROCK_TYPES.LARGE
+            }
+        ],
+        backgroundGrass: [
+            // Far left grass
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: -1400, config: GRASS_TYPES.BLUE_TALL },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: -1100, config: GRASS_TYPES.GOLDEN_SHORT },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: -950, config: GRASS_TYPES.TALL },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: -350, config: GRASS_TYPES.SHORT },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: -180, config: GRASS_TYPES.GOLDEN_TALL },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 100, config: GRASS_TYPES.TALL },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 320, config: GRASS_TYPES.BLUE_SHORT },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 580, config: GRASS_TYPES.GOLDEN_SHORT },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 750, config: GRASS_TYPES.BLUE_TALL },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 950, config: GRASS_TYPES.TALL },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 1050, config: GRASS_TYPES.GOLDEN_TALL },
+            // Far right grass
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 1500, config: GRASS_TYPES.BLUE_SHORT },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 1750, config: GRASS_TYPES.GOLDEN_TALL },
+            { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 1850, config: GRASS_TYPES.SHORT }
+        ],
+        foregroundGrass: [
+            // Far left grass
+            { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: -1250, config: GRASS_TYPES.TALL },
+            { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: -1050, config: GRASS_TYPES.BLUE_SHORT },
+            { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: -280, config: GRASS_TYPES.BLUE_TALL },
+            { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: -50, config: GRASS_TYPES.GOLDEN_SHORT },
+            { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 150, config: GRASS_TYPES.TALL },
+            { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 420, config: GRASS_TYPES.BLUE_SHORT },
+            { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 680, config: GRASS_TYPES.GOLDEN_TALL },
+            { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 880, config: GRASS_TYPES.SHORT },
+            { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 1150, config: GRASS_TYPES.BLUE_TALL },
+            // Far right grass
+            { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 1650, config: GRASS_TYPES.GOLDEN_TALL },
+            { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 1850, config: GRASS_TYPES.BLUE_SHORT }
+        ],
+        // Track grass animation states
+        grassStates: {},
+        // Add methods for quick spatial lookups
+        getObjectsInView: function(bounds) {
+            return {
+                backgroundTrees: this.backgroundTrees.filter(tree => 
+                    tree.x > bounds.left && tree.x < bounds.right
+                ),
+                // ... similar for other object types
+            };
         }
-    ],
-    backgroundGrass: [
-        // Far left grass
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: -1400, config: GRASS_TYPES.BLUE_TALL },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: -1100, config: GRASS_TYPES.GOLDEN_SHORT },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: -950, config: GRASS_TYPES.TALL },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: -350, config: GRASS_TYPES.SHORT },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: -180, config: GRASS_TYPES.GOLDEN_TALL },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 100, config: GRASS_TYPES.TALL },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 320, config: GRASS_TYPES.BLUE_SHORT },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 580, config: GRASS_TYPES.GOLDEN_SHORT },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 750, config: GRASS_TYPES.BLUE_TALL },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 950, config: GRASS_TYPES.TALL },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 1050, config: GRASS_TYPES.GOLDEN_TALL },
-        // Far right grass
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 1500, config: GRASS_TYPES.BLUE_SHORT },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 1750, config: GRASS_TYPES.GOLDEN_TALL },
-        { type: WORLD_OBJECTS.GRASS_BACKGROUND, x: 1850, config: GRASS_TYPES.SHORT }
-    ],
-    foregroundGrass: [
-        // Far left grass
-        { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: -1250, config: GRASS_TYPES.TALL },
-        { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: -1050, config: GRASS_TYPES.BLUE_SHORT },
-        { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: -280, config: GRASS_TYPES.BLUE_TALL },
-        { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: -50, config: GRASS_TYPES.GOLDEN_SHORT },
-        { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 150, config: GRASS_TYPES.TALL },
-        { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 420, config: GRASS_TYPES.BLUE_SHORT },
-        { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 680, config: GRASS_TYPES.GOLDEN_TALL },
-        { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 880, config: GRASS_TYPES.SHORT },
-        { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 1150, config: GRASS_TYPES.BLUE_TALL },
-        // Far right grass
-        { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 1650, config: GRASS_TYPES.GOLDEN_TALL },
-        { type: WORLD_OBJECTS.GRASS_FOREGROUND, x: 1850, config: GRASS_TYPES.BLUE_SHORT }
-    ],
-    // Track grass animation states
-    grassStates: {}
-});
+    };
+    
+    return world;
+};
 
 // Add seededRandom function
 const seededRandom = (x, y) => {