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

2013/1/27

Switching "Weapons"

RedManRocket RedManRocket

2013/1/27

#
I've been trying to figure out for some time now how to switch "weapons" but i can't figure out how to switch a class when a key is pressed. Any help? Or methods that would be of use?
moobe moobe

2013/1/28

#
I think you have two options. 1: You have different images and switch them, if the key is pressed. 2: You don't switch the images, but you have different classes for your weapons. So your weapon is an object which you have to remove and set an other one when the weapon is switched.
RedManRocket RedManRocket

2013/1/28

#
I'm not planning on switching the image of the gun just the bullet, but i would like to switch the bullet class so i can program the other bullet to do other things, right now i just have a machine gun, but when "1" is pressed it will switch to a faster machine gun.
danpost danpost

2013/1/28

#
One thing many new programmers do not seem to grasp is this: the different characteristics and behaviours of a certain type object does not neccessarily require a new class of object. Variables can be used to determine the image to use or the speed of the object it creates, The class can be given methods to access the value of those variables so that other classes can determine the appropriate actions to perform when dealing with those objects. Please review the first section in the Java Tutorials for an example of using these fields (or variables).
RedManRocket RedManRocket

2013/1/28

#
I will try the tutorials, Thank you.
You need to login to post a reply.