• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to not load removed object?  RSS feed

 
Robert Hunt
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on this game in android, but the issue I have is more about basic java.

In my game there are players and an enemy. If the player shoots an enemy, that enemy dies. Easy. If I want to save that individual enemy's dead or alive state and load it, how would I go about doing that? For example:

In my XML level file, there are three different enemies, like so:
<entity x="400" y="400" type="enemy"/>
<entity x="600" y="200" type="enemy"/>
<entity x="700" y="900" type="enemy"/>
If the player shoots the enemy that originated at 400, 400, or any other coordinate and that enemy dies I want to save that to sharedPreferences(a simple saving and loading system done in android) or in an array of enemies or as a boolean, and when the game is loaded, I want the dead enemy to stay dead and not be loaded. I could easily make an enemy1, enemy2, enemy3... object and have individual booleans for them, but there has to be a way to save and load for multiple objects of the same entity, if that makes any sense. (The enemy at 400, 400 the enemy at 600, 200 etc...)

How would I go about doing this?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...... but there has to be a way to save and load for multiple objects of the same entity, if that makes any sense. (The enemy at 400, 400 the enemy at 600, 200 etc...)

How would I go about doing this?


You want to save the state of the enemy object when it dies and then bring it up again when the game is reloaded at exact same coordinates. Correct? Do you know what is Serialization in Java?
 
Robert Hunt
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not so much how to save it it's more of what to save. And yes, that is correct.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Green Eight wrote:It's not so much how to save it it's more of what to save. And yes, that is correct.


Your opening question was "How would I go about doing this?". First, always be sure what is exactly you are confused about. Identifying the problem is the first step in solving it.

Anyways, first make a concrete model of your game, the various entities which would be part of it, the relationships between them, the cardinality etc. that should be your first step- proper schema design.

While designing the game etc, you may consider many aspects, for instance :

a) What are the attributes an enemy can have , apart from his location in (x,y) on the map, maybe his dress color, mask, life-left, weapons, rank, militant organization etc?

b) Under what circumstances would you want the enemy to be displayed dead / alive.

Like I said, it is a design question. There could be N entities(like special forces, artillery, militants, villagers, spies, infiltrators etc.) and R type of relationships between them(forces have artillery.... and so on). There could be endless design considerations. YOU need to decide the what part first yourself.

And "what" should always be the first question that should be answered. The "how" part is merely a technicality, though that too requires practice.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!