• entries
455
639
• views
421674

# Bonsai lives!

78 views

So, after much procrastination by myself I've finally got Bonsai doing "stuff". OK, I admit the stuff is basically bouncing two quads about the screen but it works and this is the main thing [grin]

The two squares bounce about and the window responds to move events. Closing the window exits the scipt.

require "engine"eng = bonsai.createGraphics()print ("Created : " .. eng:__tostring())eng:createWindow()print "Window Created"tex = eng:createTexture("test.jpg")baseimg = {dirx = 0.1, diry = 0.1}function baseimg:update()			self.x = self.x + self.dirx			self.y = self.y + self.diry						if self.x + self.width > 800 			or self.x < 0			then self.dirx = -self.dirx end			if self.y + self.height > 600			or self.y < 0			then self.diry = -self.diry end		endfunction baseimg:new(o)	o = o or {}	setmetatable(o,self)	self.__index = self	return oendimg = baseimg:new({x = 0, y = 0, width = 200, height = 200, id = tex})img2 = baseimg:new({x = 0, y = 100, width = 40, height = 10, id = tex})imgs = {img, img2}while(eng:startFrame())do	eng:renderQuads(imgs)	img:update()	img2:update()	eng:endFrame()endeng:deleteTexture(tex)eng:destroyWindow()

require "engine" is what does the magic to load the DLL in; in future this will be hidden away behind Lua's load system, however for test reasons it'll do.

The 'baseimg' stuff is to give my two 'sprites' a common base to work from so that I can do a single update call in the main loop. Bit of OO in Lua for you there [grin]

The loop itself might get changed a bit as things progress; right now I've got "startFrame" checking to see if it's time to quit and if so returning false. I'm tempted to instead rig up some event handlers and have a 'processEvents()' function which returns a table with the different events which have occured in, including the 'quit' message.

One little issue to work out is why it crashes when I try to run it a second time. This isn't a Lua thing is a OGLWFW thing as it crashes before it returns from 'create window', which is a tad puzzling.

I've still got a fair amount of functionality I want to get sorted before I can remake that little 'game' I did, but with the advent of being able to draw bouncing boxes we are that much closer; huzzah! [grin]

There are no comments to display.