This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
################################################################################################ | |
# #FLMobiGame FutureLearn Begin Programming # | |
# End of week 4 code # | |
# # | |
# Sound added with the use of the SoundPool library # | |
################################################################################################ | |
*/ | |
package uk.ac.reading.sis05kol.mooc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This starts a "multi line comment | |
This ends a multi line comment */ | |
/* Anything within a comment is ignored so you can put what ever you like in a comment. | |
This can go on for line after line. | |
The last line should finish with */ | |
/* This can be very handy when writing software. | |
If you write a new piece of code, you can put comments around the old piece and test out a new part | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # This is a copy of my current code at then end of week 3 | |
// # You can download some instructions and the sound files I used in a zip file from | |
// # http://www.robsbots.org.uk/files/mooc/sounds.zip | |
// # You will need to extract the contents into a folder on your computer, | |
// # then open the instructions.txt file to explain how to enable sound. | |
// # | |
package uk.ac.reading.sis05kol.mooc; | |
//Other parts of the android libraries that we use | |
import android.graphics.Bitmap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This is run just before the game "scenario" is printed on the screen | |
@Override | |
protected void updateGame(float secondsElapsed) { | |
float distanceBetweenBallAndPaddle; | |
float distanceBetweenBallAndSmiley; | |
if (mBallSpeedY > 0){ // If the ball is moving down the screen do this block | |
// Removed ball speed calculations to after the "if ball hits paddle" code | |
// Only need to change the speed/direction if a hit is detected. Otherwise leave it alone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ############################################################################################ | |
// All added or edited lines have comments like this near at hand. | |
// Just a variable definition near the top of the code. | |
// Plus some code at the bottom of updateGame | |
// Otherwise the code is the same | |
// ############################################################################################ | |
package uk.ac.reading.sis05kol.mooc; | |
//Other parts of the android libraries that we use | |
import android.graphics.Bitmap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// These lines create a new "ink" to write with and sets the colour and size of the text | |
Paint textPaint = new Paint(); | |
textPaint.setColor(Color.WHITE); | |
textPaint.setTextSize(12); | |
// This is the code that actually writes to the screen. | |
// The command used takes a few values to achieve this. | |
// canvas.draw("text to print out",X_location,Y_location, textPaint); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define TEMP_SENSOR_0 0 | |
#define TEMP_SENSOR_1 0 | |
#define TEMP_SENSOR_2 0 | |
#define TEMP_SENSOR_BED 0 | |
// This makes temp sensor 1 a redundant sensor for sensor 0. If the temperatures difference between these sensors is to high the print will be aborted. | |
//#define TEMP_SENSOR_1_AS_REDUNDANT | |
#define MAX_REDUNDANT_TEMP_SENSOR_DIFF 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # Function to generate random numbers | |
// # This function generates a random whole number (An integer) | |
// # between a min and max number inclusive | |
// # Paste it into your code to call it from your program | |
// # This function requires an import | |
import java.util.Random; | |
// # The random generator function. | |
public int Rand_number(int min, int max) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Should be added to the updateGame method. | |
// below the current code | |
if (mBallX < 0) mBallX = mCanvasWidth; // If the ball hits the left wall, move it to the right | |
if (mBallX > mCanvasWidth) mBallX = 0; // If the ball hits the right wall, move it to the left | |
if (mBallY < 0) mBallY = mCanvasHeight; // If it hits the top, move it to the bottom | |
if (mBallY > mCanvasHeight) mBallY = 0; // If it hits the bottom, move it to the top. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code should be added to the updateGame function below the two lines of code currently in there. | |
// The ball speed is positive when moving right, and negative when moving left | |
// To reverse the ball direction we need to change the sign of the ball speed variable. | |
// If the ball speed is 100, it moves right at 100 pixels per second. | |
// To reverse direction we change the sign of the ball speed variable and make it -100 and it moves left. | |
// If ball hits left side, reverse direction | |
if (mBallX <= 0) mBallSpeedX = -mBallSpeedX; | |
// If ball hits right side of screen reverse direction |
NewerOlder