<< Chapter < Page Chapter >> Page >

A 3D display

As mentioned earlier, this game is fully three dimensional. The prey fish and the predator are free to swim in any direction in 3D space. The tails on theprey fish and the predator appear longest when they are swimming parallel to the x-y plane. As they change their angle relative to the x-y plane, the tailsappear to become shorter or longer and in some cases, they appear not to have a tail at all. The fish that appear to have no tails are either swimming directlytoward the viewer or swimming directly away from the viewer.

This can best be observed by clicking the Stop button just as the fish scatter during an attack and freezing the state of the fish in the 3D world asshown in Figure 1 . If you examine the image at that point, you are likely to see some fish with shorter tails than other fish. This is evident by some of theprey fish near the center of Figure 1 that appear to have no tails at all.

Enough talk, let's see some code

A complete listing of this program is provided in Listing 31 near the end of the module.

Portions of this program are very similar to programs that I have explained in earlier modules in this series. I won't repeat those explanations here.Rather, I will concentrate mostly on the code that is new and different in this module.

Abbreviated constructor for the GUI class

Listing 1 shows an abbreviated constructor for the GUI class. (Much of the code in the constructor has been explained before, and was deleted from Listing1 for brevity.)

Listing 1 . Abbreviated constructor for the GUI class in GM01test08.
GUI(){//constructor//Code deleted for brevity //Register this object as an action listener on all// three buttons. startButton.addActionListener(this);attackButton.addActionListener(this); stopButton.addActionListener(this);//Make the drawing color RED at startup.g2D.setColor(Color.RED); }//end constructor

If you examine Listing 31 , you will see that the GUI class implements the ActionListener interface. Therefore, an object of the GUI class can be registered as an action listener on a button. Listing 1 registers the object of the GUI class as a listener on all three of the buttons shown in Figure 6 .

Beginning of the actionPerformed method

The actionPerformed method that begins in Listing 2 is called whenever the player clicks any of the three buttons shown in Figure 6 .

Listing 2 . Beginning of the actionPerformed method in GM01test08.
public void actionPerformed(ActionEvent e){ if(e.getActionCommand().equals("Start")&&!animate){ //Service the Start button.//Get several user input values.numberPoints = Integer.parseInt( numberPointsField.getText());if(drawPointsBox.getState()){ drawPoints = true;}else{ drawPoints = false;}//end elseif(drawVectorsBox.getState()){ drawVectors = true;}else{ drawVectors = false;}//end else //Initialize some working variables used in the// animation process. animate = true;baseTime = new Date().getTime(); killCount = 0;//Enable the Attack button.attackButton.setEnabled(true);//Initialize the text in the timer field. timer.setText("0 / 0");//Cause the run method belonging to the animation// thread object to be executed. new Animate().start();}//end if

Questions & Answers

what is defense mechanism
Chinaza Reply
what is defense mechanisms
Chinaza
I'm interested in biological psychology and cognitive psychology
Tanya Reply
what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask