I thought for a bit of fun, I would open DBPro for the first time in years and thought I'd see how I might structure it as MVC.
Main.dba
GameInit()
function GameInit()
sync on
sync rate 60
CharacterController()
GameController()
endfunction
Models:
CharacterModel.dba
type Position
x as float
y as float
z as float
endtype
type CharacterModel
ID as integer
Name as string
Description as string
Health as integer
Default as Position
endtype
function _CharacterModel()
dim Character(2) as CharacterModel
Character(0).ID = FindFree("object",1,100000)
Character(0).Name = "Seppuku"
Character(0).Description = "Totally Awesome"
Character(0).Health = 100
Character(0).Default.x = 0 : Character(0).Default.y = 0 : Character(0).Default.z = 0
make object cube Character(0).ID, 100
Character(1).ID = FindFree("object",1,100000)
Character(1).Name = "SteveWithChips"
Character(1).Description = "Totally Chips"
Character(1).Health = 100
Character(0).Default.x = 0 : Character(0).Default.y = 20 : Character(0).Default.z = 100
make object cube Character(1).ID, 100
endfunction
GameModel.dba
Rem ***** Included Source File *****
type GameModel
Title as string
Description as string
Version as float
Author as string
endtype
function _GameModel()
global Game as GameModel
Game.Title = "Hello World"
Game.Description = "Is it me you're looking for?"
Game.Version = 0.5
Game.Author = "Seppuku"
endfunction
Controllers
CharacterController.dba
function CharacterController()
_CharacterModel()
position object Character(0).ID, Character(0).Default.x, Character(0).Default.y, Character(0).Default.z
position object Character(1).ID, Character(1).Default.x, Character(1).Default.y, Character(1).Default.z
endfunction
GameController.dba
function GameController()
_GameModel()
point camera 0,0,0
do
CameraAction()
GameView()
sync
loop
endfunction
function CameraAction()
if upkey() = 1 then move camera 1
if downkey() = 1 then move camera - 1
if leftkey() = 1 then turn camera left 1
if rightkey() = 1 then turn camera right 1
endfunction
Views
GameView.dba
function GameView()
text 10, 20, "Character: " + Character(0).Name
endfunction
Of course, this is just a little experiment. I theory, one could have the "Models" use something like DarkData for all the info, then LUA scripting for the Views, which will be all the levels and stuff.
The above could be improved, just been so long since I've used DBPro.
But the principle here would be: all gameplay logic is handled by the controller, how it's presented is handled by the view, the data used it handled by the model, there's a separate area for "helpers" to help your coding and you have the "main" code for initiating everything. The idea is for the model and controller to chat to each other, and also, the view and controller to chat.
Seems long winded for just 2 cubes and rudimentary camera control, but of course, the idea is for a structure that can be scaled.