Overhaul Progress: Day 1

I think the overhaul has been going pretty well. Yes, it does mean I am recoding the entire engine, but of course most of the data is already there so in a way I’ve already done a lot of the work. Today has mostly been introducing user-defined types and working towards tidy code. But I’ve also gotten to work on the transitions between map areas, which was the main call for this overhaul. UDT’s have actually shown themselves to be really useful in managing the scene transitions.

In the main code, calling each scene change is simple as this:

if Scene(bedroom).Map.exist = 1
Scene(bedroom).Map.file = “Media/Maps/Warehouse/Set 1/Scene1.x”
Scene(bedroom).Map.lmfile = “media/Maps/Warehouse/Set 1/Scene1_lm.x”
LOADScene(bedroom, 35)
SetScene(bedroom)
endif

So, when I call a new scene (if I hit space in this test), then what’ll happen is all of the data will be deleted from the scene and replaced with a new scene.

Or like so:

DeleteAll()

Scene(bedroom).Map.exist = 0
Scene(storage).Map.exist = 1

goto LOAD

Don’t let the GOTO command scare you, whilst many programmers are so adamant against the use of a GOTO command because it usually means spaghetti code, but it isn’t the case here. The code is very tidy and labels make it simple for me to differentiate the 2 main points in the main code – the ‘start’ (where the loop starts) and ‘Load’ where the media for the particular scene is loaded. This means I can have functions looping for the battle system and also the menus. The DeleteAll() function will get rid of any media I don’t need and this means ‘current’ Scene (bedroom) no longer exists so I tell the program that and tell it to give me the new scene (storage).

One of the important functions is ‘SetScene(object)’, because inside of it it will detect what current scene is loaded (which is what ‘obj’ is for) and will set specific settings for that scene, such as object positions, player/Enemy positions, camera position, light position and colour. The commands look like this:

Scene(obj).Light.colour.red = 255
Scene(obj).Light.Colour.green = 200
Scene(obj).Light.Colour.blue = 100

Scene(obj).Light.position.x = 0
Scene(obj).Light.position.y = 700
Scene(obj).Light.position.z = 500

Scene(obj).Cam.position.x = -10
Scene(obj).Cam.position.y = 200
Scene(obj).cam.position.z = -250

Then you’ve got the LoadScene(obj, scale) function too. Which just loads the scene object file, lightmap, scales them and turns the object into a static rigid body.

Combined, the result of Scene(bedroom) is this (please ignore the cubes):

And for Scene(Storage):

The cubes were only tests for creating and transforming my character objects through my UDT’s; adding characters to the scene will be the next stage. I know it seems like it’s back to stage 1 again, but this code is much better and will be more manageable, particularly as the game grows but also in terms of hunting down bugs. The last engine code was feature being built on top of feature, but as all the features are coded this rewrite just means placing them somewhere sensible.

Also, I guess I ought to use this post to plug a pretty cool Dark Basic Professional IDE called Indigo. It really has made recoding this game more conveniently, especially as its syntax highlighting will highlight functions regardless of where you’ve declared them, the elements pane can display elements from all source data if you want it to instead of ones in the currently opened source file, which is useful for quickly accessing a variable or function that needs changing. What’s even more cool is that it comes with UDT  Auto-suggestions (makes coding with UDT’s a lot quicker), actively tries to correct or warn you about any mistakes inside your code before you compile it and if you want it to it can automatically indent your code so it looks neat and tidy. There’s other useful features and I recommend anybody using DBP to try the latest download. Linky McLink Link

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s