Create the circle moving program using the new language

Assignment Help Programming Languages
Reference no: EM131056153

Pass Task 8.2: Circle Moving in C

Overview

In Topic 3 you developed a Circle Moving Program using Pascal. To check your reference sheet, and to see how similar Pascal and C programs really are, you will now implement an- other version of this program using C.

Purpose: Start to learn a new language.

Task: Create the circle moving program using the new language, and your reference sheet.

Instructions

Here is a list of C functions and procedures available in C to help you with this program.

Function / Procedure

Does

void open_graphics_window(title, width, height);

Opens a new window, with indicated title and size

void load_default_colors ( );

Loads the default colours such as COLOR_RED.

void clear_screen ( );

Clears the screen to a color, e.g. COLOR_WHITE

void delay ( time );

Delays for a number of milliseconds

void process_events ( );

Listens for user input - required for any input

int screen_width ( ); int screen_height ( );

The width and height of the window

float mouse_x( ); float mouse_y( );

X or Y location of the mouse

bool mouse_clicked(button)

Was the mouse button clicked?

Buttons are LEFT_BUTTON and RIGHT_BUTTON

bool window_close_requested();

Has the user asked to close the Window?

bool key_down(key);

Is the key currently held down?

Keys are in the format A_KEY, NUM_1_KEY, LEFT_KEY etc

bool key_typed(key);

Was the key typed? (Pressed then released)

1. Download the starter code for this task.

2. Extract the zip file to your code directory (e.g. Documents/Code)

3. Rename the Project Template folder to CharacterMoving2

4. Open a Terminal window and navigate to your CharacterMoving2 directory.

5. Write the code to implement a basic SwinGame program using the following code.

1524_code.jpg

6. Switch back to the Terminal and compile and run your program.

7. As with Pascal, the window closes after 5 seconds when the program's instructions end. Implement an event loop to allow you to control the life of the program.

- The event loop will be located in Main, and will loop until the user closes the window.
- Process Events needs to be called once each event loop to update SwinGame with the actions that have occurred since the last time through the loop.

6. Switch back to the Terminal and compile and run your program.

7. As with Pascal, the window closes after 5 seconds when the program's instructions end. Implement an event loop to allow you to control the life of the program.

- The event loop will be located in Main, and will loop until the user closes the window.

- Process Events needs to be called once each event loop to update SwinGame with the actions that have occurred since the last time through the loop.

8. Switch back to the Terminal and compile and run the program. It should now remain open until you close the window.

9. Create a constant named CIRCLE_RADIUS and set it to 100.

10. Alter Main to draw a circle on the screen, using variables for the circle's x and y location.

---------------------------------
Procedure: Main
---------------------------------
Local Variables:
- x, y: Single data for the circle's location Steps:
1: Open a Graphics Window with title 'Character Moving' that is 800x600
2: Assign x the value 400
3: Assign y the value 300
4: Do
5: Process Events
6: Clear the Screen to COLOR_WHITE
7: Fill a Circle using COLOR_GREEN, at location x,y with a radius CIRCLE_RADIUS
8: Refresh the Screen limiting it to 60 FPS 9: While Window Close is not Requested

11. Switch to the Terminal, compile and run the program. You should be able to see a green circle in the centre of the screen.

- The x and y variables in Main store all of the data for this game: the location of the cir- cle. As these are the only variables in the "game" (which is being run by the steps in the Main procedure), these are the only things that can change.

The next step will involve using if statements to selectively run sections of your code.

12. Alter Main to update the x variable when the user is holding down the arrow keys. The fol- lowing pseudocode shows the changes for moving left and right. Include the code to move in all four directions.

---------------------------------
Procedure: Main
---------------------------------
Local Variables:
- x, y: Single data for the circle's location Steps:
1: Open a Graphics Window with title 'Character Moving' that is 800x600
2: Assign x the value 400
3: Assign y the value 300
4: Repeat
5: Process Events

6: if the LEFT_KEY Key is Down then
7: Assign x, the value x - 1
8: if the RIGHT_KEY Key is Down then
9: Assign x, the value x + 1

10: Clear the Screen to ColorWhite
11: Fill a Circle using ColorGreen, at location x,y with a radius 100
12: Refresh the Screen limiting it to 60 FPS 13: Until Window Close is Requested

13. Switch back to the Terminal and compile and run the program. You should be able to move the circle using the left and right arrow keys. If you keep your finger on the one arrow key long enough, the circle will disappear off the edge of the screen.

14. Now, adjust the if statements so that the program will ensure that the circle remains on the screen.

15. Switch to the Terminal. Compile and run the program, and test that you cannot move the circle off the screen to the left or right.

Compare your final program to your Pascal program... Notice how similar they are. If you can see that they are basically the same you are well on the way with your understanding of pro- gramming.

Reference no: EM131056153

Questions Cloud

How many years will it take the firm to pay off this debt : Berkley Trucking recently purchased a new truck costing $147,800. The firm financed this purchase at 7.6 percent interest with monthly payments of $2,100. How many years will it take the firm to pay off this debt?
What is the bonds nominal yield to call : Walker Industries has a bond outstanding with 12 years to maturity, a 9% coupon paid annually, and a $1,000 par value. The bond has a 7% nominal yield to maturity, but it can be called in 4 years at a price of $1,025. What is the bond’s nominal yield..
Compare the cost to the bank lending rate : James wants to buy a flat screen television for his new apartment. He has saved $700, but still needs $500 more. The bank where he has a checking and savings account will loan him $500 at 12% annual interest using a 90-day promissory note. He wondere..
What will be the expected return on your portfolio : State of the economy Probability Return on Stock A Return on Stock B “Fiscal Cliff” resolved 0.3 25% -10% “Fiscal Cliff” not resolved 0.7 -5% 30% Suppose you have $10,000 total. If you put $4,000 in Stock A and the remainder in Stock B, what will be ..
Create the circle moving program using the new language : Create the circle moving program using the new language, and your reference sheet - Process Events needs to be called once each event loop to update SwinGame with the actions that have occurred since the last time through the loop.
Removed the ethidium bromide : If you started with the nicked molecule, added ethidium bromide, ligated the molecule to be a closed circle, and then removed the ethidium bromide, would the molecule have positive supercoils, negative supercoils, or no supercoils? Explain.
Demonstrate that you can read and understand code : What will the code output when run - What are individualScores, bonusScore, baseScore, and teamScore? What do you think the difference is between the keywords let and var?
Double stranded dna circle : The double stranded DNA circle is nicked in two places, and is 400 base pairs long. If you denatured the 66 ng of the double stranded DNA and let it hybridize in 4 ml solution under standard conditions, how many seconds would it take for the reacti..
What impact is vr making in the corporate world : What impact is VR making in the corporate world and Is it making any improvements in the corporate world.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd