Monthly Archives: October 2013

Realbasic/Xojo: an Isometric engine (2.5D)

isometric
Tim Seyfarth had a specific question about adding a Z-axis to a floorplan. Immidiately I was thinking about the Isometric games like Diablo and I thought it would be a nice thing to try it out in Realbasic/Xojo. However, it looked like it was not that easy to implement as it seems. A lot of math is needed to create an engine like this. As my time is limited, I decided to spend some evenings translating an existing engine into Realbasic/Xojo. I have chosen the μIso (μIsometric Engine: A Java Isometric Engine) engine. The original code can be found here. All credit for the think work goes to Luis Henrique Oliveira Rios. Visit his page for some explanation.

μIso has some flaws I noticed (sometimes a ‘strange’ hole is visible in the montains or the mouse pointer loses track) but as you have the source code you can try to figure it out for yourself.

The speed in Realbasic/Xojo is also very slow (I get 7 frames per second, while the original java code got over 30 fps), but don’t let this discourage you to take a look on how it works. I don’t see this as an engine to create games with, but rather a tool to generate static pictures (like a floorplan).

You can scroll through the demo with the cursor keys (the minotaur does not move as I did not include the pathfinding algorithm). You can move the mouse to highlight a tile.

The program consists of two main folders:
1. UISO2.5D
This contains the real engine. Except for bug fixing, you should not need to make any changes to these classes.
2. Demo
This is a demo how you use the engine. All classes here are subclasses of the engine classes.
isometric folders

The full source code can be downloaded here UISO2.5D.zip

Some notes about the code:
1. change the path to the sprites (SpritePath) !!!!!!!!!!!!
2. if working with PRE Xojo, download the PNGutilities plugin (http://gorgeousapps.com/PNGUtilitiesPlugin.zip) and change in LoadABImage (ABGlobal):

for RB 2007:
dim img as new ABImage(PNGu.OpenAsPictureWithMask(f))
for xojo:
dim img as new ABImage(picture.Open(f))

Have fun programming and cheers for now!

Alwaysbusy

Click here to Donation if you like my work

Advertisements

RealBasic/Xojo: An ADODB Wrapper around the OLEObject framework

Note:
All problems seem to be solved for Xojo, thanks to John Hansen and Paul Lefebvre! Redownload the Wrapper at the end of the article if you had already downloaded it before.

For a project at OneTwo I needed ADODB instead of ODBC to connect to a database. Realbasic/Xojo can do this through the OLEObject, but non of the methods or properties are exposed to the programmer. If you only need it now and then that’s not a real problem, but in some cases you’ll use it all the time. So I decided to write a wrapper around the OLEObjects to make it easier. Also, all available Enums are available (ADOConstants) This way you can just program like this:

BlogArt1a

The code is also much more readable and familiar looking:

  dim CurrentPath as string
  CurrentPath = GetFolderItem("").AbsolutePath
  
  Dim conn as new ADOConnection
  conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + CurrentPath + "Test.mdb"
  
  if conn.Open() then
    MsgBox "Database open!"
  else
    if conn.ErrorsCount > 0 then
      MsgBox str(conn.GetError(0).Number) + "- " + conn.GetError(0).Description
    end if
  end if
  
  dim SQL_str as string
  dim tmp_rs as ADORecordset
  dim ret as Boolean
  
  SQL_str = "INSERT INTO tData ( datText, datValue, datParentID ) SELECT tUren.Uur, 1 AS Expr1, 1 AS Expr2 FROM tUren ORDER BY tUren.Uur;"
  tmp_rs = conn.Execute(SQL_str)
  if tmp_rs <> nil then
    ret = tmp_rs.close
    tmp_rs = nil
    MsgBox "Records added!"
  else
    if conn.ErrorsCount > 0 then
      MsgBox str(conn.GetError(0).Number) + "- " + conn.GetError(0).Description
    end if
  end if
  
  SQL_str = "UPDATE tData SET datValue=datValue+1;"
  tmp_rs = conn.Execute(SQL_str)
  if tmp_rs <> nil then
    ret = tmp_rs.close
    tmp_rs = nil
    MsgBox "Records updated!"
  else
    if conn.ErrorsCount > 0 then
      MsgBox str(conn.GetError(0).Number) + "- " + conn.GetError(0).Description
    end if
  end if
  
  SQL_str = "SELECT datValue FROM tData WHERE datText='12:00';"
  tmp_rs = new ADORecordset
  ret = tmp_rs.Open(SQL_str, conn)
  if ret then
    MsgBox "Selected 12:00 value=" + str(tmp_rs.Field("datValue").IntegerValue)
    ret = tmp_rs.close
    tmp_rs = nil
  else
    if conn.ErrorsCount > 0 then
      MsgBox str(conn.GetError(0).Number) + "- " + conn.GetError(0).Description
    end if
  end if
  
  SQL_str = "DELETE * FROM tData;"
  tmp_rs = conn.Execute(SQL_str)
  if tmp_rs <> nil then
    ret = tmp_rs.close
    tmp_rs = nil
    MsgBox "Records deleted!"
  else
    if conn.ErrorsCount > 0 then
      MsgBox str(conn.GetError(0).Number) + "- " + conn.GetError(0).Description
    end if
  end if
  
  ret = conn.Close
  conn = nil
  
  MsgBox "Done!"

Much more like it! The framework contains the following classes:

BlogArt1b

Note:
You’ll notice that every class contains a inner… OLEObject. This is the real ADODB object, just in case I forgot something 🙂

The fun part is that also objects like Stream are now available in a convenient way. You can program stuff like this with ease:

  dim objStream as new ADOStream()
  dim ret as Boolean
  ret = objStream.Open
  
  ret = objStream.WriteText("Dit is een é text")
  
  objStream.Position = 0
  MsgBox objStream.ReadText + "(" + str(objStream.Size) + ")"
  
  objStream.Position = 0
  objStream.Type = StreamTypeEnum.adTypeBinary
  MsgBox  objStream.Read(2)
  
  ret = objStream.SaveToFile("c:\adodb.txt", SaveOptionsEnum.adSaveCreateOverWrite)
  
  ret = objStream.Close
  objStream = nil

Not all classes have been tested, so if you find an error please report them so I can make the needed changes for everybody.

All classes are open source and can be used for non-commercial and commercial use but you have to include the license.txt file.

Download classes + demo:
ADODBWrapper

Bye for now!


%d bloggers like this: