Posted to tcl by steve at Wed Oct 29 04:14:53 GMT 2014view raw

  1. // Compile with: valac --pkg aries --pkg posix trees.gs
  2.  
  3. uses Aries
  4.  
  5. // some constants
  6. const sw : int = 256
  7. const sh : int = 180
  8. const fs : int = 0 // not full-screen
  9. const zf : int = 3 // accel zoom-factor of 3x
  10. const pane_w : int = 80
  11. const pane_h : int = 100
  12.  
  13.  
  14. init
  15.  
  16. // Almost all aries projects will use at least one layer.
  17. layer : Layer
  18.  
  19. // a scratchpad frame we use to load and convert the images from disk
  20. f : Frame
  21.  
  22. // the sprites, and a color key for the bear
  23. glass, bear : Sprite
  24.  
  25. // a buffer to hold the pixel displacement data for the pane of glass
  26. pane : array of int16[,,]
  27.  
  28. // the bear sprite's position
  29. bx, by : int
  30.  
  31.  
  32. // Let's begin!
  33. Aries.init()
  34. layer = Layer()
  35. layer.set_sorting(1)
  36.  
  37.  
  38. // Now, we're going to create the stained glass effect by combining two sprites:
  39. // a color-adjustment sprite to give the glass some color, and a displacement
  40. // sprite to give it the fuzzy, mottled look. First we'll create a
  41. // displacement map for the fuzzy effect, by making a list of small random
  42. // pixel displacement values, which will comprise the displacement sprite.
  43. pane = new array of int16[pane_w, pane_h, 2]
  44. for i:int = 0 to (pane_w-1)
  45. for j:int = 0 to (pane_h-1)
  46. pane[i, j, 0] = (int16)Random.int_range(-3, 3);
  47. pane[i, j, 1] = (int16)Random.int_range(-3, 3);
  48.  
  49. // Then we'll load the colored pane of glass, and add the displacement effect to it.
  50. f = new Frame.from_disk("images/window.png")
  51. f.convert(Frame_type.LT, null)
  52. glass = new Sprite
  53. glass.add_frame( f.copy() )
  54. glass.add_subframe( 0, new Frame(Frame_type.DISPL, pane_w, pane_h, pane, null).copy() )
  55.  
  56. // Place the pane of glass and add it to our layer's spritelist.
  57. glass.set_position(100, 20)
  58. glass.set_z_hint(10)
  59. layer.get_sprite_list().add(glass)
  60.  
  61.  
  62. // And last, load the bear sprite, and set a color key to make
  63. // sure that the magenta background is made transparent.
  64. bear = new Sprite
  65. bear.add_frame( new Frame.from_disk("images/bear.png").copy() )
  66. layer.get_sprite_list().add(bear)
  67.  
  68.  
  69. // open the graphics display
  70. Graphics.open(Graphics_mode.ON, sw, sh, fs, zf)
  71.  
  72. // initialize the bear position and enter the main loop
  73. bx = 0;
  74. by = 0;
  75.  
  76. while true
  77.  
  78. // the input result
  79. io : Input_res
  80. Io.fetch(0, out io)
  81.  
  82. // Update the sprite position.
  83. bx += io.hat[0].x
  84. by += io.hat[0].y
  85. bear.set_position(bx, by)
  86.  
  87. // display the frame and run the delay loop
  88. Render.display()
  89. Clock.wait(50);
  90.  
  91. // quit on escape keypress
  92. if io.esc == 1 || Io.has_quit() == 1
  93. Posix.exit(0)
  94.