damage status

Monkey Forums/Monkey Beginners/damage status

Rell(Posted 2015) [#1]
I have the slash.png out and I have shadow dragon.png out what I want to do is click on the slash.png with the mouse to attack shadow dragon. I also want to put a hit point status next to shadow dragon 100/100 and every time he's hit it go down ex. 90/100 slash does 10 points of damage


Gerry Quinn(Posted 2015) [#2]
Probably you are using some kind of 'game creation' system. They make it easier to do certain pre-programmed things, but harder to do anything that is not designed in advance. What you describe above sounds like the sort of thing such systems are made to do. Monkey is a programming language, meaning it is very flexible but what you want to do is not built in.


MikeHart(Posted 2015) [#3]
Ok, you did really ask a question. How about you showing us what you have so far and we go from there on thing at a time.


Rell(Posted 2015) [#4]
Thanks Gerry and Mike for your quick response and appreciate it what I'm trying to do or say is not as complex as it sounds but here what I got so far
[ Import mojo

Class Fest Extends App
Field slash:Image
Field shadowdragon:Image
Field question:Image
Method OnCreate()
SetUpdateRate(60)
slash = LoadImage("slash.png")
shadowdragon = LoadImage("shadowdragon.png")
question = LoadImage("question.png")
End
Method OnUpdate()
MouseX()
MouseY()
MouseDown

End
Method OnRender()
Cls (123,123,255)
DrawImage(slash, 20, 20)
DrawImage(shadowdragon, 300,300)
DrawImage(question, 150,300)
End
Method OnLoading()
End
Method OnSuspend()
End
Method OnResume()
End
End

Function Main()

New Fest()

End
[/codebox]
Not sure how to use code box apologies


MikeHart(Posted 2015) [#5]
Np, you have to add a [ codebox] to the beginning too. I don't know how your coding background is, so I have attached an example. As always, many roads lead to Rome. So there are several ways to do things. Try to study it. If you have any questions, let me know:




Rell(Posted 2015) [#6]
Thanks Mike but one more question and that will do me good for awhile How do I change the image on question.png when I click on slash.png that is change a image when i click on another image.


MikeHart(Posted 2015) [#7]
Add this method to the myObj class and call it when you want to change an image:

Method ChangeImage(name:String)
	Self.fname = name
	Self.img.Discard()      'This deletes the old image.
	Self.img = LoadImage(Self.fname, 1, Image.MidHandle)
End	



Gerry Quinn(Posted 2015) [#8]
I think in this case the 'slash' image probably represents a button or an animated sword, with two or more images that will be used often. I this case you would generally load all the images at the start and keep them around. You might eventually put everything into MyObj or an extended class, but you could start by using an array of MyObj[] and adding an int called currentSlash which you would change as appropriate. [There's actually a frames parameter in Image that could be used for this, but it's easier to roll your own.]


Rell(Posted 2015) [#9]
Thanks Gerry for the help I have another question in above help with Mike I try to add a new thing like slash but called stab I try to mimic above but it had a error for method onrender but show me how to fix this it about causing damage like slash which is above example.


MikeHart(Posted 2015) [#10]
Sorry, I have a had time understanding.

Please show your code which is not working.


MikeHart(Posted 2015) [#11]
Another advice. Before you start working on your own code, work yourself through the tutorials which ship with Monkey X.