Digital
and Interactive Games 2015 – Term 2, Session
2
S2W1Q1
Today
Casting
While Loop
Input
Some simple Maths and figures
int i = 10;
float f = 10.25;
i = (int)f;
while loop
while (condition(s)) {
}
sum to n (from 1)
int sum = 0;
int n = 10;
int i = 1;
while (i < n) {
sum += I;
i += 1;
}
It is important to know who to 'walk' through the code.
int sum = 0;
int n = 10;
int i = 1;
S2W1Q1
Today
Casting
While Loop
Input
Some simple Maths and figures
int i = 10;
float f = 10.25;
i = (int)f;
while loop
while (condition(s)) {
}
sum to n (from 1)
int sum = 0;
int n = 10;
int i = 1;
while (i < n) {
sum += I;
i += 1;
}
It is important to know who to 'walk' through the code.
int sum = 0;
int n = 10;
int i = 1;
while
(i < n) {
sum += I;
i += 1;
}
System.out.Println(sum);
int sum = 0;
int n = 10;
int i = 1;
while (i < n) {
sum += I;
i += 1;
}
System.out.Println((float)sum);
boolean exit;
int sum = 0;
int n = 10;
int i = 1;
while(!exit) {
sum += I;
i += 1;
if (i < n)exit = true;
}
System.out.Println((float)sum);
BMI calculation
– Formula
BMI = mass/weight
Think
– Formula
– variable types
– test values
Factorial (maximum of 12)
– Formula
– Variables
– how many times?
– Hold result, counter, temp
BMI Calculation
Declare BMI
Declare Mass
Declare height
Calculate
sum += I;
i += 1;
}
System.out.Println(sum);
int sum = 0;
int n = 10;
int i = 1;
while (i < n) {
sum += I;
i += 1;
}
System.out.Println((float)sum);
boolean exit;
int sum = 0;
int n = 10;
int i = 1;
while(!exit) {
sum += I;
i += 1;
if (i < n)exit = true;
}
System.out.Println((float)sum);
BMI calculation
– Formula
BMI = mass/weight
Think
– Formula
– variable types
– test values
Factorial (maximum of 12)
– Formula
– Variables
– how many times?
– Hold result, counter, temp
BMI Calculation
Declare BMI
Declare Mass
Declare height
Calculate
Factorial
No input larger than 12
LoopsTrajectories
<a href="http://s483.photobucket.com/user/Brenorenz/media/W9S004_zps6mvllvka.png.html" target="_blank"><img src="http://i483.photobucket.com/albums/rr193/Brenorenz/W9S004_zps6mvllvka.png" border="0" alt=" photo W9S004_zps6mvllvka.png"/></a>
http://i483.photobucket.com/albums/rr193/Brenorenz/W9S004_zps6mvllvka.png
Fifth Program
char ch;
System.out.Println(“Enter a key and press enter”);
ch (char) System.in.read();
System.out.Println(“Your Key is: “ + ch);
Trajectories
<a href="http://s483.photobucket.com/user/Brenorenz/media/W9S005_zpsfvpnqjpl.png.html" target="_blank"><img src="http://i483.photobucket.com/albums/rr193/Brenorenz/W9S005_zpsfvpnqjpl.png" border="0" alt=" photo W9S005_zpsfvpnqjpl.png"/></a>
http://i483.photobucket.com/albums/rr193/Brenorenz/W9S005_zpsfvpnqjpl.png
Speed of the Plane
700 km/hr → m/s
700 * 1000 m/hr
700 * 1000m/60 min
700 * 1000 m/3600s
194.4m/s
1 ) (Speed x 1000)/(60 * 60)
Math function
2 Velocity * Math.cos(angle)
angle.degreeAngle * Math.PI/180
Distance = velocity x time
time = distance / velocity
= 10.29s
Initial velocity
yVelocity * Math.sin(angle);
y = vy + (1/2)g(t^2)
Quadratic formula
x = (b +/ (b^2 – 4ac)^0.5)/(2a)
t = (vy +/(vy^2 – 5 * 4.9 * 2000)^0.5)/(2 * 4.9)
Square root
Math.sqrt
Power
Math.pow(base, 2)
#gamedesign #gameprogramming #java #programming
No input larger than 12
LoopsTrajectories
<a href="http://s483.photobucket.com/user/Brenorenz/media/W9S004_zps6mvllvka.png.html" target="_blank"><img src="http://i483.photobucket.com/albums/rr193/Brenorenz/W9S004_zps6mvllvka.png" border="0" alt=" photo W9S004_zps6mvllvka.png"/></a>
http://i483.photobucket.com/albums/rr193/Brenorenz/W9S004_zps6mvllvka.png
Fifth Program
char ch;
System.out.Println(“Enter a key and press enter”);
ch (char) System.in.read();
System.out.Println(“Your Key is: “ + ch);
Trajectories
<a href="http://s483.photobucket.com/user/Brenorenz/media/W9S005_zpsfvpnqjpl.png.html" target="_blank"><img src="http://i483.photobucket.com/albums/rr193/Brenorenz/W9S005_zpsfvpnqjpl.png" border="0" alt=" photo W9S005_zpsfvpnqjpl.png"/></a>
http://i483.photobucket.com/albums/rr193/Brenorenz/W9S005_zpsfvpnqjpl.png
Speed of the Plane
700 km/hr → m/s
700 * 1000 m/hr
700 * 1000m/60 min
700 * 1000 m/3600s
194.4m/s
1 ) (Speed x 1000)/(60 * 60)
Math function
2 Velocity * Math.cos(angle)
angle.degreeAngle * Math.PI/180
Distance = velocity x time
time = distance / velocity
= 10.29s
Initial velocity
yVelocity * Math.sin(angle);
y = vy + (1/2)g(t^2)
Quadratic formula
x = (b +/ (b^2 – 4ac)^0.5)/(2a)
t = (vy +/(vy^2 – 5 * 4.9 * 2000)^0.5)/(2 * 4.9)
Square root
Math.sqrt
Power
Math.pow(base, 2)
#gamedesign #gameprogramming #java #programming
No comments:
Post a Comment