This site requires JavaScript, please enable it in your browser!
Greenfoot back
Lari2311
Lari2311 wrote ...

2015/5/25

Life Counter

Lari2311 Lari2311

2015/5/25

#
Hey guys, I have to program a game as a school project (I want to program sth like a Jump 'n Run game) and here's the problem: I just can't seem to get a life counter to work... The counter should be located in the upper left corner. There should be 3 hearts (as an object except sb has another idea) representing the life. Every time the playable character (controlled through the keyboard) hits an obstacle (e.g. a tree) one of the hearts should delete itself/be deleted. If there are no more hearts left sth like a 'Game Over' screen should pop up. (Before someone asks: Yes I tried to search for sth like this and also tried some things myself, but either I didn't understand how it worked or it wouldn't work...so an explanation would be very helpful too :) ) ~Lg Lari2311
danpost danpost

2015/5/25

#
What do you have for a Heart or Health class? Please show your code (read the 'Posting code? read this!' link below the reply box before posting any codes).
Lari2311 Lari2311

2015/5/26

#
That's the problem. I don't really have anything programmed for that class yet...
danpost danpost

2015/5/26

#
You need an Actor subclass to display the images (lives). It can have an int field to hold the current number of lives remaining and that field can be used to 'draw' that many icon images onto the image of the actor. Do not use the act method to keep the image of the actor updated; it only needs to be re-drawn when its value is initially set and when its value is changed. Add the needed methods that other classes can use to 'get' and 'set' its value. Do what you can. If you run into difficulties, then post the current code and ask for help on the specific issue at hand.
You need to login to post a reply.