Creeper/Anti-Creeper Flow models

Started by jim_de_hunter, February 16, 2015, 09:38:34 AM

Previous topic - Next topic

jim_de_hunter

Long story short.

I'm in my last semester of graduate school and I need a mini project for my numerical analysis class.  I need to use PDE's to model physical behavior and I remembered from CW1 that the programmers used heat flow models for the creeper flows.

Do anybody have any information on the heat flow models for the game?

Jim

J

Basically you 'move' numbers based on the current numbers in the cell and the four neighboring cells.
In my game water world I copied the entire data grid to a new grid, and with that copied grid I recalculate the values for the original grid. You can have the code for that if you want.

jim_de_hunter

Quote from: J on February 16, 2015, 10:04:10 AM
Basically you 'move' numbers based on the current numbers in the cell and the four neighboring cells.

That's perfect.  That's exactly how PDE's are solved using finite elements to model.  I'd like to see the code.

J

First the values are stored locally (because in gamemaker that's faster than in the global container).

{
  var i, j;
  for(i=0; i<=29; i+=1)
  {
    for(j=0; j<=29; j+=1)
    {
      heat1[i,j]=0
      heat2[i,j]=0
      heat3[i,j]=0
      heat1[i,j]=ds_grid_get(global.grid,i,j)
      if(i!=29)
      {
        heat2[i,j]=ds_grid_get(global.grid,i+1,j)
      }
      if(j!=29)
      {
        heat3[i,j]=ds_grid_get(global.grid,i,j+1)
      }
    }
  }
}

Then the global grid is edited using the values from the local storage.

{
  var i, j;
  for(i=0; i<=29; i+=1)
  {
    for(j=0; j<=29; j+=1)
    {
      if(i!=29)
      {
        ds_grid_add(global.grid,i,j,(heat2[i,j]/14)-(heat1[i,j]/14))
        ds_grid_add(global.grid,i+1,j,(heat1[i,j]/14)-(heat2[i,j]/14))
      }
      if(j!=29)
      {
        ds_grid_add(global.grid,i,j,(heat3[i,j]/12)-(heat1[i,j]/15))
        ds_grid_add(global.grid,i,j+1,(heat1[i,j]/15)-(heat3[i,j]/12))
      }
    }
  }
}

With these values, there's upwards gravity.
Now that I'm looking at it, this could probably be made more efficient by changing heat2[i,j] to heat1[i+1,j] and heat3[i,j] to heat1[i,j+1]. I can't remember if there was a reason why I didn't do that.

jim_de_hunter

Cool.  Let me see what I can do with this.