Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #16  
Old 10-11-2010, 09:11 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
More fun!

Grid-based Level Generator to compliment my Maze Generator, not sure if I should give it's own thread but it's very basic right now.

How it works.. (In relation to my example)

Every level in the grid starts off as mazeconcept2a.nw, and then depending on it's walls borrows the cell data from mazeconcept2b.nw and overwrites it's original data resulting in paths/exits.

I plan on adding support for further randomizing grid levels so with enough level work you could make it generate a fairly unique maze every time.

As well as support for level NPCs, and a generate GMAP file function.

PHP Code:
function onCreated() {
  
// Generate Maze
  
temp.maze generateMaze(44);
  
// Make levels
  // Adjust paths for your own server
  
createGridMaze("cartridge/maze/mazeconcept2""cartridge/maze/generation"temp.maze.link());
}

/*
    !! INCLUDE MY PREVIOUS MAZE CODE FOR WORKING EXAMPLE !!
*/

/*
   Level Generation
*/

public function createGridMaze(mazepathnewpathmaze) {
  
// Load Template Levels
  
temp.grid_a.loadlines(mazepath "a.nw");
  
temp.grid_b.loadlines(mazepath "b.nw");
  
// Get Grid Size
  
temp.gridhead temp.grid_a.index("//MAZEGRID");
  
temp.gridwidth temp.grid_a[temp.gridhead+1].substring("//GRIDWIDTH".length()).trim().tokenize(","); 
  
temp.gridheight temp.grid_a[temp.gridhead+1].substring("//GRIDHEIGHT".length()).trim().tokenize(","); 
  
// Determine Grids Width and Height
  
temp.mazeheight maze.size();
  
temp.mazewidth  maze[0].size();
  
// Generate Levels
  
for (temp.0temp.temp.mazewidthtemp.y++) {
    for (
temp.0temp.temp.mazeheighttemp.x++) {
      
// Generate Level
      
temp.lvlname newpath "_" num(temp.xmazewidth) @ "_" num(temp.ymazeheight) @ ".nw";
      
temp.lvl "";
      
temp.lvl temp.grid_a.subarray(065);
      
// Begin Removing Walls
      
temp.cell maze[temp.y][temp.x];
      for (
temp.0temp.4temp.i++) {
        
// Remove Wall
        
if (temp.cell[temp.i] == false) {
          
// Locate Grid Positions
          
temp.tx temp.ty 0;
          
temp.gx vecx(temp.i);
          
temp.gy vecy(temp.i);
          for (
temp.0temp.temp.gxtemp.j++) temp.tx += temp.gridwidth[j];
          for (
temp.0temp.temp.gytemp.j++) temp.ty += temp.gridheight[j];
          
// Cut-n-paste Level Data
          
for (temp.0temp.temp.gridheight[temp.gy]; temp.j++) {
            
temp.rowstart format("BOARD 0 %i 64 0 "temp.ty).length();
            
temp.line "";
            
temp.line temp.lvl[temp.ty+1+temp.j];
            
temp.newl temp.grid_b[temp.ty+temp.j+1].substring(temp.rowstart + (temp.tx 2), temp.gridwidth[temp.gx] * 2);
            
temp.line temp.line.substring(0temp.rowstart + (temp.tx 2)) @ temp.newl temp.line.substring(temp.rowstart + (temp.tx 2) + (temp.gridwidth[temp.gx] * 2));
            
temp.lvl[temp.ty+temp.j+1] = temp.line;
          }
          
// Add Level Link
          
if (temp.== 0) {
            
temp.lx temp.tx;
            
temp.ly 0;
            
temp.lw temp.gridwidth[temp.gx];
            
temp.lh 1;
            
temp."playerx 61";
          }
          else if (
temp.== 1) {
            
temp.lx 0;
            
temp.ly temp.ty;
            
temp.lw 1;
            
temp.lh temp.gridheight[temp.gy];
            
temp."61 playery";
          }
          else if (
temp.== 2) {
            
temp.lx temp.tx;
            
temp.ly 63;
            
temp.lw temp.gridwidth[temp.gx];
            
temp.lh 1;
            
temp."playerx 0";
          }
          else if (
temp.== 3) {
            
temp.lx 63;
            
temp.ly temp.ty;
            
temp.lw 1;
            
temp.lh temp.gridheight[temp.gy];
            
temp."0 playery";
          }
          
temp.nlvlname extractfilebase(newpath) @ "_" num(temp.vecx(temp.i), mazewidth) @ "_" num(temp.vecy(temp.i), mazeheight) @ ".nw";
          
temp.link format("LINK %s %i %i %i %i %s"nlvlnamelxlylwlhp);
          
temp.lvl.add(temp.link);
        }
        
// Save Level
        
temp.lvl.savelines(temp.lvlname0);
      }
    }
  }
}

function 
num(am) {
  if (
10) {
    return (
10 "0" a);
  }
  return 
a;

Attached Files
File Type: zip mazelevels.zip (2.3 KB, 150 views)
File Type: zip testmaze.zip (10.0 KB, 134 views)
File Type: zip cronomaze.zip (82.1 KB, 137 views)
__________________
Quote:

Last edited by fowlplay4; 10-11-2010 at 09:43 PM.. Reason: Added another test maze.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.