Dynamic game development framework thingy WIP

Started by LemonWizard, February 10, 2013, 06:59:55 PM

Previous topic - Next topic

LemonWizard

Here I have no GUI yet. But basically the start of an abstraction layer I'm working on in order to aid me in the development of my platformer engine.
Basically my platformer engine will be built ontop of this and just today finally I was able to put some of my codebase to use to render a simple sprite.
It may seem like more work than it's worth but it functions and it seems to do what I want so far. So I'm happy.

Here's the code:

PlayBASIC Code: [Select]
; PROJECT : Game Creator System
; AUTHOR : Microsoft
; CREATED : 2/7/2013
; EDITED : 2/10/2013
; ---------------------------------------------------------------------


;;;platformer editor 2013

;;made by LemonWizard AKA RAIN

;;;STILL KICKING AND SCREAMING FOR 2013 YEAHH!!!


;;;This is the template file to the game engine and object engine

;;;functions


;;basic functions library

;; A literal building block of the game engine.
;;This is used for the tile engine alot now.
;;Basically the only MAJOR function needed right now


;;it should be noted that THIS set of objects is the global static objects the user creates.
;;scripts allow the user to create instances of these specific types of objects
;;so we need a global array list of the current types of objects that exist
;;and then a local array list of the objects that are in memory in the "level" and of what parent objects they are
;;That is the mistake I was making with the abstraction layer here before.



type global_object
obj_id
name$
obj_type
current_sprite
endtype

type game_sprite
sprite_id ;gives the sprite a parent Id which can be used to reference to child objects using this sprite
name$ ;gives the sprite a name so the editor will show up with the sprite's name
image_scriptname$ ;;this makes it so the sprite can actually link to an image or a series of images
endtype

dim game_scriptnames$(1)
dim game_sprites(1) as game_sprite
dim global_objects(1) as global_object
dim game_sprites(1) as game_sprite
dim game_images(1) ;create the game images array
dim game_filenames$(1);
game_filenames$(1)="internal_image" ;;the first indice is always going to be used for a local only image
game_images(1)=newfximage(32, 32) ;;create the game images thing here
dim objects(1) as global_object

;;;now we basically need foundational handler code that allows all these "game elements" to work together.


;;prepare

create_new_image("Cursor Glove.png", "glove")
assign_sprite_image("glove", 1)
draw_a_sprite(1, 0, 0)
do

draw_a_sprite(1, 0, 0)


sync
cls rgb(0,0,0)
loop

function box_in_box(objx1, objy1, objx2, objy2, colx1, colx2, colx2, coly2)



result=false

if objx2=>colx1
if objy2=>coly1
if objx<=colx2
if objy<=coly1
result=true
endif
endif
endif
endif



r=result

endfunction r

;;this is an abstraction function so that the scripting engine can use the command
;;"if obj_id!=value"

function obj_id_is_not(objid, compareval)

if objid <> compareval

result=true

else
result=false

endif

r=result



endfunction r


;;this is an abstraction function so that the scripting engine can use the command
;;"if obj_id_is=value" and is also the inverse of the function obj_id_is_not

function obj_id_is(objid, compareval)

if objid <> compareval

result=false

else
result=true

endif

r=result


endfunction r


;;this is an abstraction function so that the scripting engine can load new images to the game engine
;;and in script the game engine will refer to the images by their scripted names

function create_new_image(filename$, scriptname$)

index=getarrayelements(game_images(), 1 )

index=index+1
redim game_images(index)
redim game_scriptnames$(index)
redim game_filenames$(index)

Login required to view complete source code


You can download the image required in the attachments if you want to try it out.
Another note. I'm accessing the parent objects directly but later it'll abstract to child object creation and what not. Then I'll be adding in a lot of other features. I plan to seperate and abstract as much as I can for my game engine you can already see the start of some basic work.

One feature will be changing "one game object" into "another" with a script. based on conditions set by the game engine at read time. (When level layer data is loaded)


LemonWizard

#1
Here's a newly modified version of the code no other requirements just that image file still.

it adds gravity, and shows how easily it will be for me to set certain parameters for things in my game such as gravity.

PlayBASIC Code: [Select]
; PROJECT : Game Creator System
; AUTHOR : Microsoft
; CREATED : 2/7/2013
; EDITED : 2/10/2013
; ---------------------------------------------------------------------


;;;platformer editor 2013

;;made by LemonWizard AKA RAIN

;;;STILL KICKING AND SCREAMING FOR 2013 YEAHH!!!


;;;This is the template file to the game engine and object engine

;;;functions


;;basic functions library

;; A literal building block of the game engine.
;;This is used for the tile engine alot now.
;;Basically the only MAJOR function needed right now


;;it should be noted that THIS set of objects is the global static objects the user creates.
;;scripts allow the user to create instances of these specific types of objects
;;so we need a global array list of the current types of objects that exist
;;and then a local array list of the objects that are in memory in the "level" and of what parent objects they are
;;That is the mistake I was making with the abstraction layer here before.

gravity_direction$="down"


type global_object
obj_id
name$
obj_type
current_sprite
endtype

type game_sprite
sprite_id ;gives the sprite a parent Id which can be used to reference to child objects using this sprite
name$ ;gives the sprite a name so the editor will show up with the sprite's name
image_scriptname$ ;;this makes it so the sprite can actually link to an image or a series of images
x
y
gravity_applies
endtype

dim game_scriptnames$(1)
dim game_sprites(1) as game_sprite
dim global_objects(1) as global_object
dim game_sprites(1) as game_sprite
game_sprites(1).x=0
game_sprites(1).y=0
game_sprites(1).gravity_applies=true
dim game_images(1) ;create the game images array
dim game_filenames$(1);
game_filenames$(1)="internal_image" ;;the first indice is always going to be used for a local only image
game_images(1)=newfximage(32, 32) ;;create the game images thing here
dim objects(1) as global_object

;;;now we basically need foundational handler code that allows all these "game elements" to work together.


;;prepare

create_new_image("Cursor Glove.png", "glove")
assign_sprite_image("glove", 1)
draw_a_sprite(1)
do

draw_a_sprite(1)
gravity()

if upkey()
game_sprites(1).gravity_applies=false
else
game_sprites(1).gravity_applies=true
endif


sync
cls rgb(0,0,0)
loop

function box_in_box(objx1, objy1, objx2, objy2, colx1, colx2, colx2, coly2)



result=false

if objx2=>colx1
if objy2=>coly1
if objx<=colx2
if objy<=coly1
result=true
endif
endif
endif
endif



r=result

endfunction r

;;this is an abstraction function so that the scripting engine can use the command
;;"if obj_id!=value"

function obj_id_is_not(objid, compareval)

if objid <> compareval

result=true

else
result=false

endif

r=result



endfunction r


;;this is an abstraction function so that the scripting engine can use the command
;;"if obj_id_is=value" and is also the inverse of the function obj_id_is_not

function obj_id_is(objid, compareval)

if objid <> compareval

result=false

else
result=true

endif

r=result


Login required to view complete source code



kevin


  Some of the functions have unnecessary logic in the,,  stuff like this..

PlayBASIC Code: [Select]
function obj_id_is_not(objid, compareval)
if objid <> compareval
result=true
else
result=false
endif
r=result
endfunction r



  This really should be a PSUB. 

PlayBASIC Code: [Select]
psub obj_id_is_not(objid, compareval)
result=objid <> compareval
endPsub result



Stuff like this,

PlayBASIC Code: [Select]
function get_image_id(scriptname$)

for temp=1 to getarrayelements(game_images(), 1)

s_temp_string$=game_scriptnames$(temp)
if s_temp_string$=scriptname$
img_id=temp
exitfor
endif
next temp


endfunction img_id





  A routine like this, could probably be replaced  entirely by FindArrayCell

  But one thing for sure the string copy in the loop really isn't needed. 
PlayBASIC Code: [Select]
psub get_image_id(scriptname$)

img_id=0
for temp=1 to getarrayelements(game_images(), 1)
if game_scriptnames$(temp)=scriptname$
img_id=temp
exitfor
endif
next temp

endpsub img_id