0% found this document useful (0 votes)
26 views7 pages

Game Dev

The document contains the solution to a sample midterm exam for a game programming course. It includes multiple choice questions about game engines and programming concepts like the game loop. It also includes explanations of pseudocode to implement a flipping bottle behavior and a description of code that generates 20 cubes arranged in a circle.

Uploaded by

Salman Farhat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views7 pages

Game Dev

The document contains the solution to a sample midterm exam for a game programming course. It includes multiple choice questions about game engines and programming concepts like the game loop. It also includes explanations of pseudocode to implement a flipping bottle behavior and a description of code that generates 20 cubes arranged in a circle.

Uploaded by

Salman Farhat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Faculty of Arts & Sciences

Department of Computer Science


CMPS 297V—Game Programming
Sample Midterm Solution

Student name:

Question 1 [30 pts]: Choose one answer for each.

1. The following is a part of the game engine code:


a) Isolate the game from the hardware on which it is running
b) Network communication and synchronization for multiplayer games
c) Collision detection and response
d) All of the above

2. To make the game independent of the speed of the system on which it runs:
a) Use higher level libraries
b) Use mathematical optimization functions
c) Use a time step proportional to frame rate
d) Use a time step inversely proportional to frame rate

3. The words that best describe a game loop:


a) An infinite loop that processes input if any, updates the states of the objects and renders.
b) An infinite loop that keeps prompting the user for input
c) A loop that runs every clock cycle of the GPU
d) All of the above

4. With game engines:


a) You own the main game loop and call into the library
b) An engine owns the loop and calls into your code
c) You write a monolithic program without using libraries
d) None of the above

5. Declaring a variable "speed" public will allow:


a) Setting its value from the Unity editor
b) Directly changing its value from another script by writing speed = 10;
c) Declaring it as a global variable shared by all scripts
d) All of the above

6. To have an object A destroyed when it hits another object B, it is essential that:


a) Both must have RigidBody components
b) Both must have Collider components
c) Both must have OnCollisionEnter methods in their scripts
d) Both must contain calls to the Destroy method
7. In a system that runs at 60 frames per second the time between each screen refresh is:
a) 33.3 ms
b) 16.6 ms
c) 22.2 ms
d) 40.5 ms

8. Which of the following is true about a camera?


a) It always provides a perspective projection of the scene on the screen
b) It has a position in screen coordinates
c) It has a position in space coordinates
d) None of the above

9. To move a player humanoid in a forward motion by distance X:


a) transfom.position = transform.position + X * transform.forward
b) transfom.position = transform.position + X * Vector3.forward
c) transform.position += X * Vector3.forward;
d) All of the above

10. To rotate an object 15 degrees round the x axis


a) transform.eulerAngles.x = 15
b) transform.rotation.x = 15
c) transform.eulerAngles = new Vector3(15, 0, 0);
d) transform.Rotate(15, 0, 0);

Page 2 of 7
Question 2 [35 pts]: Write the pseudocode of a script that does the following:

1. Create a cylinder and a cube. Position and scale as shown in the figure.

2. Implement a flip-the-bottle behavior:


i- When the user clicks on the cylinder, it elevates (moves upwards) for a predefined distance
ii- Then it starts flipping and moving downwards
iii- It lands on the platform and stops

1.
GameObject cylinder;
GameObject platform;
Start(){
cylinder = GameObject.CreatePrimitive(Cylinder);
platform = GameObject.CreatePrimitive(Cube);
cylinder.transform.position = new Vector3(0, 0.5, 0);
cylinder.transform.scale = new Vector3(1, 3, 1);
platform.transform.position = new Vector3 (0, 0, 0);
platform.transform.scale = new Vector3 (10, 0.5, 10);
}

Page 3 of 7
2. state = “rest”
original_y = cylinder.transform.position.y
//this method is called before every frame is rendered
Void Update(){
dy = speed * Time.deltaTime//displacement
dalpha = rotational_speed * Time.deltaTime;
position = cylinder.transform.position
if(state == “rest” && mouse is clicked)
state = “upward”
if(state == “upward”)
position.y += dy
if(position.y≥max_hieght)
state = “downward”
if(state == “downward”)
position.y -= dy
rotate(0, 0, dalpha)//rotate around the z axis
if(position.y≤original_y)
state = “rest”
cylinder.transform.position = position
}
This is one solution. Others may work as well.

Page 4 of 7
Question 3 [35 pts]: Explain what the following code is doing. Draw a rough sketch of the scene after
this code runs.
void Start()
{
float radius = 10;
int n = 20;
float d_alpha = 360f / n;
float alpha = 0;
for (int i = 0; i < n; i++){
alpha += d_alpha;
Quaternion rotateAround = Quaternion.Euler(0, alpha, 0);
Vector3 disp = rotateAround * (Vector3.right * radius);
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.localScale = new Vector3(3, 1, 1);
cube.transform.Rotate(0, alpha, 0);
cube.transform.position = disp;
}
}

Page 5 of 7
This code creates 20 cubes.

Each cube is scaled along


the x axis

Then it is rotated around z


the y axis in the xz plane
by α = (360/n) × i x

A vector along the x axis y


and has a length = radius z disp
is also rotated around the
x α
y axis by the same angle α

The rotated cube is then


translated by the rotated
vector disp

The resulting scene is 20 cubes arranged in a circle in the xz plane around the y axis resembles this rough
sketch:

Page 6 of 7
Page 7 of 7

You might also like