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

// Compile with:  valac --pkg aries --pkg posix trees.gs

uses Aries

// some constants
const sw : int = 256
const sh : int = 180
const fs : int = 0        // not full-screen
const zf : int = 3        // accel zoom-factor of 3x
const pane_w : int = 80
const pane_h : int = 100


init

	// Almost all aries projects will use at least one layer.
	layer : Layer

	// a scratchpad frame we use to load and convert the images from disk
	f : Frame

	// the sprites, and a color key for the bear
	glass, bear : Sprite

	// a buffer to hold the pixel displacement data for the pane of glass
	pane : array of int16[,,]

	// the bear sprite's position
	bx, by : int


	// Let's begin!
	Aries.init()
	layer = Layer()
	layer.set_sorting(1)


	// Now, we're going to create the stained glass effect by combining two sprites:
	// a color-adjustment sprite to give the glass some color, and a displacement
	// sprite to give it the fuzzy, mottled look.  First we'll create a
	// displacement map for the fuzzy effect, by making a list of small random
	// pixel displacement values, which will comprise the displacement sprite.
	pane = new array of int16[pane_w, pane_h, 2]
	for i:int = 0 to (pane_w-1)
		for j:int = 0 to (pane_h-1)
			pane[i, j, 0] = (int16)Random.int_range(-3, 3);
			pane[i, j, 1] = (int16)Random.int_range(-3, 3);

	// Then we'll load the colored pane of glass, and add the displacement effect to it.
	f = new Frame.from_disk("images/window.png")
	f.convert(Frame_type.LT, null)
	glass = new Sprite
	glass.add_frame( f.copy() )
	glass.add_subframe( 0, new Frame(Frame_type.DISPL, pane_w, pane_h, pane, null).copy() )

	// Place the pane of glass and add it to our layer's spritelist.
	glass.set_position(100, 20)
	glass.set_z_hint(10)
	layer.get_sprite_list().add(glass)


	// And last, load the bear sprite, and set a color key to make
	// sure that the magenta background is made transparent.
	bear = new Sprite
	bear.add_frame( new Frame.from_disk("images/bear.png").copy() )
	layer.get_sprite_list().add(bear)


	// open the graphics display
	Graphics.open(Graphics_mode.ON, sw, sh, fs, zf)

	// initialize the bear position and enter the main loop
	bx = 0;
	by = 0;

	while true

		// the input result
		io : Input_res
		Io.fetch(0, out io)

		// Update the sprite position.
		bx += io.hat[0].x
		by += io.hat[0].y
		bear.set_position(bx, by)

		// display the frame and run the delay loop
		Render.display()
		Clock.wait(50);

		// quit on escape keypress
		if io.esc == 1 || Io.has_quit() == 1
			Posix.exit(0)