Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

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.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91780556

Have any Question?


Related Questions in Programming Language

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Php amp session managment assignment -this assignment looks

PHP & SESSION MANAGMENT ASSIGNMENT - This assignment looks at using PHP for creating cookies and session management. Class Exercise - Web Project: Member Registration/Login This exercise will cover adding data connectivi ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As