Skip to content

Instantly share code, notes, and snippets.

/*
################################################################################################
# #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 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 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;
@robsbots
robsbots / gist:9509545
Last active August 29, 2015 13:57
Week 3 Code update
//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
@robsbots
robsbots / TheGame.java
Last active December 29, 2015 09:39
Add lives to the game
// ############################################################################################
// 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;
@robsbots
robsbots / gist:7583336
Last active December 28, 2015 23:59
Printing to the screen
// 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);
@robsbots
robsbots / Marlin_Conf
Created November 13, 2013 16:25
Marlin set up
#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
@robsbots
robsbots / Random nuber generator
Last active December 28, 2015 02:59
Random numbers for Build Your First Mobile Game MOOC at FutureLearn
// # 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)
@robsbots
robsbots / Round world snippet
Created November 4, 2013 16:36
Round world snippet Ball drops off the bottom and appears at the top again. Leaves on the right, and re-enters on the left.
// 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.
@robsbots
robsbots / gist:7304257
Last active December 27, 2015 09:29
Bouncing ball
// 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