I'm making a 2D game in HTML5 canvas which will have a lot of objects. Some of the objects shares some properties with each other. Some of the properties will be for only one object. Objects may have an empty value property.
I want to to create a main object that will have the properties of all the objects. If there is an object with only 3 of the properties of the main object, the other properties will be empty.
For example, lets say that all the possible properties for any object in the game are {a,b,c,d,e,f,g} and we have 2 objects in the game ob0
& ob1
.
ob0
's properties are a,c,d so I will fill them only and the other properties {b,e,f} will be blank.
ob1
's properties are b,e,f so I will fill them only and the other properties {a,c,d} will be blank.
I thought of this presentation because of two things. the first thing is that I'm not very good in OOP and inheritance and other OOP things. and the second thing is about 2 years ago, in a game called Red Alert2
, there was a .INI
file, and in the file were all the objects in the game. Data were represented like this way
[obj1]
color=red
width=100px
cankill=yes
[obj2]
weapontype:4
canswim=yes
weapontype=4
speed=20
For example, the property cankill
is not in obj2
and obj2
couldn't kill in the game. But if you gave obj2
this property and gave it weapontype=10
it would kill in the game using the 10th weapon in the game. This tells me that if a property hasn't a value, it means that in the game it value will be zero or ??
Here comes my questions.
How could that be done in JS? I mean can I really connect the
.INI
file withJS
?Is there a more effective way to save the objects properties? I'm not asking to describe that way in two pages. I just want to know the main idea of that point.
- I thing my solution to this problem will experience the problem of overloaded size. If the game has 1000 properties, each object will be consisted of 1000 properties, when the object would need only 4 or 5 properties, and that will affect badly on the memory. How could that be solved?