windstille-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Windstille-devel] rev 411 - trunk/src


From: Ingo Ruhnke
Subject: [Windstille-devel] rev 411 - trunk/src
Date: Thu, 17 Jun 2004 15:45:03 +0200

Author: grumbel
Date: 2004-06-17 15:45:02 +0200 (Thu, 17 Jun 2004)
New Revision: 411

Modified:
   trunk/src/gui.rb
   trunk/src/gui2.rb
   trunk/src/supertux.rb
Log:
- added proof of concept smoother

Modified: trunk/src/gui.rb
===================================================================
--- trunk/src/gui.rb    2004-06-16 23:13:57 UTC (rev 410)
+++ trunk/src/gui.rb    2004-06-17 13:45:02 UTC (rev 411)
@@ -222,6 +222,48 @@
                         level.resize(CL_Size.new(w, h), CL_Point.new(x, y))})
 end
 
+def gui_smooth_level_struct()
+  puts "Smoothing level structure"
+  tilemap = TilemapLayer.current()
+  data    = tilemap.get_data()
+  width   = tilemap.get_width()
+  height  = tilemap.get_height()
+
+  get = proc { |x, y| return data[y*width + x] }
+  set = proc { |x, y, val| data[y*width + x] = val }
+
+  smooth = proc do |x, y|
+    $itile_conditions.each do |ary|
+      if (($solid_itiles.index(get[x-1,y-1]) ? 1 : 0) == ary[0] \
+          and ($solid_itiles.index(get[x,  y-1]) ? 1 : 0) == ary[1] \
+          and ($solid_itiles.index(get[x+1,y-1]) ? 1 : 0) == ary[2] \
+          and ($solid_itiles.index(get[x-1,y  ]) ? 1 : 0) == ary[3] \
+          and ($solid_itiles.index(get[x,  y  ]) ? 1 : 0) == ary[4] \
+          and ($solid_itiles.index(get[x+1,y  ]) ? 1 : 0) == ary[5] \
+          and ($solid_itiles.index(get[x-1,y+1]) ? 1 : 0) == ary[6] \
+          and ($solid_itiles.index(get[x,  y+1]) ? 1 : 0) == ary[7] \
+          and ($solid_itiles.index(get[x+1,y+1]) ? 1 : 0) == ary[8])
+      then
+        set[x,y, ary[9]]
+      end
+    end
+  end
+
+  rect  = $tilemap_select_tool.get_selection_rect()
+
+  start_x = rect.left
+  end_x   = rect.right
+  start_y = rect.top
+  end_y   = rect.bottom
+
+  for y in (start_y..end_y) do
+    for x in (start_x..end_x) do
+      smooth[x,y]
+    end
+  end
+  tilemap.set_data(data)
+end
+
 def gui_resize_level_to_selection()
   level = $workspace.get_map().get_metadata()
   rect  = $tilemap_select_tool.get_selection_rect()

Modified: trunk/src/gui2.rb
===================================================================
--- trunk/src/gui2.rb   2004-06-16 23:13:57 UTC (rev 410)
+++ trunk/src/gui2.rb   2004-06-17 13:45:02 UTC (rev 411)
@@ -119,6 +119,7 @@
 $menu.add_item("File/Save As...", proc{ gui_level_save_as() })
 $menu.add_item("File/Quit",  proc{ $gui.quit })
 
+$menu.add_item("Edit/Smooth Selection", proc{ gui_smooth_level_struct() })
 $menu.add_item("Edit/Resize", proc{ gui_resize_level() })
 $menu.add_item("Edit/Resize to selection", proc{ 
gui_resize_level_to_selection()})
 $menu.add_item("Edit/Debug Shell", proc{ run_python()})

Modified: trunk/src/supertux.rb
===================================================================
--- trunk/src/supertux.rb       2004-06-16 23:13:57 UTC (rev 410)
+++ trunk/src/supertux.rb       2004-06-17 13:45:02 UTC (rev 411)
@@ -1,3 +1,4 @@
+#!/usr/bin/ruby
 ##  $Id$
 ##
 ##  Flexlay - A Generic 2D Game Editor
@@ -196,6 +197,49 @@
   ["trampoline", "images/shared/trampoline-1.png", proc{|data| 
BadGuy.new("trampoline")}]
 ]
 
+$solid_itiles = [10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 30, 31, 113, 114]
+$air_itiles   = [7, 8, 9, 16, 17, 18, 0]
+
+$itile_conditions = [
+  [0, 0, 0, 0, 0, 1, 0, 1, 1, 7],
+  [0, 0, 1, 0, 0, 1, 0, 1, 1, 7],
+  [0, 0, 0, 0, 0, 0, 0, 1, 1, 7],
+  [0, 0, 0, 0, 0, 0, 1, 1, 1, 8],
+  [0, 0, 0, 0, 0, 0, 1, 1, 0, 9],
+  [0, 1, 1, 0, 0, 0, 0, 0, 0, 16],
+
+  [1, 1, 1, 0, 0, 0, 0, 0, 0, 17],
+  [1, 1, 1, 1, 0, 0, 0, 0, 0, 17],
+  [1, 1, 1, 0, 0, 1, 0, 0, 0, 17],
+  [1, 1, 1, 1, 0, 0, 1, 0, 0, 17],
+  [1, 1, 1, 0, 0, 1, 0, 0, 1, 17],
+
+  [1, 1, 0, 0, 0, 0, 0, 0, 0, 18],
+
+  [0, 1, 1, 0, 1, 1, 0, 0, 0, 10],
+  [1, 1, 1, 0, 1, 1, 0, 0, 0, 11],
+  [1, 1, 0, 1, 1, 0, 0, 0, 0, 12],
+
+  [0, 1, 1, 0, 1, 1, 0, 1, 1, 10],
+  [1, 1, 1, 1, 1, 1, 1, 1, 1, 11],
+  [1, 1, 0, 1, 1, 0, 1, 1, 0, 12],
+
+  [0, 0, 0, 0, 1, 1, 0, 1, 1, 13],
+  [0, 0, 0, 1, 1, 1, 1, 1, 1, 14],
+  [0, 0, 0, 1, 1, 0, 1, 1, 0, 15],
+  [1, 0, 0, 1, 1, 1, 1, 1, 1, 20],
+  [1, 1, 0, 1, 1, 0, 1, 1, 1, 21],
+  [0, 1, 1, 0, 1, 1, 1, 1, 1, 22],
+  [0, 0, 1, 1, 1, 1, 1, 1, 1, 23],
+
+  [1, 1, 1, 1, 1, 0, 1, 1, 0, 30],
+  [1, 1, 1, 0, 1, 1, 0, 1, 1, 31],
+
+  [0, 0, 0, 1, 1, 0, 1, 1, 1, 113],
+  [0, 0, 0, 0, 1, 1, 1, 1, 1, 114],
+
+]
+
 require "level.rb"
 require "sector.rb"
 require "gui2.rb"





reply via email to

[Prev in Thread] Current Thread [Next in Thread]