Sign in to follow this  
  • entries
  • comments
  • views

Bonsai lives!

Sign in to follow this  


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())
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
function baseimg:new(o)
o = o or {}
self.__index = self
return o

img = 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}



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]
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now