|
@@ -4,11 +4,11 @@
|
4
|
4
|
![main2.png](images/main2.png)
|
5
|
5
|
![main3.png](images/main3.png)
|
6
|
6
|
|
7
|
|
-[Verano 2016 - Ive]
|
|
7
|
+[Verano 2016 - Ive - Coralys]
|
8
|
8
|
|
9
|
|
-When we want to solve a problem, most of the time there is one or more options that depend on certain conditions being met. Computer programs are written to solve problems, and should therefore have a structure that allows it to make decisions. In C++ the decision (or conditional) instructions are structured using if, else, else if or switch. These structures usually involve the use of relational expressions and logical operations. In today's laboratory experience you will practice the use of certain decision structures to complete the design of a car and obstacle collision game application.
|
|
9
|
+When we want to solve a problem, most of the time there is one or more options that depend on certain conditions being met. Computer programs are written to solve problems, and should therefore have a structure that allows it to make decisions. In C++ the decision (or conditional) instructions are structured using if, else, else if or switch. These structures usually involve the use of relational expressions and logical operations. In today's laboratory experience, you will practice the use of certain decision structures to complete the design of a car and an obstacle collision game application.
|
10
|
10
|
|
11
|
|
-##Objectives:
|
|
11
|
+## Objectives:
|
12
|
12
|
|
13
|
13
|
1. Use relational expressions and select appropriate logical operators to make decisions.
|
14
|
14
|
2. Apply decision structures.
|
|
@@ -20,13 +20,13 @@ Before arriving at the laboratory you should have:
|
20
|
20
|
|
21
|
21
|
1. Reviewed the following concepts:
|
22
|
22
|
|
23
|
|
- a. logical operators
|
|
23
|
+ a. Logical operators
|
24
|
24
|
|
25
|
25
|
b. if, else, else if, switch
|
26
|
26
|
|
27
|
27
|
2. Studied the concepts and instructions for the laboratory session.
|
28
|
28
|
|
29
|
|
-3. Taken the Pre-Lab quiz available in Moodle.
|
|
29
|
+3. Taken the Pre-Lab quiz, available in Moodle.
|
30
|
30
|
|
31
|
31
|
|
32
|
32
|
---
|
|
@@ -36,9 +36,9 @@ Before arriving at the laboratory you should have:
|
36
|
36
|
|
37
|
37
|
## Car Scrolling Game
|
38
|
38
|
|
39
|
|
-Collision games consist of maneuvering an object in order to dodge incoming objects to avoid possible collision. The collision can lower the player's score, or stop the game. Sometimes, colliding with certain objects may increase the player's score. In the game from today's laboratory experience, the object the player controls is a car, the objects that cause the game to stop are pines, holes, among others, and the objects that add points to the score are flags.
|
|
39
|
+Collision games consist of maneuvering an object in order to dodge incoming objects to avoid possible collision. The collision can lower the player's score, or stop the game. Sometimes, colliding with certain objects may increase the player's score. In the game from today's laboratory experience, the object the player controls is a car, the objects that cause the game to stop are pines, holes, among others; and the objects that add points to the score are flags.
|
40
|
40
|
|
41
|
|
-The controls for this game are simple: the up arrow moves the car up and the down arrow moves the car down. During gameplay, the game simulates the movement of the car towards the right using a simple method: moving the background with its obstacles and flags towards the left while the car stays in the same place. The player can move the car up or down to dodge obstacles and to capture the flags. If the car collides with an obstacle, the game ends. The player can continue by pressing the `Retry` button.
|
|
41
|
+The controls for this game are simple: the up arrow moves the car up, and the down arrow moves the car down. During gameplay, the game simulates the movement of the car towards the right using a simple method: moving the background with its obstacles and flags towards the left while the car stays in the same place. The player can move the car up or down to dodge obstacles and to capture the flags. If the car collides with an obstacle, the game ends. The player can continue by pressing the `Retry` button.
|
42
|
42
|
|
43
|
43
|
|
44
|
44
|
---
|
|
@@ -58,13 +58,13 @@ The controls for this game are simple: the up arrow moves the car up and the dow
|
58
|
58
|
|
59
|
59
|
## Laboratory Session:
|
60
|
60
|
|
61
|
|
-In this laboratory experience you will practice the use of mathematical expressions and condition structures to implement the car's collision detection against obstacles and flags.
|
|
61
|
+In this laboratory experience, you will practice the use of mathematical expressions and condition structures to implement the car's collision detection against obstacles and flags.
|
62
|
62
|
|
63
|
63
|
Your task is to complete the design of the game application.
|
64
|
64
|
|
65
|
65
|
### Exercise 1 - Familiarize yourself with the pre-defined functions
|
66
|
66
|
|
67
|
|
-The first step in this laboratory experience is to familiarize yourself with the pre-defined functions (methods) in the code. You will invoke some of these functions in the code you will complete to detect the collisions.
|
|
67
|
+The first step in this laboratory experience is to familiarize yourself with the pre-defined functions (methods) in the code. You will invoke some of these functions in the code to detect the collisions.
|
68
|
68
|
|
69
|
69
|
#### Instructions:
|
70
|
70
|
|
|
@@ -96,7 +96,7 @@ The first step in this laboratory experience is to familiarize yourself with the
|
96
|
96
|
|
97
|
97
|
### Exercise 2 - Complete the function to change the game's track.
|
98
|
98
|
|
99
|
|
-In this exercise you will use the C++ condition structure called **switch** to change the attributes of the track. You will complete the `setTrack` method that can be found in the `work.cpp` file. This method changes the environment of the track depending on the value of `track_type` that is given as parameter.
|
|
99
|
+In this exercise you will use the C++ condition structure called **switch** to change the attributes of the track. You will complete the `setTrack` method that can be found in the `work.cpp` file. This method changes the environment of the track depending on the value of `track_type` that is given as a parameter.
|
100
|
100
|
|
101
|
101
|
The method `setTrack` receives a value of type `Track` that can be:
|
102
|
102
|
|
|
@@ -110,9 +110,9 @@ The track's attributes that can be changed are:
|
110
|
110
|
* the image on the track using the function `setTrackPixmap()`
|
111
|
111
|
* the image of the obstacles using the function `setObstaclesPixmap()`
|
112
|
112
|
|
113
|
|
-The `setTrackPixmap()` function is already defined and receives a variable of type `Track` that can be one of the following (**play::DAY**, **play::NIGHT**, **play::BEACH**, **play::CANDYLAND**).
|
|
113
|
+The `setTrackPixmap()` function is already defined and receives a variable of type `Track` that can be one of the following: **play::DAY**, **play::NIGHT**, **play::BEACH**, **play::CANDYLAND**.
|
114
|
114
|
|
115
|
|
-The `setObstaclesPixmap()` function is already defined and receives a variable of type `string` that can be one of the following (**"hole"**, **"cone"**, **"it"**, **"zombie"**, **"spongebob"**, **"patric"**, **"monster"**).
|
|
115
|
+The `setObstaclesPixmap()` function is already defined and receives a variable of type `string` that can be one of the following: **"hole"**, **"cone"**, **"it"**, **"zombie"**, **"spongebob"**, **"patric"**, **"monster"**.
|
116
|
116
|
|
117
|
117
|
#### Instructions:
|
118
|
118
|
|
|
@@ -131,7 +131,7 @@ To complete the `setTrack()` function:
|
131
|
131
|
|
132
|
132
|
### Exercise 3: Complete the function for collision with obstacles
|
133
|
133
|
|
134
|
|
-In this exercise you will complete the `obstacleCollision` method that can be found in the `work.cpp` file. The function receives an object of the `Obstacle` class and another object of the `Car` class, and should detect if there is a collision or not between the car and the obstacle. The function returns true if there is a collision between the car and an obstacle and false if there is no collision.
|
|
134
|
+In this exercise you will complete the `obstacleCollision` method that can be found in the `work.cpp` file. The function receives an object of the `Obstacle` class and another object of the `Car` class, and should detect if there is a collision or not between the car and the obstacle. The function returns true if there is a collision between the car and an obstacle, and false if there is no collision.
|
135
|
135
|
|
136
|
136
|
To detect the collision, the function should ask for the coordinates of the obstacle and the car's $$Y$$ coordinate. Remember that the car does not move on the $$X$$ axis, since that coordinate is fixed and stored in a constant variable called `CARX`. The collision occurs if the obstacle has the same $$X$$ coordinate, and is a certain distance above and below the car's $$Y$$ coordinate as shown in Figure 1. The range of the distance of the car's center upwards and downwards is stored in the variable called `OBSTACLERANGE`.
|
137
|
137
|
|
|
@@ -150,7 +150,7 @@ If a collision is detected, the function returns `true`, and if not the function
|
150
|
150
|
|
151
|
151
|
In this exercise you will complete the `flagCollision` method that can be found in the `work.cpp` file. The function receives an object of the `Obstacle` class and another object of the `Car` class, and should detect if there is a collision or not between the car and the flag. This function is very similiar to the function in Exercise 3, except that the function does not return a value. The actions that occur when a collision is detected are done inside the function.
|
152
|
152
|
|
153
|
|
-In this case if a collision is detected, the game's score should increase by 30 points using the `setScore` function and hide the flag using the `flag.hide()` function to create the illusion that the flag was picked up during the collision.
|
|
153
|
+In this case if a collision is detected, the game's score should increase by 30 points using the `setScore` function and the flags should be hidden using the `flag.hide()` function to create the illusion that the flag was picked up during the collision.
|
154
|
154
|
|
155
|
155
|
---
|
156
|
156
|
|
|
@@ -158,7 +158,7 @@ In this case if a collision is detected, the game's score should increase by 30
|
158
|
158
|
|
159
|
159
|
### Deliverables
|
160
|
160
|
|
161
|
|
-Use "Deliverable" in Moodle to upload the `work.cpp` file that contains the function calls and changes you made to the program. Remember to use good programming techniques, include the name of the programmers involved, and document your program.
|
|
161
|
+Use "Deliverable" in Moodle to upload the `work.cpp` file that contains the function calls and changes you made to the program. Remember to use good programming techniques by including the name of the programmers involved and documenting your program.
|
162
|
162
|
|
163
|
163
|
---
|
164
|
164
|
|