G12_C4_For Teacher Reference
Activity Flow | Slide No. | Topic | Time |
---|---|---|---|
TA | 4-8 | Last class revision+quiz | 1 min |
9-15 | Functions introduction | 6 min | |
16-19 | Calculation of new x,y | 6 min | |
21-25 | Teacher activity | 8 min | |
SA | 26-31 | Student activity | 8 min |
Wrap - Up | 32-35 | Quiz | 5 min |
36-40 | Additional activity | 10 min |
Slide No. | Topic |
---|---|
13-14 | Function intro code |
21-25 | TA- Code |
transform.rotate() function rotates the image at the given angle.
So option A is correct.
When a key is pressed KEYDOWN event occurs and when the key is released KEYUP event occurs. Therefore option B is correct.
B
B
B
painter()
electrician()
Calling
Function
Function
Definition of function
Function calling and storing returned value in c variable
Assigning values to variable
printing variable
y-axis
x-axis
(x, y)
(xnew, ynew)
distance
x' = distance * cos(angle)
y' = distance * sin(angle)
angle
x'
y'
xnew= x +x'
ynew= y+y'
+
+
0°
40°
5
x' = distance * cos(angle)
y' = distance * sin(angle)
xnew= x +x'
ynew= y+y'
5
Game loop
include math library to use cos() and sin() functions.
define a function newxy() that takes four variables and returns nx.
define distance=5 this is how much player will move after each frame.
Game loop
Convert the angle from degrees to radians.
This is to be done as the formula as it works with radian angle only.
Note: We have written angle+90 as in our game 0 degrees is towards up but in the formula it should be towards the right.
0 degree in game
0 degree in formula
Game loop
Create a variable forward, which will tell if the player should move forward or not.
Set it to false as at the beginning of the game player is not moving.
Checking if the up arrow key is pressed and then making forward =True, to indicate that the player should move forwards.
Make forward = False when the up arrow key is released.
Checking if forward =True, and then calling the newxy() function to get new value for the player.x
B
Hint: We can update the newxy() function with the y-axis formula as we did for the x-axis.
y' = distance * sin(angle)
ynew= y+y'
Return and use the new y position as well
calculate the new y position by using the formula.
Coordinate system in formula
Coordinate system in game
x-axis
y-axis
(0,0)
(0,0)
ynew= y - y'
Instead of adding y', we will subtract it to compensate for the direction of the y-axis.
def name():
body of function
Q.1
A
C
B
D
Syntax for defining
a function is:
def function_name():
function body
C
def name:
body of function
def():
body of function
function name():
body of function
cos()
sin()
tan()
Q.2
None
A
C
B
D
A
B
Hint:
1. Check if the player reached the left/right edge by checking if the x-axis value is 0 or 400
2. Make player.x=400 when it reaches left edge and player.x=0 when it reaches the right edge.
Task: Make the player spaceship move to alternate edges when it goes from the left or right edge.
B
Task: Make the player spaceship move to alternate edges when it goes from the top or bottom edge.
Hint:
1. Check if the player reached the top/bottom edge by checking if the y-axis value is 0 or 600
2. Make player.y=600 when it reaches top edge and player.x=0 when it reaches bottom edge.
Activity | Activity Name | Link |
---|---|---|
Teacher Activity 1 | Asteroid3 | |
Teacher Activity 2 | Asteroid 4 -final solution after the class | |
Teacher Activity 3 | AA-1 Solution | |
Teacher Activity 4 | AA-2 Solution | |
Student Activity 1 | Asteroid3.5 |