diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..78d51c4
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+misc.xml
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..63c7c6e
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..69bb0e4
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CSC-133-Final-Project.iml b/CSC-133-Final-Project.iml
new file mode 100644
index 0000000..7ffec7e
--- /dev/null
+++ b/CSC-133-Final-Project.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Chapter01/AndroidManifest.xml b/Chapter01/AndroidManifest.xml
deleted file mode 100644
index c7bba2a..0000000
--- a/Chapter01/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter01/java/SubHunter.java b/Chapter01/java/SubHunter.java
deleted file mode 100644
index ce0585d..0000000
--- a/Chapter01/java/SubHunter.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.gamecodeschool.subhunter;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class SubHunter extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
-}
-
-
-
-
diff --git a/Chapter02/AndroidManifest.xml b/Chapter02/AndroidManifest.xml
deleted file mode 100644
index dbf104e..0000000
--- a/Chapter02/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter02/java/SubHunter.java b/Chapter02/java/SubHunter.java
deleted file mode 100644
index dee3101..0000000
--- a/Chapter02/java/SubHunter.java
+++ /dev/null
@@ -1,95 +0,0 @@
-// This is our package
-// If you are copy & pasting the code then this line will probably be different to yours
-// If so, keep YOUR line- not this one
-package com.gamecodeschool.c2subhunter;
-
-// These are all the classes of other people's
-// (Android) code that we use in Sub Hunt
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.MotionEvent;
-import android.util.Log;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.view.Display;
-import android.widget.ImageView;
-import java.util.Random;
-
-
-public class SubHunter extends Activity {
-
- /*
- Android runs this code just before
- the app is seen by the player.
- This makes it a good place to add
- the code that is needed for
- the one-time setup.
- */
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Log.d("Debugging", "In onCreate");
- newGame();
- draw();
- }
-
- /*
- This code will execute when a new
- game needs to be started. It will
- happen when the app is first started
- and after the player wins a game.
- */
- void newGame(){
- Log.d("Debugging", "In newGame");
-
- }
-
- /*
- Here we will do all the drawing.
- The grid lines, the HUD and
- the touch indicator
- */
- void draw() {
- Log.d("Debugging", "In draw");
- }
-
- /*
- This part of the code will
- handle detecting that the player
- has tapped the screen
- */
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- Log.d("Debugging", "In onTouchEvent");
- takeShot();
-
- return true;
- }
-
-
- /*
- The code here will execute when
- the player taps the screen It will
- calculate distance from the sub'
- and determine a hit or miss
- */
- void takeShot(){
- Log.d("Debugging", "In takeShot");
- draw();
- }
-
- // This code says "BOOM!"
- void boom(){
-
- }
-
- // This code prints the debugging text
- void printDebuggingText(){
-
- }
-}
diff --git a/Chapter03/AndroidManifest.xml b/Chapter03/AndroidManifest.xml
deleted file mode 100644
index 7093dd3..0000000
--- a/Chapter03/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter03/java/SubHunter.java b/Chapter03/java/SubHunter.java
deleted file mode 100644
index 92a242f..0000000
--- a/Chapter03/java/SubHunter.java
+++ /dev/null
@@ -1,146 +0,0 @@
-// This is our package
-// If you are copy & pasting the code then this line will probably be different to yours
-// If so, keep YOUR line- not this one
-package com.gamecodeschool.c3subhunter;
-
-// These are all the classes of other people's
-// (Android) code that we use in Sub Hunt
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.MotionEvent;
-import android.util.Log;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.view.Display;
-import android.widget.ImageView;
-import java.util.Random;
-
-
-public class SubHunter extends Activity {
-
- // These variables can be "seen"
- // throughout the SubHunter class
- int numberHorizontalPixels;
- int numberVerticalPixels;
- int blockSize;
- int gridWidth = 40;
- int gridHeight;
- float horizontalTouched = -100;
- float verticalTouched = -100;
- int subHorizontalPosition;
- int subVerticalPosition;
- boolean hit = false;
- int shotsTaken;
- int distanceFromSub;
- boolean debugging = true;
-
- /*
- Android runs this code just before
- the app is seen by the player.
- This makes it a good place to add
- the code that is needed for
- the one-time setup.
- */
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the current device's screen resolution
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
-
- // Initialize our size based variables based on the screen resolution
- numberHorizontalPixels = size.x;
- numberVerticalPixels = size.y;
- blockSize = numberHorizontalPixels / gridWidth;
- gridHeight = numberVerticalPixels / blockSize;
-
- Log.d("Debugging", "In onCreate");
- newGame();
- draw();
- }
-
- /*
- This code will execute when a new
- game needs to be started. It will
- happen when the app is first started
- and after the player wins a game.
- */
- void newGame(){
- Log.d("Debugging", "In newGame");
-
- }
-
- /*
- Here we will do all the drawing.
- The grid lines, the HUD and
- the touch indicator
- */
- void draw() {
- Log.d("Debugging", "In draw");
- printDebuggingText();
- }
-
- /*
- This part of the code will
- handle detecting that the player
- has tapped the screen
- */
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- Log.d("Debugging", "In onTouchEvent");
- takeShot();
-
- return true;
- }
-
-
- /*
- The code here will execute when
- the player taps the screen It will
- calculate distance from the sub'
- and determine a hit or miss
- */
- void takeShot(){
- Log.d("Debugging", "In takeShot");
- draw();
- }
-
- // This code says "BOOM!"
- void boom(){
-
- }
-
- // This code prints the debugging text
- public void printDebuggingText(){
- Log.d("numberHorizontalPixels",
- "" + numberHorizontalPixels);
- Log.d("numberVerticalPixels",
- "" + numberVerticalPixels);
-
- Log.d("blockSize", "" + blockSize);
- Log.d("gridWidth", "" + gridWidth);
- Log.d("gridHeight", "" + gridHeight);
-
- //Log.d("horizontalTouched",
- //"" + horizontalTouched);
- Log.d("verticalTouched",
- "" + verticalTouched);
- Log.d("subHorizontalPosition",
- "" + subHorizontalPosition);
- Log.d("subVerticalPosition",
- "" + subVerticalPosition);
-
- Log.d("hit", "" + hit);
- Log.d("shotsTaken", "" + shotsTaken);
- Log.d("debugging", "" + debugging);
-
- Log.d("distanceFromSub",
- "" + distanceFromSub);
- }
-}
\ No newline at end of file
diff --git a/Chapter04/AndroidManifest.xml b/Chapter04/AndroidManifest.xml
deleted file mode 100644
index eb38f1d..0000000
--- a/Chapter04/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter04/Method Overloading/MainActivity.java b/Chapter04/Method Overloading/MainActivity.java
deleted file mode 100644
index 3e50e54..0000000
--- a/Chapter04/Method Overloading/MainActivity.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.gamecodeschool.exploringmethodoverloading;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.util.Log;
-
-public class MainActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Declare and initialize a String and an int
- int anInt = 10;
- String aString = "I am a string";
-
- // Now call the different versions of printStuff
- // The name stays the same, only the parameters vary
- printStuff(anInt);
- printStuff(aString);
- printStuff(anInt, aString);
-
- }
-
- void printStuff(int myInt){
- Log.i("info", "This is the int only version");
- Log.i("info", "myInt = "+ myInt);
- }
-
- void printStuff(String myString){
- Log.i("info", "This is the String only version");
- Log.i("info", "myString = "+ myString);
- }
-
- void printStuff(int myInt, String myString){
- Log.i("info", "This is the combined int and String version");
- Log.i("info", "myInt = "+ myInt);
- Log.i("info", "myString = "+ myString);
- }
-
-}
diff --git a/Chapter04/java/SubHunter.java b/Chapter04/java/SubHunter.java
deleted file mode 100644
index aecdaba..0000000
--- a/Chapter04/java/SubHunter.java
+++ /dev/null
@@ -1,151 +0,0 @@
-// This is our package
-// If you are copy & pasting the code then this line will probably be different to yours
-// If so, keep YOUR line- not this one
-package com.gamecodeschool.c4subhunter;
-
-// These are all the classes of other people's
-// (Android) code that we use in Sub Hunt
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.MotionEvent;
-import android.util.Log;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.view.Display;
-import android.widget.ImageView;
-import java.util.Random;
-
-
-public class SubHunter extends Activity {
-
- // These variables can be "seen"
- // throughout the SubHunter class
- int numberHorizontalPixels;
- int numberVerticalPixels;
- int blockSize;
- int gridWidth = 40;
- int gridHeight;
- float horizontalTouched = -100;
- float verticalTouched = -100;
- int subHorizontalPosition;
- int subVerticalPosition;
- boolean hit = false;
- int shotsTaken;
- int distanceFromSub;
- boolean debugging = true;
-
- /*
- Android runs this code just before
- the app is seen by the player.
- This makes it a good place to add
- the code that is needed for
- the one-time setup.
- */
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the current device's screen resolution
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
-
- // Initialize our size based variables based on the screen resolution
- numberHorizontalPixels = size.x;
- numberVerticalPixels = size.y;
- blockSize = numberHorizontalPixels / gridWidth;
- gridHeight = numberVerticalPixels / blockSize;
-
- Log.d("Debugging", "In onCreate");
- newGame();
- draw();
- }
-
- /*
- This code will execute when a new
- game needs to be started. It will
- happen when the app is first started
- and after the player wins a game.
- */
- void newGame(){
- Random random = new Random();
- subHorizontalPosition = random.nextInt(gridWidth);
- subVerticalPosition = random.nextInt(gridHeight);
- shotsTaken = 0;
-
- Log.d("Debugging", "In newGame");
-
- }
-
- /*
- Here we will do all the drawing.
- The grid lines, the HUD and
- the touch indicator
- */
- void draw() {
- Log.d("Debugging", "In draw");
- printDebuggingText();
- }
-
- /*
- This part of the code will
- handle detecting that the player
- has tapped the screen
- */
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- Log.d("Debugging", "In onTouchEvent");
- takeShot();
-
- return true;
- }
-
-
- /*
- The code here will execute when
- the player taps the screen It will
- calculate distance from the sub'
- and determine a hit or miss
- */
- void takeShot(){
- Log.d("Debugging", "In takeShot");
- draw();
- }
-
- // This code says "BOOM!"
- void boom(){
-
- }
-
- // This code prints the debugging text
- public void printDebuggingText(){
- Log.d("numberHorizontalPixels",
- "" + numberHorizontalPixels);
- Log.d("numberVerticalPixels",
- "" + numberVerticalPixels);
-
- Log.d("blockSize", "" + blockSize);
- Log.d("gridWidth", "" + gridWidth);
- Log.d("gridHeight", "" + gridHeight);
-
- Log.d("horizontalTouched",
- "" + horizontalTouched);
- Log.d("verticalTouched",
- "" + verticalTouched);
- Log.d("subHorizontalPosition",
- "" + subHorizontalPosition);
- Log.d("subVerticalPosition",
- "" + subVerticalPosition);
-
- Log.d("hit", "" + hit);
- Log.d("shotsTaken", "" + shotsTaken);
- Log.d("debugging", "" + debugging);
-
- Log.d("distanceFromSub",
- "" + distanceFromSub);
- }
-}
\ No newline at end of file
diff --git a/Chapter05/AndroidManifest.xml b/Chapter05/AndroidManifest.xml
deleted file mode 100644
index 643bf50..0000000
--- a/Chapter05/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter05/Canvas Demo/MainActivity.java b/Chapter05/Canvas Demo/MainActivity.java
deleted file mode 100644
index 2903ef4..0000000
--- a/Chapter05/Canvas Demo/MainActivity.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.gamecodeschool.canvasdemo;
-
-import android.app.Activity;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.os.Bundle;
-import android.widget.ImageView;
-
-public class MainActivity extends Activity {
-
- // Here are all the objects(instances)
- // of classes that we need to do some drawing
- ImageView myImageView;
- Bitmap myBlankBitmap;
- Canvas myCanvas;
- Paint myPaint;
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Initialize all the objects ready for drawing
- // We will do this inside the onCreate method
- int widthInPixels = 800;
- int heightInPixels = 600;
-
- // Create a new Bitmap
- myBlankBitmap = Bitmap.createBitmap(widthInPixels,
- heightInPixels,
- Bitmap.Config.ARGB_8888);
-
- // Initialize the Canvas and asociate it
- // with the Bitmap to draw on
- myCanvas = new Canvas(myBlankBitmap);
-
- // Initialize the ImageView and the Paint
- myImageView = new ImageView(this);
- myPaint = new Paint();
-
-
- // Draw on the Bitmap
- // Wipe the Bitmap with a blue color
- myCanvas.drawColor(Color.argb(255, 0, 0, 255));
-
- // Re-size the text
- myPaint.setTextSize(100);
- // Change the paint to white
- myPaint.setColor(Color.argb(255, 255, 255, 255));
- // Actually draw the text
- myCanvas.drawText("Hello World!",100, 100, myPaint);
-
- // Change the paint to yellow
- myPaint.setColor(Color.argb(255, 212, 207, 62));
- // Draw a circle
- myCanvas.drawCircle(400,250, 100, myPaint);
-
- // Associate the drawn upon Bitmap with the ImageView
- myImageView.setImageBitmap(myBlankBitmap);
- // Tell Android to set our drawing
- // as the view for this app
- // via the ImageView
- setContentView(myImageView);
-
-
- }
-}
diff --git a/Chapter05/java/SubHunter.java b/Chapter05/java/SubHunter.java
deleted file mode 100644
index 9f7bc3e..0000000
--- a/Chapter05/java/SubHunter.java
+++ /dev/null
@@ -1,210 +0,0 @@
-// This is our package
-// If you are copy & pasting the code then this line will probably be different to yours
-// If so, keep YOUR line- not this one
-package com.gamecodeschool.c5subhunter;
-
-// These are all the classes of other people's
-// (Android) code that we use in Sub Hunt
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.MotionEvent;
-import android.util.Log;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.view.Display;
-import android.widget.ImageView;
-import java.util.Random;
-
-
-public class SubHunter extends Activity {
-
- // These variables can be "seen"
- // throughout the SubHunter class
- int numberHorizontalPixels;
- int numberVerticalPixels;
- int blockSize;
- int gridWidth = 40;
- int gridHeight;
- float horizontalTouched = -100;
- float verticalTouched = -100;
- int subHorizontalPosition;
- int subVerticalPosition;
- boolean hit = false;
- int shotsTaken;
- int distanceFromSub;
- boolean debugging = true;
-
- // Here are all the objects(instances)
- // of classes that we need to do some drawing
- ImageView gameView;
- Bitmap blankBitmap;
- Canvas canvas;
- Paint paint;
-
-
- /*
- Android runs this code just before
- the app is seen by the player.
- This makes it a good place to add
- the code that is needed for
- the one-time setup.
- */
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the current device's screen resolution
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
-
- // Initialize our size based variables based on the screen resolution
- numberHorizontalPixels = size.x;
- numberVerticalPixels = size.y;
- blockSize = numberHorizontalPixels / gridWidth;
- gridHeight = numberVerticalPixels / blockSize;
-
- // Initialize all the objects ready for drawing
- blankBitmap = Bitmap.createBitmap(numberHorizontalPixels,
- numberVerticalPixels,
- Bitmap.Config.ARGB_8888);
-
- canvas = new Canvas(blankBitmap);
- gameView = new ImageView(this);
- paint = new Paint();
-
- // Tell Android to set our drawing
- // as the view for this app
- setContentView(gameView);
-
- Log.d("Debugging", "In onCreate");
- newGame();
- draw();
- }
-
- /*
- This code will execute when a new
- game needs to be started. It will
- happen when the app is first started
- and after the player wins a game.
- */
- void newGame(){
- Random random = new Random();
- subHorizontalPosition = random.nextInt(gridWidth);
- subVerticalPosition = random.nextInt(gridHeight);
- shotsTaken = 0;
-
- Log.d("Debugging", "In newGame");
-
- }
-
- /*
- Here we will do all the drawing.
- The grid lines, the HUD and
- the touch indicator
- */
- void draw() {
- gameView.setImageBitmap(blankBitmap);
-
- // Wipe the screen with a white color
- canvas.drawColor(Color.argb(255, 255, 255, 255));
-
- // Change the paint color to black
- paint.setColor(Color.argb(255, 0, 0, 0));
-
- // Draw the vertical lines of the grid
- canvas.drawLine(blockSize * 1, 0,
- blockSize * 1, numberVerticalPixels,
- paint);
-
- // Draw the horizontal lines of the grid
- canvas.drawLine(0, blockSize * 1,
- numberHorizontalPixels, blockSize * 1,
- paint);
-
- // Re-size the text appropriate for the
- // score and distance text
- paint.setTextSize(blockSize * 2);
- paint.setColor(Color.argb(255, 0, 0, 255));
- canvas.drawText(
- "Shots Taken: " + shotsTaken +
- " Distance: " + distanceFromSub,
- blockSize, blockSize * 1.75f,
- paint);
-
-
- Log.d("Debugging", "In draw");
- printDebuggingText();
- }
-
- /*
- This part of the code will
- handle detecting that the player
- has tapped the screen
- */
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- Log.d("Debugging", "In onTouchEvent");
- takeShot();
-
- return true;
- }
-
-
- /*
- The code here will execute when
- the player taps the screen It will
- calculate distance from the sub'
- and determine a hit or miss
- */
- void takeShot(){
- Log.d("Debugging", "In takeShot");
- draw();
- }
-
- // This code says "BOOM!"
- void boom(){
-
- }
-
- // This code prints the debugging text
- public void printDebuggingText(){
- paint.setTextSize(blockSize);
- canvas.drawText("numberHorizontalPixels = "
- + numberHorizontalPixels,
- 50, blockSize * 3, paint);
- canvas.drawText("numberVerticalPixels = "
- + numberVerticalPixels,
- 50, blockSize * 4, paint);
- canvas.drawText("blockSize = " + blockSize,
- 50, blockSize * 5, paint);
- canvas.drawText("gridWidth = " + gridWidth,
- 50, blockSize * 6, paint);
- canvas.drawText("gridHeight = " + gridHeight,
- 50, blockSize * 7, paint);
- canvas.drawText("horizontalTouched = " +
- horizontalTouched, 50,
- blockSize * 8, paint);
- canvas.drawText("verticalTouched = " +
- verticalTouched, 50,
- blockSize * 9, paint);
- canvas.drawText("subHorizontalPosition = " +
- subHorizontalPosition, 50,
- blockSize * 10, paint);
- canvas.drawText("subVerticalPosition = " +
- subVerticalPosition, 50,
- blockSize * 11, paint);
- canvas.drawText("hit = " + hit,
- 50, blockSize * 12, paint);
- canvas.drawText("shotsTaken = " +
- shotsTaken,
- 50, blockSize * 13, paint);
- canvas.drawText("debugging = " + debugging,
- 50, blockSize * 14, paint);
-
- }
-}
diff --git a/Chapter06/AndroidManifest.xml b/Chapter06/AndroidManifest.xml
deleted file mode 100644
index 3ad0714..0000000
--- a/Chapter06/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter06/java/SubHunter.java b/Chapter06/java/SubHunter.java
deleted file mode 100644
index 1256099..0000000
--- a/Chapter06/java/SubHunter.java
+++ /dev/null
@@ -1,214 +0,0 @@
-// This is our package
-// If you are copy & pasting the code then this line will probably be different to yours
-// If so, keep YOUR line- not this one
-package com.gamecodeschool.c6subhunter;
-
-// These are all the classes of other people's
-// (Android) code that we use in Sub Hunt
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.MotionEvent;
-import android.util.Log;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.view.Display;
-import android.widget.ImageView;
-import java.util.Random;
-
-
-public class SubHunter extends Activity {
-
- // These variables can be "seen"
- // throughout the SubHunter class
- int numberHorizontalPixels;
- int numberVerticalPixels;
- int blockSize;
- int gridWidth = 40;
- int gridHeight;
- float horizontalTouched = -100;
- float verticalTouched = -100;
- int subHorizontalPosition;
- int subVerticalPosition;
- boolean hit = false;
- int shotsTaken;
- int distanceFromSub;
- boolean debugging = true;
-
- // Here are all the objects(instances)
- // of classes that we need to do some drawing
- ImageView gameView;
- Bitmap blankBitmap;
- Canvas canvas;
- Paint paint;
-
-
- /*
- Android runs this code just before
- the app is seen by the player.
- This makes it a good place to add
- the code that is needed for
- the one-time setup.
- */
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the current device's screen resolution
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
-
- // Initialize our size based variables based on the screen resolution
- numberHorizontalPixels = size.x;
- numberVerticalPixels = size.y;
- blockSize = numberHorizontalPixels / gridWidth;
- gridHeight = numberVerticalPixels / blockSize;
-
- // Initialize all the objects ready for drawing
- blankBitmap = Bitmap.createBitmap(numberHorizontalPixels,
- numberVerticalPixels,
- Bitmap.Config.ARGB_8888);
-
- canvas = new Canvas(blankBitmap);
- gameView = new ImageView(this);
- paint = new Paint();
-
- // Tell Android to set our drawing
- // as the view for this app
- setContentView(gameView);
-
- Log.d("Debugging", "In onCreate");
- newGame();
- draw();
- }
-
- /*
- This code will execute when a new
- game needs to be started. It will
- happen when the app is first started
- and after the player wins a game.
- */
- void newGame(){
- Random random = new Random();
- subHorizontalPosition = random.nextInt(gridWidth);
- subVerticalPosition = random.nextInt(gridHeight);
- shotsTaken = 0;
-
- Log.d("Debugging", "In newGame");
-
- }
-
- /*
- Here we will do all the drawing.
- The grid lines, the HUD and
- the touch indicator
- */
- void draw() {
- gameView.setImageBitmap(blankBitmap);
-
- // Wipe the screen with a white color
- canvas.drawColor(Color.argb(255, 255, 255, 255));
-
- // Change the paint color to black
- paint.setColor(Color.argb(255, 0, 0, 0));
-
- // Draw the vertical lines of the grid
- for(int i = 0; i < gridWidth; i++){
- canvas.drawLine(blockSize * i, 0,
- blockSize * i, numberVerticalPixels,
- paint);
- }
-
- // Draw the horizontal lines of the grid
- for(int i = 0; i < gridHeight; i++){
- canvas.drawLine(0, blockSize * i,
- numberHorizontalPixels, blockSize * i,
- paint);
- }
-
- // Re-size the text appropriate for the
- // score and distance text
- paint.setTextSize(blockSize * 2);
- paint.setColor(Color.argb(255, 0, 0, 255));
- canvas.drawText(
- "Shots Taken: " + shotsTaken +
- " Distance: " + distanceFromSub,
- blockSize, blockSize * 1.75f,
- paint);
-
-
- Log.d("Debugging", "In draw");
- printDebuggingText();
- }
-
- /*
- This part of the code will
- handle detecting that the player
- has tapped the screen
- */
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- Log.d("Debugging", "In onTouchEvent");
- takeShot();
-
- return true;
- }
-
-
- /*
- The code here will execute when
- the player taps the screen It will
- calculate distance from the sub'
- and determine a hit or miss
- */
- void takeShot(){
- Log.d("Debugging", "In takeShot");
- draw();
- }
-
- // This code says "BOOM!"
- void boom(){
-
- }
-
- // This code prints the debugging text
- public void printDebuggingText(){
- paint.setTextSize(blockSize);
- canvas.drawText("numberHorizontalPixels = "
- + numberHorizontalPixels,
- 50, blockSize * 3, paint);
- canvas.drawText("numberVerticalPixels = "
- + numberVerticalPixels,
- 50, blockSize * 4, paint);
- canvas.drawText("blockSize = " + blockSize,
- 50, blockSize * 5, paint);
- canvas.drawText("gridWidth = " + gridWidth,
- 50, blockSize * 6, paint);
- canvas.drawText("gridHeight = " + gridHeight,
- 50, blockSize * 7, paint);
- canvas.drawText("horizontalTouched = " +
- horizontalTouched, 50,
- blockSize * 8, paint);
- canvas.drawText("verticalTouched = " +
- verticalTouched, 50,
- blockSize * 9, paint);
- canvas.drawText("subHorizontalPosition = " +
- subHorizontalPosition, 50,
- blockSize * 10, paint);
- canvas.drawText("subVerticalPosition = " +
- subVerticalPosition, 50,
- blockSize * 11, paint);
- canvas.drawText("hit = " + hit,
- 50, blockSize * 12, paint);
- canvas.drawText("shotsTaken = " +
- shotsTaken,
- 50, blockSize * 13, paint);
- canvas.drawText("debugging = " + debugging,
- 50, blockSize * 14, paint);
-
- }
-}
diff --git a/Chapter07/AndroidManifest.xml b/Chapter07/AndroidManifest.xml
deleted file mode 100644
index 36f718a..0000000
--- a/Chapter07/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter07/java/SubHunter.java b/Chapter07/java/SubHunter.java
deleted file mode 100644
index a2bec09..0000000
--- a/Chapter07/java/SubHunter.java
+++ /dev/null
@@ -1,279 +0,0 @@
-// This is our package
-// If you are copy & pasting the code then this line will probably be different to yours
-// If so, keep YOUR line- not this one
-package com.gamecodeschool.c7subhunter;
-
-// These are all the classes of other people's
-// (Android) code that we use in Sub Hunt
-import android.app.Activity;
-import android.os.Bundle;
-import android.view.MotionEvent;
-import android.util.Log;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.view.Display;
-import android.widget.ImageView;
-import java.util.Random;
-
-
-public class SubHunter extends Activity {
-
- // These variables can be "seen"
- // throughout the SubHunter class
- int numberHorizontalPixels;
- int numberVerticalPixels;
- int blockSize;
- int gridWidth = 40;
- int gridHeight;
- float horizontalTouched = -100;
- float verticalTouched = -100;
- int subHorizontalPosition;
- int subVerticalPosition;
- boolean hit = false;
- int shotsTaken;
- int distanceFromSub;
- boolean debugging = false;
-
- // Here are all the objects(instances)
- // of classes that we need to do some drawing
- ImageView gameView;
- Bitmap blankBitmap;
- Canvas canvas;
- Paint paint;
-
-
- /*
- Android runs this code just before
- the app is seen by the player.
- This makes it a good place to add
- the code that is needed for
- the one-time setup.
- */
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the current device's screen resolution
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
-
- // Initialize our size based variables based on the screen resolution
- numberHorizontalPixels = size.x;
- numberVerticalPixels = size.y;
- blockSize = numberHorizontalPixels / gridWidth;
- gridHeight = numberVerticalPixels / blockSize;
-
- // Initialize all the objects ready for drawing
- blankBitmap = Bitmap.createBitmap(numberHorizontalPixels,
- numberVerticalPixels,
- Bitmap.Config.ARGB_8888);
-
- canvas = new Canvas(blankBitmap);
- gameView = new ImageView(this);
- paint = new Paint();
-
- // Tell Android to set our drawing
- // as the view for this app
- setContentView(gameView);
-
- Log.d("Debugging", "In onCreate");
- newGame();
- draw();
- }
-
- /*
- This code will execute when a new
- game needs to be started. It will
- happen when the app is first started
- and after the player wins a game.
- */
- void newGame(){
- Random random = new Random();
- subHorizontalPosition = random.nextInt(gridWidth);
- subVerticalPosition = random.nextInt(gridHeight);
- shotsTaken = 0;
-
- Log.d("Debugging", "In newGame");
-
- }
-
- /*
- Here we will do all the drawing.
- The grid lines, the HUD and
- the touch indicator
- */
- void draw() {
- gameView.setImageBitmap(blankBitmap);
-
- // Wipe the screen with a white color
- canvas.drawColor(Color.argb(255, 255, 255, 255));
-
- // Change the paint color to black
- paint.setColor(Color.argb(255, 0, 0, 0));
-
- // Draw the vertical lines of the grid
- for(int i = 0; i < gridWidth; i++){
- canvas.drawLine(blockSize * i, 0,
- blockSize * i, numberVerticalPixels,
- paint);
- }
-
- // Draw the horizontal lines of the grid
- for(int i = 0; i < gridHeight; i++){
- canvas.drawLine(0, blockSize * i,
- numberHorizontalPixels, blockSize * i,
- paint);
- }
- // Draw the player's shot
- canvas.drawRect(horizontalTouched * blockSize,
- verticalTouched * blockSize,
- (horizontalTouched * blockSize) + blockSize,
- (verticalTouched * blockSize)+ blockSize,
- paint );
-
-
- // Re-size the text appropriate for the
- // score and distance text
- paint.setTextSize(blockSize * 2);
- paint.setColor(Color.argb(255, 0, 0, 255));
- canvas.drawText(
- "Shots Taken: " + shotsTaken +
- " Distance: " + distanceFromSub,
- blockSize, blockSize * 1.75f,
- paint);
-
-
- Log.d("Debugging", "In draw");
- if (debugging) {
- printDebuggingText();
- }
- }
-
- /*
- This part of the code will
- handle detecting that the player
- has tapped the screen
- */
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- Log.d("Debugging", "In onTouchEvent");
- // Has the player removed their finger from the screen?
- if((motionEvent.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
-
- // Process the player's shot by passing the
- // coordinates of the player's finger to takeShot
- takeShot(motionEvent.getX(), motionEvent.getY());
- }
-
- return true;
- }
-
-
- /*
- The code here will execute when
- the player taps the screen It will
- calculate distance from the sub'
- and determine a hit or miss
- */
- void takeShot(float touchX, float touchY){
- Log.d("Debugging", "In takeShot");
-
- // Add one to the shotsTaken variable
- shotsTaken ++;
-
- // Convert the float screen coordinates
- // into int grid coordinates
- horizontalTouched = (int)touchX/ blockSize;
- verticalTouched = (int)touchY/ blockSize;
-
- // Did the shot hit the sub?
- hit = horizontalTouched == subHorizontalPosition
- && verticalTouched == subVerticalPosition;
-
- // How far away horizontally and vertically
- // was the shot from the sub
- int horizontalGap = (int)horizontalTouched -
- subHorizontalPosition;
- int verticalGap = (int)verticalTouched -
- subVerticalPosition;
-
- // Use Pythagoras's theorem to get the
- // distance travelled in a straight line
- distanceFromSub = (int)Math.sqrt(
- ((horizontalGap * horizontalGap) +
- (verticalGap * verticalGap)));
-
- // If there is a hit call boom
- if(hit)
- boom();
- // Otherwise call draw as usual
- else draw();
- }
-
- // This code says "BOOM!"
- void boom(){
-
- gameView.setImageBitmap(blankBitmap);
-
- // Wipe the screen with a red color
- canvas.drawColor(Color.argb(255, 255, 0, 0));
-
- // Draw some huge white text
- paint.setColor(Color.argb(255, 255, 255, 255));
- paint.setTextSize(blockSize * 10);
-
- canvas.drawText("BOOM!", blockSize * 4,
- blockSize * 14, paint);
-
- // Draw some text to prompt restarting
- paint.setTextSize(blockSize * 2);
- canvas.drawText("Take a shot to start again",
- blockSize * 8,
- blockSize * 18, paint);
-
- // Start a new game
- newGame();
- }
-
- // This code prints the debugging text
- public void printDebuggingText(){
- paint.setTextSize(blockSize);
- canvas.drawText("numberHorizontalPixels = "
- + numberHorizontalPixels,
- 50, blockSize * 3, paint);
- canvas.drawText("numberVerticalPixels = "
- + numberVerticalPixels,
- 50, blockSize * 4, paint);
- canvas.drawText("blockSize = " + blockSize,
- 50, blockSize * 5, paint);
- canvas.drawText("gridWidth = " + gridWidth,
- 50, blockSize * 6, paint);
- canvas.drawText("gridHeight = " + gridHeight,
- 50, blockSize * 7, paint);
- canvas.drawText("horizontalTouched = " +
- horizontalTouched, 50,
- blockSize * 8, paint);
- canvas.drawText("verticalTouched = " +
- verticalTouched, 50,
- blockSize * 9, paint);
- canvas.drawText("subHorizontalPosition = " +
- subHorizontalPosition, 50,
- blockSize * 10, paint);
- canvas.drawText("subVerticalPosition = " +
- subVerticalPosition, 50,
- blockSize * 11, paint);
- canvas.drawText("hit = " + hit,
- 50, blockSize * 12, paint);
- canvas.drawText("shotsTaken = " +
- shotsTaken,
- 50, blockSize * 13, paint);
- canvas.drawText("debugging = " + debugging,
- 50, blockSize * 14, paint);
-
- }
-}
diff --git a/Chapter08/AccessScopeThisAndStatic/AccessScopeThisAndStatic/AlienShip.java b/Chapter08/AccessScopeThisAndStatic/AccessScopeThisAndStatic/AlienShip.java
deleted file mode 100644
index 2e71146..0000000
--- a/Chapter08/AccessScopeThisAndStatic/AccessScopeThisAndStatic/AlienShip.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.packtpub.accessscopethisandstatic.app;
-
-import android.util.Log;
-
-public class AlienShip {
- private static int numShips;
- private int shieldStrength;
- public String shipName;
-
- public AlienShip(){
- numShips++;
- //Can call private methods from here because I am part
- //of the class
- //If didn't have "this" then this call might be less clear
- //But this "this" isn't strictly necessary
- this.setShieldStrength(100);
- //Because of "this" I am sure I am setting the correct shieldStrength
- }
-
- public static int getNumShips(){
- return numShips;
-
- }
-
- private void setShieldStrength(int shieldStrength){
- //"this" distinguishes between the member variable shieldStrength
- //And the local variable/paramater of the same name
- this.shieldStrength = shieldStrength;
- }
-
-
- public int getShieldStrength(){
- return this.shieldStrength;
- }
-
- public void hitDetected(){
-
- shieldStrength -=25;
- Log.i("Incomiming: ","Bam!!");
- if (shieldStrength == 0){
- destroyShip();
- }
-
- }
-
- private void destroyShip(){
- numShips--;
- Log.i("Explosion: ", ""+this.shipName + " destroyed");
- }
-}
diff --git a/Chapter08/AccessScopeThisAndStatic/AccessScopeThisAndStatic/MainActivity.java b/Chapter08/AccessScopeThisAndStatic/AccessScopeThisAndStatic/MainActivity.java
deleted file mode 100644
index 44c2156..0000000
--- a/Chapter08/AccessScopeThisAndStatic/AccessScopeThisAndStatic/MainActivity.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.packtpub.accessscopethisandstatic.app;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.util.Log;
-
-public class MainActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- //every time we do this the constructor runs
- AlienShip girlShip = new AlienShip();
- AlienShip boyShip = new AlienShip();
-
- //Look no objects but using the static method
- Log.i("numShips: ", "" + AlienShip.getNumShips());
-
- //This works because shipName is public
- girlShip.shipName = "Corrine Yu";
- boyShip.shipName = "Andre LaMothe";
-
- //This won't work because shieldStrenth is private
- //girlship.shieldStrength = 999;
-
- //But we have a public getter
- Log.i("girlShip shieldStrngth: ", "" + girlShip.getShieldStrength());
- Log.i("boyShip shieldStrngth: ", "" + boyShip.getShieldStrength());
-
- //But we can't do this because it's private
- //boyship.setShieldStrength(1000000);
-
- //lets shoot some ships
- girlShip.hitDetected();
- Log.i("girlShip shieldStrngth: ", "" + girlShip.getShieldStrength());
- Log.i("boyShip shieldStrngth: ", "" + boyShip.getShieldStrength());
- boyShip.hitDetected();
- boyShip.hitDetected();
- boyShip.hitDetected();
- Log.i("girlShip shieldStrngth: ", "" + girlShip.getShieldStrength());
- Log.i("boyShip shieldStrngth: ", "" + boyShip.getShieldStrength());
- boyShip.hitDetected();//ahhh
- Log.i("girlShip shieldStrngth: ", "" + girlShip.getShieldStrength());
- Log.i("boyShip shieldStrngth: ", "" + boyShip.getShieldStrength());
- Log.i("numShips: ", "" + AlienShip.getNumShips());
- }
-
-}
diff --git a/Chapter08/BasicClasses/RTSActivity.java b/Chapter08/BasicClasses/RTSActivity.java
deleted file mode 100644
index 11228cb..0000000
--- a/Chapter08/BasicClasses/RTSActivity.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.gamecodeschool.basicclasses;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.util.Log;
-
-public class RTSActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // first we make an object of type soldier
- Soldier rambo = new Soldier();
- rambo.soldierType = "Green Beret";
- rambo.health = 150;
- // It takes allot to kill Rambo
-
- // Now we make another Soldier object
- Soldier vassily = new Soldier();
- vassily.soldierType = "Sniper";
- vassily.health = 50;
- // Snipers have less health
-
- // And one more Soldier object
- Soldier wellington = new Soldier();
- wellington.soldierType = "Sailor";
- wellington.health = 100;
- // He's tough but no green beret
-
- Log.d("Rambo's health = ", "" + rambo.health);
- Log.d("Vassily's health = ", "" + vassily.health);
- Log.d("Wellington's health = ", "" + wellington.health);
-
- rambo.shootEnemy();
- vassily.shootEnemy();
- wellington.shootEnemy();
-
-
- }
-}
diff --git a/Chapter08/BasicClasses/Soldier.java b/Chapter08/BasicClasses/Soldier.java
deleted file mode 100644
index cafc529..0000000
--- a/Chapter08/BasicClasses/Soldier.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.gamecodeschool.basicclasses;
-
-import android.util.Log;
-
-/**
- * Created by johnh on 08/12/2017.
- */
-
-public class Soldier {
- int health;
- String soldierType;
-
- void shootEnemy(){
- //let's print which type of soldier is shooting
- Log.d(soldierType, " is shooting");
- }
-
-}
diff --git a/Chapter08/C8Pong/AndroidManifest.xml b/Chapter08/C8Pong/AndroidManifest.xml
deleted file mode 100644
index 7e3e325..0000000
--- a/Chapter08/C8Pong/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter08/C8Pong/java/Ball.java b/Chapter08/C8Pong/java/Ball.java
deleted file mode 100644
index 8860150..0000000
--- a/Chapter08/C8Pong/java/Ball.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.gamecodeschool.c8pong;
-
-class Ball {
-}
\ No newline at end of file
diff --git a/Chapter08/C8Pong/java/Bat.java b/Chapter08/C8Pong/java/Bat.java
deleted file mode 100644
index b4b66a1..0000000
--- a/Chapter08/C8Pong/java/Bat.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.gamecodeschool.c8pong;
-
-class Bat {
-}
diff --git a/Chapter08/C8Pong/java/PongActivity.java b/Chapter08/C8Pong/java/PongActivity.java
deleted file mode 100644
index 7fda723..0000000
--- a/Chapter08/C8Pong/java/PongActivity.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gamecodeschool.c8pong;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class PongActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- }
-
-}
diff --git a/Chapter08/C8Pong/java/PongGame.java b/Chapter08/C8Pong/java/PongGame.java
deleted file mode 100644
index b53f601..0000000
--- a/Chapter08/C8Pong/java/PongGame.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gamecodeschool.c8pong;
-
-class PongGame{
-}
-
-
-
-
-
-
-
-
-
-
diff --git a/Chapter08/InheritanceExample/InheritanceExample/AlienShip.java b/Chapter08/InheritanceExample/InheritanceExample/AlienShip.java
deleted file mode 100644
index b94de1c..0000000
--- a/Chapter08/InheritanceExample/InheritanceExample/AlienShip.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.packtpub.inheritanceexample.app;
-
-import android.util.Log;
-
-public abstract class AlienShip {
- private static int numShips;
- private int shieldStrength;
- public String shipName;
-
- public AlienShip(int shieldStrength){
- Log.i("Location: ", "AlienShip constructor");
- numShips++;
- setShieldStrength(shieldStrength);
- }
-
- public abstract void fireWeapon();//Ahh my body
-
- public static int getNumShips(){
- return numShips;
- }
-
- private void setShieldStrength(int shieldStrength){
- this.shieldStrength = shieldStrength;
- }
-
-
- public int getShieldStrength(){
- return this.shieldStrength;
- }
-
- public void hitDetected(){
- shieldStrength -=25;
- Log.i("Incomiming: ", "Bam!!");
- if (shieldStrength == 0){
- destroyShip();
- }
-
- }
-
- private void destroyShip(){
- numShips--;
- Log.i("Explosion: ", ""+this.shipName + " destroyed");
- }
-
-}
diff --git a/Chapter08/InheritanceExample/InheritanceExample/Bomber.java b/Chapter08/InheritanceExample/InheritanceExample/Bomber.java
deleted file mode 100644
index 5acd919..0000000
--- a/Chapter08/InheritanceExample/InheritanceExample/Bomber.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.packtpub.inheritanceexample.app;
-
-import android.util.Log;
-
-public class Bomber extends AlienShip {
-
- public Bomber(){
- super(100);
- //Weak shields for a bomber
- Log.i("Location: ", "Bomber constructor");
- }
-
- public void fireWeapon(){
- Log.i("Firing weapon: ", "bombs away");
- }
-}
diff --git a/Chapter08/InheritanceExample/InheritanceExample/Fighter.java b/Chapter08/InheritanceExample/InheritanceExample/Fighter.java
deleted file mode 100644
index 4a0c814..0000000
--- a/Chapter08/InheritanceExample/InheritanceExample/Fighter.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.packtpub.inheritanceexample.app;
-
-import android.util.Log;
-
-public class Fighter extends AlienShip{
-
- public Fighter(){
- super(400);
- //Strong shields for a fighter
- Log.i("Location: ", "Fighter constructor");
- }
-
- public void fireWeapon(){
- Log.i("Firing weapon: ", "lasers firing");
- }
-
-}
diff --git a/Chapter08/InheritanceExample/InheritanceExample/MainActivity.java b/Chapter08/InheritanceExample/InheritanceExample/MainActivity.java
deleted file mode 100644
index cc20815..0000000
--- a/Chapter08/InheritanceExample/InheritanceExample/MainActivity.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.packtpub.inheritanceexample.app;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.util.Log;
-
-public class MainActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- Fighter aFighter = new Fighter();
- Bomber aBomber = new Bomber();
-
- //Can't do this AlienShip is abstract -
- //Literally speaking as well as in code
- //AlienShip alienShip = new AlienShip(500);
-
- //But our objects of the subclasses can still do
- //everything the AlienShip is meant to do
- aBomber.shipName = "Newell Bomber";
- aFighter.shipName = "Meier Fighter";
-
- //And because of the overiden constructor
- //That still calls the super constructor
- //They have unique properties
- Log.i("aFighter Shield:", ""+ aFighter.getShieldStrength());
- Log.i("aBomber Shield:", ""+ aBomber.getShieldStrength());
-
- //As well as certain things in certain ways
- //That are unique to the subclass
- aBomber.fireWeapon();
- aFighter.fireWeapon();
-
- //Take down those alien ships
- //Focus on the bomber it has a weaker shield
- aBomber.hitDetected();
- aBomber.hitDetected();
- aBomber.hitDetected();
- aBomber.hitDetected();
- }
-
-}
diff --git a/Chapter09/AndroidManifest.xml b/Chapter09/AndroidManifest.xml
deleted file mode 100644
index 7980510..0000000
--- a/Chapter09/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter09/java/Ball.java b/Chapter09/java/Ball.java
deleted file mode 100644
index 7ab7e50..0000000
--- a/Chapter09/java/Ball.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.gamecodeschool.c9pong;
-
-class Ball {
-}
diff --git a/Chapter09/java/Bat.java b/Chapter09/java/Bat.java
deleted file mode 100644
index eff2a44..0000000
--- a/Chapter09/java/Bat.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.gamecodeschool.c9pong;
-
-class Bat {
-}
diff --git a/Chapter09/java/PongActivity.java b/Chapter09/java/PongActivity.java
deleted file mode 100644
index bbf1ae6..0000000
--- a/Chapter09/java/PongActivity.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.gamecodeschool.c9pong;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class PongActivity extends Activity {
- private PongGame mPongGame;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
-
- mPongGame = new PongGame(this, size.x, size.y);
- setContentView(mPongGame);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- // More code here later in the chapter
- mPongGame.resume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
-
- // More code here later in the chapter
- mPongGame.pause();
- }
-}
diff --git a/Chapter09/java/PongGame.java b/Chapter09/java/PongGame.java
deleted file mode 100644
index 73e5578..0000000
--- a/Chapter09/java/PongGame.java
+++ /dev/null
@@ -1,229 +0,0 @@
-package com.gamecodeschool.c9pong;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.util.Log;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-class PongGame extends SurfaceView implements Runnable{
-
- // Are we debugging?
- private final boolean DEBUGGING = true;
-
- // These objects are needed to do the drawing
- private SurfaceHolder mOurHolder;
- private Canvas mCanvas;
- private Paint mPaint;
-
- // How many frames per second did we get?
- private long mFPS;
- // The number of milliseconds in a second
- private final int MILLIS_IN_SECOND = 1000;
-
- // Holds the resolution of the screen
- private int mScreenX;
- private int mScreenY;
- // How big will the text be?
- private int mFontSize;
- private int mFontMargin;
-
- // The game objects
- private Bat mBat;
- private Ball mBall;
-
- // The current score and lives remaining
- private int mScore = 0;
- private int mLives = 3;
-
- // Here is the Thread and two control variables
- private Thread mGameThread = null;
- // This volatile vaiable can be accessed
- // from inside and outside the thread
- private volatile boolean mPlaying;
- private boolean mPaused = true;
-
- // The PongGame constructor
- // Called when this line:
- // mPongGame = new PongGame(this, size.x, size.y);
- // is executed from PongActivity
- public PongGame(Context context, int x, int y) {
- // Super... calls the parent class
- // constructor of SurfaceView
- // provided by Android
- super(context);
-
- // Initialize these two members/fields
- // With the values passesd in as parameters
- mScreenX = x;
- mScreenY = y;
-
- // Font is 5% (1/20th) of screen width
- mFontSize = mScreenX / 20;
- // Margin is 1.5% (1/75th) of screen width
- mFontMargin = mScreenX / 75;
-
- // Initialize the objects
- // ready for drawing with
- // getHolder is a method of SurfaceView
- mOurHolder = getHolder();
- mPaint = new Paint();
-
- // Initialize the bat and ball
-
- // Everything is ready so start the game
- startNewGame();
- }
-
- // The player has just lost
- // or is starting their first game
- private void startNewGame(){
-
- // Put the ball back to the starting position
-
- // Rest the score and the player's chances
- mScore = 0;
- mLives = 3;
-
- }
-
- // When we start the thread with:
- // mGameThread.start();
- // the run method is continuously called by Android
- // because we implemented the Runnable interface
- // Calling mGameThread.join();
- // will stop the thread
- @Override
- public void run() {
- // mPlaying gives us finer control
- // rather than just relying on the calls to run
- // mPlaying must be true AND
- // the thread running for the main loop to execute
- while (mPlaying) {
-
- // What time is it now at the start of the loop?
- long frameStartTime = System.currentTimeMillis();
-
- // Provided the game isn't paused call the update method
- if(!mPaused){
- update();
- // Now the bat and ball are in their new positions
- // we can see if there have been any collisions
- detectCollisions();
-
- }
-
- // The movement has been handled and collisions
- // detected now we can draw the scene.
- draw();
-
- // How long did this frame/loop take?
- // Store the answer in timeThisFrame
- long timeThisFrame = System.currentTimeMillis() - frameStartTime;
-
- // Make sure timeThisFrame is at least 1 millisecond
- // because accidentally dividing by zero crashes the game
- if (timeThisFrame > 0) {
- // Store the current frame rate in mFPS
- // ready to pass to the update methods of
- // mBat and mBall next frame/loop
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
-
- }
-
- }
-
- private void update() {
- // Update the bat and the ball
- }
-
- private void detectCollisions(){
- // Has the bat hit the ball?
-
- // Has the ball hit the edge of the screen
-
- // Bottom
-
- // Top
-
- // Left
-
- // Right
-
- }
-
- // Draw the game objects and the HUD
- void draw() {
- if (mOurHolder.getSurface().isValid()) {
- // Lock the canvas (graphics memory) ready to draw
- mCanvas = mOurHolder.lockCanvas();
-
- // Fill the screen with a solid color
- mCanvas.drawColor(Color.argb
- (255, 26, 128, 182));
-
- // Choose a color to paint with
- mPaint.setColor(Color.argb
- (255, 255, 255, 255));
-
- // Draw the bat and ball
-
- // Choose the font size
- mPaint.setTextSize(mFontSize);
-
- // Draw the HUD
- mCanvas.drawText("Score: " + mScore +
- " Lives: " + mLives,
- mFontMargin , mFontSize, mPaint);
-
- if(DEBUGGING){
- printDebuggingText();
- }
- // Display the drawing on screen
- // unlockCanvasAndPost is a method of SurfaceView
- mOurHolder.unlockCanvasAndPost(mCanvas);
- }
-
- }
-
- private void printDebuggingText(){
- int debugSize = mFontSize / 2;
- int debugStart = 150;
- mPaint.setTextSize(debugSize);
- mCanvas.drawText("FPS: " + mFPS ,
- 10, debugStart + debugSize, mPaint);
-
- }
-
- // This method is called by PongActivity
- // when the player quits the game
- public void pause() {
-
- // Set mPlaying to false
- // Stopping the thread isn't
- // always instant
- mPlaying = false;
- try {
- // Stop the thread
- mGameThread.join();
- } catch (InterruptedException e) {
- Log.e("Error:", "joining thread");
- }
-
- }
-
-
- // This method is called by PongActivity
- // when the player starts the game
- public void resume() {
- mPlaying = true;
- // Initialize the instance of Thread
- mGameThread = new Thread(this);
-
- // Start the thread
- mGameThread.start();
- }
-}
diff --git a/Chapter10/AndroidManifest.xml b/Chapter10/AndroidManifest.xml
deleted file mode 100644
index dd7aed0..0000000
--- a/Chapter10/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter10/java/Ball.java b/Chapter10/java/Ball.java
deleted file mode 100644
index cd0d9e7..0000000
--- a/Chapter10/java/Ball.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package com.gamecodeschool.c10pong;
-
-import android.graphics.RectF;
-
-class Ball {
-
- // These are the member variables (fields)
- // They all have the m prefix
- // They are all private
- // because direct access is not required
- private RectF mRect;
- private float mXVelocity;
- private float mYVelocity;
- private float mBallWidth;
- private float mBallHeight;
-
- // This is the constructor method.
- // It is called when by the code:
- // mBall = new Ball(mScreenX);
- // In the PongGame class
- Ball(int screenX){
-
- // Make the ball square and 1% of screen width
- // of the screen width
- mBallWidth = screenX / 100;
- mBallHeight = screenX / 100;
-
- // Initialize the RectF with 0, 0, 0, 0
- // We do it here because we only want to
- // do it once.
- // WE will initialize the detail
- // at the start of each game
- mRect = new RectF();
- }
-
-
- // Return a reference to mRect to PongGame
- RectF getRect(){
- return mRect;
- }
-
- // Update the ball position.
- // Called each frame/loop
- void update(long fps){
- // Move the ball based upon the
- // horizontal (mXVelocity) and
- // vertical(mYVelocity) speed
- // and the current frame rate(fps)
-
- // Move the top left corner
- mRect.left = mRect.left + (mXVelocity / fps);
- mRect.top = mRect.top + (mYVelocity / fps);
-
- // Match up the bottom right corner
- // based on the size of the ball
- mRect.right = mRect.left + mBallWidth;
- mRect.bottom = mRect.top + mBallHeight;
- }
-
- // Reverse the vertical direction of travel
- void reverseYVelocity(){
- mYVelocity = -mYVelocity;
- }
-
- // Reverse the horizontal direction of travel
- void reverseXVelocity(){
- mXVelocity = -mXVelocity;
- }
-
- void reset(int x, int y){
-
- // Initialise the four points of
- // the rectangle which defines the ball
- mRect.left = x / 2;
- mRect.top = 0;
- mRect.right = x / 2 + mBallWidth;
- mRect.bottom = mBallHeight;
-
- // How fast will the ball travel
- // You could vary this to suit
- // You could even increase it as the game progresses
- // to make it harder
- mYVelocity = -(y / 3);
- mXVelocity = (y / 3);
- }
-
- void increaseVelocity(){
- // increase the speed by 10%
- mXVelocity = mXVelocity * 1.1f;
- mYVelocity = mYVelocity * 1.1f;
- }
-
-
- // Bounce the ball back based upon
- // whether it hits the left or right hand side
- void batBounce(RectF batPosition){
-
- // Detect center of bat
- float batCenter = batPosition.left +
- (batPosition.width() / 2);
-
- // detect the center of the ball
- float ballCenter = mRect.left +
- (mBallWidth / 2);
-
- // Where on the bat did the ball hit?
- float relativeIntersect = (batCenter - ballCenter);
-
- // Pick a bounce direction
- if(relativeIntersect < 0){
- // Go right
- mXVelocity = Math.abs(mXVelocity);
- // Math.abs is a static method that
- // strips any negative values from a value.
- // So -1 becomes 1 and 1 stays as 1
- }else{
- // Go left
- mXVelocity = -Math.abs(mXVelocity);
- }
-
- // Having calculated left or right for
- // horizontal direction simply reverse the
- // vertical direction to go back up
- // the screen
- reverseYVelocity();
- }
-}
\ No newline at end of file
diff --git a/Chapter10/java/Bat.java b/Chapter10/java/Bat.java
deleted file mode 100644
index b945313..0000000
--- a/Chapter10/java/Bat.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package com.gamecodeschool.c10pong;
-
-import android.graphics.RectF;
-
-class Bat {
-
- // These are the member variables (fields)
- // They all have the m prefix
- // They are all private
- // because direct access is not required
- private RectF mRect;
- private float mLength;
- private float mXCoord;
- private float mBatSpeed;
- private int mScreenX;
-
- // These variables are public and final
- // They can be directly accessed by
- // the instance (in PongGame)
- // because they are part of the same
- // package but cannot be changed
- final int STOPPED = 0;
- final int LEFT = 1;
- final int RIGHT = 2;
-
- // Keeps track of if an how the ball is moving
- // Starting with STOPPED
- private int mBatMoving = STOPPED;
-
- Bat(int sx, int sy){
-
- // Bat needs to know the screen
- // horizontal resolution
- // Outside of this method
- mScreenX = sx;
-
- // Configure the size of the bat based on
- // the screen resolution
- // One eighth the screen width
- mLength = mScreenX / 8;
- // One fortieth the screen height
- float height = sy / 40;
-
- // Configure the starting locaion of the bat
- // Roughly the middle horizontally
- mXCoord = mScreenX / 2;
- // The height of the bat
- // off of the bottom of the screen
- float mYCoord = sy - height;
-
- // Initialize mRect based on the size and position
- mRect = new RectF(mXCoord, mYCoord,
- mXCoord + mLength,
- mYCoord + height);
-
- // Configure the speed of the bat
- // This code means the bat can cover the
- // width of the screen in 1 second
- mBatSpeed = mScreenX;
- }
-
- // Return a reference to the mRect object
- RectF getRect(){
- return mRect;
- }
-
- // Update the movement state passed
- // in by the onTouchEvent method
- void setMovementState(int state){
- mBatMoving = state;
- }
-
-
- // Update the bat- Called each frame/loop
- void update(long fps){
-
- // Move the bat based on the mBatMoving variable
- // and the speed of the previous frame
- if(mBatMoving == LEFT){
- mXCoord = mXCoord - mBatSpeed / fps;
- }
-
- if(mBatMoving == RIGHT){
- mXCoord = mXCoord + mBatSpeed / fps;
- }
-
- // Stop the bat going off the screen
- if(mXCoord < 0){
- mXCoord = 0;
- }
-
- if(mXCoord + mLength > mScreenX){
- mXCoord = mScreenX - mLength;
- }
-
- // Update mRect based on the results from
- // the previous code in update
- mRect.left = mXCoord;
- mRect.right = mXCoord + mLength;
- }
-
-}
diff --git a/Chapter10/java/PongActivity.java b/Chapter10/java/PongActivity.java
deleted file mode 100644
index 101c6da..0000000
--- a/Chapter10/java/PongActivity.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.gamecodeschool.c10pong;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class PongActivity extends Activity {
- private PongGame mPongGame;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
-
- mPongGame = new PongGame(this, size.x, size.y);
- setContentView(mPongGame);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- // More code here later in the chapter
- mPongGame.resume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
-
- // More code here later in the chapter
- mPongGame.pause();
- }
-}
diff --git a/Chapter10/java/PongGame.java b/Chapter10/java/PongGame.java
deleted file mode 100644
index 7e40508..0000000
--- a/Chapter10/java/PongGame.java
+++ /dev/null
@@ -1,279 +0,0 @@
-package com.gamecodeschool.c10pong;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-class PongGame extends SurfaceView implements Runnable{
-
- // Are we debugging?
- private final boolean DEBUGGING = true;
-
- // These objects are needed to do the drawing
- private SurfaceHolder mOurHolder;
- private Canvas mCanvas;
- private Paint mPaint;
-
- // How many frames per second did we get?
- private long mFPS;
- // The number of milliseconds in a second
- private final int MILLIS_IN_SECOND = 1000;
-
- // Holds the resolution of the screen
- private int mScreenX;
- private int mScreenY;
- // How big will the text be?
- private int mFontSize;
- private int mFontMargin;
-
- // The game objects
- private Bat mBat;
- private Ball mBall;
-
- // The current score and lives remaining
- private int mScore = 0;
- private int mLives = 3;
-
- // Here is the Thread and two control variables
- private Thread mGameThread = null;
- // This volatile vaiable can be accessed
- // from inside and outside the thread
- private volatile boolean mPlaying;
- private boolean mPaused = true;
-
- // The PongGame constructor
- // Called when this line:
- // mPongGame = new PongGame(this, size.x, size.y);
- // is executed from PongActivity
- public PongGame(Context context, int x, int y) {
- // Super... calls the parent class
- // constructor of SurfaceView
- // provided by Android
- super(context);
-
- // Initialize these two members/fields
- // With the values passesd in as parameters
- mScreenX = x;
- mScreenY = y;
-
- // Font is 5% (1/20th) of screen width
- mFontSize = mScreenX / 20;
- // Margin is 1.5% (1/75th) of screen width
- mFontMargin = mScreenX / 75;
-
- // Initialize the objects
- // ready for drawing with
- // getHolder is a method of SurfaceView
- mOurHolder = getHolder();
- mPaint = new Paint();
-
- // Initialize the bat and ball
- mBall = new Ball(mScreenX);
- mBat = new Bat(mScreenX, mScreenY);
-
- // Everything is ready so start the game
- startNewGame();
- }
-
- // The player has just lost
- // or is starting their first game
- private void startNewGame(){
-
- // Put the ball back to the starting position
- mBall.reset(mScreenX, mScreenY);
-
- // Rest the score and the player's chances
- mScore = 0;
- mLives = 3;
-
- }
-
- // When we start the thread with:
- // mGameThread.start();
- // the run method is continuously called by Android
- // because we implemented the Runnable interface
- // Calling mGameThread.join();
- // will stop the thread
- @Override
- public void run() {
- // mPlaying gives us finer control
- // rather than just relying on the calls to run
- // mPlaying must be true AND
- // the thread running for the main loop to execute
- while (mPlaying) {
-
- // What time is it now at the start of the loop?
- long frameStartTime = System.currentTimeMillis();
-
- // Provided the game isn't paused call the update method
- if(!mPaused){
- update();
- // Now the bat and ball are in their new positions
- // we can see if there have been any collisions
- detectCollisions();
-
- }
-
- // The movement has been handled and collisions
- // detected now we can draw the scene.
- draw();
-
- // How long did this frame/loop take?
- // Store the answer in timeThisFrame
- long timeThisFrame = System.currentTimeMillis() - frameStartTime;
-
- // Make sure timeThisFrame is at least 1 millisecond
- // because accidentally dividing by zero crashes the game
- if (timeThisFrame > 0) {
- // Store the current frame rate in mFPS
- // ready to pass to the update methods of
- // mBat and mBall next frame/loop
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
-
- }
-
- }
-
- private void update() {
- // Update the bat and the ball
- mBall.update(mFPS);
- mBat.update(mFPS);
- }
-
- private void detectCollisions(){
- // Has the bat hit the ball?
-
- // Has the ball hit the edge of the screen
-
- // Bottom
-
- // Top
-
- // Left
-
- // Right
-
- }
-
- // Draw the game objects and the HUD
- void draw() {
- if (mOurHolder.getSurface().isValid()) {
- // Lock the canvas (graphics memory) ready to draw
- mCanvas = mOurHolder.lockCanvas();
-
- // Fill the screen with a solid color
- mCanvas.drawColor(Color.argb
- (255, 26, 128, 182));
-
- // Choose a color to paint with
- mPaint.setColor(Color.argb
- (255, 255, 255, 255));
-
- // Draw the bat and ball
- mCanvas.drawRect(mBall.getRect(), mPaint);
- mCanvas.drawRect(mBat.getRect(), mPaint);
-
- // Choose the font size
- mPaint.setTextSize(mFontSize);
-
- // Draw the HUD
- mCanvas.drawText("Score: " + mScore +
- " Lives: " + mLives,
- mFontMargin , mFontSize, mPaint);
-
- if(DEBUGGING){
- printDebuggingText();
- }
- // Display the drawing on screen
- // unlockCanvasAndPost is a method of SurfaceView
- mOurHolder.unlockCanvasAndPost(mCanvas);
- }
-
- }
-
- // Handle all the screen touches
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
-
- // This switch block replaces the
- // if statement from the Sub Hunter game
- switch (motionEvent.getAction() &
- MotionEvent.ACTION_MASK) {
-
- // The player has put their finger on the screen
- case MotionEvent.ACTION_DOWN:
-
- // If the game was paused unpause
- mPaused = false;
-
- // Where did the touch happen
- if(motionEvent.getX() > mScreenX / 2){
- // On the right hand side
- mBat.setMovementState(mBat.RIGHT);
- }
- else{
- // On the left hand side
- mBat.setMovementState(mBat.LEFT);
- }
-
- break;
-
- // The player lifted their finger
- // from anywhere on screen.
- // It is possible to create bugs by using
- // multiple fingers. We will use more
- // complicated and robust touch handling
- // in later projects
- case MotionEvent.ACTION_UP:
-
- // Stop the bat moving
- mBat.setMovementState(mBat.STOPPED);
- break;
- }
- return true;
- }
-
- private void printDebuggingText(){
- int debugSize = mFontSize / 2;
- int debugStart = 150;
- mPaint.setTextSize(debugSize);
- mCanvas.drawText("FPS: " + mFPS ,
- 10, debugStart + debugSize, mPaint);
-
- }
-
- // This method is called by PongActivity
- // when the player quits the game
- public void pause() {
-
- // Set mPlaying to false
- // Stopping the thread isn't
- // always instant
- mPlaying = false;
- try {
- // Stop the thread
- mGameThread.join();
- } catch (InterruptedException e) {
- Log.e("Error:", "joining thread");
- }
-
- }
-
-
- // This method is called by PongActivity
- // when the player starts the game
- public void resume() {
- mPlaying = true;
- // Initialize the instance of Thread
- mGameThread = new Thread(this);
-
- // Start the thread
- mGameThread.start();
- }
-}
\ No newline at end of file
diff --git a/Chapter11/AndroidManifest.xml b/Chapter11/AndroidManifest.xml
deleted file mode 100644
index 25110f0..0000000
--- a/Chapter11/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter11/assets/beep.ogg b/Chapter11/assets/beep.ogg
deleted file mode 100644
index 16e0e30..0000000
Binary files a/Chapter11/assets/beep.ogg and /dev/null differ
diff --git a/Chapter11/assets/boop.ogg b/Chapter11/assets/boop.ogg
deleted file mode 100644
index e9e729a..0000000
Binary files a/Chapter11/assets/boop.ogg and /dev/null differ
diff --git a/Chapter11/assets/bop.ogg b/Chapter11/assets/bop.ogg
deleted file mode 100644
index 6253161..0000000
Binary files a/Chapter11/assets/bop.ogg and /dev/null differ
diff --git a/Chapter11/assets/miss.ogg b/Chapter11/assets/miss.ogg
deleted file mode 100644
index 0c8e4d6..0000000
Binary files a/Chapter11/assets/miss.ogg and /dev/null differ
diff --git a/Chapter11/java/Ball.java b/Chapter11/java/Ball.java
deleted file mode 100644
index 6493c1a..0000000
--- a/Chapter11/java/Ball.java
+++ /dev/null
@@ -1,127 +0,0 @@
-package com.gamecodeschool.c11pong;
-
-import android.graphics.RectF;
-
-class Ball {
-
- // These are the member variables (fields)
- // They all have the m prefix
- // They are all private
- // because direct access is not required
- private RectF mRect;
- private float mXVelocity;
- private float mYVelocity;
- private float mBallWidth;
- private float mBallHeight;
-
- // This is the constructor method.
- // It is called when by the code:
- // mBall = new Ball(mScreenX);
- // In the PongGame class
- Ball(int screenX){
-
- // Make the ball square and 1% of screen width
- // of the screen width
- mBallWidth = screenX / 100;
- mBallHeight = screenX / 100;
-
- // Initialize the RectF with 0, 0, 0, 0
- // We do it here because we only want to
- // do it once.
- // WE will initialize the detail
- // at the start of each game
- mRect = new RectF();
- }
-
-
- // Return a reference to mRect to PongGame
- RectF getRect(){
- return mRect;
- }
-
- // Update the ball position.
- // Called each frame/loop
- void update(long fps){
- // Move the ball based upon the
- // horizontal (mXVelocity) and
- // vertical(mYVelocity) speed
- // and the current frame rate(mFPS)
-
- // Move the top left corner
- mRect.left = mRect.left + (mXVelocity / fps);
- mRect.top = mRect.top + (mYVelocity / fps);
-
- // Match up the bottom right corner
- // based on the size of the ball
- mRect.right = mRect.left + mBallWidth;
- mRect.bottom = mRect.top + mBallHeight;
- }
-
- // Reverse the vertical direction of travel
- void reverseYVelocity(){
- mYVelocity = -mYVelocity;
- }
-
- // Reverse the horizontal direction of travel
- void reverseXVelocity(){
- mXVelocity = -mXVelocity;
- }
-
- void reset(int x, int y){
-
- // Initialise the four points of
- // the rectangle which defines the ball
- mRect.left = x / 2;
- mRect.top = 0;
- mRect.right = x / 2 + mBallWidth;
- mRect.bottom = mBallHeight;
-
- // How fast will the ball travel
- // You could vary this to suit
- // You could even increase it as the game progresses
- // to make it harder
- mYVelocity = -(y / 3);
- mXVelocity = (y / 3);
- }
-
- void increaseVelocity(){
- // increase the speed by 10%
- mXVelocity = mXVelocity * 1.1f;
- mYVelocity = mYVelocity * 1.1f;
- }
-
-
- // Bounce the ball back based upon
- // whether it hits the left or right hand side
- void batBounce(RectF batPosition){
-
- // Detect center of bat
- float batCenter = batPosition.left +
- (batPosition.width() / 2);
-
- // detect the center of the ball
- float ballCenter = mRect.left +
- (mBallWidth / 2);
-
- // Where on the bat did the ball hit?
- float relativeIntersect = (batCenter - ballCenter);
-
- // Pick a bounce direction
- if(relativeIntersect < 0){
- // Go right
- mXVelocity = Math.abs(mXVelocity);
- // Math.abs is a static method that
- // strips any negative values from a value.
- // So -1 becomes 1 and 1 stays as 1
- }else{
- // Go left
- mXVelocity = -Math.abs(mXVelocity);
- }
-
- // Having calculated left or right for
- // horizontal direction simply reverse the
- // vertical direction to go back up
- // the screen
- reverseYVelocity();
- }
-}
\ No newline at end of file
diff --git a/Chapter11/java/Bat.java b/Chapter11/java/Bat.java
deleted file mode 100644
index 48f8fd0..0000000
--- a/Chapter11/java/Bat.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package com.gamecodeschool.c11pong;
-
-import android.graphics.RectF;
-
-class Bat {
-
- // These are the member variables (fields)
- // They all have the m prefix
- // They are all private
- // because direct access is not required
- private RectF mRect;
- private float mLength;
- private float mXCoord;
- private float mBatSpeed;
- private int mScreenX;
-
- // These variables are public and final
- // They can be directly accessed by
- // the instance (in PongGame)
- // because they are part of the same
- // package but cannot be changed
- final int STOPPED = 0;
- final int LEFT = 1;
- final int RIGHT = 2;
-
- // Keeps track of if an how the ball is moving
- // Starting with STOPPED
- private int mBatMoving = STOPPED;
-
- Bat(int sx, int sy){
-
- // Bat needs to know the screen
- // horizontal resolution
- // Outside of this method
- mScreenX = sx;
-
- // Configure the size of the bat based on
- // the screen resolution
- // One eighth the screen width
- mLength = mScreenX / 8;
- // One fortieth the screen height
- float height = sy / 40;
-
- // Configure the starting locaion of the bat
- // Roughly the middle horizontally
- mXCoord = mScreenX / 2;
- // The height of the bat
- // off of the bottom of the screen
- float mYCoord = sy - height;
-
- // Initialize mRect based on the size and position
- mRect = new RectF(mXCoord, mYCoord,
- mXCoord + mLength,
- mYCoord + height);
-
- // Configure the speed of the bat
- // This code means the bat can cover the
- // width of the screen in 1 second
- mBatSpeed = mScreenX;
- }
-
- // Return a reference to the mRect object
- RectF getRect(){
- return mRect;
- }
-
- // Update the movement state passed
- // in by the onTouchEvent method
- void setMovementState(int state){
- mBatMoving = state;
- }
-
-
- // Update the bat- Called each frame/loop
- void update(long fps){
-
- // Move the bat based on the mBatMoving variable
- // and the speed of the previous frame
- if(mBatMoving == LEFT){
- mXCoord = mXCoord - mBatSpeed / fps;
- }
-
- if(mBatMoving == RIGHT){
- mXCoord = mXCoord + mBatSpeed / fps;
- }
-
- // Stop the bat going off the screen
- if(mXCoord < 0){
- mXCoord = 0;
- }
-
- if(mXCoord + mLength > mScreenX){
- mXCoord = mScreenX - mLength;
- }
-
- // Update mRect based on the results from
- // the previous code in update
- mRect.left = mXCoord;
- mRect.right = mXCoord + mLength;
- }
-
-}
diff --git a/Chapter11/java/PongActivity.java b/Chapter11/java/PongActivity.java
deleted file mode 100644
index e7c48e3..0000000
--- a/Chapter11/java/PongActivity.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.gamecodeschool.c11pong;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class PongActivity extends Activity {
- private PongGame mPongGame;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
-
- mPongGame = new PongGame(this, size.x, size.y);
- setContentView(mPongGame);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- // More code here later in the chapter
- mPongGame.resume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
-
- // More code here later in the chapter
- mPongGame.pause();
- }
-}
diff --git a/Chapter11/java/PongGame.java b/Chapter11/java/PongGame.java
deleted file mode 100644
index e3caa42..0000000
--- a/Chapter11/java/PongGame.java
+++ /dev/null
@@ -1,369 +0,0 @@
-package com.gamecodeschool.c11pong;
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.RectF;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-import java.io.IOException;
-
-class PongGame extends SurfaceView implements Runnable{
-
- // Are we debugging?
- private final boolean DEBUGGING = true;
-
- // These objects are needed to do the drawing
- private SurfaceHolder mOurHolder;
- private Canvas mCanvas;
- private Paint mPaint;
-
- // How many frames per second did we get?
- private long mFPS;
- // The number of milliseconds in a second
- private final int MILLIS_IN_SECOND = 1000;
-
- // Holds the resolution of the screen
- private int mScreenX;
- private int mScreenY;
- // How big will the text be?
- private int mFontSize;
- private int mFontMargin;
-
- // The game objects
- private Bat mBat;
- private Ball mBall;
-
- // The current score and lives remaining
- private int mScore = 0;
- private int mLives = 3;
-
- // Here is the Thread and two control variables
- private Thread mGameThread = null;
- // This volatile variable can be accessed
- // from inside and outside the thread
- private volatile boolean mPlaying;
- private boolean mPaused = true;
-
- // All these are for playing sounds
- private SoundPool mSP;
- private int mBeepID = -1;
- private int mBoopID = -1;
- private int mBopID = -1;
- private int mMissID = -1;
-
- // The PongGame constructor
- // Called when this line:
- // mPongGame = new PongGame(this, size.x, size.y);
- // is executed from PongActivity
- public PongGame(Context context, int x, int y) {
- // Super... calls the parent class
- // constructor of SurfaceView
- // provided by Android
- super(context);
-
- // Initialize these two members/fields
- // With the values passesd in as parameters
- mScreenX = x;
- mScreenY = y;
-
- // Font is 5% (1/20th) of screen width
- mFontSize = mScreenX / 20;
- // Margin is 1.5% (1/75th) of screen width
- mFontMargin = mScreenX / 75;
-
- // Initialize the objects
- // ready for drawing with
- // getHolder is a method of SurfaceView
- mOurHolder = getHolder();
- mPaint = new Paint();
-
- // Initialize the bat and ball
- mBall = new Ball(mScreenX);
- mBat = new Bat(mScreenX, mScreenY);
-
- // Prepare the SoundPool instance
- // Depending upon the version of Android
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
-
-
-
- // Open each of the sound files in turn
- // and load them in to Ram ready to play
- // The try-catch blocks handle when this fails
- // and is required.
- try{
- AssetManager assetManager = context.getAssets();
- AssetFileDescriptor descriptor;
-
- descriptor = assetManager.openFd("beep.ogg");
- mBeepID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("boop.ogg");
- mBoopID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("bop.ogg");
- mBopID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("miss.ogg");
- mMissID = mSP.load(descriptor, 0);
-
-
- }catch(IOException e){
- Log.e("error", "failed to load sound files");
- }
-
- // Everything is ready so start the game
- startNewGame();
- }
-
- // The player has just lost
- // or is starting their first game
- private void startNewGame(){
-
- // Put the ball back to the starting position
- mBall.reset(mScreenX, mScreenY);
-
- // Rest the score and the player's chances
- mScore = 0;
- mLives = 3;
-
- }
-
- // When we start the thread with:
- // mGameThread.start();
- // the run method is continuously called by Android
- // because we implemented the Runnable interface
- // Calling mGameThread.join();
- // will stop the thread
- @Override
- public void run() {
- // mPlaying gives us finer control
- // rather than just relying on the calls to run
- // mPlaying must be true AND
- // the thread running for the main loop to execute
- while (mPlaying) {
-
- // What time is it now at the start of the loop?
- long frameStartTime = System.currentTimeMillis();
-
- // Provided the game isn't paused call the update method
- if(!mPaused){
- update();
- // Now the bat and ball are in their new positions
- // we can see if there have been any collisions
- detectCollisions();
-
- }
-
- // The movement has been handled and collisions
- // detected now we can draw the scene.
- draw();
-
- // How long did this frame/loop take?
- // Store the answer in timeThisFrame
- long timeThisFrame = System.currentTimeMillis() - frameStartTime;
-
- // Make sure timeThisFrame is at least 1 millisecond
- // because accidentally dividing by zero crashes the game
- if (timeThisFrame > 0) {
- // Store the current frame rate in mFPS
- // ready to pass to the update methods of
- // mBat and mBall next frame/loop
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
-
- }
-
- }
-
- private void update() {
- // Update the bat and the ball
- mBall.update(mFPS);
- mBat.update(mFPS);
- }
-
- private void detectCollisions(){
- // Has the bat hit the ball?
- if(RectF.intersects(mBat.getRect(), mBall.getRect())) {
- // Realistic-ish bounce
- mBall.batBounce(mBat.getRect());
- mBall.increaseVelocity();
- mScore++;
- mSP.play(mBeepID, 1, 1, 0, 0, 1);
- }
-
- // Has the ball hit the edge of the screen
-
- // Bottom
- if(mBall.getRect().bottom > mScreenY){
- mBall.reverseYVelocity();
-
- mLives--;
- mSP.play(mMissID, 1, 1, 0, 0, 1);
-
- if(mLives == 0){
- mPaused = true;
- startNewGame();
- }
- }
-
- // Top
- if(mBall.getRect().top < 0){
- mBall.reverseYVelocity();
- mSP.play(mBoopID, 1, 1, 0, 0, 1);
- }
-
- // Left
- if(mBall.getRect().left < 0){
- mBall.reverseXVelocity();
- mSP.play(mBopID, 1, 1, 0, 0, 1);
- }
-
- // Right
- if(mBall.getRect().right > mScreenX){
- mBall.reverseXVelocity();
- mSP.play(mBopID, 1, 1, 0, 0, 1);
- }
-
- }
-
- // Draw the game objects and the HUD
- void draw() {
- if (mOurHolder.getSurface().isValid()) {
- // Lock the canvas (graphics memory) ready to draw
- mCanvas = mOurHolder.lockCanvas();
-
- // Fill the screen with a solid color
- mCanvas.drawColor(Color.argb
- (255, 26, 128, 182));
-
- // Choose a color to paint with
- mPaint.setColor(Color.argb
- (255, 255, 255, 255));
-
- // Draw the bat and ball
- mCanvas.drawRect(mBall.getRect(), mPaint);
- mCanvas.drawRect(mBat.getRect(), mPaint);
-
- // Choose the font size
- mPaint.setTextSize(mFontSize);
-
- // Draw the HUD
- mCanvas.drawText("Score: " + mScore +
- " Lives: " + mLives,
- mFontMargin , mFontSize, mPaint);
-
- if(DEBUGGING){
- printDebuggingText();
- }
- // Display the drawing on screen
- // unlockCanvasAndPost is a method of SurfaceView
- mOurHolder.unlockCanvasAndPost(mCanvas);
- }
-
- }
-
- // Handle all the screen touches
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
-
- // This switch block replaces the
- // if statement from the Sub Hunter game
- switch (motionEvent.getAction() &
- MotionEvent.ACTION_MASK) {
-
- // The player has put their finger on the screen
- case MotionEvent.ACTION_DOWN:
-
- // If the game was paused unpause
- mPaused = false;
-
- // Where did the touch happen
- if(motionEvent.getX() > mScreenX / 2){
- // On the right hand side
- mBat.setMovementState(mBat.RIGHT);
- }
- else{
- // On the left hand side
- mBat.setMovementState(mBat.LEFT);
- }
-
- break;
-
- // The player lifted their finger
- // from anywhere on screen.
- // It is possible to create bugs by using
- // multiple fingers. We will use more
- // complicated and robust touch handling
- // in later projects
- case MotionEvent.ACTION_UP:
-
- // Stop the bat moving
- mBat.setMovementState(mBat.STOPPED);
- break;
- }
- return true;
- }
-
- private void printDebuggingText(){
- int debugSize = mFontSize / 2;
- int debugStart = 150;
- mPaint.setTextSize(debugSize);
- mCanvas.drawText("FPS: " + mFPS ,
- 10, debugStart + debugSize, mPaint);
-
- }
-
- // This method is called by PongActivity
- // when the player quits the game
- public void pause() {
-
- // Set mPlaying to false
- // Stopping the thread isn't
- // always instant
- mPlaying = false;
- try {
- // Stop the thread
- mGameThread.join();
- } catch (InterruptedException e) {
- Log.e("Error:", "joining thread");
- }
-
- }
-
-
- // This method is called by PongActivity
- // when the player starts the game
- public void resume() {
- mPlaying = true;
- // Initialize the instance of Thread
- mGameThread = new Thread(this);
-
- // Start the thread
- mGameThread.start();
- }
-}
diff --git a/Chapter12/C12BulletHell/AndroidManifest.xml b/Chapter12/C12BulletHell/AndroidManifest.xml
deleted file mode 100644
index dc37e8f..0000000
--- a/Chapter12/C12BulletHell/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter12/C12BulletHell/assets/beep.ogg b/Chapter12/C12BulletHell/assets/beep.ogg
deleted file mode 100644
index 16e0e30..0000000
Binary files a/Chapter12/C12BulletHell/assets/beep.ogg and /dev/null differ
diff --git a/Chapter12/C12BulletHell/assets/teleport.ogg b/Chapter12/C12BulletHell/assets/teleport.ogg
deleted file mode 100644
index fb2eb90..0000000
Binary files a/Chapter12/C12BulletHell/assets/teleport.ogg and /dev/null differ
diff --git a/Chapter12/C12BulletHell/drawable/bob.png b/Chapter12/C12BulletHell/drawable/bob.png
deleted file mode 100644
index 251d305..0000000
Binary files a/Chapter12/C12BulletHell/drawable/bob.png and /dev/null differ
diff --git a/Chapter12/C12BulletHell/java/Bob.java b/Chapter12/C12BulletHell/java/Bob.java
deleted file mode 100644
index 6f2a3ee..0000000
--- a/Chapter12/C12BulletHell/java/Bob.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.gamecodeschool.c12bullethell;
-
-class Bob {
-}
diff --git a/Chapter12/C12BulletHell/java/Bullet.java b/Chapter12/C12BulletHell/java/Bullet.java
deleted file mode 100644
index f866a6a..0000000
--- a/Chapter12/C12BulletHell/java/Bullet.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.gamecodeschool.c12bullethell;
-
-import android.graphics.RectF;
-
-class Bullet {
-
- // A RectF to represent the size and location of the bullet
- private RectF mRect;
-
- // How fast is the bullet travelling?
- private float mXVelocity;
- private float mYVelocity;
-
- // How big is a bullet
- private float mWidth;
- private float mHeight;
-
- // The constructor
- Bullet(int screenX){
-
- // Configure the bullet based on
- // the screen width in pixels
- mWidth = screenX / 100;
- mHeight = screenX / 100;
- mRect = new RectF();
- mYVelocity = (screenX / 5);
- mXVelocity = (screenX / 5);
- }
-
- // Return a reference to the RectF
- RectF getRect(){
- return mRect;
- }
-
-
- // Move the bullet based on the speed and the frame rate
- void update(long fps){
- mRect.left = mRect.left + (mXVelocity / fps);
- mRect.top = mRect.top + (mYVelocity / fps);
- mRect.right = mRect.left + mWidth;
- mRect.bottom = mRect.top - mHeight;
- }
-
- // Reverse the bullets vertical direction
- void reverseYVelocity(){
- mYVelocity = -mYVelocity;
- }
-
- // Reverse the bullets horizontal direction
- void reverseXVelocity(){
- mXVelocity = -mXVelocity;
- }
-
- // Spawn a new bullet
- void spawn(int pX, int pY, int vX, int vY){
-
- // Spawn the bullet at the location
- // passed in as parameters
- mRect.left = pX;
- mRect.top = pY;
- mRect.right = pX + mWidth;
- mRect.bottom = pY + mHeight;
-
- // Head away from the player
- // It's only fair
- mXVelocity = mXVelocity * vX;
- mYVelocity = mYVelocity * vY;
-
-
- }
-}
diff --git a/Chapter12/C12BulletHell/java/BulletHellActivity.java b/Chapter12/C12BulletHell/java/BulletHellActivity.java
deleted file mode 100644
index 545459b..0000000
--- a/Chapter12/C12BulletHell/java/BulletHellActivity.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.gamecodeschool.c12bullethell;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-
-// This class is almost exactly the same as the Pong project
-public class BulletHellActivity extends Activity {
-
- // An instance of the main class of this project
- private BulletHellGame mBHGame;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the screen resolution
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
-
- // Call the constructor(initialize) the BulletHellGame instance
- mBHGame = new BulletHellGame(this, size.x, size.y);
- setContentView(mBHGame);
- }
-
- @Override
- // Start the main game thread when the game is launched
- protected void onResume() {
- super.onResume();
-
- mBHGame.resume();
- }
-
- @Override
- // Stop the thread when the player quits
- protected void onPause() {
- super.onPause();
-
- mBHGame.pause();
- }
-}
diff --git a/Chapter12/C12BulletHell/java/BulletHellGame.java b/Chapter12/C12BulletHell/java/BulletHellGame.java
deleted file mode 100644
index 30757e8..0000000
--- a/Chapter12/C12BulletHell/java/BulletHellGame.java
+++ /dev/null
@@ -1,262 +0,0 @@
-package com.gamecodeschool.c12bullethell;
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import java.io.IOException;
-import java.util.Random;
-
-class BulletHellGame extends SurfaceView implements Runnable{
-
- // Are we currently debugging
- boolean mDebugging = true;
-
- // Objects for the game loop/thread
- private Thread mGameThread = null;
- private volatile boolean mPlaying;
- private boolean mPaused = true;
-
- // Objects for drawing
- private SurfaceHolder mOurHolder;
- private Canvas mCanvas;
- private Paint mPaint;
-
- // Keep track of the frame rate
- private long mFPS;
- // The number of milliseconds in a second
- private final int MILLIS_IN_SECOND = 1000;
-
- // Holds the resolution of the screen
- private int mScreenX;
- private int mScreenY;
-
- // How big will the text be?
- private int mFontSize;
- private int mFontMargin;
-
- // These are for the sound
- private SoundPool mSP;
- private int mBeepID = -1;
- private int mTeleportID = -1;
-
- // Up to 10000 bullets
- private Bullet[] mBullets = new Bullet[10];
- private int mNumBullets = 0;
- private int mSpawnRate = 1;
-
- private Random mRandomX = new Random();
- private Random mRandomY = new Random();
-
- // This is the constructor method that gets called
- // from BullethellActivity
- public BulletHellGame(Context context, int x, int y) {
- super(context);
-
- mScreenX = x;
- mScreenY = y;
- // Font is 5% of screen width
- mFontSize = mScreenX / 20;
- // Margin is 2% of screen width
- mFontMargin = mScreenX / 50;
-
- mOurHolder = getHolder();
- mPaint = new Paint();
-
-
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
-
-
- try{
- AssetManager assetManager = context.getAssets();
- AssetFileDescriptor descriptor;
-
- descriptor = assetManager.openFd("beep.ogg");
- mBeepID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("teleport.ogg");
- mTeleportID = mSP.load(descriptor, 0);
-
- }catch(IOException e){
- Log.e("error", "failed to load sound files");
- }
-
- for(int i = 0; i < mBullets.length; i++){
- mBullets[i] = new Bullet(mScreenX);
- }
-
- startGame();
- }
-
-
- // Called to start a new game
- public void startGame(){
- }
-
- // Spawns ANOTHER bullet
- private void spawnBullet(){
- // Add one to the number of bullets
- mNumBullets++;
-
- // Where to spawn the next bullet
- // And in which direction should it travel
- int spawnX;
- int spawnY;
- int velocityX;
- int velocityY;
-
- // This code will change in chapter 13
-
- // Pick a random point on the screen
- // to spawn a bullet
- spawnX = mRandomX.nextInt(mScreenX);
- spawnY = mRandomY.nextInt(mScreenY);
-
- // The horizontal direction of travel
- velocityX = 1;
- // Randomly make velocityX negative
- if(mRandomX.nextInt(2)==0){
- velocityX = -1;
- }
-
- velocityY = 1;
- // Randomly make velocityY negative
- if(mRandomY.nextInt(2)==0){
- velocityY = -1;
- }
-
- // Spawn the bullet
- mBullets[mNumBullets - 1].spawn(spawnX, spawnY, velocityX, velocityY);
- }
-
- // Handles the game loop
- @Override
- public void run() {
- while (mPlaying) {
-
- long frameStartTime = System.currentTimeMillis();
-
- if(!mPaused){
- update();
- // Now all the bullets have been moved
- // we can detect any collisions
- detectCollisions();
-
- }
-
- draw();
-
- long timeThisFrame = System.currentTimeMillis() - frameStartTime;
- if (timeThisFrame >= 1) {
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
-
- }
- }
-
-
- // Update all the game objects
- private void update(){
- for(int i = 0; i < mNumBullets; i++){
- mBullets[i].update(mFPS);
- }
- }
-
- private void detectCollisions(){
- // Has a bullet collided with a wall?
- // Loop through each active bullet in turn
- for(int i = 0; i < mNumBullets; i++) {
- if (mBullets[i].getRect().bottom > mScreenY) {
- mBullets[i].reverseYVelocity();
- }
-
- if (mBullets[i].getRect().top < 0) {
- mBullets[i].reverseYVelocity();
- }
-
- if (mBullets[i].getRect().left < 0) {
- mBullets[i].reverseXVelocity();
- }
-
- if (mBullets[i].getRect().right > mScreenX) {
- mBullets[i].reverseXVelocity();
- }
-
- }
- }
-
- private void draw(){
- if (mOurHolder.getSurface().isValid()) {
- mCanvas = mOurHolder.lockCanvas();
- mCanvas.drawColor(Color.argb(255, 243, 111, 36));
- mPaint.setColor(Color.argb(255, 255, 255, 255));
-
- // All the drawing code will go here
- for(int i = 0; i < mNumBullets; i++){
- mCanvas.drawRect(mBullets[i].getRect(), mPaint);
- }
-
- if(mDebugging) {
- printDebuggingText();
- }
-
- mOurHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
-
- mPaused = false;
- spawnBullet();
-
- return true;
- }
-
- public void pause() {
- mPlaying = false;
- try {
- mGameThread.join();
- } catch (InterruptedException e) {
- Log.e("Error:", "joining thread");
- }
- }
-
- public void resume() {
- mPlaying = true;
- mGameThread = new Thread(this);
- mGameThread.start();
- }
-
- private void printDebuggingText(){
- int debugSize = 35;
- int debugStart = 150;
- mPaint.setTextSize(debugSize);
-
- mCanvas.drawText("FPS: " + mFPS , 10, debugStart + debugSize, mPaint);
-
- }
-}
diff --git a/Chapter12/DynamicArrayExample/MainActivity.java b/Chapter12/DynamicArrayExample/MainActivity.java
deleted file mode 100644
index adeb3f2..0000000
--- a/Chapter12/DynamicArrayExample/MainActivity.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.packtpub.dynamicarrayexample.dynamicarrayexample;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.util.Log;
-
-
-public class MainActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- //Declaring and allocating in one step
- int[] ourArray = new int[1000];
-
- //Let's initialize ourArray using a for loop
- //Because more than a few variables is allot of typing!
- for(int i = 0; i < 1000; i++){
- //Put the value of ourValue into our array
- //At the position determined by i.
- ourArray[i] = i*5;
-
- //Output what is going on
- Log.i("info", "i = " + i);
- Log.i("info", "ourArray[i] = " + ourArray[i]);
- }
- }
-
-}
diff --git a/Chapter12/MultidimensionalArrayExample/MainActivity.java b/Chapter12/MultidimensionalArrayExample/MainActivity.java
deleted file mode 100644
index adeb3f2..0000000
--- a/Chapter12/MultidimensionalArrayExample/MainActivity.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.packtpub.dynamicarrayexample.dynamicarrayexample;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.util.Log;
-
-
-public class MainActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- //Declaring and allocating in one step
- int[] ourArray = new int[1000];
-
- //Let's initialize ourArray using a for loop
- //Because more than a few variables is allot of typing!
- for(int i = 0; i < 1000; i++){
- //Put the value of ourValue into our array
- //At the position determined by i.
- ourArray[i] = i*5;
-
- //Output what is going on
- Log.i("info", "i = " + i);
- Log.i("info", "ourArray[i] = " + ourArray[i]);
- }
- }
-
-}
diff --git a/Chapter12/SimpleArrayExample/MainActivity.java b/Chapter12/SimpleArrayExample/MainActivity.java
deleted file mode 100644
index e9e24a4..0000000
--- a/Chapter12/SimpleArrayExample/MainActivity.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.packtpub.simplearrayexample.simplearrayexample;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.util.Log;
-
-
-public class MainActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- //Declaring an array
- int[] ourArray;
-
- //Allocate memory for a maximum size of 5 elements
- ourArray = new int[5];
-
- //Initialize ourArray with values
- //The values are arbitrary as long as they are int
- //The indexes are not arbitrary 0 through 4 or crash!
- ourArray[0] = 25;
- ourArray[1] = 50;
- ourArray[2] = 125;
- ourArray[3] = 68;
- ourArray[4] = 47;
-
- //Output all the stored values
- Log.i("info", "Here is ourArray:");
- Log.i("info", "[0] = "+ourArray[0]);
- Log.i("info", "[1] = "+ourArray[1]);
- Log.i("info", "[2] = "+ourArray[2]);
- Log.i("info", "[3] = "+ourArray[3]);
- Log.i("info", "[4] = "+ourArray[4]);
-
- //We can do any calculation with an array element
- //As long as it is appropriate to the contained type
- //Like this:
- int answer = ourArray[0] +
- ourArray[1] +
- ourArray[2] +
- ourArray[3] +
- ourArray[4];
-
- Log.i("info", "Answer = "+answer);
- }
-
-
-
-}
diff --git a/Chapter13/AndroidManifest.xml b/Chapter13/AndroidManifest.xml
deleted file mode 100644
index 8893921..0000000
--- a/Chapter13/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter13/assets/beep.ogg b/Chapter13/assets/beep.ogg
deleted file mode 100644
index 16e0e30..0000000
Binary files a/Chapter13/assets/beep.ogg and /dev/null differ
diff --git a/Chapter13/assets/teleport.ogg b/Chapter13/assets/teleport.ogg
deleted file mode 100644
index fb2eb90..0000000
Binary files a/Chapter13/assets/teleport.ogg and /dev/null differ
diff --git a/Chapter13/drawable/bob.png b/Chapter13/drawable/bob.png
deleted file mode 100644
index 251d305..0000000
Binary files a/Chapter13/drawable/bob.png and /dev/null differ
diff --git a/Chapter13/java/Bob.java b/Chapter13/java/Bob.java
deleted file mode 100644
index 2237b62..0000000
--- a/Chapter13/java/Bob.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.gamecodeschool.c13bullethell;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.RectF;
-
-class Bob {
-
- RectF mRect;
- float mBobHeight;
- float mBobWidth;
- boolean mTeleporting = false;
-
- Bitmap bitmap;
-
- public Bob(Context context, float screenX, float screenY){
- mBobHeight = screenY / 10;
- mBobWidth = mBobHeight / 2;
-
- mRect = new RectF(screenX / 2,
- screenY / 2,
- (screenX / 2) + mBobWidth,
- (screenY / 2) + mBobHeight);
-
- // Prepare the bitmap
- // Load Bob from his .png file
- // Bob practices responsible encapsulato
- // looking after his own resources
- bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.bob);
- }
-
- boolean teleport(float newX, float newY){
-
- // Did Bob manage to teleport?
- boolean success = false;
-
- // Move Bob to the new position
- // If not already teleporting
- if(!mTeleporting){
-
- // Make him roughly central to the touch
- mRect.left = newX - mBobWidth / 2;
- mRect.top = newY - mBobHeight / 2;
- mRect.bottom = mRect.top + mBobHeight;
- mRect.right = mRect.left + mBobWidth;
-
- mTeleporting = true;
-
- // Notify BulletHellGame that teleport
- // attempt was successful
- success = true;
- }
-
- return success;
- }
-
- void setTelePortAvailable(){
- mTeleporting = false;
- }
-
- // Return a reference to mRect
- RectF getRect(){
- return mRect;
- }
-
- // Return a reference to bitmap
- Bitmap getBitmap(){
-
- return bitmap;
- }
-
-}
\ No newline at end of file
diff --git a/Chapter13/java/Bullet.java b/Chapter13/java/Bullet.java
deleted file mode 100644
index 100f198..0000000
--- a/Chapter13/java/Bullet.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.gamecodeschool.c13bullethell;
-
-import android.graphics.RectF;
-
-class Bullet {
-
- // A RectF to represent the size and location of the bullet
- private RectF mRect;
-
- // How fast is the bullet travelling?
- private float mXVelocity;
- private float mYVelocity;
-
- // How big is a bullet
- private float mWidth;
- private float mHeight;
-
- // The constructor
- Bullet(int screenX){
-
- // Configure the bullet based on
- // the screen width in pixels
- mWidth = screenX / 100;
- mHeight = screenX / 100;
- mRect = new RectF();
- mYVelocity = (screenX / 5);
- mXVelocity = (screenX / 5);
- }
-
- // Return a reference to the RectF
- RectF getRect(){
- return mRect;
- }
-
-
- // Move the bullet based on the speed and the frame rate
- void update(long fps){
- mRect.left = mRect.left + (mXVelocity / fps);
- mRect.top = mRect.top + (mYVelocity / fps);
- mRect.right = mRect.left + mWidth;
- mRect.bottom = mRect.top - mHeight;
- }
-
- // Reverse the bullets vertical direction
- void reverseYVelocity(){
- mYVelocity = -mYVelocity;
- }
-
- // Reverse the bullets horizontal direction
- void reverseXVelocity(){
- mXVelocity = -mXVelocity;
- }
-
- // Spawn a new bullet
- void spawn(int pX, int pY, int vX, int vY){
-
- // Spawn the bullet at the location
- // passed in as parameters
- mRect.left = pX;
- mRect.top = pY;
- mRect.right = pX + mWidth;
- mRect.bottom = pY + mHeight;
-
- // Head away from the player
- // It's only fair
- mXVelocity = mXVelocity * vX;
- mYVelocity = mYVelocity * vY;
-
-
- }
-}
\ No newline at end of file
diff --git a/Chapter13/java/BulletHellActivity.java b/Chapter13/java/BulletHellActivity.java
deleted file mode 100644
index 2f66765..0000000
--- a/Chapter13/java/BulletHellActivity.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.gamecodeschool.c13bullethell;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-
-// This class is almost exactly the same as the Pong project
-public class BulletHellActivity extends Activity {
-
- // An instance of the main class of this project
- private BulletHellGame mBHGame;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the screen resolution
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
-
- // Call the constructor(initialize) the BulletHellGame instance
- mBHGame = new BulletHellGame(this, size.x, size.y);
- setContentView(mBHGame);
- }
-
- @Override
- // Start the main game thread when the game is launched
- protected void onResume() {
- super.onResume();
-
- mBHGame.resume();
- }
-
- @Override
- // Stop the thread when the player quits
- protected void onPause() {
- super.onPause();
-
- mBHGame.pause();
- }
-}
diff --git a/Chapter13/java/BulletHellGame.java b/Chapter13/java/BulletHellGame.java
deleted file mode 100644
index f25cf9a..0000000
--- a/Chapter13/java/BulletHellGame.java
+++ /dev/null
@@ -1,381 +0,0 @@
-package com.gamecodeschool.c13bullethell;
-
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.RectF;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import java.io.IOException;
-import java.util.Random;
-
-class BulletHellGame extends SurfaceView implements Runnable{
-
- // Are we currently debugging
- boolean mDebugging = true;
-
- // Objects for the game loop/thread
- private Thread mGameThread = null;
- private volatile boolean mPlaying;
- private boolean mPaused = true;
-
- // Objects for drawing
- private SurfaceHolder mOurHolder;
- private Canvas mCanvas;
- private Paint mPaint;
-
- // Keep track of the frame rate
- private long mFPS;
- // The number of milliseconds in a second
- private final int MILLIS_IN_SECOND = 1000;
-
- // Holds the resolution of the screen
- private int mScreenX;
- private int mScreenY;
-
- // How big will the text be?
- private int mFontSize;
- private int mFontMargin;
-
- // These are for the sound
- private SoundPool mSP;
- private int mBeepID = -1;
- private int mTeleportID = -1;
-
- // Up to 10000 bullets
- private Bullet[] mBullets = new Bullet[10000];
- private int mNumBullets = 0;
- private int mSpawnRate = 1;
-
- private Random mRandomX = new Random();
- private Random mRandomY = new Random();
-
- private Bob mBob;
- private boolean mHit = false;
- private int mNumHits;
- private int mShield = 10;
-
- // Let's time the game
- private long mStartGameTime;
- private long mBestGameTime;
- private long mTotalGameTime;
-
- // This is the constructor method that gets called
- // from BullethellActivity
- public BulletHellGame(Context context, int x, int y) {
- super(context);
-
- mScreenX = x;
- mScreenY = y;
- // Font is 5% of screen width
- mFontSize = mScreenX / 20;
- // Margin is 2% of screen width
- mFontMargin = mScreenX / 50;
-
- mOurHolder = getHolder();
- mPaint = new Paint();
-
-
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
-
-
- try{
- AssetManager assetManager = context.getAssets();
- AssetFileDescriptor descriptor;
-
- descriptor = assetManager.openFd("beep.ogg");
- mBeepID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("teleport.ogg");
- mTeleportID = mSP.load(descriptor, 0);
-
- }catch(IOException e){
- Log.e("error", "failed to load sound files");
- }
-
- for(int i = 0; i < mBullets.length; i++){
- mBullets[i] = new Bullet(mScreenX);
- }
-
- mBob = new Bob(context, mScreenX, mScreenY);
-
- startGame();
- }
-
-
- // Called to start a new game
- public void startGame(){
- mNumHits = 0;
- mNumBullets = 0;
- mHit = false;
-
- // Did the player survive longer than previously
- if(mTotalGameTime > mBestGameTime){
- mBestGameTime = mTotalGameTime;
- }
-
- }
-
- // Spawns ANOTHER bullet
- private void spawnBullet(){
- // Add one to the number of bullets
- mNumBullets++;
-
- // Where to spawn the next bullet
- // And in which direction should it travel
- int spawnX;
- int spawnY;
- int velocityX;
- int velocityY;
-
- // This code will change in chapter 13
- // Don't spawn to close to Bob
- if (mBob.getRect().centerX() < mScreenX / 2) {
- // Bob is on the left
- // Spawn bullet on the right
- spawnX = mRandomX.nextInt
- (mScreenX / 2) + mScreenX / 2;
- // Head right
- velocityX = 1;
- } else {
- // Bob is on the right
- // Spawn bullet on the left
- spawnX = mRandomX.nextInt
- (mScreenX / 2);
- // Head left
- velocityX = -1;
- }
-
- // Don't spawn to close to Bob
- if (mBob.getRect().centerY() < mScreenY / 2) {
- // Bob is on the top
- // Spawn bullet on the bottom
- spawnY = mRandomY.nextInt
- (mScreenY / 2) + mScreenY / 2;
- // Head down
- velocityY = 1;
- } else {
- // Bob is on the bottom
- // Spawn bullet on the top
- spawnY = mRandomY.nextInt
- (mScreenY / 2);
- // head up
- velocityY = -1;
- }
-
- // Spawn the bullet
- mBullets[mNumBullets - 1]
- .spawn(spawnX, spawnY, velocityX, velocityY);
- }
-
- // Handles the game loop
- @Override
- public void run() {
- while (mPlaying) {
-
- long frameStartTime = System.currentTimeMillis();
-
- if(!mPaused){
- update();
- // Now all the bullets have been moved
- // we can detect any collisions
- detectCollisions();
-
- }
-
- draw();
-
- long timeThisFrame = System.currentTimeMillis() - frameStartTime;
- if (timeThisFrame >= 1) {
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
-
- }
- }
-
-
- // Update all the game objects
- private void update(){
- for(int i = 0; i < mNumBullets; i++){
- mBullets[i].update(mFPS);
- }
- }
-
- private void detectCollisions(){
- // Has a bullet collided with a wall?
- // Loop through each active bullet in turn
- for(int i = 0; i < mNumBullets; i++) {
- if (mBullets[i].getRect().bottom > mScreenY) {
- mBullets[i].reverseYVelocity();
- }
-
- if (mBullets[i].getRect().top < 0) {
- mBullets[i].reverseYVelocity();
- }
-
- if (mBullets[i].getRect().left < 0) {
- mBullets[i].reverseXVelocity();
- }
-
- if (mBullets[i].getRect().right > mScreenX) {
- mBullets[i].reverseXVelocity();
- }
-
- }
-
- // Has a bullet hit Bob?
- // Check each bullet for an intersection with Bob's RectF
- for (int i = 0; i < mNumBullets; i++) {
-
- if (RectF.intersects(mBullets[i].getRect(), mBob.getRect())) {
- // Bob has been hit
- mSP.play(mBeepID, 1, 1, 0, 0, 1);
-
- // This flags that a hit occured so that the draw
- // method "knows" as well
- mHit = true;
-
- // Rebound the bullet that collided
- mBullets[i].reverseXVelocity();
- mBullets[i].reverseYVelocity();
-
- // keep track of the number of hits
- mNumHits++;
-
- if(mNumHits == mShield) {
- mPaused = true;
- mTotalGameTime = System.currentTimeMillis() - mStartGameTime;
- startGame();
- }
- }
-
- }
- }
-
- private void draw(){
- if (mOurHolder.getSurface().isValid()) {
- mCanvas = mOurHolder.lockCanvas();
- mCanvas.drawColor(Color.argb(255, 243, 111, 36));
- mPaint.setColor(Color.argb(255, 255, 255, 255));
-
- // All the drawing code will go here
- for(int i = 0; i < mNumBullets; i++){
- mCanvas.drawRect(mBullets[i].getRect(), mPaint);
- }
-
- mCanvas.drawBitmap(mBob.getBitmap(),
- mBob.getRect().left, mBob.getRect().top, mPaint);
-
-
- mPaint.setTextSize(mFontSize);
- mCanvas.drawText("Bullets: " + mNumBullets +
- " Shield: " + (mShield - mNumHits) +
- " Best Time: " + mBestGameTime /
- MILLIS_IN_SECOND,
- mFontMargin, mFontSize, mPaint);
-
-
- // Don't draw the current time when paused
- if(!mPaused) {
- mCanvas.drawText("Seconds Survived: " +
- ((System.currentTimeMillis() -
- mStartGameTime) / MILLIS_IN_SECOND),
- mFontMargin, mFontMargin * 30, mPaint);
- }
-
-
- if(mDebugging) {
- printDebuggingText();
- }
-
- mOurHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
-
- switch (motionEvent.getAction() &
- MotionEvent.ACTION_MASK) {
-
- case MotionEvent.ACTION_DOWN:
-
- if(mPaused){
- mStartGameTime = System.currentTimeMillis();
- mPaused = false;
- }
-
- if(mBob.teleport(motionEvent.getX(), motionEvent.getY())){
- mSP.play(mTeleportID, 1, 1, 0, 0, 1);
- }
- break;
-
- case MotionEvent.ACTION_UP:
-
- mBob.setTelePortAvailable();
- spawnBullet();
- break;
- }
- return true;
- }
-
- public void pause() {
- mPlaying = false;
- try {
- mGameThread.join();
- } catch (InterruptedException e) {
- Log.e("Error:", "joining thread");
- }
- }
-
- public void resume() {
- mPlaying = true;
- mGameThread = new Thread(this);
- mGameThread.start();
- }
-
- private void printDebuggingText(){
- int debugSize = 35;
- int debugStart = 150;
- mPaint.setTextSize(debugSize);
-
- mCanvas.drawText("FPS: " + mFPS , 10,
- debugStart + debugSize, mPaint);
- mCanvas.drawText("Bob left: " + mBob.getRect().left , 10,
- debugStart + debugSize *2, mPaint);
- mCanvas.drawText("Bob top: " + mBob.getRect().top , 10,
- debugStart + debugSize *3, mPaint);
- mCanvas.drawText("Bob right: " + mBob.getRect().right , 10,
- debugStart + debugSize *4, mPaint);
- mCanvas.drawText("Bob bottom: " + mBob.getRect().bottom , 10,
- debugStart + debugSize *5, mPaint);
- mCanvas.drawText("Bob centerX: " + mBob.getRect().centerX() , 10,
- debugStart + debugSize *6, mPaint);
- mCanvas.drawText("Bob centerY: " + mBob.getRect().centerY() , 10,
- debugStart + debugSize *7, mPaint);
-
- }
-}
diff --git a/Chapter14/AndroidManifest.xml b/Chapter14/AndroidManifest.xml
deleted file mode 100644
index 30febdb..0000000
--- a/Chapter14/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter14/assets/get_apple.ogg b/Chapter14/assets/get_apple.ogg
deleted file mode 100644
index fcea634..0000000
Binary files a/Chapter14/assets/get_apple.ogg and /dev/null differ
diff --git a/Chapter14/assets/snake_death.ogg b/Chapter14/assets/snake_death.ogg
deleted file mode 100644
index a4ab72b..0000000
Binary files a/Chapter14/assets/snake_death.ogg and /dev/null differ
diff --git a/Chapter14/java/Apple.java b/Chapter14/java/Apple.java
deleted file mode 100644
index d044113..0000000
--- a/Chapter14/java/Apple.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.gamecodeschool.c14snake;
-
-/**
- * Created by johnh on 22/12/2017.
- */
-
-class Apple {
-}
diff --git a/Chapter14/java/Snake.java b/Chapter14/java/Snake.java
deleted file mode 100644
index 67fd55f..0000000
--- a/Chapter14/java/Snake.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.gamecodeschool.c14snake;
-
-/**
- * Created by johnh on 22/12/2017.
- */
-
-class Snake {
-}
diff --git a/Chapter14/java/SnakeActivity.java b/Chapter14/java/SnakeActivity.java
deleted file mode 100644
index 4ab3367..0000000
--- a/Chapter14/java/SnakeActivity.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.gamecodeschool.c14snake;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class SnakeActivity extends Activity {
-
- // Declare an instance of SnakeGame
- SnakeGame mSnakeGame;
-
- // Set the game up
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the pixel dimensions of the screen
- Display display = getWindowManager().getDefaultDisplay();
-
- // Initialize the result into a Point object
- Point size = new Point();
- display.getSize(size);
-
- // Create a new instance of the SnakeEngine class
- mSnakeGame = new SnakeGame(this, size);
-
- // Make snakeEngine the view of the Activity
- setContentView(mSnakeGame);
- }
-
- // Start the thread in snakeEngine
- @Override
- protected void onResume() {
- super.onResume();
- mSnakeGame.resume();
- }
-
- // Stop the thread in snakeEngine
- @Override
- protected void onPause() {
- super.onPause();
- mSnakeGame.pause();
- }
-}
\ No newline at end of file
diff --git a/Chapter14/java/SnakeGame.java b/Chapter14/java/SnakeGame.java
deleted file mode 100644
index 11c7e46..0000000
--- a/Chapter14/java/SnakeGame.java
+++ /dev/null
@@ -1,251 +0,0 @@
-package com.gamecodeschool.c14snake;
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import java.io.IOException;
-
-class SnakeGame extends SurfaceView implements Runnable{
-
- // Objects for the game loop/thread
- private Thread mThread = null;
- // Control pausing between updates
- private long mNextFrameTime;
- // Is the game currently playing and or paused?
- private volatile boolean mPlaying = false;
- private volatile boolean mPaused = true;
-
- // for playing sound effects
- private SoundPool mSP;
- private int mEat_ID = -1;
- private int mCrashID = -1;
-
- // The size in segments of the playable area
- private final int NUM_BLOCKS_WIDE = 40;
- private int mNumBlocksHigh;
-
- // How many points does the player have
- private int mScore;
-
- // Objects for drawing
- private Canvas mCanvas;
- private SurfaceHolder mSurfaceHolder;
- private Paint mPaint;
-
- // A snake ssss
- private Snake mSnake;
- // And an apple
- private Apple mApple;
-
-
- // This is the constructor method that gets called
- // from SnakeActivity
- public SnakeGame(Context context, Point size) {
- super(context);
-
- // Work out how many pixels each block is
- int blockSize = size.x / NUM_BLOCKS_WIDE;
- // How many blocks of the same size will fit into the height
- mNumBlocksHigh = size.y / blockSize;
-
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
- try {
- AssetManager assetManager = context.getAssets();
- AssetFileDescriptor descriptor;
-
- // Prepare the sounds in memory
- descriptor = assetManager.openFd("get_apple.ogg");
- mEat_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("snake_death.ogg");
- mCrashID = mSP.load(descriptor, 0);
-
- } catch (IOException e) {
- // Error
- }
-
- // Initialize the drawing objects
- mSurfaceHolder = getHolder();
- mPaint = new Paint();
-
- // Call the constructors of our two game objects
-
- }
-
-
- // Called to start a new game
- public void newGame() {
-
- // reset the snake
-
-
- // Get the apple ready for dinner
-
-
- // Reset the mScore
- mScore = 0;
-
- // Setup mNextFrameTime so an update can triggered
- mNextFrameTime = System.currentTimeMillis();
- }
-
-
- // Handles the game loop
- @Override
- public void run() {
- while (mPlaying) {
- if(!mPaused) {
- // Update 10 times a second
- if (updateRequired()) {
- update();
- }
- }
-
- draw();
- }
- }
-
-
- // Check to see if it is time for an update
- public boolean updateRequired() {
-
- // Run at 10 frames per second
- final long TARGET_FPS = 10;
- // There are 1000 milliseconds in a second
- final long MILLIS_PER_SECOND = 1000;
-
- // Are we due to update the frame
- if(mNextFrameTime <= System.currentTimeMillis()){
- // Tenth of a second has passed
-
- // Setup when the next update will be triggered
- mNextFrameTime =System.currentTimeMillis()
- + MILLIS_PER_SECOND / TARGET_FPS;
-
- // Return true so that the update and draw
- // methods are executed
- return true;
- }
-
- return false;
- }
-
-
- // Update all the game objects
- public void update() {
-
- // Move the snake
-
- // Did the head of the snake eat the apple?
-
- // Did the snake die?
-
- }
-
-
- // Do all the drawing
- public void draw() {
- // Get a lock on the mCanvas
- if (mSurfaceHolder.getSurface().isValid()) {
- mCanvas = mSurfaceHolder.lockCanvas();
-
- // Fill the screen with a color
- mCanvas.drawColor(Color.argb(255, 26, 128, 182));
-
- // Set the size and color of the mPaint for the text
- mPaint.setColor(Color.argb(255, 255, 255, 255));
- mPaint.setTextSize(120);
-
- // Draw the score
- mCanvas.drawText("" + mScore, 20, 120, mPaint);
-
- // Draw the apple and the snake
-
- // Draw some text while paused
- if(mPaused){
-
- // Set the size and color of the mPaint for the text
- mPaint.setColor(Color.argb(255, 255, 255, 255));
- mPaint.setTextSize(250);
-
- // Draw the message
- // We will give this an international upgrade soon
- mCanvas.drawText("Tap To Play!", 200, 700, mPaint);
- }
-
-
- // Unlock the mCanvas and reveal the graphics for this frame
- mSurfaceHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-
-
-
-
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
- case MotionEvent.ACTION_UP:
- if (mPaused) {
- mPaused = false;
- newGame();
-
- // Don't want to process snake direction for this tap
- return true;
- }
-
- // Let the Snake class handle the input
-
- break;
-
- default:
- break;
-
- }
- return true;
- }
-
-
- // Stop the thread
- public void pause() {
- mPlaying = false;
- try {
- mThread.join();
- } catch (InterruptedException e) {
- // Error
- }
- }
-
-
- // Start the thread
- public void resume() {
- mPlaying = true;
- mThread = new Thread(this);
- mThread.start();
- }
-}
\ No newline at end of file
diff --git a/Chapter15/AndroidManifest.xml b/Chapter15/AndroidManifest.xml
deleted file mode 100644
index 1035cdb..0000000
--- a/Chapter15/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter15/assets/get_apple.ogg b/Chapter15/assets/get_apple.ogg
deleted file mode 100644
index fcea634..0000000
Binary files a/Chapter15/assets/get_apple.ogg and /dev/null differ
diff --git a/Chapter15/assets/snake_death.ogg b/Chapter15/assets/snake_death.ogg
deleted file mode 100644
index a4ab72b..0000000
Binary files a/Chapter15/assets/snake_death.ogg and /dev/null differ
diff --git a/Chapter15/java/Apple.java b/Chapter15/java/Apple.java
deleted file mode 100644
index 9b8e0a1..0000000
--- a/Chapter15/java/Apple.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.gamecodeschool.c15snake;
-
-/**
- * Created by johnh on 22/12/2017.
- */
-
-class Apple {
-}
diff --git a/Chapter15/java/Snake.java b/Chapter15/java/Snake.java
deleted file mode 100644
index 3b9c9c5..0000000
--- a/Chapter15/java/Snake.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.gamecodeschool.c15snake;
-
-/**
- * Created by johnh on 22/12/2017.
- */
-
-class Snake {
-}
diff --git a/Chapter15/java/SnakeActivity.java b/Chapter15/java/SnakeActivity.java
deleted file mode 100644
index 156daca..0000000
--- a/Chapter15/java/SnakeActivity.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.gamecodeschool.c15snake;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class SnakeActivity extends Activity {
-
- // Declare an instance of SnakeGame
- SnakeGame mSnakeGame;
-
- // Set the game up
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the pixel dimensions of the screen
- Display display = getWindowManager().getDefaultDisplay();
-
- // Initialize the result into a Point object
- Point size = new Point();
- display.getSize(size);
-
- // Create a new instance of the SnakeEngine class
- mSnakeGame = new SnakeGame(this, size);
-
- // Make snakeEngine the view of the Activity
- setContentView(mSnakeGame);
- }
-
- // Start the thread in snakeEngine
- @Override
- protected void onResume() {
- super.onResume();
- mSnakeGame.resume();
- }
-
- // Stop the thread in snakeEngine
- @Override
- protected void onPause() {
- super.onPause();
- mSnakeGame.pause();
- }
-}
\ No newline at end of file
diff --git a/Chapter15/java/SnakeGame.java b/Chapter15/java/SnakeGame.java
deleted file mode 100644
index f2d7a49..0000000
--- a/Chapter15/java/SnakeGame.java
+++ /dev/null
@@ -1,254 +0,0 @@
-package com.gamecodeschool.c15snake;
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import java.io.IOException;
-
-class SnakeGame extends SurfaceView implements Runnable{
-
- // Objects for the game loop/thread
- private Thread mThread = null;
- // Control pausing between updates
- private long mNextFrameTime;
- // Is the game currently playing and or paused?
- private volatile boolean mPlaying = false;
- private volatile boolean mPaused = true;
-
- // for playing sound effects
- private SoundPool mSP;
- private int mEat_ID = -1;
- private int mCrashID = -1;
-
- // The size in segments of the playable area
- private final int NUM_BLOCKS_WIDE = 40;
- private int mNumBlocksHigh;
-
- // How many points does the player have
- private int mScore;
-
- // Objects for drawing
- private Canvas mCanvas;
- private SurfaceHolder mSurfaceHolder;
- private Paint mPaint;
-
- // A snake ssss
- private Snake mSnake;
- // And an apple
- private Apple mApple;
-
-
- // This is the constructor method that gets called
- // from SnakeActivity
- public SnakeGame(Context context, Point size) {
- super(context);
-
- // Work out how many pixels each block is
- int blockSize = size.x / NUM_BLOCKS_WIDE;
- // How many blocks of the same size will fit into the height
- mNumBlocksHigh = size.y / blockSize;
-
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
- try {
- AssetManager assetManager = context.getAssets();
- AssetFileDescriptor descriptor;
-
- // Prepare the sounds in memory
- descriptor = assetManager.openFd("get_apple.ogg");
- mEat_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("snake_death.ogg");
- mCrashID = mSP.load(descriptor, 0);
-
- } catch (IOException e) {
- // Error
- }
-
- // Initialize the drawing objects
- mSurfaceHolder = getHolder();
- mPaint = new Paint();
-
- // Call the constructors of our two game objects
-
- }
-
-
- // Called to start a new game
- public void newGame() {
-
- // reset the snake
-
-
- // Get the apple ready for dinner
-
-
- // Reset the mScore
- mScore = 0;
-
- // Setup mNextFrameTime so an update can triggered
- mNextFrameTime = System.currentTimeMillis();
- }
-
-
- // Handles the game loop
- @Override
- public void run() {
- while (mPlaying) {
- if(!mPaused) {
- // Update 10 times a second
- if (updateRequired()) {
- update();
- }
- }
-
- draw();
- }
- }
-
-
- // Check to see if it is time for an update
- public boolean updateRequired() {
-
- // Run at 10 frames per second
- final long TARGET_FPS = 10;
- // There are 1000 milliseconds in a second
- final long MILLIS_PER_SECOND = 1000;
-
- // Are we due to update the frame
- if(mNextFrameTime <= System.currentTimeMillis()){
- // Tenth of a second has passed
-
- // Setup when the next update will be triggered
- mNextFrameTime =System.currentTimeMillis()
- + MILLIS_PER_SECOND / TARGET_FPS;
-
- // Return true so that the update and draw
- // methods are executed
- return true;
- }
-
- return false;
- }
-
-
- // Update all the game objects
- public void update() {
-
- // Move the snake
-
- // Did the head of the snake eat the apple?
-
- // Did the snake die?
-
- }
-
-
- // Do all the drawing
- public void draw() {
- // Get a lock on the mCanvas
- if (mSurfaceHolder.getSurface().isValid()) {
- mCanvas = mSurfaceHolder.lockCanvas();
-
- // Fill the screen with a color
- mCanvas.drawColor(Color.argb(255, 26, 128, 182));
-
- // Set the size and color of the mPaint for the text
- mPaint.setColor(Color.argb(255, 255, 255, 255));
- mPaint.setTextSize(120);
-
- // Draw the score
- mCanvas.drawText("" + mScore, 20, 120, mPaint);
-
- // Draw the apple and the snake
-
- // Draw some text while paused
- if(mPaused){
-
- // Set the size and color of the mPaint for the text
- mPaint.setColor(Color.argb(255, 255, 255, 255));
- mPaint.setTextSize(120);
-
- // Draw the message
- // We will give this an international upgrade soon
- //mCanvas.drawText("Tap To Play!", 200, 700, mPaint);
- mCanvas.drawText(getResources().
- getString(R.string.tap_to_play),
- 200, 700, mPaint);
- }
-
-
- // Unlock the mCanvas and reveal the graphics for this frame
- mSurfaceHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-
-
-
-
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
- case MotionEvent.ACTION_UP:
- if (mPaused) {
- mPaused = false;
- newGame();
-
- // Don't want to process snake direction for this tap
- return true;
- }
-
- // Let the Snake class handle the input
-
- break;
-
- default:
- break;
-
- }
- return true;
- }
-
-
- // Stop the thread
- public void pause() {
- mPlaying = false;
- try {
- mThread.join();
- } catch (InterruptedException e) {
- // Error
- }
- }
-
-
- // Start the thread
- public void resume() {
- mPlaying = true;
- mThread = new Thread(this);
- mThread.start();
- }
-}
diff --git a/Chapter15/values-de/strings.xml b/Chapter15/values-de/strings.xml
deleted file mode 100644
index 58d4bd8..0000000
--- a/Chapter15/values-de/strings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
- Tippen Sie, um zu spielen!
-
\ No newline at end of file
diff --git a/Chapter15/values-es/strings.xml b/Chapter15/values-es/strings.xml
deleted file mode 100644
index 47da145..0000000
--- a/Chapter15/values-es/strings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
- Toque para jugar!
-
\ No newline at end of file
diff --git a/Chapter15/values/colors.xml b/Chapter15/values/colors.xml
deleted file mode 100644
index 3ab3e9c..0000000
--- a/Chapter15/values/colors.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
- #3F51B5
- #303F9F
- #FF4081
-
diff --git a/Chapter15/values/strings.xml b/Chapter15/values/strings.xml
deleted file mode 100644
index 1b00486..0000000
--- a/Chapter15/values/strings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
- C15Snake
- Tap To Play!
-
diff --git a/Chapter15/values/styles.xml b/Chapter15/values/styles.xml
deleted file mode 100644
index ff6c9d2..0000000
--- a/Chapter15/values/styles.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
diff --git a/Chapter16/AndroidManifest.xml b/Chapter16/AndroidManifest.xml
deleted file mode 100644
index 0815cfb..0000000
--- a/Chapter16/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter16/assets/get_apple.ogg b/Chapter16/assets/get_apple.ogg
deleted file mode 100644
index fcea634..0000000
Binary files a/Chapter16/assets/get_apple.ogg and /dev/null differ
diff --git a/Chapter16/assets/snake_death.ogg b/Chapter16/assets/snake_death.ogg
deleted file mode 100644
index a4ab72b..0000000
Binary files a/Chapter16/assets/snake_death.ogg and /dev/null differ
diff --git a/Chapter16/java/Apple.java b/Chapter16/java/Apple.java
deleted file mode 100644
index b0197ef..0000000
--- a/Chapter16/java/Apple.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.gamecodeschool.c16snake;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.Point;
-import java.util.Random;
-
-class Apple {
-
- // The location of the apple on the grid
- // Not in pixels
- private Point location = new Point();
-
- // The range of values we can choose from
- // to spawn an apple
- private Point mSpawnRange;
- private int mSize;
-
- // An image to represent the apple
- private Bitmap mBitmapApple;
-
- /// Set up the apple in the constructor
- Apple(Context context, Point sr, int s){
-
- // Make a note of the passed in spawn range
- mSpawnRange = sr;
- // Make a note of the size of an apple
- mSize = s;
- // Hide the apple off-screen until the game starts
- location.x = -10;
-
- // Load the image to the bitmap
- mBitmapApple = BitmapFactory.decodeResource(context.getResources(), R.drawable.apple);
-
- // Resize the bitmap
- mBitmapApple = Bitmap.createScaledBitmap(mBitmapApple, s, s, false);
- }
-
- // This is called every time an apple is eaten
- void spawn(){
- // Choose two random values and place the apple
- Random random = new Random();
- location.x = random.nextInt(mSpawnRange.x) + 1;
- location.y = random.nextInt(mSpawnRange.y - 1) + 1;
- }
-
- // Let SnakeGame know where the apple is
- // SnakeGame can share this with the snake
- Point getLocation(){
- return location;
- }
-
- // Draw the apple
- void draw(Canvas canvas, Paint paint){
- canvas.drawBitmap(mBitmapApple,
- location.x * mSize, location.y * mSize, paint);
-
- }
-
-}
-
diff --git a/Chapter16/java/Snake.java b/Chapter16/java/Snake.java
deleted file mode 100644
index 4beabf5..0000000
--- a/Chapter16/java/Snake.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.gamecodeschool.c16snake;
-
-/**
- * Created by johnh on 22/12/2017.
- */
-
-class Snake {
-}
diff --git a/Chapter16/java/SnakeActivity.java b/Chapter16/java/SnakeActivity.java
deleted file mode 100644
index 7fc1134..0000000
--- a/Chapter16/java/SnakeActivity.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.gamecodeschool.c16snake;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class SnakeActivity extends Activity {
-
- // Declare an instance of SnakeGame
- SnakeGame mSnakeGame;
-
- // Set the game up
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the pixel dimensions of the screen
- Display display = getWindowManager().getDefaultDisplay();
-
- // Initialize the result into a Point object
- Point size = new Point();
- display.getSize(size);
-
- // Create a new instance of the SnakeEngine class
- mSnakeGame = new SnakeGame(this, size);
-
- // Make snakeEngine the view of the Activity
- setContentView(mSnakeGame);
- }
-
- // Start the thread in snakeEngine
- @Override
- protected void onResume() {
- super.onResume();
- mSnakeGame.resume();
- }
-
- // Stop the thread in snakeEngine
- @Override
- protected void onPause() {
- super.onPause();
- mSnakeGame.pause();
- }
-}
diff --git a/Chapter16/java/SnakeGame.java b/Chapter16/java/SnakeGame.java
deleted file mode 100644
index 33dc159..0000000
--- a/Chapter16/java/SnakeGame.java
+++ /dev/null
@@ -1,259 +0,0 @@
-package com.gamecodeschool.c16snake;
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import java.io.IOException;
-
-class SnakeGame extends SurfaceView implements Runnable{
-
- // Objects for the game loop/thread
- private Thread mThread = null;
- // Control pausing between updates
- private long mNextFrameTime;
- // Is the game currently playing and or paused?
- private volatile boolean mPlaying = false;
- private volatile boolean mPaused = true;
-
- // for playing sound effects
- private SoundPool mSP;
- private int mEat_ID = -1;
- private int mCrashID = -1;
-
- // The size in segments of the playable area
- private final int NUM_BLOCKS_WIDE = 40;
- private int mNumBlocksHigh;
-
- // How many points does the player have
- private int mScore;
-
- // Objects for drawing
- private Canvas mCanvas;
- private SurfaceHolder mSurfaceHolder;
- private Paint mPaint;
-
- // A snake ssss
- private Snake mSnake;
- // And an apple
- private Apple mApple;
-
-
- // This is the constructor method that gets called
- // from SnakeActivity
- public SnakeGame(Context context, Point size) {
- super(context);
-
- // Work out how many pixels each block is
- int blockSize = size.x / NUM_BLOCKS_WIDE;
- // How many blocks of the same size will fit into the height
- mNumBlocksHigh = size.y / blockSize;
-
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
- try {
- AssetManager assetManager = context.getAssets();
- AssetFileDescriptor descriptor;
-
- // Prepare the sounds in memory
- descriptor = assetManager.openFd("get_apple.ogg");
- mEat_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("snake_death.ogg");
- mCrashID = mSP.load(descriptor, 0);
-
- } catch (IOException e) {
- // Error
- }
-
- // Initialize the drawing objects
- mSurfaceHolder = getHolder();
- mPaint = new Paint();
-
- // Call the constructors of our two game objects
- mApple = new Apple(context,
- new Point(NUM_BLOCKS_WIDE,
- mNumBlocksHigh),
- blockSize);
-
- }
-
-
- // Called to start a new game
- public void newGame() {
-
- // reset the snake
-
-
- // Get the apple ready for dinner
- mApple.spawn();
-
- // Reset the mScore
- mScore = 0;
-
- // Setup mNextFrameTime so an update can triggered
- mNextFrameTime = System.currentTimeMillis();
- }
-
-
- // Handles the game loop
- @Override
- public void run() {
- while (mPlaying) {
- if(!mPaused) {
- // Update 10 times a second
- if (updateRequired()) {
- update();
- }
- }
-
- draw();
- }
- }
-
-
- // Check to see if it is time for an update
- public boolean updateRequired() {
-
- // Run at 10 frames per second
- final long TARGET_FPS = 10;
- // There are 1000 milliseconds in a second
- final long MILLIS_PER_SECOND = 1000;
-
- // Are we due to update the frame
- if(mNextFrameTime <= System.currentTimeMillis()){
- // Tenth of a second has passed
-
- // Setup when the next update will be triggered
- mNextFrameTime =System.currentTimeMillis()
- + MILLIS_PER_SECOND / TARGET_FPS;
-
- // Return true so that the update and draw
- // methods are executed
- return true;
- }
-
- return false;
- }
-
-
- // Update all the game objects
- public void update() {
-
- // Move the snake
-
- // Did the head of the snake eat the apple?
-
- // Did the snake die?
-
- }
-
-
- // Do all the drawing
- public void draw() {
- // Get a lock on the mCanvas
- if (mSurfaceHolder.getSurface().isValid()) {
- mCanvas = mSurfaceHolder.lockCanvas();
-
- // Fill the screen with a color
- mCanvas.drawColor(Color.argb(255, 26, 128, 182));
-
- // Set the size and color of the mPaint for the text
- mPaint.setColor(Color.argb(255, 255, 255, 255));
- mPaint.setTextSize(120);
-
- // Draw the score
- mCanvas.drawText("" + mScore, 20, 120, mPaint);
-
- // Draw the apple and the snake
- mApple.draw(mCanvas, mPaint);
-
- // Draw some text while paused
- if(mPaused){
-
- // Set the size and color of the mPaint for the text
- mPaint.setColor(Color.argb(255, 255, 255, 255));
- mPaint.setTextSize(250);
-
- // Draw the message
- // We will give this an international upgrade soon
- //mCanvas.drawText("Tap To Play!", 200, 700, mPaint);
- mCanvas.drawText(getResources().
- getString(R.string.tap_to_play),
- 200, 700, mPaint);
- }
-
-
- // Unlock the mCanvas and reveal the graphics for this frame
- mSurfaceHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-
-
-
-
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
- case MotionEvent.ACTION_UP:
- if (mPaused) {
- mPaused = false;
- newGame();
-
- // Don't want to process snake direction for this tap
- return true;
- }
-
- // Let the Snake class handle the input
-
- break;
-
- default:
- break;
-
- }
- return true;
- }
-
-
- // Stop the thread
- public void pause() {
- mPlaying = false;
- try {
- mThread.join();
- } catch (InterruptedException e) {
- // Error
- }
- }
-
-
- // Start the thread
- public void resume() {
- mPlaying = true;
- mThread = new Thread(this);
- mThread.start();
- }
-}
\ No newline at end of file
diff --git a/Chapter17/AndroidManifest.xml b/Chapter17/AndroidManifest.xml
index 408d7ef..485270a 100644
--- a/Chapter17/AndroidManifest.xml
+++ b/Chapter17/AndroidManifest.xml
@@ -1,23 +1,29 @@
+ xmlns:tools="http://schemas.android.com/tools">
-
+
+
+ android:exported="true">
-
+
+
diff --git a/Chapter17/assets/gameOver.ogg b/Chapter17/assets/gameOver.ogg
new file mode 100644
index 0000000..5ebd309
Binary files /dev/null and b/Chapter17/assets/gameOver.ogg differ
diff --git a/Chapter17/drawable/badapple.png b/Chapter17/drawable/badapple.png
new file mode 100644
index 0000000..688f879
Binary files /dev/null and b/Chapter17/drawable/badapple.png differ
diff --git a/Chapter17/java/Apple.java b/Chapter17/java/Apple.java
index 199f303..b1fb929 100644
--- a/Chapter17/java/Apple.java
+++ b/Chapter17/java/Apple.java
@@ -3,61 +3,57 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Paint;
import android.graphics.Point;
import java.util.Random;
-class Apple {
+public class Apple extends GameObject{
- // The location of the apple on the grid
- // Not in pixels
private Point location = new Point();
-
- // The range of values we can choose from
- // to spawn an apple
- private Point mSpawnRange;
- private int mSize;
-
- // An image to represent the apple
private Bitmap mBitmapApple;
- /// Set up the apple in the constructor
- Apple(Context context, Point sr, int s){
-
- // Make a note of the passed in spawn range
- mSpawnRange = sr;
- // Make a note of the size of an apple
- mSize = s;
- // Hide the apple off-screen until the game starts
- location.x = -10;
-
- // Load the image to the bitmap
- mBitmapApple = BitmapFactory.decodeResource(context.getResources(), R.drawable.apple);
-
- // Resize the bitmap
- mBitmapApple = Bitmap.createScaledBitmap(mBitmapApple, s, s, false);
+ // Private constructor to enforce the use of the builder
+ private Apple(Point spawnRange, int size, Bitmap bitmapApple) {
+ super(spawnRange, size, bitmapApple);
+ location.x = -10; // Hide the apple off-screen until the game starts
+ mbitmapobject = bitmapApple;
+ mbitmapobject = Bitmap.createScaledBitmap(mbitmapobject, size, size, false);
}
// This is called every time an apple is eaten
- void spawn(){
- // Choose two random values and place the apple
+ void spawn(Point spawnRange) {
Random random = new Random();
- location.x = random.nextInt(mSpawnRange.x) + 1;
- location.y = random.nextInt(mSpawnRange.y - 1) + 1;
+ location.x = random.nextInt(spawnRange.x) + 1;
+ location.y = random.nextInt(spawnRange.y - 1) + 1;
}
// Let SnakeGame know where the apple is
// SnakeGame can share this with the snake
- Point getLocation(){
+ Point getLocation() {
return location;
}
-
- // Draw the apple
- void draw(Canvas canvas, Paint paint){
- canvas.drawBitmap(mBitmapApple,
- location.x * mSize, location.y * mSize, paint);
-
+ // Builder class for Apple
+ public static class AppleBuilder {
+ private Point mSpawnRange;
+ private int mSize;
+ private Bitmap mBitmapApple;
+
+ public AppleBuilder setSpawnRange(Point spawnRange) {
+ mSpawnRange = spawnRange;
+ return this;
+ }
+
+ public AppleBuilder setSize(int size) {
+ mSize = size;
+ return this;
+ }
+
+ public AppleBuilder setBitmap(Context context, int resourceId) {
+ mBitmapApple = BitmapFactory.decodeResource(context.getResources(), resourceId);
+ return this;
+ }
+
+ public Apple build() {
+ return new Apple(mSpawnRange, mSize, mBitmapApple);
+ }
}
-
}
\ No newline at end of file
diff --git a/Chapter17/java/AppleBuilder.java b/Chapter17/java/AppleBuilder.java
new file mode 100644
index 0000000..02aab73
--- /dev/null
+++ b/Chapter17/java/AppleBuilder.java
@@ -0,0 +1,17 @@
+package com.gamecodeschool.c17snake;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Point;
+
+public interface AppleBuilder {
+ Point getLocation();
+ public void spawn(Point spawnRange, boolean hide);
+ public void setSize(int size);
+// public void draw(Canvas canvas, Paint paint);
+ public void setBitmap(Context context, int resourceId);
+// public void build();
+};
+
diff --git a/Chapter17/java/Audio.java b/Chapter17/java/Audio.java
new file mode 100644
index 0000000..02a4e32
--- /dev/null
+++ b/Chapter17/java/Audio.java
@@ -0,0 +1,8 @@
+package com.gamecodeschoolc17.c17snake;
+
+// added the audio class for strategy implementation
+public interface Audio {
+ void playEatSound();
+
+ void playCrashSound();
+}
diff --git a/Chapter17/java/BadAppleBuilder.java b/Chapter17/java/BadAppleBuilder.java
new file mode 100644
index 0000000..22a25ea
--- /dev/null
+++ b/Chapter17/java/BadAppleBuilder.java
@@ -0,0 +1,67 @@
+package com.gamecodeschool.c17snake;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Point;
+
+import java.util.Random;
+
+public class BadAppleBuilder implements AppleBuilder {
+ private NewApple Apple;
+
+ // constructor for BadAppleBuilder
+ public BadAppleBuilder(Bitmap mBitmapApple, Point location, Point mSpawnRange, int mSize){
+ this.Apple = new NewApple();
+ this.Apple.location = location;
+ this.Apple.mBitmapApple = mBitmapApple;
+ this.Apple.mSpawnRange = mSpawnRange;
+ this.Apple.mSize = mSize;
+ };
+
+ @Override
+ public Point getLocation() {
+ return this.Apple.location;
+ }
+
+// @Override
+// public void draw(Canvas canvas, Paint paint) {
+// canvas.drawBitmap(this.Apple.mBitmapApple,
+// this.Apple.location.x * this.Apple.mBitmapApple.getWidth(),
+// this.Apple.location.y * this.Apple.mBitmapApple.getHeight(), paint);
+// }
+
+ @Override
+ public void spawn(Point spawnRange, boolean hide) {
+ if (hide == true) {
+ this.Apple.location.x = -10; // Hide the apple off-screen until the game starts
+ } else {
+ this.Apple.mSpawnRange = spawnRange;
+ Random random = new Random();
+ this.Apple.location.x = random.nextInt(this.Apple.mSpawnRange.x) + 1;
+ this.Apple.location.y = random.nextInt(this.Apple.mSpawnRange.y - 1) + 1;
+ }
+ }
+
+ @Override
+ public void setSize(int size) {
+ this.Apple.mSize = size;
+ }
+
+ @Override
+ public void setBitmap(Context context, int resourceId) {
+ this.Apple.mBitmapApple = BitmapFactory.decodeResource(context.getResources(), resourceId);
+ }
+
+ public NewApple returnApple() {
+ return this.Apple;
+ }
+
+// @Override
+// public NewApple build() {
+// return Apple(Apple.mSpawnRange, Apple.mSize, Apple.mBitmapApple);
+// }
+
+}
\ No newline at end of file
diff --git a/Chapter17/java/DefaultAudio.java b/Chapter17/java/DefaultAudio.java
new file mode 100644
index 0000000..2d44cfb
--- /dev/null
+++ b/Chapter17/java/DefaultAudio.java
@@ -0,0 +1,25 @@
+package com.gamecodeschoolc17.c17snake;
+import android.media.SoundPool;
+
+// added the default audio class for strategy implementation
+public class DefaultAudio implements Audio {
+ private SoundPool soundPool;
+ private int eatSoundId;
+ private int crashSoundId;
+
+ public DefaultAudio(SoundPool soundPool, int eatSoundId, int crashSoundId) {
+ this.soundPool = soundPool;
+ this.eatSoundId = eatSoundId;
+ this.crashSoundId = crashSoundId;
+ }
+
+ @Override
+ public void playEatSound() {
+ soundPool.play(eatSoundId, 1, 1, 0, 0, 1);
+ }
+
+ @Override
+ public void playCrashSound() {
+ soundPool.play(crashSoundId, 1, 1, 0, 0, 1);
+ }
+}
diff --git a/Chapter17/java/GameObject.java b/Chapter17/java/GameObject.java
new file mode 100644
index 0000000..7cc38b2
--- /dev/null
+++ b/Chapter17/java/GameObject.java
@@ -0,0 +1,47 @@
+package com.gamecodeschool.c17snake;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Point;
+
+public abstract class GameObject {
+
+
+ // The location of the object on the grid
+ // Not in pixels
+ protected Point location = new Point();
+
+ // The range of values we can choose from
+ // to spawn an object
+ protected Point mSpawnRange;
+ protected int mSize;
+ // How big is the entire grid
+ protected Point mRange;
+
+ // An image to represent the object
+ protected Bitmap mbitmapobject;
+ GameObject(Point spawnRange, int size, Bitmap bitmapApple){
+
+ // Make a note of the passed in spawn range
+ mRange = spawnRange;
+ // Make a note of the size of an object
+ mSize = size;
+ // Hide the object off-screen until the game starts
+ location.x = -10;
+
+ }
+
+ void draw(Canvas canvas, Paint paint){
+ canvas.drawBitmap(mbitmapobject,
+ location.x * mSize, location.y * mSize, paint);
+
+ }
+ //let game know where the location of the object is
+ Point getLocation(){
+ return location;
+ }
+
+}
\ No newline at end of file
diff --git a/Chapter17/java/GoodAppleBuilder.java b/Chapter17/java/GoodAppleBuilder.java
new file mode 100644
index 0000000..a7ae723
--- /dev/null
+++ b/Chapter17/java/GoodAppleBuilder.java
@@ -0,0 +1,67 @@
+package com.gamecodeschool.c17snake;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Point;
+
+import java.util.Random;
+
+public class GoodAppleBuilder implements AppleBuilder {
+ private NewApple Apple;
+
+ // constructor GoodAppleBuilder
+ public GoodAppleBuilder(Bitmap mBitmapApple, Point location, Point mSpawnRange, int mSize){
+ this.Apple = new NewApple();
+ this.Apple.location = location;
+ this.Apple.mBitmapApple = mBitmapApple;
+ this.Apple.mSpawnRange = mSpawnRange;
+ this.Apple.mSize = mSize;
+ };
+
+ @Override
+ public Point getLocation() {
+ return this.Apple.location;
+ }
+
+// @Override
+// public void draw(Canvas canvas, Paint paint) {
+// canvas.drawBitmap(this.Apple.mBitmapApple,
+// this.Apple.location.x * this.Apple.mBitmapApple.getWidth(),
+// this.Apple.location.y * this.Apple.mBitmapApple.getHeight(), paint);
+// }
+
+ @Override
+ public void spawn(Point spawnRange, boolean hide) {
+ if (hide == true) {
+ this.Apple.location.x = -10; // Hide the apple off-screen until the game starts
+ } else {
+ this.Apple.mSpawnRange = spawnRange;
+ Random random = new Random();
+ this.Apple.location.x = random.nextInt(this.Apple.mSpawnRange.x) + 1;
+ this.Apple.location.y = random.nextInt(this.Apple.mSpawnRange.y - 1) + 1;
+ }
+ }
+
+ @Override
+ public void setSize(int size) {
+ this.Apple.mSize = size;
+ }
+
+ @Override
+ public void setBitmap(Context context, int resourceId) {
+ this.Apple.mBitmapApple = BitmapFactory.decodeResource(context.getResources(), resourceId);
+ }
+
+ public NewApple returnApple() {
+ return this.Apple;
+ }
+
+// @Override
+// public NewApple build() {
+// return Apple(Apple.mSpawnRange, Apple.mSize, Apple.mBitmapApple);
+// }
+
+}
\ No newline at end of file
diff --git a/Chapter17/java/NewApple.java b/Chapter17/java/NewApple.java
new file mode 100644
index 0000000..a9a944a
--- /dev/null
+++ b/Chapter17/java/NewApple.java
@@ -0,0 +1,19 @@
+package com.gamecodeschool.c17snake;
+
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Point;
+
+public class NewApple {
+ public Bitmap mBitmapApple;
+ public Point location;
+ public Point mSpawnRange;
+ public int mSize;
+
+ public void draw(Canvas canvas, Paint paint) {
+ canvas.drawBitmap(this.mBitmapApple,
+ this.location.x * this.mBitmapApple.getWidth(),
+ this.location.y * this.mBitmapApple.getHeight(), paint);
+ };
+}
diff --git a/Chapter17/java/Obstacle.java b/Chapter17/java/Obstacle.java
new file mode 100644
index 0000000..037b70c
--- /dev/null
+++ b/Chapter17/java/Obstacle.java
@@ -0,0 +1,51 @@
+package com.gamecodeschool.c17snake;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Point;
+
+import java.util.Random;
+
+public class Obstacle {
+
+ private Point location = new Point();
+ private Bitmap mBitmapObstacle;
+ private Point mSpawnRange;
+ private int mSize;
+
+ Obstacle(Context context, Point sr, int s) {
+ // spawn range
+ mSpawnRange = sr;
+ // size of an obstacle
+ mSize = s;
+
+ mBitmapObstacle = BitmapFactory.decodeResource(context.getResources(), R.drawable.obstacle);
+ mBitmapObstacle = Bitmap.createScaledBitmap(mBitmapObstacle, s, s, false);
+
+ // initial spawn range
+ Random random = new Random();
+ location.x = random.nextInt(mSpawnRange.x);
+ location.y = random.nextInt(mSpawnRange.y);
+
+ }
+
+ void spawn() {
+ Random random = new Random();
+ location.x = random.nextInt(mSpawnRange.x) + 1;
+ location.y = random.nextInt(mSpawnRange.y - 1) + 1;
+ }
+
+ Point getLocation() {
+ return location;
+ }
+
+ // draw the obstacle
+ void draw(Canvas canvas, Paint paint) {
+ canvas.drawBitmap(mBitmapObstacle,
+ location.x * mSize, location.y * mSize, paint);
+ }
+
+}
diff --git a/Chapter17/java/Snake.java b/Chapter17/java/Snake.java
index 5c1184c..6372783 100644
--- a/Chapter17/java/Snake.java
+++ b/Chapter17/java/Snake.java
@@ -1,299 +1,324 @@
-package com.gamecodeschool.c17snake;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-class Snake {
-
- // The location in the grid of all the segments
- private ArrayList segmentLocations;
-
- // How big is each segment of the snake?
- private int mSegmentSize;
-
- // How big is the entire grid
- private Point mMoveRange;
-
- // Where is the centre of the screen
- // horizontally in pixels?
- private int halfWayPoint;
-
- // For tracking movement Heading
- private enum Heading {
- UP, RIGHT, DOWN, LEFT
- }
-
- // Start by heading to the right
- private Heading heading = Heading.RIGHT;
-
- // A bitmap for each direction the head can face
- private Bitmap mBitmapHeadRight;
- private Bitmap mBitmapHeadLeft;
- private Bitmap mBitmapHeadUp;
- private Bitmap mBitmapHeadDown;
-
- // A bitmap for the body
- private Bitmap mBitmapBody;
-
-
- Snake(Context context, Point mr, int ss) {
-
- // Initialize our ArrayList
- segmentLocations = new ArrayList<>();
-
- // Initialize the segment size and movement
- // range from the passed in parameters
- mSegmentSize = ss;
- mMoveRange = mr;
-
- // Create and scale the bitmaps
- mBitmapHeadRight = BitmapFactory
- .decodeResource(context.getResources(),
- R.drawable.head);
-
- // Create 3 more versions of the head for different headings
- mBitmapHeadLeft = BitmapFactory
- .decodeResource(context.getResources(),
- R.drawable.head);
-
- mBitmapHeadUp = BitmapFactory
- .decodeResource(context.getResources(),
- R.drawable.head);
-
- mBitmapHeadDown = BitmapFactory
- .decodeResource(context.getResources(),
- R.drawable.head);
-
- // Modify the bitmaps to face the snake head
- // in the correct direction
- mBitmapHeadRight = Bitmap
- .createScaledBitmap(mBitmapHeadRight,
- ss, ss, false);
-
- // A matrix for scaling
- Matrix matrix = new Matrix();
- matrix.preScale(-1, 1);
-
- mBitmapHeadLeft = Bitmap
- .createBitmap(mBitmapHeadRight,
- 0, 0, ss, ss, matrix, true);
-
- // A matrix for rotating
- matrix.preRotate(-90);
- mBitmapHeadUp = Bitmap
- .createBitmap(mBitmapHeadRight,
- 0, 0, ss, ss, matrix, true);
-
- // Matrix operations are cumulative
- // so rotate by 180 to face down
- matrix.preRotate(180);
- mBitmapHeadDown = Bitmap
- .createBitmap(mBitmapHeadRight,
- 0, 0, ss, ss, matrix, true);
-
- // Create and scale the body
- mBitmapBody = BitmapFactory
- .decodeResource(context.getResources(),
- R.drawable.body);
-
- mBitmapBody = Bitmap
- .createScaledBitmap(mBitmapBody,
- ss, ss, false);
-
- // The halfway point across the screen in pixels
- // Used to detect which side of screen was pressed
- halfWayPoint = mr.x * ss / 2;
- }
-
- // Get the snake ready for a new game
- void reset(int w, int h) {
-
- // Reset the heading
- heading = Heading.RIGHT;
-
- // Delete the old contents of the ArrayList
- segmentLocations.clear();
-
- // Start with a single snake segment
- segmentLocations.add(new Point(w / 2, h / 2));
- }
-
-
- void move() {
- // Move the body
- // Start at the back and move it
- // to the position of the segment in front of it
- for (int i = segmentLocations.size() - 1; i > 0; i--) {
-
- // Make it the same value as the next segment
- // going forwards towards the head
- segmentLocations.get(i).x = segmentLocations.get(i - 1).x;
- segmentLocations.get(i).y = segmentLocations.get(i - 1).y;
- }
-
- // Move the head in the appropriate heading
- // Get the existing head position
- Point p = segmentLocations.get(0);
-
- // Move it appropriately
- switch (heading) {
- case UP:
- p.y--;
- break;
-
- case RIGHT:
- p.x++;
- break;
-
- case DOWN:
- p.y++;
- break;
-
- case LEFT:
- p.x--;
- break;
- }
-
- }
-
- boolean detectDeath() {
- // Has the snake died?
- boolean dead = false;
-
- // Hit any of the screen edges
- if (segmentLocations.get(0).x == -1 ||
- segmentLocations.get(0).x > mMoveRange.x ||
- segmentLocations.get(0).y == -1 ||
- segmentLocations.get(0).y > mMoveRange.y) {
-
- dead = true;
- }
-
- // Eaten itself?
- for (int i = segmentLocations.size() - 1; i > 0; i--) {
- // Have any of the sections collided with the head
- if (segmentLocations.get(0).x == segmentLocations.get(i).x &&
- segmentLocations.get(0).y == segmentLocations.get(i).y) {
-
- dead = true;
- }
- }
- return dead;
- }
-
- boolean checkDinner(Point l) {
- //if (snakeXs[0] == l.x && snakeYs[0] == l.y) {
- if (segmentLocations.get(0).x == l.x &&
- segmentLocations.get(0).y == l.y) {
-
- // Add a new Point to the list
- // located off-screen.
- // This is OK because on the next call to
- // move it will take the position of
- // the segment in front of it
- segmentLocations.add(new Point(-10, -10));
- return true;
- }
- return false;
- }
-
- void draw(Canvas canvas, Paint paint) {
-
- // Don't run this code if ArrayList has nothing in it
- if (!segmentLocations.isEmpty()) {
- // All the code from this method goes here
- // Draw the head
- switch (heading) {
- case RIGHT:
- canvas.drawBitmap(mBitmapHeadRight,
- segmentLocations.get(0).x
- * mSegmentSize,
- segmentLocations.get(0).y
- * mSegmentSize, paint);
- break;
-
- case LEFT:
- canvas.drawBitmap(mBitmapHeadLeft,
- segmentLocations.get(0).x
- * mSegmentSize,
- segmentLocations.get(0).y
- * mSegmentSize, paint);
- break;
-
- case UP:
- canvas.drawBitmap(mBitmapHeadUp,
- segmentLocations.get(0).x
- * mSegmentSize,
- segmentLocations.get(0).y
- * mSegmentSize, paint);
- break;
-
- case DOWN:
- canvas.drawBitmap(mBitmapHeadDown,
- segmentLocations.get(0).x
- * mSegmentSize,
- segmentLocations.get(0).y
- * mSegmentSize, paint);
- break;
- }
-
- // Draw the snake body one block at a time
- for (int i = 1; i < segmentLocations.size(); i++) {
- canvas.drawBitmap(mBitmapBody,
- segmentLocations.get(i).x
- * mSegmentSize,
- segmentLocations.get(i).y
- * mSegmentSize, paint);
- }
- }
- }
-
-
- // Handle changing direction
- void switchHeading(MotionEvent motionEvent) {
-
- // Is the tap on the right hand side?
- if (motionEvent.getX() >= halfWayPoint) {
- switch (heading) {
- // Rotate right
- case UP:
- heading = Heading.RIGHT;
- break;
- case RIGHT:
- heading = Heading.DOWN;
- break;
- case DOWN:
- heading = Heading.LEFT;
- break;
- case LEFT:
- heading = Heading.UP;
- break;
-
- }
- } else {
- // Rotate left
- switch (heading) {
- case UP:
- heading = Heading.LEFT;
- break;
- case LEFT:
- heading = Heading.DOWN;
- break;
- case DOWN:
- heading = Heading.RIGHT;
- break;
- case RIGHT:
- heading = Heading.UP;
- break;
- }
- }
- }
-}
+package com.gamecodeschool.c17snake;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.Point;
+import android.view.MotionEvent;
+import android.os.Handler;
+import android.os.Looper;
+
+import java.util.ArrayList;
+
+class Snake {
+
+ // The location in the grid of all the segments
+ private ArrayList segmentLocations;
+
+ // How big is each segment of the snake?
+ private int mSegmentSize;
+
+ // How big is the entire grid
+ private Point mMoveRange;
+
+ // Where is the centre of the screen
+ // horizontally in pixels?
+ private int halfWayPoint;
+
+ // For tracking movement Heading
+ private enum Heading {
+ UP, RIGHT, DOWN, LEFT
+ }
+
+ // Start by heading to the right
+ private Heading heading = Heading.RIGHT;
+
+ // A bitmap for each direction the head can face
+ private Bitmap mBitmapHeadRight;
+ private Bitmap mBitmapHeadLeft;
+ private Bitmap mBitmapHeadUp;
+ private Bitmap mBitmapHeadDown;
+
+ // A bitmap for the body
+ private Bitmap mBitmapBody;
+
+ // The snake's speed
+ private int speed;
+
+ Snake(Context context, Point mr, int ss) {
+
+ // Initialize our ArrayList
+ segmentLocations = new ArrayList<>();
+
+ // Set the initial speed
+ speed = 1;
+
+ // Initialize the segment size and movement
+ // range from the passed in parameters
+ mSegmentSize = ss;
+ mMoveRange = mr;
+
+ // Create and scale the bitmaps
+ mBitmapHeadRight = createVersion(context, "head");
+
+ // Create 3 more versions of the head for different headings
+ //Separated the creating of different versions to improve readability and redundancy
+ mBitmapHeadLeft = createVersion(context, "head");
+
+ mBitmapHeadUp = createVersion(context, "head");
+
+ mBitmapHeadDown = createVersion(context, "head");
+
+ // Modify the bitmaps to face the snake head
+ // in the correct direction
+ mBitmapHeadRight = Bitmap
+ .createScaledBitmap(mBitmapHeadRight,
+ ss, ss, false);
+
+ // A matrix for scaling
+ Matrix matrix = new Matrix();
+ matrix.preScale(-1, 1);
+
+ mBitmapHeadLeft = modifySnakeHead(ss, matrix);
+
+ // A matrix for rotating
+ matrix.preRotate(-90);
+ mBitmapHeadUp = modifySnakeHead(ss, matrix);
+
+ // Matrix operations are cumulative
+ // so rotate by 180 to face down
+ matrix.preRotate(180);
+ mBitmapHeadDown = modifySnakeHead(ss, matrix);
+
+ // Create and scale the body
+ mBitmapBody = createVersion(context, "body");
+
+ mBitmapBody = Bitmap
+ .createScaledBitmap(mBitmapBody,
+ ss, ss, false);
+
+ // The halfway point across the screen in pixels
+ // Used to detect which side of screen was pressed
+ halfWayPoint = mr.x * ss / 2;
+ }
+ private Bitmap createVersion(Context context, String drawing){
+ switch(drawing){
+ case "head":
+ return BitmapFactory.decodeResource(context.getResources(), R.drawable.head);
+ }
+ return BitmapFactory.decodeResource(context.getResources(), R.drawable.body);
+ }
+ private Bitmap modifySnakeHead(int ss, Matrix matrix){
+ return Bitmap.createBitmap(mBitmapHeadRight,
+ 0, 0, ss, ss, matrix, true);
+ }
+
+ public int getSegmentSize(){
+ return mSegmentSize;
+ }
+
+ // Get the snake ready for a new game
+ void reset(int w, int h) {
+
+ // Reset the heading
+ heading = Heading.RIGHT;
+
+ // Delete the old contents of the ArrayList
+ segmentLocations.clear();
+
+ // Start with a single snake segment
+ segmentLocations.add(new Point(w / 2, h / 2));
+ }
+
+
+ void move() {
+ // Move the body
+ // Start at the back and move it
+ // to the position of the segment in front of it
+ for (int i = segmentLocations.size() - 1; i > 0; i--) {
+
+ // Make it the same value as the next segment
+ // going forwards towards the head
+ segmentLocations.get(i).x = segmentLocations.get(i - 1).x;
+ segmentLocations.get(i).y = segmentLocations.get(i - 1).y;
+ }
+
+ // Move the head in the appropriate heading
+ // Get the existing head position
+ Point p = segmentLocations.get(0);
+
+ // Move it appropriately
+ switch (heading) {
+ case UP:
+ p.y -= speed;
+ break;
+
+ case RIGHT:
+ p.x += speed;
+ break;
+
+ case DOWN:
+ p.y += speed;
+ break;
+
+ case LEFT:
+ p.x -= speed;
+ break;
+ }
+
+ }
+
+ // Consume star >> get boosted
+ private boolean isSpeedBoostActive = false;
+ void applySpeedBoost() {
+ // Increase the speed for a brief period
+ speed = 2;
+ isSpeedBoostActive = true;
+
+ // Using new imports to schedule a task to run after half a second of in-game time
+ new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ // Task to reset the snake's speed
+ speed = 1;
+ isSpeedBoostActive = false;
+ }
+ }, 500); // 500 = half a second
+ }
+
+ boolean detectDeath() {
+ // Has the snake died?
+ boolean dead = false;
+
+ // Hit any of the screen edges
+ if (segmentLocations.get(0).x == -1 ||
+ segmentLocations.get(0).x > mMoveRange.x ||
+ segmentLocations.get(0).y == -1 ||
+ segmentLocations.get(0).y > mMoveRange.y) {
+
+ dead = true;
+ }
+
+ // Eaten itself?
+ for (int i = segmentLocations.size() - 1; i > 0; i--) {
+ // Have any of the sections collided with the head
+ if (segmentLocations.get(0).x == segmentLocations.get(i).x &&
+ segmentLocations.get(0).y == segmentLocations.get(i).y) {
+
+ dead = true;
+ }
+ }
+ return dead;
+ }
+
+ boolean checkDinner(Point l) {
+ //if (snakeXs[0] == l.x && snakeYs[0] == l.y) {
+ if (segmentLocations.get(0).x == l.x &&
+ segmentLocations.get(0).y == l.y) {
+
+ // Add a new Point to the list
+ // located off-screen.
+ // This is OK because on the next call to
+ // move it will take the position of
+ // the segment in front of it
+ segmentLocations.add(new Point(-10, -10));
+ return true;
+ }
+ return false;
+ }
+
+ void draw(Canvas canvas, Paint paint) {
+
+ // Don't run this code if ArrayList has nothing in it
+ if (!segmentLocations.isEmpty()) {
+ // All the code from this method goes here
+ // Draw the head
+ switch (heading) {
+ case RIGHT:
+ canvas.drawBitmap(mBitmapHeadRight,
+ segmentLocations.get(0).x
+ * mSegmentSize,
+ segmentLocations.get(0).y
+ * mSegmentSize, paint);
+ break;
+
+ case LEFT:
+ canvas.drawBitmap(mBitmapHeadLeft,
+ segmentLocations.get(0).x
+ * mSegmentSize,
+ segmentLocations.get(0).y
+ * mSegmentSize, paint);
+ break;
+
+ case UP:
+ canvas.drawBitmap(mBitmapHeadUp,
+ segmentLocations.get(0).x
+ * mSegmentSize,
+ segmentLocations.get(0).y
+ * mSegmentSize, paint);
+ break;
+
+ case DOWN:
+ canvas.drawBitmap(mBitmapHeadDown,
+ segmentLocations.get(0).x
+ * mSegmentSize,
+ segmentLocations.get(0).y
+ * mSegmentSize, paint);
+ break;
+ }
+
+ // Draw the snake body one block at a time
+ for (int i = 1; i < segmentLocations.size(); i++) {
+ canvas.drawBitmap(mBitmapBody,
+ segmentLocations.get(i).x
+ * mSegmentSize,
+ segmentLocations.get(i).y
+ * mSegmentSize, paint);
+ }
+ }
+ }
+
+
+ // Handle changing direction
+ void switchHeading(MotionEvent motionEvent) {
+
+ // Is the tap on the right hand side?
+ if (motionEvent.getX() >= halfWayPoint) {
+ switch (heading) {
+ // Rotate right
+ case UP:
+ heading = Heading.RIGHT;
+ break;
+ case RIGHT:
+ heading = Heading.DOWN;
+ break;
+ case DOWN:
+ heading = Heading.LEFT;
+ break;
+ case LEFT:
+ heading = Heading.UP;
+ break;
+
+ }
+ } else {
+ // Rotate left
+ switch (heading) {
+ case UP:
+ heading = Heading.LEFT;
+ break;
+ case LEFT:
+ heading = Heading.DOWN;
+ break;
+ case DOWN:
+ heading = Heading.RIGHT;
+ break;
+ case RIGHT:
+ heading = Heading.UP;
+ break;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Chapter17/java/SnakeActivity.java b/Chapter17/java/SnakeActivity.java
index 6d4dc42..0452df3 100644
--- a/Chapter17/java/SnakeActivity.java
+++ b/Chapter17/java/SnakeActivity.java
@@ -23,7 +23,7 @@ protected void onCreate(Bundle savedInstanceState) {
display.getSize(size);
// Create a new instance of the SnakeEngine class
- mSnakeGame = new SnakeGame(this, size);
+ mSnakeGame = new SnakeGame(this, size, null);
// Make snakeEngine the view of the Activity
setContentView(mSnakeGame);
diff --git a/Chapter17/java/SnakeGame.java b/Chapter17/java/SnakeGame.java
index 97338a3..b51bfdf 100644
--- a/Chapter17/java/SnakeGame.java
+++ b/Chapter17/java/SnakeGame.java
@@ -1,279 +1,434 @@
-package com.gamecodeschool.c17snake;
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-import android.view.MotionEvent;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import java.io.IOException;
-
-class SnakeGame extends SurfaceView implements Runnable{
-
- // Objects for the game loop/thread
- private Thread mThread = null;
- // Control pausing between updates
- private long mNextFrameTime;
- // Is the game currently playing and or paused?
- private volatile boolean mPlaying = false;
- private volatile boolean mPaused = true;
-
- // for playing sound effects
- private SoundPool mSP;
- private int mEat_ID = -1;
- private int mCrashID = -1;
-
- // The size in segments of the playable area
- private final int NUM_BLOCKS_WIDE = 40;
- private int mNumBlocksHigh;
-
- // How many points does the player have
- private int mScore;
-
- // Objects for drawing
- private Canvas mCanvas;
- private SurfaceHolder mSurfaceHolder;
- private Paint mPaint;
-
- // A snake ssss
- private Snake mSnake;
- // And an apple
- private Apple mApple;
-
-
- // This is the constructor method that gets called
- // from SnakeActivity
- public SnakeGame(Context context, Point size) {
- super(context);
-
- // Work out how many pixels each block is
- int blockSize = size.x / NUM_BLOCKS_WIDE;
- // How many blocks of the same size will fit into the height
- mNumBlocksHigh = size.y / blockSize;
-
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
- try {
- AssetManager assetManager = context.getAssets();
- AssetFileDescriptor descriptor;
-
- // Prepare the sounds in memory
- descriptor = assetManager.openFd("get_apple.ogg");
- mEat_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("snake_death.ogg");
- mCrashID = mSP.load(descriptor, 0);
-
- } catch (IOException e) {
- // Error
- }
-
- // Initialize the drawing objects
- mSurfaceHolder = getHolder();
- mPaint = new Paint();
-
- // Call the constructors of our two game objects
- mApple = new Apple(context,
- new Point(NUM_BLOCKS_WIDE,
- mNumBlocksHigh),
- blockSize);
-
- mSnake = new Snake(context,
- new Point(NUM_BLOCKS_WIDE,
- mNumBlocksHigh),
- blockSize);
-
- }
-
-
- // Called to start a new game
- public void newGame() {
-
- // reset the snake
- mSnake.reset(NUM_BLOCKS_WIDE, mNumBlocksHigh);
-
- // Get the apple ready for dinner
- mApple.spawn();
-
- // Reset the mScore
- mScore = 0;
-
- // Setup mNextFrameTime so an update can triggered
- mNextFrameTime = System.currentTimeMillis();
- }
-
-
- // Handles the game loop
- @Override
- public void run() {
- while (mPlaying) {
- if(!mPaused) {
- // Update 10 times a second
- if (updateRequired()) {
- update();
- }
- }
-
- draw();
- }
- }
-
-
- // Check to see if it is time for an update
- public boolean updateRequired() {
-
- // Run at 10 frames per second
- final long TARGET_FPS = 10;
- // There are 1000 milliseconds in a second
- final long MILLIS_PER_SECOND = 1000;
-
- // Are we due to update the frame
- if(mNextFrameTime <= System.currentTimeMillis()){
- // Tenth of a second has passed
-
- // Setup when the next update will be triggered
- mNextFrameTime =System.currentTimeMillis()
- + MILLIS_PER_SECOND / TARGET_FPS;
-
- // Return true so that the update and draw
- // methods are executed
- return true;
- }
-
- return false;
- }
-
-
- // Update all the game objects
- public void update() {
-
- // Move the snake
- mSnake.move();
-
- // Did the head of the snake eat the apple?
- if(mSnake.checkDinner(mApple.getLocation())){
- // This reminds me of Edge of Tomorrow.
- // One day the apple will be ready!
- mApple.spawn();
-
- // Add to mScore
- mScore = mScore + 1;
-
- // Play a sound
- mSP.play(mEat_ID, 1, 1, 0, 0, 1);
- }
-
- // Did the snake die?
- if (mSnake.detectDeath()) {
- // Pause the game ready to start again
- mSP.play(mCrashID, 1, 1, 0, 0, 1);
-
- mPaused =true;
- }
-
- }
-
-
- // Do all the drawing
- public void draw() {
- // Get a lock on the mCanvas
- if (mSurfaceHolder.getSurface().isValid()) {
- mCanvas = mSurfaceHolder.lockCanvas();
-
- // Fill the screen with a color
- mCanvas.drawColor(Color.argb(255, 26, 128, 182));
-
- // Set the size and color of the mPaint for the text
- mPaint.setColor(Color.argb(255, 255, 255, 255));
- mPaint.setTextSize(120);
-
- // Draw the score
- mCanvas.drawText("" + mScore, 20, 120, mPaint);
-
- // Draw the apple and the snake
- mApple.draw(mCanvas, mPaint);
- mSnake.draw(mCanvas, mPaint);
-
- // Draw some text while paused
- if(mPaused){
-
- // Set the size and color of the mPaint for the text
- mPaint.setColor(Color.argb(255, 255, 255, 255));
- mPaint.setTextSize(250);
-
- // Draw the message
- // We will give this an international upgrade soon
- //mCanvas.drawText("Tap To Play!", 200, 700, mPaint);
- mCanvas.drawText(getResources().
- getString(R.string.tap_to_play),
- 200, 700, mPaint);
- }
-
-
- // Unlock the mCanvas and reveal the graphics for this frame
- mSurfaceHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
- case MotionEvent.ACTION_UP:
- if (mPaused) {
- mPaused = false;
- newGame();
-
- // Don't want to process snake direction for this tap
- return true;
- }
-
- // Let the Snake class handle the input
- mSnake.switchHeading(motionEvent);
- break;
-
- default:
- break;
-
- }
- return true;
- }
-
-
- // Stop the thread
- public void pause() {
- mPlaying = false;
- try {
- mThread.join();
- } catch (InterruptedException e) {
- // Error
- }
- }
-
-
- // Start the thread
- public void resume() {
- mPlaying = true;
- mThread = new Thread(this);
- mThread.start();
- }
-}
+package com.gamecodeschool.cscfinalproject;
+
+import android.content.Context;
+import android.content.res.AssetFileDescriptor;
+import android.content.res.AssetManager;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Point;
+import android.media.SoundPool;
+import android.media.MediaPlayer;
+import android.view.MotionEvent;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.InputMismatchException;
+import java.util.Random;
+import java.util.Scanner;
+
+
+class SnakeGame extends SurfaceView implements Runnable{
+
+ // Objects for the game loop/thread
+ private Thread mThread = null;
+ // Control pausing between updates
+ private long mNextFrameTime;
+ // Is the game currently playing and or paused?
+ private volatile boolean mPlaying = false;
+ private volatile boolean mPaused = true;
+
+ // for playing sound effects
+ private SoundPool mSP;
+ private int mEat_ID = -1;
+ private int mCrashID = -1;
+ private int mGameOverID = -1;
+
+ //for playing background music
+ private MediaPlayer mediaBackground;
+
+ // The size in segments of the playable area
+ private final int NUM_BLOCKS_WIDE = 40;
+ private int mNumBlocksHigh;
+
+ // How many points does the player have
+ private int mScore;
+ private int mHighScore;
+ private int blockSize;
+
+ Random random = new Random();
+
+ // Objects for drawing
+ private Canvas mCanvas;
+ private SurfaceHolder mSurfaceHolder;
+ private Paint mPaint;
+
+ // A snake ssss
+ private Snake mSnake;
+ // And an apple
+ // Two Apple types
+ private NewApple mGoodApple;
+ private NewApple mBadApple;
+
+ // adding in a star power-up!
+ private Star mStar;
+
+ // adding in obstacles
+ private Obstacle mObstacle;
+
+ // Apple Builders
+ private GoodAppleBuilder mGoodAppleBuilder;
+ private BadAppleBuilder mBadAppleBuilder;
+
+ // Good/Bad Apple bitmaps
+ private Bitmap mBitmapGoodApple;
+ private Bitmap mBitmapBadApple;
+
+ // adding reference to audio
+ private Audio audio;
+
+
+ // added the audio class for strategy implementation
+ public interface Audio {
+ void playEatSound();
+ void playCrashSound();
+ }
+
+
+
+ // This is the constructor method that gets called
+ // from SnakeActivity
+ public SnakeGame(Context context, Point size, Audio audio) {
+ super(context);
+ mSP = new SoundPool.Builder().build();
+ // Work out how many pixels each block is
+ int blockSize = size.x / NUM_BLOCKS_WIDE;
+ // How many blocks of the same size will fit into the height
+ mNumBlocksHigh = size.y / blockSize;
+
+ // Initialize the SoundPool
+ try {
+ AssetManager assetManager = context.getAssets();
+ AssetFileDescriptor descriptor;
+
+ // Prepare the sounds in mem
+ descriptor = assetManager.openFd("get_apple.ogg");
+ mEat_ID = mSP.load(descriptor, 0);
+
+ descriptor = assetManager.openFd("snake_death.ogg");
+ mCrashID = mSP.load(descriptor, 0);
+
+ descriptor = assetManager.openFd("gameOver.ogg");
+ mGameOverID = mSP.load(descriptor, 0);
+
+ this.audio = audio;
+
+ } catch (IOException e) {
+ // Error
+ }
+
+ // Initialize the drawing objects
+ mSurfaceHolder = getHolder();
+ mPaint = new Paint();
+
+ // Call the constructors of our two game objects
+ // initialize GoodApple bitmap
+ this.mBitmapGoodApple = BitmapFactory.decodeResource(context.getResources(), R.drawable.apple);
+ this.mBitmapGoodApple = Bitmap.createScaledBitmap(mBitmapGoodApple, blockSize, blockSize, false);
+
+ // initialize BadApple bitmap
+ this.mBitmapBadApple = BitmapFactory.decodeResource(context.getResources(), R.drawable.badapple);
+ this.mBitmapBadApple = Bitmap.createScaledBitmap(mBitmapBadApple, blockSize, blockSize, false);
+
+
+ this.mGoodAppleBuilder = new GoodAppleBuilder(mBitmapGoodApple, new Point (0, 40) , new Point(NUM_BLOCKS_WIDE, mNumBlocksHigh), blockSize);
+ this.mGoodApple = this.mGoodAppleBuilder.returnApple();
+
+ this.mBadAppleBuilder = new BadAppleBuilder(mBitmapBadApple, new Point (10, 30) , new Point(NUM_BLOCKS_WIDE, mNumBlocksHigh), blockSize);
+ this.mBadApple = this.mBadAppleBuilder.returnApple();
+
+ mStar = new Star(context,
+ new Point(NUM_BLOCKS_WIDE,
+ mNumBlocksHigh),
+ blockSize);
+ mStar.spawn();
+
+ mObstacle = new Obstacle(context,
+ new Point(NUM_BLOCKS_WIDE,
+ mNumBlocksHigh),
+ blockSize);
+ mObstacle.spawn();
+
+ mSnake = new Snake(context,
+ new Point(NUM_BLOCKS_WIDE,
+ mNumBlocksHigh),
+ blockSize);
+
+ //Initializing MediaPlayer
+ mediaBackground = MediaPlayer.create(this.getContext(), R.raw.background);
+
+ }
+
+
+ // Called to start a new game
+ public void newGame() {
+
+ // reset the snake
+ mSnake.reset(NUM_BLOCKS_WIDE, mNumBlocksHigh);
+
+ // Get the apple ready for dinner
+ if (random.nextInt(2) + 1 > 1) {
+ this.mGoodApple.location.x = random.nextInt(this.mGoodApple.mSpawnRange.x - 1) + 1;
+ this.mGoodApple.location.y = random.nextInt(this.mGoodApple.mSpawnRange.y - 1) + 1;
+ this.mBadApple.location.x = -10;
+ this.mBadApple.location.y = 0;
+ } else {
+ this.mBadApple.location.x = random.nextInt(this.mBadApple.mSpawnRange.x - 1) + 1;
+ this.mBadApple.location.y = random.nextInt(this.mBadApple.mSpawnRange.y - 1) + 1;
+ this.mGoodApple.location.x = -10;
+ this.mGoodApple.location.y = 0;
+ }
+
+ // Reset the mScore
+ mScore = 0;
+ Scanner input = new Scanner("highscore.txt");
+
+ System.out.println(new File("highscore.txt").getAbsolutePath());
+ System.out.println("Testing");
+ try {
+
+ int test = input.nextInt();
+ mHighScore = test;
+ input.close();
+ }catch(InputMismatchException e){
+ //discards
+ }
+ // Respawn tertiary items
+ mStar.spawn();
+ mObstacle.spawn();
+
+ // Setup mNextFrameTime so an update can triggered
+ mNextFrameTime = System.currentTimeMillis();
+ }
+
+
+ // Handles the game loop
+ @Override
+ public void run() {
+ while (mPlaying) {
+ if(!mPaused) {
+ // Update 10 times a second
+ if (updateRequired()) {
+ update();
+ }
+ }
+
+ draw();
+ }
+ }
+
+
+ // Check to see if it is time for an update
+ public boolean updateRequired() {
+
+ // Run at 10 frames per second
+ final long TARGET_FPS = 10;
+ // There are 1000 milliseconds in a second
+ final long MILLIS_PER_SECOND = 1000;
+
+ // Are we due to update the frame
+ if(mNextFrameTime <= System.currentTimeMillis()){
+ // Tenth of a second has passed
+
+ // Setup when the next update will be triggered
+ mNextFrameTime =System.currentTimeMillis()
+ + MILLIS_PER_SECOND / TARGET_FPS;
+
+ // Return true so that the update and draw
+ // methods are executed
+ return true;
+ }
+
+ return false;
+ }
+
+
+ // Update all the game objects
+ public void update() {
+
+ // Move the snake
+ mSnake.move();
+
+ //checking if background music is playing
+ if(!mediaBackground.isPlaying()){
+ mediaBackground = MediaPlayer.create(this.getContext(), R.raw.background);
+ mediaBackground.start();
+ }
+
+ // Did the head of the snake eat the apple?
+ // Check if GoodApple was eaten
+ if(mSnake.checkDinner(this.mGoodApple.location)){
+ // After eating an apple, randomly spawn a GoodApple or BadApple
+ // If: Spawns GoodApple hides BadApple; Else: vice versa
+ if (random.nextInt(2) + 1 > 1) {
+ this.mGoodApple.location.x = random.nextInt(this.mGoodApple.mSpawnRange.x - 1) + 1;
+ this.mGoodApple.location.y = random.nextInt(this.mGoodApple.mSpawnRange.y - 1) + 1;
+ this.mBadApple.location.x = -10;
+ this.mBadApple.location.y = 0;
+ } else {
+ this.mBadApple.location.x = random.nextInt(this.mBadApple.mSpawnRange.x - 1) + 1;
+ this.mBadApple.location.y = random.nextInt(this.mBadApple.mSpawnRange.y - 1) + 1;
+ this.mGoodApple.location.x = -10;
+ this.mGoodApple.location.y = 0;
+ }
+ // Add to 2 mScore for GoodApple
+ mScore = mScore + 2;
+
+ // Play a sound
+ mSP.play(mEat_ID, 1, 1, 0, 0, 1);
+ }
+
+ // Check if bad apple was eaten
+ if(mSnake.checkDinner(this.mBadApple.location)){
+ // After eating an apple, randomly spawn a GoodApple or BadApple
+ // If: Spawns GoodApple hides BadApple; Else: vice versa
+ if (random.nextInt(2) + 1 > 1) {
+ this.mGoodApple.location.x = random.nextInt(this.mGoodApple.mSpawnRange.x - 1) + 1;
+ this.mGoodApple.location.y = random.nextInt(this.mGoodApple.mSpawnRange.y - 1) + 1;
+ this.mBadApple.location.x = -10;
+ this.mBadApple.location.y = 0;
+ } else {
+ this.mBadApple.location.x = random.nextInt(this.mBadApple.mSpawnRange.x - 1) + 1;
+ this.mBadApple.location.y = random.nextInt(this.mBadApple.mSpawnRange.y - 1) + 1;
+ this.mGoodApple.location.x = -10;
+ this.mGoodApple.location.y = 0;
+ }
+ // Add to 1 mScore for BadApple
+ mScore = mScore + 1;
+
+ // Play a sound
+ mSP.play(mEat_ID, 1, 1, 0, 0, 1);
+ }
+
+ // Did the head of the snake eat the star?
+ if (mSnake.checkDinner(mStar.getLocation())) {
+ mStar.spawn(); // spawn a new star
+ mSP.play(mEat_ID, 1, 1, 0, 0, 1);
+ mStar.applySpeedBoost(mSnake); // speed booster
+ mObstacle.spawn(); // spawn new obstacle >:)
+ }
+
+ // Did the head of the snake eat the obstacle?
+ if (mSnake.checkDinner(mObstacle.getLocation())) {
+ mScore = mScore -1;
+ mObstacle.spawn(); // spawn new obstacle
+ }
+
+ // Did the snake die?
+ if (mSnake.detectDeath()) {
+ // play the new crash sound using strategy ;)
+ if (audio != null) {
+ audio.playCrashSound();
+ }
+ mSP.play(mGameOverID, 1, 1, 0, 0, 1);
+ if(mScore > mHighScore){
+ mHighScore = mScore;
+
+ try {
+ FileWriter output = new FileWriter("HighScore.txt");
+ output.write(mHighScore);
+ } catch (IOException e) {
+ //in the case the save file is not present discards
+ }
+
+ }
+ mPaused =true;
+ }
+
+ }
+
+
+ // Do all the drawing
+ public void draw() {
+ // Get a lock on the mCanvas
+ if (mSurfaceHolder.getSurface().isValid()) {
+ mCanvas = mSurfaceHolder.lockCanvas();
+
+ // Fill the screen with a color
+ mCanvas.drawColor(Color.argb(255, 26, 128, 182));
+
+ // Set the size and color of the mPaint for the text
+ mPaint.setColor(Color.argb(255, 255, 255, 255));
+ mPaint.setTextSize(70);
+ // Draw the score
+ mCanvas.drawText("Score: " + mScore, 20, 100, mPaint);
+ mCanvas.drawText("HighScore: " + mHighScore, 20, 200, mPaint);
+
+
+ // Draw the apple, snake, star, and obstacle
+ this.mGoodApple.draw(mCanvas, mPaint);
+ this.mBadApple.draw(mCanvas, mPaint);
+ mSnake.draw(mCanvas, mPaint);
+ mStar.draw(mCanvas, mPaint);
+ mObstacle.draw(mCanvas, mPaint);
+
+
+ // Draw some text while paused
+ if(mPaused){
+
+ // Set the size and color of the mPaint for the text
+ mPaint.setColor(Color.argb(255, 255, 255, 255));
+ mPaint.setTextSize(250);
+
+ // Draw the message
+ // We will give this an international upgrade soon
+ //mCanvas.drawText("Tap To Play!", 200, 700, mPaint);
+ mCanvas.drawText(getResources().
+ getString(R.string.tap_to_play),
+ 200, 700, mPaint);
+ }
+
+
+ // Unlock the mCanvas and reveal the graphics for this frame
+ mSurfaceHolder.unlockCanvasAndPost(mCanvas);
+ }
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent motionEvent) {
+ switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
+ case MotionEvent.ACTION_UP:
+ if (mPaused) {
+ mPaused = false;
+ newGame();
+
+ // Don't want to process snake direction for this tap
+ return true;
+ }
+
+ // Let the Snake class handle the input
+ mSnake.switchHeading(motionEvent);
+ break;
+
+ default:
+ break;
+
+ }
+ return true;
+ }
+
+
+ // Stop the thread
+ public void pause() {
+ mPlaying = false;
+ try {
+ mThread.join();
+ } catch (InterruptedException e) {
+ // Error
+ }
+ }
+
+
+ // Start the thread
+ public void resume() {
+ mPlaying = true;
+ mThread = new Thread(this);
+ mThread.start();
+ }
+}
diff --git a/Chapter17/java/Star.java b/Chapter17/java/Star.java
new file mode 100644
index 0000000..429d2ea
--- /dev/null
+++ b/Chapter17/java/Star.java
@@ -0,0 +1,54 @@
+package com.gamecodeschool.c17snake;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Point;
+
+import java.util.Random;
+
+public class Star {
+
+ private Point location = new Point();
+ private Bitmap mBitmapStar;
+ private Point mSpawnRange;
+ private int mSize;
+
+ Star(Context context, Point sr, int s) {
+ // spawn range
+ mSpawnRange = sr;
+ // size of a star
+ mSize = s;
+
+ mBitmapStar = BitmapFactory.decodeResource(context.getResources(), R.drawable.star);
+ mBitmapStar = Bitmap.createScaledBitmap(mBitmapStar, s, s, false);
+
+ // initial spawn range
+ Random random = new Random();
+ location.x = random.nextInt(mSpawnRange.x);
+ location.y = random.nextInt(mSpawnRange.y);
+ }
+
+ void spawn() {
+ Random random = new Random();
+ location.x = random.nextInt(mSpawnRange.x) + 1;
+ location.y = random.nextInt(mSpawnRange.y - 1) + 1;
+ }
+
+ Point getLocation() {
+ return location;
+ }
+
+ // draw the star
+ void draw(Canvas canvas, Paint paint) {
+ canvas.drawBitmap(mBitmapStar,
+ location.x * mSize, location.y * mSize, paint);
+ }
+
+ // consume star >> get boosted!
+ void applySpeedBoost(Snake snake) {
+ snake.applySpeedBoost();
+ }
+}
diff --git a/Chapter17/java/highscore.txt b/Chapter17/java/highscore.txt
new file mode 100644
index 0000000..9a03714
--- /dev/null
+++ b/Chapter17/java/highscore.txt
@@ -0,0 +1 @@
+10
\ No newline at end of file
diff --git a/Chapter16/drawable/apple.png b/Chapter17/res/drawable/apple.png
similarity index 100%
rename from Chapter16/drawable/apple.png
rename to Chapter17/res/drawable/apple.png
diff --git a/Chapter17/res/drawable/badapple.png b/Chapter17/res/drawable/badapple.png
new file mode 100644
index 0000000..43315b9
Binary files /dev/null and b/Chapter17/res/drawable/badapple.png differ
diff --git a/Chapter17/res/drawable/bapple.png b/Chapter17/res/drawable/bapple.png
new file mode 100644
index 0000000..81115b6
Binary files /dev/null and b/Chapter17/res/drawable/bapple.png differ
diff --git a/Chapter16/drawable/body.png b/Chapter17/res/drawable/body.png
similarity index 100%
rename from Chapter16/drawable/body.png
rename to Chapter17/res/drawable/body.png
diff --git a/Chapter16/drawable/head.png b/Chapter17/res/drawable/head.png
similarity index 100%
rename from Chapter16/drawable/head.png
rename to Chapter17/res/drawable/head.png
diff --git a/Chapter17/res/drawable/ic_launcher_background.xml b/Chapter17/res/drawable/ic_launcher_background.xml
new file mode 100644
index 0000000..07d5da9
--- /dev/null
+++ b/Chapter17/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,170 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Chapter17/res/drawable/ic_launcher_foreground.xml b/Chapter17/res/drawable/ic_launcher_foreground.xml
new file mode 100644
index 0000000..2b068d1
--- /dev/null
+++ b/Chapter17/res/drawable/ic_launcher_foreground.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Chapter17/res/drawable/obstacle.png b/Chapter17/res/drawable/obstacle.png
new file mode 100644
index 0000000..c10b22e
Binary files /dev/null and b/Chapter17/res/drawable/obstacle.png differ
diff --git a/Chapter17/res/drawable/star.png b/Chapter17/res/drawable/star.png
new file mode 100644
index 0000000..c10f4b1
Binary files /dev/null and b/Chapter17/res/drawable/star.png differ
diff --git a/Chapter17/res/mipmap-anydpi-v26/ic_launcher.xml b/Chapter17/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 0000000..6f3b755
--- /dev/null
+++ b/Chapter17/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Chapter17/res/mipmap-anydpi-v26/ic_launcher_round.xml b/Chapter17/res/mipmap-anydpi-v26/ic_launcher_round.xml
new file mode 100644
index 0000000..6f3b755
--- /dev/null
+++ b/Chapter17/res/mipmap-anydpi-v26/ic_launcher_round.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Chapter17/res/mipmap-hdpi/ic_launcher.webp b/Chapter17/res/mipmap-hdpi/ic_launcher.webp
new file mode 100644
index 0000000..c209e78
Binary files /dev/null and b/Chapter17/res/mipmap-hdpi/ic_launcher.webp differ
diff --git a/Chapter17/res/mipmap-hdpi/ic_launcher_round.webp b/Chapter17/res/mipmap-hdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..b2dfe3d
Binary files /dev/null and b/Chapter17/res/mipmap-hdpi/ic_launcher_round.webp differ
diff --git a/Chapter17/res/mipmap-mdpi/ic_launcher.webp b/Chapter17/res/mipmap-mdpi/ic_launcher.webp
new file mode 100644
index 0000000..4f0f1d6
Binary files /dev/null and b/Chapter17/res/mipmap-mdpi/ic_launcher.webp differ
diff --git a/Chapter17/res/mipmap-mdpi/ic_launcher_round.webp b/Chapter17/res/mipmap-mdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..62b611d
Binary files /dev/null and b/Chapter17/res/mipmap-mdpi/ic_launcher_round.webp differ
diff --git a/Chapter17/res/mipmap-xhdpi/ic_launcher.webp b/Chapter17/res/mipmap-xhdpi/ic_launcher.webp
new file mode 100644
index 0000000..948a307
Binary files /dev/null and b/Chapter17/res/mipmap-xhdpi/ic_launcher.webp differ
diff --git a/Chapter17/res/mipmap-xhdpi/ic_launcher_round.webp b/Chapter17/res/mipmap-xhdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..1b9a695
Binary files /dev/null and b/Chapter17/res/mipmap-xhdpi/ic_launcher_round.webp differ
diff --git a/Chapter17/res/mipmap-xxhdpi/ic_launcher.webp b/Chapter17/res/mipmap-xxhdpi/ic_launcher.webp
new file mode 100644
index 0000000..28d4b77
Binary files /dev/null and b/Chapter17/res/mipmap-xxhdpi/ic_launcher.webp differ
diff --git a/Chapter17/res/mipmap-xxhdpi/ic_launcher_round.webp b/Chapter17/res/mipmap-xxhdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..9287f50
Binary files /dev/null and b/Chapter17/res/mipmap-xxhdpi/ic_launcher_round.webp differ
diff --git a/Chapter17/res/mipmap-xxxhdpi/ic_launcher.webp b/Chapter17/res/mipmap-xxxhdpi/ic_launcher.webp
new file mode 100644
index 0000000..aa7d642
Binary files /dev/null and b/Chapter17/res/mipmap-xxxhdpi/ic_launcher.webp differ
diff --git a/Chapter17/res/mipmap-xxxhdpi/ic_launcher_round.webp b/Chapter17/res/mipmap-xxxhdpi/ic_launcher_round.webp
new file mode 100644
index 0000000..9126ae3
Binary files /dev/null and b/Chapter17/res/mipmap-xxxhdpi/ic_launcher_round.webp differ
diff --git a/Chapter17/res/raw/background.ogg b/Chapter17/res/raw/background.ogg
new file mode 100644
index 0000000..44199be
Binary files /dev/null and b/Chapter17/res/raw/background.ogg differ
diff --git a/Chapter17/res/values/colors.xml b/Chapter17/res/values/colors.xml
new file mode 100644
index 0000000..f8c6127
--- /dev/null
+++ b/Chapter17/res/values/colors.xml
@@ -0,0 +1,10 @@
+
+
+ #FFBB86FC
+ #FF6200EE
+ #FF3700B3
+ #FF03DAC5
+ #FF018786
+ #FF000000
+ #FFFFFFFF
+
\ No newline at end of file
diff --git a/Chapter17/res/values/strings.xml b/Chapter17/res/values/strings.xml
new file mode 100644
index 0000000..5627111
--- /dev/null
+++ b/Chapter17/res/values/strings.xml
@@ -0,0 +1,4 @@
+
+ My Application
+ Tap to Play
+
\ No newline at end of file
diff --git a/Chapter17/res/values/themes.xml b/Chapter17/res/values/themes.xml
new file mode 100644
index 0000000..e48770a
--- /dev/null
+++ b/Chapter17/res/values/themes.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/Chapter17/res/xml/backup_rules.xml b/Chapter17/res/xml/backup_rules.xml
new file mode 100644
index 0000000..fa0f996
--- /dev/null
+++ b/Chapter17/res/xml/backup_rules.xml
@@ -0,0 +1,13 @@
+
+
+
+
\ No newline at end of file
diff --git a/Chapter17/res/xml/data_extraction_rules.xml b/Chapter17/res/xml/data_extraction_rules.xml
new file mode 100644
index 0000000..9ee9997
--- /dev/null
+++ b/Chapter17/res/xml/data_extraction_rules.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Chapter18/AndroidManifest.xml b/Chapter18/AndroidManifest.xml
deleted file mode 100644
index ab565fd..0000000
--- a/Chapter18/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter18/assets/alien_explosion.ogg b/Chapter18/assets/alien_explosion.ogg
deleted file mode 100644
index cfb3087..0000000
Binary files a/Chapter18/assets/alien_explosion.ogg and /dev/null differ
diff --git a/Chapter18/assets/player_explosion.ogg b/Chapter18/assets/player_explosion.ogg
deleted file mode 100644
index 6463b70..0000000
Binary files a/Chapter18/assets/player_explosion.ogg and /dev/null differ
diff --git a/Chapter18/assets/shoot.ogg b/Chapter18/assets/shoot.ogg
deleted file mode 100644
index 6a051ed..0000000
Binary files a/Chapter18/assets/shoot.ogg and /dev/null differ
diff --git a/Chapter18/java/GameActivity.java b/Chapter18/java/GameActivity.java
deleted file mode 100644
index d1b26b7..0000000
--- a/Chapter18/java/GameActivity.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.gamecodeschool.c18scrollingshooter;
-
-import android.app.Activity;
- import android.graphics.Point;
- import android.os.Bundle;
- import android.view.Display;
-
-public class GameActivity extends Activity {
-
- GameEngine mGameEngine;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Display display = getWindowManager()
- .getDefaultDisplay();
-
- Point size = new Point();
- display.getSize(size);
- mGameEngine = new GameEngine(this, size);
- setContentView(mGameEngine);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mGameEngine.startThread();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mGameEngine.stopThread();
- }
-}
\ No newline at end of file
diff --git a/Chapter18/java/GameEngine.java b/Chapter18/java/GameEngine.java
deleted file mode 100644
index 71876fa..0000000
--- a/Chapter18/java/GameEngine.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.gamecodeschool.c18scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Point;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceView;
-
-class GameEngine extends SurfaceView implements Runnable, GameStarter {
- private Thread mThread = null;
- private long mFPS;
-
- private GameState mGameState;
- private SoundEngine mSoundEngine;
- HUD mHUD;
- Renderer mRenderer;
-
- public GameEngine(Context context, Point size) {
- super(context);
-
- mGameState = new GameState(this, context);
- mSoundEngine = new SoundEngine(context);
- mHUD = new HUD(size);
- mRenderer = new Renderer(this);
- }
-
- public void deSpawnReSpawn() {
- // Eventually this will despawn
- // and then respawn all the game objects
- }
-
- @Override
- public void run() {
- while (mGameState.getThreadRunning()) {
- long frameStartTime = System.currentTimeMillis();
-
- if (!mGameState.getPaused()) {
- // Update all the game objects here
- // in a new way
- }
-
- // Draw all the game objects here
- // in a new way
- mRenderer.draw(mGameState, mHUD);
-
- // Measure the frames per second in the usual way
- long timeThisFrame = System.currentTimeMillis()
- - frameStartTime;
- if (timeThisFrame >= 1) {
- final int MILLIS_IN_SECOND = 1000;
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- // Handle the player's input here
- // But in a new way
- mSoundEngine.playShoot();
-
- return true;
- }
-
- public void stopThread() {
- // New code here soon
- mGameState.stopEverything();
-
- try {
- mThread.join();
- } catch (InterruptedException e) {
- Log.e("Exception","stopThread()" + e.getMessage());
- }
- }
-
- public void startThread() {
- // New code here soon
- mGameState.startThread();
-
- mThread = new Thread(this);
- mThread.start();
- }
-}
diff --git a/Chapter18/java/GameStarter.java b/Chapter18/java/GameStarter.java
deleted file mode 100644
index 7471863..0000000
--- a/Chapter18/java/GameStarter.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.gamecodeschool.c18scrollingshooter;
-
-interface GameStarter {
- // This allows the State class to
- // spawn and despawn objects via the game engine
- public void deSpawnReSpawn();
-}
diff --git a/Chapter18/java/GameState.java b/Chapter18/java/GameState.java
deleted file mode 100644
index 43561de..0000000
--- a/Chapter18/java/GameState.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package com.gamecodeschool.c18scrollingshooter;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-
-final class GameState {
- private static volatile boolean mThreadRunning = false;
- private static volatile boolean mPaused = true;
- private static volatile boolean mGameOver = true;
- private static volatile boolean mDrawing = false;
-
- // This object will have access to the deSpawnReSpawn method
- // in GameEngine- once it is initialized
- private static GameStarter gameStarter;
-
- private int mScore;
- private int mHighScore;
- private int mNumShips;
-
- // This is how we will make all the high scores persist
- private SharedPreferences.Editor mEditor;
-
- GameState(GameStarter gs, Context context){
- // This initializes the gameStarter reference
- gameStarter = gs;
-
- // Get the current high score
- SharedPreferences prefs;
- prefs = context.getSharedPreferences("HiScore",
- Context.MODE_PRIVATE);
-
- // Initialize the mEditor ready
- mEditor = prefs.edit();
-
- // Load high score from a entry in the file
- // labeled "hiscore"
- // if not available highscore set to zero 0
- mHighScore = prefs.getInt("hi_score", 0);
- }
-
- private void endGame(){
- mGameOver = true;
- mPaused = true;
- if(mScore > mHighScore){
- mHighScore = mScore;
- // Save high score
- mEditor.putInt("hi_score", mHighScore);
- mEditor.commit();
- }
- }
-
- void startNewGame(){
- mScore = 0;
- mNumShips = 3;
- // Don'mTransform want to be drawing objects while deSpawnReSpawn is
- // clearing ArrayList and filling it up again
- stopDrawing();
- gameStarter.deSpawnReSpawn();
- resume();
-
- // Now we can draw again
- startDrawing();
- }
-
- void loseLife(SoundEngine se){
- mNumShips--;
- se.playPlayerExplode();
- if(mNumShips == 0){
- pause();
- endGame();
- }
- }
-
-
-
- int getNumShips(){
- return mNumShips;
- }
-
- void increaseScore(){
- mScore++;
- }
-
- int getScore(){
- return mScore;
- }
-
- int getHighScore(){
- return mHighScore;
- }
-
- void pause(){
- mPaused = true;
- }
-
- void resume(){
- mGameOver = false;
- mPaused = false;
- }
-
- void stopEverything(){
- mPaused = true;
- mGameOver = true;
- mThreadRunning = false;
- }
-
- boolean getThreadRunning(){
- return mThreadRunning;
- }
-
- void startThread(){
- mThreadRunning = true;
- }
-
- private void stopDrawing(){
- mDrawing = false;
- }
-
- private void startDrawing(){
- mDrawing = true;
- }
-
- boolean getDrawing() {return mDrawing;}
-
- boolean getPaused(){
- return mPaused;
- }
-
- boolean getGameOver(){
- return mGameOver;
- }
-
-}
diff --git a/Chapter18/java/HUD.java b/Chapter18/java/HUD.java
deleted file mode 100644
index 545f5e8..0000000
--- a/Chapter18/java/HUD.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package com.gamecodeschool.c18scrollingshooter;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.graphics.Rect;
-
-import java.util.ArrayList;
-
-class HUD {
- private int mTextFormatting;
- private int mScreenHeight;
- private int mScreenWidth;
-
- private ArrayList controls;
-
- static int UP = 0;
- static int DOWN = 1;
- static int FLIP = 2;
- static int SHOOT = 3;
- static int PAUSE = 4;
-
- HUD(Point size){
- mScreenHeight = size.y;
- mScreenWidth = size.x;
- mTextFormatting = size.x / 50;
-
- prepareControls();
- }
-
- private void prepareControls(){
- int buttonWidth = mScreenWidth / 14;
- int buttonHeight = mScreenHeight / 12;
- int buttonPadding = mScreenWidth / 90;
-
- Rect up = new Rect(
- buttonPadding,
- mScreenHeight - (buttonHeight * 2) - (buttonPadding * 2),
- buttonWidth + buttonPadding,
- mScreenHeight - buttonHeight - (buttonPadding *2) );
-
- Rect down = new Rect(
- buttonPadding,
- mScreenHeight - buttonHeight - buttonPadding,
- buttonWidth + buttonPadding,
- mScreenHeight - buttonPadding);
-
- Rect flip = new Rect(mScreenWidth - buttonPadding - buttonWidth,
- mScreenHeight - buttonHeight - buttonPadding,
- mScreenWidth - buttonPadding,
- mScreenHeight - buttonPadding
-
- );
-
- Rect shoot = new Rect(mScreenWidth - buttonPadding - buttonWidth,
- mScreenHeight - (buttonHeight * 2) - (buttonPadding * 2),
- mScreenWidth - buttonPadding,
- mScreenHeight - buttonHeight - (buttonPadding *2)
- );
-
- Rect pause = new Rect(
- mScreenWidth - buttonPadding - buttonWidth,
- buttonPadding,
- mScreenWidth - buttonPadding,
- buttonPadding + buttonHeight);
-
- controls = new ArrayList<>();
- controls.add(UP,up);
- controls.add(DOWN,down);
- controls.add(FLIP, flip);
- controls.add(SHOOT, shoot);
- controls.add(PAUSE, pause);
- }
-
- void draw(Canvas c, Paint p, GameState gs){
-
- // Draw the HUD
- p.setColor(Color.argb(255,255,255,255));
- p.setTextSize(mTextFormatting);
- c.drawText("Hi: " + gs.getHighScore(), mTextFormatting,mTextFormatting,p);
- c.drawText("Scrore: " + gs.getScore(), mTextFormatting,mTextFormatting * 2,p);
- c.drawText("Lives: " + gs.getNumShips(), mTextFormatting,mTextFormatting * 3,p);
-
- if(gs.getGameOver()){
- p.setTextSize(mTextFormatting * 5);
- c.drawText("PRESS PLAY", mScreenWidth /4, mScreenHeight /2 ,p);
- }
-
- if(gs.getPaused() && !gs.getGameOver()){
- p.setTextSize(mTextFormatting * 5);
- c.drawText("PAUSED", mScreenWidth /3, mScreenHeight /2 ,p);
- }
- drawControls(c, p);
- }
-
- private void drawControls(Canvas c, Paint p){
- p.setColor(Color.argb(100,255,255,255));
-
- for(Rect r : controls){
- c.drawRect(r.left, r.top, r.right, r.bottom, p);
- }
-
- // Set the colors back
- p.setColor(Color.argb(255,255,255,255));
- }
- ArrayList getControls(){
- return controls;
- }
-}
diff --git a/Chapter18/java/Renderer.java b/Chapter18/java/Renderer.java
deleted file mode 100644
index 5dc89ea..0000000
--- a/Chapter18/java/Renderer.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.gamecodeschool.c18scrollingshooter;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-import java.util.ArrayList;
-
-class Renderer {
- private Canvas mCanvas;
- private SurfaceHolder mSurfaceHolder;
- private Paint mPaint;
-
- Renderer(SurfaceView sh){
- mSurfaceHolder = sh.getHolder();
- mPaint = new Paint();
- }
-
- void draw(GameState gs, HUD hud) {
- if (mSurfaceHolder.getSurface().isValid()) {
- mCanvas = mSurfaceHolder.lockCanvas();
- mCanvas.drawColor(Color.argb(255, 0, 0, 0));
-
- if (gs.getDrawing()) {
- // Draw all the game objects here
- }
-
- if(gs.getGameOver()) {
- // Draw a background graphic here
- }
-
- // Draw a particle system explosion here
-
- // Now we draw the HUD on top of everything else
- hud.draw(mCanvas, mPaint, gs);
-
- mSurfaceHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-}
diff --git a/Chapter18/java/SoundEngine.java b/Chapter18/java/SoundEngine.java
deleted file mode 100644
index a5f379d..0000000
--- a/Chapter18/java/SoundEngine.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.gamecodeschool.c18scrollingshooter;
-
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-
-import java.io.IOException;
-
-class SoundEngine {
- // for playing sound effects
- private SoundPool mSP;
- private int mShoot_ID = -1;
- private int mAlien_Explode_ID = -1;
- private int mPlayer_explode_ID = -1;
-
-
- SoundEngine(Context c){
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
- try {
- AssetManager assetManager = c.getAssets();
- AssetFileDescriptor descriptor;
-
- // Prepare the sounds in memory
- descriptor = assetManager.openFd("shoot.ogg");
- mShoot_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("alien_explosion.ogg");
- mAlien_Explode_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("player_explosion.ogg");
- mPlayer_explode_ID = mSP.load(descriptor, 0);
-
- } catch (IOException e) {
- // Error
- }
-
- }
-
- void playShoot(){
- mSP.play(mShoot_ID,1, 1, 0, 0, 1);
- }
-
- void playAlienExplode(){
- mSP.play(mAlien_Explode_ID,1, 1, 0, 0, 1);
- }
-
- void playPlayerExplode(){
- mSP.play(mPlayer_explode_ID,1, 1, 0, 0, 1);
- }
-}
diff --git a/Chapter19/AndroidManifest.xml b/Chapter19/AndroidManifest.xml
deleted file mode 100644
index 0cd7b64..0000000
--- a/Chapter19/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter19/assets/alien_explosion.ogg b/Chapter19/assets/alien_explosion.ogg
deleted file mode 100644
index cfb3087..0000000
Binary files a/Chapter19/assets/alien_explosion.ogg and /dev/null differ
diff --git a/Chapter19/assets/player_explosion.ogg b/Chapter19/assets/player_explosion.ogg
deleted file mode 100644
index 6463b70..0000000
Binary files a/Chapter19/assets/player_explosion.ogg and /dev/null differ
diff --git a/Chapter19/assets/shoot.ogg b/Chapter19/assets/shoot.ogg
deleted file mode 100644
index 6a051ed..0000000
Binary files a/Chapter19/assets/shoot.ogg and /dev/null differ
diff --git a/Chapter19/java/GameActivity.java b/Chapter19/java/GameActivity.java
deleted file mode 100644
index 499595c..0000000
--- a/Chapter19/java/GameActivity.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class GameActivity extends Activity {
-
- GameEngine mGameEngine;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Display display = getWindowManager()
- .getDefaultDisplay();
-
- Point size = new Point();
- display.getSize(size);
- mGameEngine = new GameEngine(this, size);
- setContentView(mGameEngine);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mGameEngine.startThread();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mGameEngine.stopThread();
- }
-}
\ No newline at end of file
diff --git a/Chapter19/java/GameEngine.java b/Chapter19/java/GameEngine.java
deleted file mode 100644
index 766393e..0000000
--- a/Chapter19/java/GameEngine.java
+++ /dev/null
@@ -1,115 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Point;
-import android.graphics.PointF;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceView;
-
-import java.util.ArrayList;
-
-class GameEngine extends SurfaceView implements Runnable, GameStarter, GameEngineBroadcaster {
- private Thread mThread = null;
- private long mFPS;
-
- private ArrayList inputObservers = new ArrayList();
- UIController mUIController;
-
- private GameState mGameState;
- private SoundEngine mSoundEngine;
- HUD mHUD;
- Renderer mRenderer;
- ParticleSystem mParticleSystem;
- PhysicsEngine mPhysicsEngine;
-
-
- public GameEngine(Context context, Point size) {
- super(context);
-
- mUIController = new UIController(this);
- mGameState = new GameState(this, context);
- mSoundEngine = new SoundEngine(context);
- mHUD = new HUD(size);
- mRenderer = new Renderer(this);
- mPhysicsEngine = new PhysicsEngine();
-
- mParticleSystem = new ParticleSystem();
- mParticleSystem.init(1000);
- }
-
- // For the game engine broadcaster interface
- public void addObserver(InputObserver o) {
-
- inputObservers.add(o);
- }
-
- public void deSpawnReSpawn() {
- // Eventually this will despawn
- // and then respawn all the game objects
- }
-
- @Override
- public void run() {
- while (mGameState.getThreadRunning()) {
- long frameStartTime = System.currentTimeMillis();
-
- if (!mGameState.getPaused()) {
- // Update all the game objects here
- // in a new way
-
- // This call to update will eveolve with the project
- if(mPhysicsEngine.update(mFPS, mParticleSystem)) {
- // Player hit
- deSpawnReSpawn();
- }
- }
-
- // Draw all the game objects here
- // in a new way
- mRenderer.draw(mGameState, mHUD, mParticleSystem);
-
- // Measure the frames per second in the usual way
- long timeThisFrame = System.currentTimeMillis()
- - frameStartTime;
- if (timeThisFrame >= 1) {
- final int MILLIS_IN_SECOND = 1000;
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- // Handle the player's input here
- // But in a new way
- for (InputObserver o : inputObservers) {
- o.handleInput(motionEvent, mGameState, mHUD.getControls());
- }
-
- // This is temporary code to emit a particle system
- mParticleSystem.emitParticles(
- new PointF(500,500));
-
- return true;
- }
-
- public void stopThread() {
- // New code here soon
- mGameState.stopEverything();
-
- try {
- mThread.join();
- } catch (InterruptedException e) {
- Log.e("Exception","stopThread()" + e.getMessage());
- }
- }
-
- public void startThread() {
- // New code here soon
- mGameState.startThread();
-
- mThread = new Thread(this);
- mThread.start();
- }
-}
diff --git a/Chapter19/java/GameEngineBroadcaster.java b/Chapter19/java/GameEngineBroadcaster.java
deleted file mode 100644
index 103c83f..0000000
--- a/Chapter19/java/GameEngineBroadcaster.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-interface GameEngineBroadcaster {
-
- void addObserver(InputObserver o);
-}
diff --git a/Chapter19/java/GameStarter.java b/Chapter19/java/GameStarter.java
deleted file mode 100644
index 9e4c42f..0000000
--- a/Chapter19/java/GameStarter.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-interface GameStarter {
- // This allows the State class to
- // spawn and despawn objects via the game engine
- public void deSpawnReSpawn();
-}
diff --git a/Chapter19/java/GameState.java b/Chapter19/java/GameState.java
deleted file mode 100644
index 36e138b..0000000
--- a/Chapter19/java/GameState.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-
-final class GameState {
- private static volatile boolean mThreadRunning = false;
- private static volatile boolean mPaused = true;
- private static volatile boolean mGameOver = true;
- private static volatile boolean mDrawing = false;
-
- // This object will have access to the deSpawnReSpawn method
- // in GameEngine- once it is initialized
- private static GameStarter gameStarter;
-
- private int mScore;
- private int mHighScore;
- private int mNumShips;
-
- // This is how we will make all the high scores persist
- private SharedPreferences.Editor mEditor;
-
- GameState(GameStarter gs, Context context){
- // This initializes the gameStarter reference
- gameStarter = gs;
-
- // Get the current high score
- SharedPreferences prefs;
- prefs = context.getSharedPreferences("HiScore",
- Context.MODE_PRIVATE);
-
- // Initialize the mEditor ready
- mEditor = prefs.edit();
-
- // Load high score from a entry in the file
- // labeled "hiscore"
- // if not available highscore set to zero 0
- mHighScore = prefs.getInt("hi_score", 0);
- }
-
- private void endGame(){
- mGameOver = true;
- mPaused = true;
- if(mScore > mHighScore){
- mHighScore = mScore;
- // Save high score
- mEditor.putInt("hi_score", mHighScore);
- mEditor.commit();
- }
- }
-
- void startNewGame(){
- mScore = 0;
- mNumShips = 3;
- // Don'mTransform want to be drawing objects while deSpawnReSpawn is
- // clearing ArrayList and filling it up again
- stopDrawing();
- gameStarter.deSpawnReSpawn();
- resume();
-
- // Now we can draw again
- startDrawing();
- }
-
- void loseLife(SoundEngine se){
- mNumShips--;
- se.playPlayerExplode();
- if(mNumShips == 0){
- pause();
- endGame();
- }
- }
-
-
-
- int getNumShips(){
- return mNumShips;
- }
-
- void increaseScore(){
- mScore++;
- }
-
- int getScore(){
- return mScore;
- }
-
- int getHighScore(){
- return mHighScore;
- }
-
- void pause(){
- mPaused = true;
- }
-
- void resume(){
- mGameOver = false;
- mPaused = false;
- }
-
- void stopEverything(){
- mPaused = true;
- mGameOver = true;
- mThreadRunning = false;
- }
-
- boolean getThreadRunning(){
- return mThreadRunning;
- }
-
- void startThread(){
- mThreadRunning = true;
- }
-
- private void stopDrawing(){
- mDrawing = false;
- }
-
- private void startDrawing(){
- mDrawing = true;
- }
-
- boolean getDrawing() {return mDrawing;}
-
- boolean getPaused(){
- return mPaused;
- }
-
- boolean getGameOver(){
- return mGameOver;
- }
-
-}
diff --git a/Chapter19/java/HUD.java b/Chapter19/java/HUD.java
deleted file mode 100644
index f3fca47..0000000
--- a/Chapter19/java/HUD.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.graphics.Rect;
-
-import java.util.ArrayList;
-
-class HUD {
- private int mTextFormatting;
- private int mScreenHeight;
- private int mScreenWidth;
-
- private ArrayList controls;
-
- static int UP = 0;
- static int DOWN = 1;
- static int FLIP = 2;
- static int SHOOT = 3;
- static int PAUSE = 4;
-
- HUD(Point size){
- mScreenHeight = size.y;
- mScreenWidth = size.x;
- mTextFormatting = size.x / 50;
-
- prepareControls();
- }
-
- private void prepareControls(){
- int buttonWidth = mScreenWidth / 14;
- int buttonHeight = mScreenHeight / 12;
- int buttonPadding = mScreenWidth / 90;
-
- Rect up = new Rect(
- buttonPadding,
- mScreenHeight - (buttonHeight * 2) - (buttonPadding * 2),
- buttonWidth + buttonPadding,
- mScreenHeight - buttonHeight - (buttonPadding *2) );
-
- Rect down = new Rect(
- buttonPadding,
- mScreenHeight - buttonHeight - buttonPadding,
- buttonWidth + buttonPadding,
- mScreenHeight - buttonPadding);
-
- Rect flip = new Rect(mScreenWidth - buttonPadding - buttonWidth,
- mScreenHeight - buttonHeight - buttonPadding,
- mScreenWidth - buttonPadding,
- mScreenHeight - buttonPadding
-
- );
-
- Rect shoot = new Rect(mScreenWidth - buttonPadding - buttonWidth,
- mScreenHeight - (buttonHeight * 2) - (buttonPadding * 2),
- mScreenWidth - buttonPadding,
- mScreenHeight - buttonHeight - (buttonPadding *2)
- );
-
- Rect pause = new Rect(
- mScreenWidth - buttonPadding - buttonWidth,
- buttonPadding,
- mScreenWidth - buttonPadding,
- buttonPadding + buttonHeight);
-
- controls = new ArrayList<>();
- controls.add(UP,up);
- controls.add(DOWN,down);
- controls.add(FLIP, flip);
- controls.add(SHOOT, shoot);
- controls.add(PAUSE, pause);
- }
-
- void draw(Canvas c, Paint p, GameState gs){
-
- // Draw the HUD
- p.setColor(Color.argb(255,255,255,255));
- p.setTextSize(mTextFormatting);
- c.drawText("Hi: " + gs.getHighScore(), mTextFormatting,mTextFormatting,p);
- c.drawText("Scrore: " + gs.getScore(), mTextFormatting,mTextFormatting * 2,p);
- c.drawText("Lives: " + gs.getNumShips(), mTextFormatting,mTextFormatting * 3,p);
-
- if(gs.getGameOver()){
- p.setTextSize(mTextFormatting * 5);
- c.drawText("PRESS PLAY", mScreenWidth /4, mScreenHeight /2 ,p);
- }
-
- if(gs.getPaused() && !gs.getGameOver()){
- p.setTextSize(mTextFormatting * 5);
- c.drawText("PAUSED", mScreenWidth /3, mScreenHeight /2 ,p);
- }
- drawControls(c, p);
- }
-
- private void drawControls(Canvas c, Paint p){
- p.setColor(Color.argb(100,255,255,255));
-
- for(Rect r : controls){
- c.drawRect(r.left, r.top, r.right, r.bottom, p);
- }
-
- // Set the colors back
- p.setColor(Color.argb(255,255,255,255));
- }
- ArrayList getControls(){
- return controls;
- }
-}
diff --git a/Chapter19/java/InputObserver.java b/Chapter19/java/InputObserver.java
deleted file mode 100644
index f7514b5..0000000
--- a/Chapter19/java/InputObserver.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-interface InputObserver {
-
- void handleInput(MotionEvent event, GameState gs, ArrayList controls);
-}
diff --git a/Chapter19/java/Particle.java b/Chapter19/java/Particle.java
deleted file mode 100644
index c8bd938..0000000
--- a/Chapter19/java/Particle.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-import android.graphics.PointF;
-
-class Particle {
-
- PointF mVelocity;
- PointF mPosition;
-
- Particle(PointF direction)
- {
- mVelocity = new PointF();
- mPosition = new PointF();
-
- // Determine the direction
- mVelocity.x = direction.x;
- mVelocity.y = direction.y;
- }
-
- void update(float fps)
- {
- // Move the particle
- mPosition.x += mVelocity.x;
- mPosition.y += mVelocity.y;
- }
-
- void setPosition(PointF position)
- {
- mPosition.x = position.x;
- mPosition.y = position.y;
- }
-
- PointF getPosition()
- {
- return mPosition;
- }
-}
diff --git a/Chapter19/java/ParticleSystem.java b/Chapter19/java/ParticleSystem.java
deleted file mode 100644
index 85a09dd..0000000
--- a/Chapter19/java/ParticleSystem.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-import java.util.ArrayList;
-import java.util.Random;
-
-class ParticleSystem {
-
- float mDuration;
-
- ArrayList mParticles;
- Random random = new Random();
- boolean mIsRunning = false;
-
- void init(int numParticles){
-
- mParticles = new ArrayList<>();
- // Create the particles
-
- for (int i = 0; i < numParticles; i++) {
- float angle = (random.nextInt(360)) ;
- angle = angle * 3.14f / 180.f;
- float speed = (random.nextInt(20)+1);
-
- PointF direction;
-
- direction = new PointF((float)Math.cos(angle) * speed,
- (float)Math.sin(angle) * speed);
-
- mParticles.add(new Particle(direction));
- }
- }
-
- void update(long fps){
- mDuration -= (1f/fps);
-
- for(Particle p : mParticles){
- p.update(fps);
- }
-
- if (mDuration < 0)
- {
- mIsRunning = false;
- }
- }
-
- void emitParticles(PointF startPosition){
-
- mIsRunning = true;
- mDuration = 1f;
-
- for(Particle p : mParticles){
- p.setPosition(startPosition);
- }
-
- }
-
- void draw(Canvas canvas, Paint paint){
-
- for (Particle p : mParticles) {
-
- paint.setARGB(255, random.nextInt(256),
- random.nextInt(256),
- random.nextInt(256));
-
- // Uncomment the next line to have plain white particles
- //paint.setColor(Color.argb(255,255,255,255));
- canvas.drawRect(p.getPosition().x, p.getPosition().y,
- p.getPosition().x+25,
- p.getPosition().y+25, paint);
- }
- }
-
-
-}
diff --git a/Chapter19/java/PhysicsEngine.java b/Chapter19/java/PhysicsEngine.java
deleted file mode 100644
index d401938..0000000
--- a/Chapter19/java/PhysicsEngine.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-class PhysicsEngine {
-
- // This signature and much more will change later in the project
- boolean update(long fps, ParticleSystem ps){
-
- if(ps.mIsRunning){
- ps.update(fps);
- }
-
- return false;
- }
-
- // Collision detection will go here
-
-}
diff --git a/Chapter19/java/Renderer.java b/Chapter19/java/Renderer.java
deleted file mode 100644
index d3f8238..0000000
--- a/Chapter19/java/Renderer.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-class Renderer {
- private Canvas mCanvas;
- private SurfaceHolder mSurfaceHolder;
- private Paint mPaint;
-
- Renderer(SurfaceView sh){
- mSurfaceHolder = sh.getHolder();
- mPaint = new Paint();
- }
-
- void draw(GameState gs, HUD hud, ParticleSystem ps) {
- if (mSurfaceHolder.getSurface().isValid()) {
- mCanvas = mSurfaceHolder.lockCanvas();
- mCanvas.drawColor(Color.argb(255, 0, 0, 0));
-
- if (gs.getDrawing()) {
- // Draw all the game objects here
- }
-
- if(gs.getGameOver()) {
- // Draw a background graphic here
- }
-
- // Draw a particle system explosion here
- if(ps.mIsRunning){
- ps.draw(mCanvas, mPaint);
- }
-
- // Now we draw the HUD on top of everything else
- hud.draw(mCanvas, mPaint, gs);
-
- mSurfaceHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-}
diff --git a/Chapter19/java/SoundEngine.java b/Chapter19/java/SoundEngine.java
deleted file mode 100644
index 50843b5..0000000
--- a/Chapter19/java/SoundEngine.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-
-import java.io.IOException;
-
-class SoundEngine {
- // for playing sound effects
- private SoundPool mSP;
- private int mShoot_ID = -1;
- private int mAlien_Explode_ID = -1;
- private int mPlayer_explode_ID = -1;
-
-
- SoundEngine(Context c){
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
- try {
- AssetManager assetManager = c.getAssets();
- AssetFileDescriptor descriptor;
-
- // Prepare the sounds in memory
- descriptor = assetManager.openFd("shoot.ogg");
- mShoot_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("alien_explosion.ogg");
- mAlien_Explode_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("player_explosion.ogg");
- mPlayer_explode_ID = mSP.load(descriptor, 0);
-
- } catch (IOException e) {
- // Error
- }
-
- }
-
- void playShoot(){
- mSP.play(mShoot_ID,1, 1, 0, 0, 1);
- }
-
- void playAlienExplode(){
- mSP.play(mAlien_Explode_ID,1, 1, 0, 0, 1);
- }
-
- void playPlayerExplode(){
- mSP.play(mPlayer_explode_ID,1, 1, 0, 0, 1);
- }
-}
diff --git a/Chapter19/java/UIController.java b/Chapter19/java/UIController.java
deleted file mode 100644
index 93aec91..0000000
--- a/Chapter19/java/UIController.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.gamecodeschool.c19scrollingshooter;
-
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-class UIController implements InputObserver {
-
-
- public UIController(GameEngineBroadcaster b){
- b.addObserver(this);
-
- }
-
- @Override
- public void handleInput(MotionEvent event, GameState gameState, ArrayList buttons) {
-
- int i = event.getActionIndex();
- int x = (int) event.getX(i);
- int y = (int) event.getY(i);
-
- int eventType = event.getAction() & MotionEvent.ACTION_MASK;
-
- if(eventType == MotionEvent.ACTION_UP ||
- eventType == MotionEvent.ACTION_POINTER_UP) {
-
-
- if (buttons.get(HUD.PAUSE).contains(x, y)){
- // Player pressed the pause button
- // Respond differently depending upon the game's state
-
- // If the game is not paused
- if (!gameState.getPaused()) {
- // Pause the game
- gameState.pause();
- }
-
- // If game is over start a new game
- else if (gameState.getGameOver()) {
-
- gameState.startNewGame();
- }
-
- // Paused and not game over
- else if (gameState.getPaused()
- && !gameState.getGameOver()) {
-
- gameState.resume();
- }
- }
-
-
- }
-
- }
-
-}
diff --git a/Chapter20/AndroidManifest.xml b/Chapter20/AndroidManifest.xml
deleted file mode 100644
index bf09c93..0000000
--- a/Chapter20/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter20/assets/alien_explosion.ogg b/Chapter20/assets/alien_explosion.ogg
deleted file mode 100644
index cfb3087..0000000
Binary files a/Chapter20/assets/alien_explosion.ogg and /dev/null differ
diff --git a/Chapter20/assets/player_explosion.ogg b/Chapter20/assets/player_explosion.ogg
deleted file mode 100644
index 6463b70..0000000
Binary files a/Chapter20/assets/player_explosion.ogg and /dev/null differ
diff --git a/Chapter20/assets/shoot.ogg b/Chapter20/assets/shoot.ogg
deleted file mode 100644
index 6a051ed..0000000
Binary files a/Chapter20/assets/shoot.ogg and /dev/null differ
diff --git a/Chapter20/drawable/alien_laser.png b/Chapter20/drawable/alien_laser.png
deleted file mode 100644
index 2f0048e..0000000
Binary files a/Chapter20/drawable/alien_laser.png and /dev/null differ
diff --git a/Chapter20/drawable/alien_ship1.png b/Chapter20/drawable/alien_ship1.png
deleted file mode 100644
index 14c30dc..0000000
Binary files a/Chapter20/drawable/alien_ship1.png and /dev/null differ
diff --git a/Chapter20/drawable/alien_ship2.png b/Chapter20/drawable/alien_ship2.png
deleted file mode 100644
index ac86083..0000000
Binary files a/Chapter20/drawable/alien_ship2.png and /dev/null differ
diff --git a/Chapter20/drawable/alien_ship3.png b/Chapter20/drawable/alien_ship3.png
deleted file mode 100644
index 4a05e06..0000000
Binary files a/Chapter20/drawable/alien_ship3.png and /dev/null differ
diff --git a/Chapter20/drawable/background.png b/Chapter20/drawable/background.png
deleted file mode 100644
index 7469d2b..0000000
Binary files a/Chapter20/drawable/background.png and /dev/null differ
diff --git a/Chapter20/drawable/player_laser.png b/Chapter20/drawable/player_laser.png
deleted file mode 100644
index 092da9f..0000000
Binary files a/Chapter20/drawable/player_laser.png and /dev/null differ
diff --git a/Chapter20/drawable/player_ship.png b/Chapter20/drawable/player_ship.png
deleted file mode 100644
index 9e9bcb7..0000000
Binary files a/Chapter20/drawable/player_ship.png and /dev/null differ
diff --git a/Chapter20/java/AlienChaseSpec.java b/Chapter20/java/AlienChaseSpec.java
deleted file mode 100644
index 79df4fa..0000000
--- a/Chapter20/java/AlienChaseSpec.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.PointF;
-
-class AlienChaseSpec extends ObjectSpec {
- // This is all the unique specifications for a alien that chases the player
- private static final String tag = "Alien";
- private static final String bitmapName = "alien_ship1";
- private static final float speed = 4f;
- private static final PointF relativeScale = new PointF(15f, 15f);
- private static final String[] components = new String [] {
- "StdGraphicsComponent","AlienChaseMovementComponent", "AlienHorizontalSpawnComponent"};
-
- AlienChaseSpec(){
- super(tag, bitmapName, speed, relativeScale, components);
- }
-}
diff --git a/Chapter20/java/AlienDiverSpec.java b/Chapter20/java/AlienDiverSpec.java
deleted file mode 100644
index 4d0552f..0000000
--- a/Chapter20/java/AlienDiverSpec.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-
-import android.graphics.PointF;
-
-class AlienDiverSpec extends ObjectSpec {
- // This is all the unique specifications
- // for an alien that dives
- private static final String tag = "Alien";
- private static final String bitmapName = "alien_ship3";
- private static final float speed = 4f;
- private static final PointF relativeScale =
- new PointF(60f, 30f);
-
- private static final String[] components = new String [] {
- "StdGraphicsComponent",
- "AlienDiverMovementComponent",
- "AlienVerticalSpawnComponent"};
-
- AlienDiverSpec(){
- super(tag, bitmapName, speed, relativeScale, components);
- }
-}
diff --git a/Chapter20/java/AlienLaserSpec.java b/Chapter20/java/AlienLaserSpec.java
deleted file mode 100644
index c92122e..0000000
--- a/Chapter20/java/AlienLaserSpec.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.PointF;
-
-class AlienLaserSpec extends ObjectSpec {
- // This is all the unique specifications
- // for an alien laser
- private static final String tag = "Alien Laser";
- private static final String bitmapName = "alien_laser";
- private static final float speed = .75f;
- private static final PointF relativeScale =
- new PointF(14f, 160f);
-
- private static final String[] components = new String [] {
- "StdGraphicsComponent",
- "LaserMovementComponent",
- "LaserSpawnComponent"};
-
- AlienLaserSpec(){
- super(tag, bitmapName,
- speed, relativeScale,
- components);
- }
-}
diff --git a/Chapter20/java/AlienPatrolSpec.java b/Chapter20/java/AlienPatrolSpec.java
deleted file mode 100644
index abc7322..0000000
--- a/Chapter20/java/AlienPatrolSpec.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.PointF;
-
-class AlienPatrolSpec extends ObjectSpec {
- // This is all the unique specifications
- // for a patrolling alien
- private static final String tag = "Alien";
- private static final String bitmapName = "alien_ship2";
- private static final float speed = 5f;
- private static final PointF relativeScale =
- new PointF(15f, 15f);
-
- private static final String[] components = new String [] {
- "StdGraphicsComponent",
- "AlienPatrolMovementComponent",
- "AlienHorizontalSpawnComponent"};
-
- AlienPatrolSpec(){
- super(tag, bitmapName,
- speed, relativeScale,
- components);
- }
-}
diff --git a/Chapter20/java/BackgroundGraphicsComponent.java b/Chapter20/java/BackgroundGraphicsComponent.java
deleted file mode 100644
index d756b12..0000000
--- a/Chapter20/java/BackgroundGraphicsComponent.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-class BackgroundGraphicsComponent implements GraphicsComponent {
-
- private Bitmap mBitmap;
- private Bitmap mBitmapReversed;
-
- @Override
- public void initialize(Context c, ObjectSpec s, PointF objectSize) {
-
- // Make a resource id out of the string of the file name
- int resID = c.getResources().getIdentifier(s.getBitmapName(),
- "drawable", c.getPackageName());
-
- // Load the bitmap using the id
- mBitmap = BitmapFactory.decodeResource(c.getResources(), resID);
-
- // Resize the bitmap
- mBitmap = Bitmap
- .createScaledBitmap(mBitmap,
- (int)objectSize.x,
- (int)objectSize.y,
- false);
-
- // Create a mirror image of the bitmap
- Matrix matrix = new Matrix();
- matrix.setScale(-1, 1);
- mBitmapReversed = Bitmap
- .createBitmap(mBitmap,
- 0, 0,
- mBitmap.getWidth(),
- mBitmap.getHeight(),
- matrix, true);
- }
-
- @Override
- public void draw(Canvas canvas, Paint paint, Transform t) {
-
- int xClip = t.getXClip();
- int width = mBitmap.getWidth();
- int height = mBitmap.getHeight();
- int startY = 0;
- int endY = (int)t.getmScreenSize().y +20;
-
- // For the regular bitmap
- Rect fromRect1 = new Rect(0, 0, width - xClip, height);
- Rect toRect1 = new Rect(xClip, startY, width, endY);
-
- // For the reversed background
- Rect fromRect2 = new Rect(width - xClip, 0, width, height);
- Rect toRect2 = new Rect(0, startY, xClip, endY);
-
- //draw the two background bitmaps
-
- if (!t.getReversedFirst()) {
- canvas.drawBitmap(mBitmap, fromRect1, toRect1, paint);
- canvas.drawBitmap(mBitmapReversed, fromRect2, toRect2, paint);
- } else {
- canvas.drawBitmap(mBitmap, fromRect2, toRect2, paint);
- canvas.drawBitmap(mBitmapReversed, fromRect1, toRect1, paint);
- }
-
-
- }
-
-}
diff --git a/Chapter20/java/BackgroundMovementComponent.java b/Chapter20/java/BackgroundMovementComponent.java
deleted file mode 100644
index 720c130..0000000
--- a/Chapter20/java/BackgroundMovementComponent.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-class BackgroundMovementComponent implements MovementComponent {
- @Override
- public boolean move(long fps, Transform t, Transform playerTransform) {
-
- int currentXClip = t.getXClip();
-
- if(playerTransform.getFacingRight()) {
- currentXClip -= t.getSpeed() / fps;
- t.setXClip(currentXClip);
- }
- else {
- currentXClip += t.getSpeed() / fps;
- t.setXClip(currentXClip);
- }
-
- if (currentXClip >= t.getSize().x) {
- t.setXClip(0);
- t.flipReversedFirst();
- } else if (currentXClip <= 0) {
- t.setXClip((int)t.getSize().x);
- t.flipReversedFirst();
- }
-
- return true;
- }
-}
diff --git a/Chapter20/java/BackgroundSpawnComponent.java b/Chapter20/java/BackgroundSpawnComponent.java
deleted file mode 100644
index 6e019ea..0000000
--- a/Chapter20/java/BackgroundSpawnComponent.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-class BackgroundSpawnComponent implements SpawnComponent {
- @Override
- public void spawn(Transform playerLTransform, Transform t) {
- // Place the background in the top left corner
- t.setLocation(0f,0);
- }
-}
diff --git a/Chapter20/java/BackgroundSpec.java b/Chapter20/java/BackgroundSpec.java
deleted file mode 100644
index 971dac4..0000000
--- a/Chapter20/java/BackgroundSpec.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.PointF;
-
-class BackgroundSpec extends ObjectSpec {
- // This is all the unique specifications
- // for the background
- private static final String tag = "Background";
- private static final String bitmapName = "background";
- private static final float speed = 2f;
- private static final PointF relativeScale =
- new PointF(1f, 1f);
-
- private static final String[] components = new String [] {
- "BackgroundGraphicsComponent",
- "BackgroundMovementComponent",
- "BackgroundSpawnComponent"};
-
- BackgroundSpec() {
- super(tag, bitmapName,
- speed, relativeScale,
- components);
- }
-}
diff --git a/Chapter20/java/GameActivity.java b/Chapter20/java/GameActivity.java
deleted file mode 100644
index e45a30c..0000000
--- a/Chapter20/java/GameActivity.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class GameActivity extends Activity {
-
- GameEngine mGameEngine;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Display display = getWindowManager()
- .getDefaultDisplay();
-
- Point size = new Point();
- display.getSize(size);
- mGameEngine = new GameEngine(this, size);
- setContentView(mGameEngine);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mGameEngine.startThread();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mGameEngine.stopThread();
- }
-}
\ No newline at end of file
diff --git a/Chapter20/java/GameEngine.java b/Chapter20/java/GameEngine.java
deleted file mode 100644
index 50c01fd..0000000
--- a/Chapter20/java/GameEngine.java
+++ /dev/null
@@ -1,143 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Point;
-import android.graphics.PointF;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceView;
-
-import java.util.ArrayList;
-
-class GameEngine extends SurfaceView implements Runnable, GameStarter, GameEngineBroadcaster, PlayerLaserSpawner {
- private Thread mThread = null;
- private long mFPS;
-
- private ArrayList inputObservers = new ArrayList();
- UIController mUIController;
-
- private GameState mGameState;
- private SoundEngine mSoundEngine;
- HUD mHUD;
- Renderer mRenderer;
- ParticleSystem mParticleSystem;
- PhysicsEngine mPhysicsEngine;
- Level mLevel;
-
-
- public GameEngine(Context context, Point size) {
- super(context);
-
- mUIController = new UIController(this);
- mGameState = new GameState(this, context);
- mSoundEngine = new SoundEngine(context);
- mHUD = new HUD(size);
- mRenderer = new Renderer(this);
- mPhysicsEngine = new PhysicsEngine();
-
- mParticleSystem = new ParticleSystem();
- mParticleSystem.init(1000);
-
- mLevel = new Level(context,
- new PointF(size.x, size.y), this);
- }
-
- // For the game engine broadcaster interface
- public void addObserver(InputObserver o) {
-
- inputObservers.add(o);
- }
-
- public void deSpawnReSpawn() {
- // Eventually this will despawn
- // and then respawn all the game objects
- ArrayList objects = mLevel.getGameObjects();
-
- for(GameObject o : objects){
- o.setInactive();
- }
- objects.get(Level.PLAYER_INDEX).spawn(objects.get(Level.PLAYER_INDEX).getTransform());
- objects.get(Level.BACKGROUND_INDEX).spawn(objects.get(Level.PLAYER_INDEX).getTransform());
-
-
-
- }
-
- @Override
- public void run() {
- while (mGameState.getThreadRunning()) {
- long frameStartTime = System.currentTimeMillis();
- ArrayList objects = mLevel.getGameObjects();
-
- if (!mGameState.getPaused()) {
- // Update all the game objects here
- // in a new way
-
- // This call to update will eveolve with the project
- if(mPhysicsEngine.update(mFPS,objects, mGameState, mSoundEngine, mParticleSystem)){
- // Player hit
- deSpawnReSpawn();
- }
- }
-
- // Draw all the game objects here
- // in a new way
- mRenderer.draw(objects, mGameState, mHUD, mParticleSystem);
-
- // Measure the frames per second in the usual way
- long timeThisFrame = System.currentTimeMillis()
- - frameStartTime;
- if (timeThisFrame >= 1) {
- final int MILLIS_IN_SECOND = 1000;
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- // Handle the player's input here
- // But in a new way
- for (InputObserver o : inputObservers) {
- o.handleInput(motionEvent, mGameState, mHUD.getControls());
- }
-
-
-
- return true;
- }
-
- public void stopThread() {
- // New code here soon
- mGameState.stopEverything();
-
- try {
- mThread.join();
- } catch (InterruptedException e) {
- Log.e("Exception","stopThread()" + e.getMessage());
- }
- }
-
- public void startThread() {
- // New code here soon
- mGameState.startThread();
-
- mThread = new Thread(this);
- mThread.start();
- }
-
- @Override
- public boolean spawnPlayerLaser(Transform transform) {
- ArrayList objects = mLevel.getGameObjects();
- if (objects.get(Level.mNextPlayerLaser).spawn(transform)) {
- Level.mNextPlayerLaser++;
- mSoundEngine.playShoot();
- if (Level.mNextPlayerLaser == Level.LAST_PLAYER_LASER + 1) {
- // Just used the last laser
- Level.mNextPlayerLaser = Level.FIRST_PLAYER_LASER;
-
- }
- }
- return true;
- }
-}
diff --git a/Chapter20/java/GameEngineBroadcaster.java b/Chapter20/java/GameEngineBroadcaster.java
deleted file mode 100644
index 9103cb7..0000000
--- a/Chapter20/java/GameEngineBroadcaster.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-interface GameEngineBroadcaster {
-
- void addObserver(InputObserver o);
-}
diff --git a/Chapter20/java/GameObject.java b/Chapter20/java/GameObject.java
deleted file mode 100644
index e1256c0..0000000
--- a/Chapter20/java/GameObject.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-class GameObject {
-
- private Transform mTransform;
- private boolean isActive = false;
- private String mTag;
-
- private GraphicsComponent graphicsComponent;
- private MovementComponent movementComponent;
- private SpawnComponent spawnComponent;
-
- void setSpawner(SpawnComponent s) {
- spawnComponent = s;
- }
-
- void setGraphics(GraphicsComponent g, Context c,
- ObjectSpec spec, PointF objectSize) {
-
- graphicsComponent = g;
- g.initialize(c, spec, objectSize);
- }
-
- void setMovement(MovementComponent m) {
- movementComponent = m;
- }
-
- void setInput(InputComponent s) {
- s.setTransform(mTransform);
- }
-
- void setmTag(String tag) {
- mTag = tag;
- }
-
- void setTransform(Transform t) {
- mTransform = t;
- }
-
- void draw(Canvas canvas, Paint paint) {
- graphicsComponent.draw(canvas, paint, mTransform);
- }
-
- void update(long fps, Transform playerTransform) {
- if (!(movementComponent.move(fps,
- mTransform, playerTransform))) {
- // Component returned false
- isActive = false;
- }
- }
-
- boolean checkActive() {
- return isActive;
- }
-
- String getTag() {
- return mTag;
- }
-
- void setInactive() {
- isActive = false;
- }
-
- boolean spawn(Transform playerTransform) {
- // Only spawnComponent if not already active
- if (!isActive) {
- spawnComponent.spawn(playerTransform, mTransform);
- isActive = true;
- return true;
- }
- return false;
- }
-
- Transform getTransform() {
- return mTransform;
- }
-}
diff --git a/Chapter20/java/GameObjectFactory.java b/Chapter20/java/GameObjectFactory.java
deleted file mode 100644
index 5ecca2b..0000000
--- a/Chapter20/java/GameObjectFactory.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.content.Context;
-import android.graphics.PointF;
-
-class GameObjectFactory {
- private Context mContext;
- private PointF mScreenSize;
- private GameEngine mGameEngineReference;
-
- GameObjectFactory(Context c, PointF screenSize,
- GameEngine gameEngine) {
-
- this.mContext = c;
- this.mScreenSize = screenSize;
- mGameEngineReference = gameEngine;
- }
-
- GameObject create(ObjectSpec spec) {
- GameObject object = new GameObject();
-
- int mNumComponents = spec.getComponents().length;
-
- final float HIDDEN = -2000f;
-
- object.setmTag(spec.getTag());
-
- // Configure the speed relative to the screen size
- float mSpeed = mScreenSize.x / spec.getSpeed();
-
- // Configure the object size relative to screen size
- PointF objectSize =
- new PointF(mScreenSize.x / spec.getScale().x,
- mScreenSize.y / spec.getScale().y);
-
- // Set the location to somewhere off-screen
- PointF mLocation = new PointF(HIDDEN, HIDDEN);
-
- object.setTransform(new Transform(mSpeed, objectSize.x,
- objectSize.y, mLocation, mScreenSize));
-
- // Loop through and add/initialize all the components
- for (int i = 0; i < mNumComponents; i++) {
- switch (spec.getComponents()[i]) {
- case "PlayerInputComponent":
- object.setInput(new PlayerInputComponent
- (mGameEngineReference));
- break;
- case "StdGraphicsComponent":
- object.setGraphics(new StdGraphicsComponent(),
- mContext, spec, objectSize);
- break;
- case "PlayerMovementComponent":
- object.setMovement(new PlayerMovementComponent());
- break;
- case "LaserMovementComponent":
- object.setMovement(new LaserMovementComponent());
- break;
- case "PlayerSpawnComponent":
- object.setSpawner(new PlayerSpawnComponent());
- break;
- case "LaserSpawnComponent":
- object.setSpawner(new LaserSpawnComponent());
- break;
- case "BackgroundGraphicsComponent":
- object.setGraphics(new BackgroundGraphicsComponent(),
- mContext, spec, objectSize);
- break;
- case "BackgroundMovementComponent":
- object.setMovement(new BackgroundMovementComponent());
- break;
- case "BackgroundSpawnComponent":
- object.setSpawner(new BackgroundSpawnComponent());
- break;
-
- default:
- // Error unidentified component
- break;
- }
- }
- // Return the completed GameObject to the Level class
- return object;
- }
-}
diff --git a/Chapter20/java/GameStarter.java b/Chapter20/java/GameStarter.java
deleted file mode 100644
index f2d4511..0000000
--- a/Chapter20/java/GameStarter.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-interface GameStarter {
- // This allows the State class to
- // spawn and despawn objects via the game engine
- public void deSpawnReSpawn();
-}
diff --git a/Chapter20/java/GameState.java b/Chapter20/java/GameState.java
deleted file mode 100644
index a5424c7..0000000
--- a/Chapter20/java/GameState.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-
-final class GameState {
- private static volatile boolean mThreadRunning = false;
- private static volatile boolean mPaused = true;
- private static volatile boolean mGameOver = true;
- private static volatile boolean mDrawing = false;
-
- // This object will have access to the deSpawnReSpawn method
- // in GameEngine- once it is initialized
- private static GameStarter gameStarter;
-
- private int mScore;
- private int mHighScore;
- private int mNumShips;
-
- // This is how we will make all the high scores persist
- private SharedPreferences.Editor mEditor;
-
- GameState(GameStarter gs, Context context){
- // This initializes the gameStarter reference
- gameStarter = gs;
-
- // Get the current high score
- SharedPreferences prefs;
- prefs = context.getSharedPreferences("HiScore",
- Context.MODE_PRIVATE);
-
- // Initialize the mEditor ready
- mEditor = prefs.edit();
-
- // Load high score from a entry in the file
- // labeled "hiscore"
- // if not available highscore set to zero 0
- mHighScore = prefs.getInt("hi_score", 0);
- }
-
- private void endGame(){
- mGameOver = true;
- mPaused = true;
- if(mScore > mHighScore){
- mHighScore = mScore;
- // Save high score
- mEditor.putInt("hi_score", mHighScore);
- mEditor.commit();
- }
- }
-
- void startNewGame(){
- mScore = 0;
- mNumShips = 3;
- // Don'mTransform want to be drawing objects while deSpawnReSpawn is
- // clearing ArrayList and filling it up again
- stopDrawing();
- gameStarter.deSpawnReSpawn();
- resume();
-
- // Now we can draw again
- startDrawing();
- }
-
- void loseLife(SoundEngine se){
- mNumShips--;
- se.playPlayerExplode();
- if(mNumShips == 0){
- pause();
- endGame();
- }
- }
-
-
-
- int getNumShips(){
- return mNumShips;
- }
-
- void increaseScore(){
- mScore++;
- }
-
- int getScore(){
- return mScore;
- }
-
- int getHighScore(){
- return mHighScore;
- }
-
- void pause(){
- mPaused = true;
- }
-
- void resume(){
- mGameOver = false;
- mPaused = false;
- }
-
- void stopEverything(){
- mPaused = true;
- mGameOver = true;
- mThreadRunning = false;
- }
-
- boolean getThreadRunning(){
- return mThreadRunning;
- }
-
- void startThread(){
- mThreadRunning = true;
- }
-
- private void stopDrawing(){
- mDrawing = false;
- }
-
- private void startDrawing(){
- mDrawing = true;
- }
-
- boolean getDrawing() {return mDrawing;}
-
- boolean getPaused(){
- return mPaused;
- }
-
- boolean getGameOver(){
- return mGameOver;
- }
-
-}
diff --git a/Chapter20/java/GraphicsComponent.java b/Chapter20/java/GraphicsComponent.java
deleted file mode 100644
index fc09468..0000000
--- a/Chapter20/java/GraphicsComponent.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-interface GraphicsComponent {
-
- void initialize(Context c,
- ObjectSpec s,
- PointF screensize);
-
- void draw(Canvas canvas,
- Paint paint,
- Transform t);
-}
diff --git a/Chapter20/java/HUD.java b/Chapter20/java/HUD.java
deleted file mode 100644
index 3938dab..0000000
--- a/Chapter20/java/HUD.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.graphics.Rect;
-
-import java.util.ArrayList;
-
-class HUD {
- private int mTextFormatting;
- private int mScreenHeight;
- private int mScreenWidth;
-
- private ArrayList controls;
-
- static int UP = 0;
- static int DOWN = 1;
- static int FLIP = 2;
- static int SHOOT = 3;
- static int PAUSE = 4;
-
- HUD(Point size){
- mScreenHeight = size.y;
- mScreenWidth = size.x;
- mTextFormatting = size.x / 50;
-
- prepareControls();
- }
-
- private void prepareControls(){
- int buttonWidth = mScreenWidth / 14;
- int buttonHeight = mScreenHeight / 12;
- int buttonPadding = mScreenWidth / 90;
-
- Rect up = new Rect(
- buttonPadding,
- mScreenHeight - (buttonHeight * 2) - (buttonPadding * 2),
- buttonWidth + buttonPadding,
- mScreenHeight - buttonHeight - (buttonPadding *2) );
-
- Rect down = new Rect(
- buttonPadding,
- mScreenHeight - buttonHeight - buttonPadding,
- buttonWidth + buttonPadding,
- mScreenHeight - buttonPadding);
-
- Rect flip = new Rect(mScreenWidth - buttonPadding - buttonWidth,
- mScreenHeight - buttonHeight - buttonPadding,
- mScreenWidth - buttonPadding,
- mScreenHeight - buttonPadding
-
- );
-
- Rect shoot = new Rect(mScreenWidth - buttonPadding - buttonWidth,
- mScreenHeight - (buttonHeight * 2) - (buttonPadding * 2),
- mScreenWidth - buttonPadding,
- mScreenHeight - buttonHeight - (buttonPadding *2)
- );
-
- Rect pause = new Rect(
- mScreenWidth - buttonPadding - buttonWidth,
- buttonPadding,
- mScreenWidth - buttonPadding,
- buttonPadding + buttonHeight);
-
- controls = new ArrayList<>();
- controls.add(UP,up);
- controls.add(DOWN,down);
- controls.add(FLIP, flip);
- controls.add(SHOOT, shoot);
- controls.add(PAUSE, pause);
- }
-
- void draw(Canvas c, Paint p, GameState gs){
-
- // Draw the HUD
- p.setColor(Color.argb(255,255,255,255));
- p.setTextSize(mTextFormatting);
- c.drawText("Hi: " + gs.getHighScore(), mTextFormatting,mTextFormatting,p);
- c.drawText("Scrore: " + gs.getScore(), mTextFormatting,mTextFormatting * 2,p);
- c.drawText("Lives: " + gs.getNumShips(), mTextFormatting,mTextFormatting * 3,p);
-
- if(gs.getGameOver()){
- p.setTextSize(mTextFormatting * 5);
- c.drawText("PRESS PLAY", mScreenWidth /4, mScreenHeight /2 ,p);
- }
-
- if(gs.getPaused() && !gs.getGameOver()){
- p.setTextSize(mTextFormatting * 5);
- c.drawText("PAUSED", mScreenWidth /3, mScreenHeight /2 ,p);
- }
- drawControls(c, p);
- }
-
- private void drawControls(Canvas c, Paint p){
- p.setColor(Color.argb(100,255,255,255));
-
- for(Rect r : controls){
- c.drawRect(r.left, r.top, r.right, r.bottom, p);
- }
-
- // Set the colors back
- p.setColor(Color.argb(255,255,255,255));
- }
- ArrayList getControls(){
- return controls;
- }
-}
diff --git a/Chapter20/java/InputComponent.java b/Chapter20/java/InputComponent.java
deleted file mode 100644
index e263399..0000000
--- a/Chapter20/java/InputComponent.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-interface InputComponent {
-
- void setTransform(Transform t);
-}
diff --git a/Chapter20/java/InputObserver.java b/Chapter20/java/InputObserver.java
deleted file mode 100644
index b3c1096..0000000
--- a/Chapter20/java/InputObserver.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-interface InputObserver {
-
- void handleInput(MotionEvent event, GameState gs, ArrayList controls);
-}
diff --git a/Chapter20/java/LaserMovementComponent.java b/Chapter20/java/LaserMovementComponent.java
deleted file mode 100644
index d1f9d78..0000000
--- a/Chapter20/java/LaserMovementComponent.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.PointF;
-
-class LaserMovementComponent implements MovementComponent {
-
- @Override
- public boolean move(long fps, Transform t, Transform playerTransform) {
-
- // Laser can only travel two screen widths
- float range = t.getmScreenSize().x * 2;
-
- // Where is the laser
- PointF location = t.getLocation();
-
- // How fast is it going
- float speed = t.getSpeed();
-
- if(t.headingRight()){
- location.x += speed / fps;
- }
- else if(t.headingLeft()){
- location.x -= speed / fps;
- }
-
- // Has the laser gone out of range
- if(location.x < - range || location.x > range){
- // disable the laser
- return false;
- }
-
- t.updateCollider();
- return true;
- }
-}
diff --git a/Chapter20/java/LaserSpawnComponent.java b/Chapter20/java/LaserSpawnComponent.java
deleted file mode 100644
index 303ac7b..0000000
--- a/Chapter20/java/LaserSpawnComponent.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.PointF;
-
-class LaserSpawnComponent implements SpawnComponent {
- @Override
- public void spawn(Transform playerTransform, Transform t) {
-
- PointF startPosition =
- playerTransform.getFiringLocation(t.getSize().x);
-
- t.setLocation((int)startPosition.x, (int)startPosition.y);
-
- if(playerTransform.getFacingRight()){
- t.headRight();
- }
- else{
- t.headLeft();
- }
-
- }
-}
diff --git a/Chapter20/java/Level.java b/Chapter20/java/Level.java
deleted file mode 100644
index 13dc974..0000000
--- a/Chapter20/java/Level.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.content.Context;
-import android.graphics.PointF;
-
-import java.util.ArrayList;
-
-class Level {
-
- // Keep track of specific types
- public static final int BACKGROUND_INDEX = 0;
- public static final int PLAYER_INDEX = 1;
- public static final int FIRST_PLAYER_LASER = 2;
- public static final int LAST_PLAYER_LASER = 4;
- public static int mNextPlayerLaser;
- public static final int FIRST_ALIEN = 5;
- public static final int SECOND_ALIEN = 6;
- public static final int THIRD_ALIEN = 7;
- public static final int FOURTH_ALIEN = 8;
- public static final int FIFTH_ALIEN = 9;
- public static final int SIXTH_ALIEN = 10;
- public static final int LAST_ALIEN = 10;
- public static final int FIRST_ALIEN_LASER = 11;
- public static final int LAST_ALIEN_LASER = 15;
- public static int mNextAlienLaser;
-
- // This will hold all the instances of GameObject
- private ArrayList objects;
-
- public Level(Context context,
- PointF mScreenSize,
- GameEngine ge){
-
- objects = new ArrayList<>();
- GameObjectFactory factory = new GameObjectFactory(
- context, mScreenSize, ge);
-
- buildGameObjects(factory);
- }
-
- ArrayList buildGameObjects(
- GameObjectFactory factory){
-
- objects.clear();
- objects.add(BACKGROUND_INDEX, factory.create(new BackgroundSpec()));
- objects.add(PLAYER_INDEX, factory.create(new PlayerSpec()));
-
- // Spawn the player's lasers
- for (int i = FIRST_PLAYER_LASER; i != LAST_PLAYER_LASER + 1; i++) {
- objects.add(i, factory.create(new PlayerLaserSpec()));
- }
-
- mNextPlayerLaser = FIRST_PLAYER_LASER;
-
- // Create some aliens
-
- // Create some alien lasers
-
- return objects;
- }
-
- ArrayList getGameObjects(){
- return objects;
- }
-
-
-}
diff --git a/Chapter20/java/MovementComponent.java b/Chapter20/java/MovementComponent.java
deleted file mode 100644
index 6baea1d..0000000
--- a/Chapter20/java/MovementComponent.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-interface MovementComponent {
-
- boolean move(long fps,
- Transform t,
- Transform playerTransform);
-}
diff --git a/Chapter20/java/ObjectSpec.java b/Chapter20/java/ObjectSpec.java
deleted file mode 100644
index a25cdb0..0000000
--- a/Chapter20/java/ObjectSpec.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.PointF;
-
-abstract class ObjectSpec {
- private String mTag;
- private String mBitmapName;
- private float mSpeed;
- private PointF mSizeScale;
- private String[] mComponents;
-
- ObjectSpec(String tag, String bitmapName, float speed, PointF relativeScale, String[] components) {
- mTag = tag;
- mBitmapName = bitmapName;
- mSpeed = speed;
- mSizeScale = relativeScale;
- mComponents = components;
- }
-
- String getTag() {
- return mTag;
- }
-
- String getBitmapName() {
- return mBitmapName;
- }
-
- float getSpeed() {
- return mSpeed;
- }
-
- PointF getScale() {
- return mSizeScale;
- }
-
- String[] getComponents() {
- return mComponents;
- }
-}
diff --git a/Chapter20/java/Particle.java b/Chapter20/java/Particle.java
deleted file mode 100644
index f9b471c..0000000
--- a/Chapter20/java/Particle.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.PointF;
-
-class Particle {
-
- PointF mVelocity;
- PointF mPosition;
-
- Particle(PointF direction)
- {
- mVelocity = new PointF();
- mPosition = new PointF();
-
- // Determine the direction
- mVelocity.x = direction.x;
- mVelocity.y = direction.y;
- }
-
- void update(float fps)
- {
- // Move the particle
- mPosition.x += mVelocity.x;
- mPosition.y += mVelocity.y;
- }
-
- void setPosition(PointF position)
- {
- mPosition.x = position.x;
- mPosition.y = position.y;
- }
-
- PointF getPosition()
- {
- return mPosition;
- }
-}
diff --git a/Chapter20/java/ParticleSystem.java b/Chapter20/java/ParticleSystem.java
deleted file mode 100644
index fe7aeab..0000000
--- a/Chapter20/java/ParticleSystem.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-import java.util.ArrayList;
-import java.util.Random;
-
-class ParticleSystem {
-
- float mDuration;
-
- ArrayList mParticles;
- Random random = new Random();
- boolean mIsRunning = false;
-
- void init(int numParticles){
-
- mParticles = new ArrayList<>();
- // Create the particles
-
- for (int i = 0; i < numParticles; i++) {
- float angle = (random.nextInt(360)) ;
- angle = angle * 3.14f / 180.f;
- float speed = (random.nextInt(20)+1);
-
- PointF direction;
-
- direction = new PointF((float)Math.cos(angle) * speed,
- (float)Math.sin(angle) * speed);
-
- mParticles.add(new Particle(direction));
- }
- }
-
- void update(long fps){
- mDuration -= (1f/fps);
-
- for(Particle p : mParticles){
- p.update(fps);
- }
-
- if (mDuration < 0)
- {
- mIsRunning = false;
- }
- }
-
- void emitParticles(PointF startPosition){
-
- mIsRunning = true;
- mDuration = 1f;
-
- for(Particle p : mParticles){
- p.setPosition(startPosition);
- }
-
- }
-
- void draw(Canvas canvas, Paint paint){
-
- for (Particle p : mParticles) {
-
- paint.setARGB(255, random.nextInt(256),
- random.nextInt(256),
- random.nextInt(256));
-
- // Uncomment the next line to have plain white particles
- //paint.setColor(Color.argb(255,255,255,255));
- canvas.drawRect(p.getPosition().x, p.getPosition().y,
- p.getPosition().x+25,
- p.getPosition().y+25, paint);
- }
- }
-
-
-}
diff --git a/Chapter20/java/PhysicsEngine.java b/Chapter20/java/PhysicsEngine.java
deleted file mode 100644
index 3918d2f..0000000
--- a/Chapter20/java/PhysicsEngine.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import java.util.ArrayList;
-
-class PhysicsEngine {
- // This signature and much more will change later in the project
- boolean update(long fps, ArrayList objects,
- GameState gs, SoundEngine se,
- ParticleSystem ps){
-
- // Update all the game objects
- for (GameObject object : objects) {
- if (object.checkActive()) {
- object.update(fps, objects
- .get(Level.PLAYER_INDEX).getTransform());
- }
- }
-
- if(ps.mIsRunning){
- ps.update(fps);
- }
-
- return false;
- }
- // Collision detection will go here
-}
diff --git a/Chapter20/java/PlayerInputComponent.java b/Chapter20/java/PlayerInputComponent.java
deleted file mode 100644
index 13f451c..0000000
--- a/Chapter20/java/PlayerInputComponent.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-class PlayerInputComponent implements InputComponent, InputObserver {
-
- private Transform mTransform;
- private PlayerLaserSpawner mPLS;
-
- PlayerInputComponent(GameEngine ger) {
- ger.addObserver(this);
- mPLS = ger;
- }
-
- @Override
- public void setTransform(Transform transform) {
- mTransform = transform;
- }
-
- // Required method of InputObserver interface called from the onTouchEvent method
- @Override
- public void handleInput(MotionEvent event, GameState gameState, ArrayList buttons) {
- // In each MotionEvent object, every active pointer is present. Therefore looping through them all for an event on only one of them is obviously wrong.
- // The getActionIndex returns the index in the array of the pointer that performed/trigged the action/method call. So using getX(i) and getY(i) only gets a true result
- // on the button that was actually pressed/removed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- int i = event.getActionIndex();
- int x = (int) event.getX(i);
- int y = (int) event.getY(i);
-
- switch (event.getAction() & MotionEvent.ACTION_MASK) {
-
- case MotionEvent.ACTION_UP:
- if (buttons.get(HUD.UP).contains(x,y)
- || buttons.get(HUD.DOWN).contains(x,y)) {
-
- // Player has released either up or down
- mTransform.stopVertical();
- }
- break;
-
- case MotionEvent.ACTION_DOWN:
- if (buttons.get(HUD.UP).contains(x,y)) {
- // Player has pressed up
- mTransform.headUp();
- } else if (buttons.get(HUD.DOWN).contains(x,y)) {
- // Player has pressed down
- mTransform.headDown();
- } else if (buttons.get(HUD.FLIP).contains(x,y)) {
- // Player has released the flip button
- mTransform.flip();
- } else if (buttons.get(HUD.SHOOT).contains(x,y)) {
- mPLS.spawnPlayerLaser(mTransform);
- }
- break;
-
- case MotionEvent.ACTION_POINTER_UP:
- if (buttons.get(HUD.UP).contains(x, y)
- || buttons.get(HUD.DOWN).contains(x, y)) {
- // Player has released either up or down
- mTransform.stopVertical();
- }
- break;
-
- case MotionEvent.ACTION_POINTER_DOWN:
- if (buttons.get(HUD.UP).contains(x, y)) {
- // Player has pressed up
- mTransform.headUp();
- } else if (buttons.get(HUD.DOWN).contains(x, y)) {
- // Player has pressed down
- mTransform.headDown();
- } else if (buttons.get(HUD.FLIP).contains(x, y)) {
- // Player has released the flip button
- mTransform.flip();
- } else if (buttons.get(HUD.SHOOT).contains(x, y)) {
- mPLS.spawnPlayerLaser(mTransform);
- }
- break;
- }
- }
-}
diff --git a/Chapter20/java/PlayerLaserSpawner.java b/Chapter20/java/PlayerLaserSpawner.java
deleted file mode 100644
index 8852ee7..0000000
--- a/Chapter20/java/PlayerLaserSpawner.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-public interface PlayerLaserSpawner {
- boolean spawnPlayerLaser(Transform transform);
-}
diff --git a/Chapter20/java/PlayerLaserSpec.java b/Chapter20/java/PlayerLaserSpec.java
deleted file mode 100644
index 275123d..0000000
--- a/Chapter20/java/PlayerLaserSpec.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-
-import android.graphics.PointF;
-
-class PlayerLaserSpec extends ObjectSpec {
- // This is all the unique specifications
- // for a player laser
- private static final String tag = "Player Laser";
- private static final String bitmapName = "player_laser";
- private static final float speed = .75f;
- private static final PointF relativeScale =
- new PointF(8f, 160f);
-
- private static final String[] components = new String [] {
- "StdGraphicsComponent",
- "LaserMovementComponent",
- "LaserSpawnComponent"};
-
- PlayerLaserSpec(){
- super(tag, bitmapName,
- speed, relativeScale,
- components);
- }
-}
diff --git a/Chapter20/java/PlayerMovementComponent.java b/Chapter20/java/PlayerMovementComponent.java
deleted file mode 100644
index 565b030..0000000
--- a/Chapter20/java/PlayerMovementComponent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.PointF;
-
-class PlayerMovementComponent implements MovementComponent {
- public boolean move(long fps, Transform t,
- Transform playerTransform){
-
- // How high is the screen?
- float screenHeight = t.getmScreenSize().y;
- // Where is the player?
- PointF location = t.getLocation();
- // How fast is it going
- float speed = t.getSpeed();
- // How tall is the ship
- float height = t.getObjectHeight();
-
- // Move the ship up or down if required
- if(t.headingDown()){
- location.y += speed / fps;
- }
- else if(t.headingUp()){
- location.y -= speed / fps;
- }
-
- // Make sure the ship can't go off the screen
- if(location.y > screenHeight - height){
- location.y = screenHeight - height;
- }
- else if(location.y < 0){
- location.y = 0;
- }
-
- // Update the collider
- t.updateCollider();
-
- return true;
- }
-}
diff --git a/Chapter20/java/PlayerSpawnComponent.java b/Chapter20/java/PlayerSpawnComponent.java
deleted file mode 100644
index 9da2969..0000000
--- a/Chapter20/java/PlayerSpawnComponent.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-
-class PlayerSpawnComponent implements SpawnComponent {
- @Override
- public void spawn(Transform playerTransform, Transform t) {
-
- // Spawn in the centre of the screen
- t.setLocation(
- t.getmScreenSize().x/2,
- t.getmScreenSize().y/2);
-
- }
-}
diff --git a/Chapter20/java/PlayerSpec.java b/Chapter20/java/PlayerSpec.java
deleted file mode 100644
index 8030242..0000000
--- a/Chapter20/java/PlayerSpec.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.PointF;
-
-class PlayerSpec extends ObjectSpec {
- // This is all the unique specifications
- // for a player
- private static final String tag = "Player";
- private static final String bitmapName = "player_ship";
- private static final float speed = 1f;
- private static final PointF relativeScale =
- new PointF(15f, 15f);
-
- private static final String[] components = new String [] {
- "PlayerInputComponent",
- "StdGraphicsComponent",
- "PlayerMovementComponent",
- "PlayerSpawnComponent"};
-
- PlayerSpec() {
- super(tag, bitmapName,
- speed, relativeScale,
- components);
- }
-}
diff --git a/Chapter20/java/Renderer.java b/Chapter20/java/Renderer.java
deleted file mode 100644
index 8789e94..0000000
--- a/Chapter20/java/Renderer.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-import java.util.ArrayList;
-
-class Renderer {
- private Canvas mCanvas;
- private SurfaceHolder mSurfaceHolder;
- private Paint mPaint;
-
- Renderer(SurfaceView sh){
- mSurfaceHolder = sh.getHolder();
- mPaint = new Paint();
- }
-
- void draw(ArrayList objects, GameState gs, HUD hud, ParticleSystem ps) {
- if (mSurfaceHolder.getSurface().isValid()) {
- mCanvas = mSurfaceHolder.lockCanvas();
- mCanvas.drawColor(Color.argb(255, 0, 0, 0));
-
- if (gs.getDrawing()) {
- // Draw all the game objects here
- for (GameObject object : objects) {
- if(object.checkActive()) {
- object.draw(mCanvas, mPaint);
- }
- }
- }
-
- if(gs.getGameOver()) {
- // Draw a background graphic here
- objects.get(Level.BACKGROUND_INDEX).draw(mCanvas, mPaint);
- }
-
- // Draw a particle system explosion here
- if(ps.mIsRunning){
- ps.draw(mCanvas, mPaint);
- }
-
- // Now we draw the HUD on top of everything else
- hud.draw(mCanvas, mPaint, gs);
-
- mSurfaceHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-}
diff --git a/Chapter20/java/SoundEngine.java b/Chapter20/java/SoundEngine.java
deleted file mode 100644
index 6a1ac52..0000000
--- a/Chapter20/java/SoundEngine.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-
-import java.io.IOException;
-
-class SoundEngine {
- // for playing sound effects
- private SoundPool mSP;
- private int mShoot_ID = -1;
- private int mAlien_Explode_ID = -1;
- private int mPlayer_explode_ID = -1;
-
-
- SoundEngine(Context c){
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
- try {
- AssetManager assetManager = c.getAssets();
- AssetFileDescriptor descriptor;
-
- // Prepare the sounds in memory
- descriptor = assetManager.openFd("shoot.ogg");
- mShoot_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("alien_explosion.ogg");
- mAlien_Explode_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("player_explosion.ogg");
- mPlayer_explode_ID = mSP.load(descriptor, 0);
-
- } catch (IOException e) {
- // Error
- }
-
- }
-
- void playShoot(){
- mSP.play(mShoot_ID,1, 1, 0, 0, 1);
- }
-
- void playAlienExplode(){
- mSP.play(mAlien_Explode_ID,1, 1, 0, 0, 1);
- }
-
- void playPlayerExplode(){
- mSP.play(mPlayer_explode_ID,1, 1, 0, 0, 1);
- }
-}
diff --git a/Chapter20/java/SpawnComponent.java b/Chapter20/java/SpawnComponent.java
deleted file mode 100644
index 0464baa..0000000
--- a/Chapter20/java/SpawnComponent.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-interface SpawnComponent {
-
- void spawn(Transform playerTransform,
- Transform t);
-}
diff --git a/Chapter20/java/StdGraphicsComponent.java b/Chapter20/java/StdGraphicsComponent.java
deleted file mode 100644
index 5848e33..0000000
--- a/Chapter20/java/StdGraphicsComponent.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-class StdGraphicsComponent implements GraphicsComponent {
-
- private Bitmap mBitmap;
- private Bitmap mBitmapReversed;
-
- @Override
- public void initialize(Context context,
- ObjectSpec spec,
- PointF objectSize){
-
- // Make a resource id out of the string of the file name
- int resID = context.getResources()
- .getIdentifier(spec.getBitmapName(),
- "drawable",
- context.getPackageName());
-
- // Load the bitmap using the id
- mBitmap = BitmapFactory.decodeResource(
- context.getResources(), resID);
-
- // Resize the bitmap
- mBitmap = Bitmap
- .createScaledBitmap(mBitmap,
- (int)objectSize.x,
- (int)objectSize.y,
- false);
-
- // Create a mirror image of the bitmap if required
- Matrix matrix = new Matrix();
- matrix.setScale(-1, 1);
- mBitmapReversed = Bitmap.createBitmap(mBitmap,
- 0, 0,
- mBitmap.getWidth(),
- mBitmap.getHeight(),
- matrix, true);
- }
-
- @Override
- public void draw(Canvas canvas, Paint paint, Transform t) {
- if(t.getFacingRight())
- canvas.drawBitmap(mBitmap,
- t.getLocation().x,
- t.getLocation().y,
- paint);
-
- else
- canvas.drawBitmap(mBitmapReversed,
- t.getLocation().x,
- t.getLocation().y,
- paint);
- }
-}
diff --git a/Chapter20/java/Transform.java b/Chapter20/java/Transform.java
deleted file mode 100644
index ba69dce..0000000
--- a/Chapter20/java/Transform.java
+++ /dev/null
@@ -1,165 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.PointF;
-import android.graphics.RectF;
-
-class Transform {
-
- // These two members are for scrolling background
- private int mXClip;
- private boolean mReversedFirst = false;
-
- private RectF mCollider;
- private PointF mLocation;
- private boolean mFacingRight = true;
- private boolean mHeadingUp = false;
- private boolean mHeadingDown = false;
- private boolean mHeadingLeft = false;
- private boolean mHeadingRight = false;
- private float mSpeed;
- private float mObjectHeight;
- private float mObjectWidth;
- private static PointF mScreenSize;
-
- Transform(float speed, float objectWidth,
- float objectHeight,
- PointF startingLocation,
- PointF screenSize){
-
- mCollider = new RectF();
- mSpeed = speed;
- mObjectHeight = objectHeight;
- mObjectWidth = objectWidth;
- mLocation = startingLocation;
- mScreenSize = screenSize;
- }
-
- boolean getReversedFirst(){
- return mReversedFirst;
- }
-
- void flipReversedFirst(){
- mReversedFirst = !mReversedFirst;
- }
-
- int getXClip(){
- return mXClip;
- }
-
- void setXClip(int newXClip){
- mXClip = newXClip;
- }
-
- PointF getmScreenSize(){
- return mScreenSize;
- }
-
-
- void headUp(){
- mHeadingUp = true;
- mHeadingDown = false;
-
- }
-
- void headDown(){
- mHeadingDown = true;
- mHeadingUp = false;
- }
-
- void headRight(){
- mHeadingRight = true;
- mHeadingLeft = false;
- mFacingRight = true;
- }
-
- void headLeft(){
- mHeadingLeft = true;
- mHeadingRight = false;
- mFacingRight = false;
- }
-
- boolean headingUp(){
- return mHeadingUp;
- }
-
- boolean headingDown(){
- return mHeadingDown;
- }
-
- boolean headingRight(){
- return mHeadingRight;
- }
-
- boolean headingLeft(){
- return mHeadingLeft;
- }
-
-
- void updateCollider(){
- // Pull the borders in a bit (10%)
- mCollider.top = mLocation.y + (mObjectHeight / 10);
- mCollider.left = mLocation.x + (mObjectWidth /10);
- mCollider.bottom = (mCollider.top + mObjectHeight)
- - mObjectHeight/10;
-
- mCollider.right = (mCollider.left + mObjectWidth)
- - mObjectWidth/10;
- }
-
- float getObjectHeight(){
- return mObjectHeight;
- }
-
- void stopVertical(){
- mHeadingDown = false;
- mHeadingUp = false;
- }
-
- float getSpeed(){
- return mSpeed;
- }
-
- void setLocation(float horizontal, float vertical){
- mLocation = new PointF(horizontal, vertical);
- updateCollider();
- }
-
-
- PointF getLocation() {
-
- return mLocation;
- }
-
- PointF getSize(){
- return new PointF((int)mObjectWidth,
- (int)mObjectHeight);
- }
-
- void flip(){
- mFacingRight = !mFacingRight;
- }
-
- boolean getFacingRight(){
- return mFacingRight;
- }
-
- RectF getCollider(){
- return mCollider;
- }
-
- PointF getFiringLocation(float laserLength){
- PointF mFiringLocation = new PointF();
-
- if(mFacingRight) {
- mFiringLocation.x = mLocation.x
- + (mObjectWidth / 8f);
- }else
- {
- mFiringLocation.x = mLocation.x
- + (mObjectWidth / 8f) - (laserLength);
- }
- // Move the height down a bit of ship height from origin
- mFiringLocation.y = mLocation.y + (mObjectHeight / 1.28f);
- return mFiringLocation;
- }
-}
diff --git a/Chapter20/java/UIController.java b/Chapter20/java/UIController.java
deleted file mode 100644
index 96d2f85..0000000
--- a/Chapter20/java/UIController.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.gamecodeschool.c20scrollingshooter;
-
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-class UIController implements InputObserver {
-
- public UIController(GameEngineBroadcaster b){
- b.addObserver(this);
- }
-
- @Override
- public void handleInput(MotionEvent event, GameState gameState, ArrayList buttons) {
-
- int i = event.getActionIndex();
- int x = (int) event.getX(i);
- int y = (int) event.getY(i);
-
- int eventType = event.getAction() & MotionEvent.ACTION_MASK;
-
- if(eventType == MotionEvent.ACTION_UP ||
- eventType == MotionEvent.ACTION_POINTER_UP) {
-
-
- if (buttons.get(HUD.PAUSE).contains(x, y)){
- // Player pressed the pause button
- // Respond differently depending upon the game's state
-
- // If the game is not paused
- if (!gameState.getPaused()) {
- // Pause the game
- gameState.pause();
- }
-
- // If game is over start a new game
- else if (gameState.getGameOver()) {
-
- gameState.startNewGame();
- }
-
- // Paused and not game over
- else if (gameState.getPaused()
- && !gameState.getGameOver()) {
-
- gameState.resume();
- }
- }
-
-
- }
-
- }
-
-}
diff --git a/Chapter21/AndroidManifest.xml b/Chapter21/AndroidManifest.xml
deleted file mode 100644
index 1382402..0000000
--- a/Chapter21/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter21/assets/alien_explosion.ogg b/Chapter21/assets/alien_explosion.ogg
deleted file mode 100644
index cfb3087..0000000
Binary files a/Chapter21/assets/alien_explosion.ogg and /dev/null differ
diff --git a/Chapter21/assets/player_explosion.ogg b/Chapter21/assets/player_explosion.ogg
deleted file mode 100644
index 6463b70..0000000
Binary files a/Chapter21/assets/player_explosion.ogg and /dev/null differ
diff --git a/Chapter21/assets/shoot.ogg b/Chapter21/assets/shoot.ogg
deleted file mode 100644
index 6a051ed..0000000
Binary files a/Chapter21/assets/shoot.ogg and /dev/null differ
diff --git a/Chapter21/drawable/alien_laser.png b/Chapter21/drawable/alien_laser.png
deleted file mode 100644
index 2f0048e..0000000
Binary files a/Chapter21/drawable/alien_laser.png and /dev/null differ
diff --git a/Chapter21/drawable/alien_ship1.png b/Chapter21/drawable/alien_ship1.png
deleted file mode 100644
index 14c30dc..0000000
Binary files a/Chapter21/drawable/alien_ship1.png and /dev/null differ
diff --git a/Chapter21/drawable/alien_ship2.png b/Chapter21/drawable/alien_ship2.png
deleted file mode 100644
index ac86083..0000000
Binary files a/Chapter21/drawable/alien_ship2.png and /dev/null differ
diff --git a/Chapter21/drawable/alien_ship3.png b/Chapter21/drawable/alien_ship3.png
deleted file mode 100644
index 4a05e06..0000000
Binary files a/Chapter21/drawable/alien_ship3.png and /dev/null differ
diff --git a/Chapter21/drawable/background.png b/Chapter21/drawable/background.png
deleted file mode 100644
index 7469d2b..0000000
Binary files a/Chapter21/drawable/background.png and /dev/null differ
diff --git a/Chapter21/drawable/player_laser.png b/Chapter21/drawable/player_laser.png
deleted file mode 100644
index 092da9f..0000000
Binary files a/Chapter21/drawable/player_laser.png and /dev/null differ
diff --git a/Chapter21/drawable/player_ship.png b/Chapter21/drawable/player_ship.png
deleted file mode 100644
index 9e9bcb7..0000000
Binary files a/Chapter21/drawable/player_ship.png and /dev/null differ
diff --git a/Chapter21/java/AlienChaseMovementComponent.java b/Chapter21/java/AlienChaseMovementComponent.java
deleted file mode 100644
index c685dab..0000000
--- a/Chapter21/java/AlienChaseMovementComponent.java
+++ /dev/null
@@ -1,131 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-import java.util.Random;
-
-class AlienChaseMovementComponent implements MovementComponent {
-
- private Random mShotRandom = new Random();
-
- // Gives this class the ability to tell the game engine
- // to spawn a laser
- private AlienLaserSpawner alienLaserSpawner;
-
- AlienChaseMovementComponent(AlienLaserSpawner als){
- alienLaserSpawner = als;
- }
-
- @Override
- public boolean move(long fps, Transform t, Transform playerTransform) {
-
- // 1 in 100 chance of shot being fired when in line with player
- final int TAKE_SHOT=0; // Arbitrary
- final int SHOT_CHANCE = 100;
-
- // How high is the screen?
- float screenWidth = t.getmScreenSize().x;
- // Where is the player?
- PointF playerLocation = playerTransform.getLocation();
-
- // How tall is the ship
- float height = t.getObjectHeight();
- // Is the ship facing right?
- boolean facingRight =t.getFacingRight();
- // How far off before the ship doesn't bother chasing?
- float mChasingDistance = t.getmScreenSize().x / 3f;
- // How far can the AI see?
- float mSeeingDistance = t.getmScreenSize().x / 1.5f;
- // Where is the ship?
- PointF location = t.getLocation();
- // How fast is the ship?
- float speed = t.getSpeed();
-
- // Relative speed difference with player
- float verticalSpeedDifference = .3f;
- float slowDownRelativeToPlayer = 1.8f;
- // Prevent the ship locking on too accurately
- float verticalSearchBounce = 20f;
-
- // move in the direction of the player
- // but relative to the player's direction of travel
- if (Math.abs(location.x - playerLocation.x)
- > mChasingDistance) {
-
- if (location.x < playerLocation.x) {
- t.headRight();
- } else if (location.x > playerLocation.x) {
- t.headLeft();
- }
- }
-
- // Can the Alien "see" the player? If so try and align vertically
- if (Math.abs(location.x - playerLocation.x)
- <= mSeeingDistance) {
-
- // Use a cast to get rid of unnecessary floats that make ship judder
- if ((int) location.y - playerLocation.y
- < -verticalSearchBounce) {
-
- t.headDown();
- } else if ((int) location.y - playerLocation.y
- > verticalSearchBounce) {
-
- t.headUp();
- }
-
- // Compensate for movement relative to player-
- // but only when in view.
- // Otherwise alien will disappear miles off to one side
- if(!playerTransform.getFacingRight()){
- location.x += speed * slowDownRelativeToPlayer / fps;
- } else{
- location.x -= speed * slowDownRelativeToPlayer / fps;
- }
- }
- else{
- // stop vertical movement otherwise alien will
- // disappear off the top or bottom
- t.stopVertical();
- }
-
- // Moving vertically is slower than horizontally
- // Change this to make game harder
- if(t.headingDown()){
- location.y += speed * verticalSpeedDifference / fps;
- }
- else if(t.headingUp()){
- location.y -= speed * verticalSpeedDifference / fps;
- }
-
- // Move horizontally
- if(t.headingLeft()){
- location.x -= (speed) / fps;
- }
- if(t.headingRight()){
- location.x += (speed) / fps;
- }
-
- // Update the collider
- t.updateCollider();
-
- // Shoot if the alien is within a ships height above,
- // below, or in line with the player?
- // This could be a hit or a miss
- if(mShotRandom.nextInt(SHOT_CHANCE) == TAKE_SHOT) {
- if (Math.abs(playerLocation.y - location.y) < height) {
- // Is the alien facing the right direction
- // and close enough to the player
- if ((facingRight && playerLocation.x > location.x
- || !facingRight && playerLocation.x < location.x)
- && Math.abs(playerLocation.x - location.x)
- < screenWidth) {
- // Fire!
- alienLaserSpawner.spawnAlienLaser(t);
- }
-
- }
- }
-
- return true;
- }
-}
diff --git a/Chapter21/java/AlienChaseSpec.java b/Chapter21/java/AlienChaseSpec.java
deleted file mode 100644
index 44981bc..0000000
--- a/Chapter21/java/AlienChaseSpec.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-
-class AlienChaseSpec extends ObjectSpec {
- // This is all the unique specifications for a alien that chases the player
- private static final String tag = "Alien";
- private static final String bitmapName = "alien_ship1";
- private static final float speed = 4f;
- private static final PointF relativeScale = new PointF(15f, 15f);
- private static final String[] components = new String [] {
- "StdGraphicsComponent","AlienChaseMovementComponent", "AlienHorizontalSpawnComponent"};
-
- AlienChaseSpec(){
- super(tag, bitmapName, speed, relativeScale, components);
- }
-}
diff --git a/Chapter21/java/AlienDiverMovementComponent.java b/Chapter21/java/AlienDiverMovementComponent.java
deleted file mode 100644
index c6ed2fc..0000000
--- a/Chapter21/java/AlienDiverMovementComponent.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-import java.util.Random;
-
-class AlienDiverMovementComponent implements MovementComponent {
-
- @Override
- public boolean move(long fps, Transform t, Transform playerTransform) {
-
- // Where is the ship?
- PointF location = t.getLocation();
- // How fast is the ship?
- float speed = t.getSpeed();
-
- // Relative speed difference with player
- float slowDownRelativeToPlayer = 1.8f;
-
- // Compensate for movement relative to player-
- // but only when in view.
- // Otherwise alien will disappear miles off to one side
- if(!playerTransform.getFacingRight()){
- location.x += speed * slowDownRelativeToPlayer / fps;
- } else{
- location.x -= speed * slowDownRelativeToPlayer / fps;
- }
-
- // Fall down then respawn at the top
- location.y += speed / fps;
-
- if(location.y > t.getmScreenSize().y){
- // Respawn at top
- Random random = new Random();
- location.y = random.nextInt(300) - t.getObjectHeight();
- location.x = random.nextInt((int)t.getmScreenSize().x);
- }
-
- // Update the collider
- t.updateCollider();
-
- return true;
- }
-}
diff --git a/Chapter21/java/AlienDiverSpec.java b/Chapter21/java/AlienDiverSpec.java
deleted file mode 100644
index f863d55..0000000
--- a/Chapter21/java/AlienDiverSpec.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-
-import android.graphics.PointF;
-
-class AlienDiverSpec extends ObjectSpec {
- // This is all the unique specifications
- // for an alien that dives
- private static final String tag = "Alien";
- private static final String bitmapName = "alien_ship3";
- private static final float speed = 4f;
- private static final PointF relativeScale =
- new PointF(60f, 30f);
-
- private static final String[] components = new String [] {
- "StdGraphicsComponent",
- "AlienDiverMovementComponent",
- "AlienVerticalSpawnComponent"};
-
- AlienDiverSpec(){
- super(tag, bitmapName, speed, relativeScale, components);
- }
-}
diff --git a/Chapter21/java/AlienHorizontalSpawnComponent.java b/Chapter21/java/AlienHorizontalSpawnComponent.java
deleted file mode 100644
index 3832c98..0000000
--- a/Chapter21/java/AlienHorizontalSpawnComponent.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-import java.util.Random;
-
-class AlienHorizontalSpawnComponent implements SpawnComponent {
- @Override
- public void spawn(Transform playerLTransform, Transform t) {
- // Get the screen size
- PointF ss = t.getmScreenSize();
-
- // Spawn just off screen randomly left or right
- Random random = new Random();
- boolean left = random.nextBoolean();
- // How far away?
- float distance = random.nextInt(2000)
- + t.getmScreenSize().x;
-
- // Generate a height to spawn at where
- // the entire ship is vertically on-screen
- float spawnHeight = random.nextFloat()
- * ss.y - t.getSize().y;
-
- // Spawn the ship
- if(left){
- t.setLocation(-distance, spawnHeight);
- t.headRight();
- }else{
- t.setLocation(distance, spawnHeight);
- t.headingLeft();
- }
-
- }
-}
diff --git a/Chapter21/java/AlienLaserSpawner.java b/Chapter21/java/AlienLaserSpawner.java
deleted file mode 100644
index d3e9b94..0000000
--- a/Chapter21/java/AlienLaserSpawner.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-// This allows an alien to communicate with the game engine
-// and spawn a laser
-interface AlienLaserSpawner {
- void spawnAlienLaser(Transform transform);
-}
diff --git a/Chapter21/java/AlienLaserSpec.java b/Chapter21/java/AlienLaserSpec.java
deleted file mode 100644
index 08dbcd2..0000000
--- a/Chapter21/java/AlienLaserSpec.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-
-class AlienLaserSpec extends ObjectSpec {
- // This is all the unique specifications
- // for an alien laser
- private static final String tag = "Alien Laser";
- private static final String bitmapName = "alien_laser";
- private static final float speed = .75f;
- private static final PointF relativeScale =
- new PointF(14f, 160f);
-
- private static final String[] components = new String [] {
- "StdGraphicsComponent",
- "LaserMovementComponent",
- "LaserSpawnComponent"};
-
- AlienLaserSpec(){
- super(tag, bitmapName,
- speed, relativeScale,
- components);
- }
-}
diff --git a/Chapter21/java/AlienPatrolMovementComponent.java b/Chapter21/java/AlienPatrolMovementComponent.java
deleted file mode 100644
index 00d194d..0000000
--- a/Chapter21/java/AlienPatrolMovementComponent.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-import java.util.Random;
-
-class AlienPatrolMovementComponent implements MovementComponent {
-
- private AlienLaserSpawner alienLaserSpawner;
- private Random mShotRandom = new Random();
-
- AlienPatrolMovementComponent(AlienLaserSpawner als){
- alienLaserSpawner = als;
- }
-
- @Override
- public boolean move(long fps, Transform t,
- Transform playerTransform) {
-
- final int TAKE_SHOT = 0; // Arbitrary
- // 1 in 100 chance of shot being fired
- // when in line with player
- final int SHOT_CHANCE = 100;
-
- // Where is the player
- PointF playerLocation = playerTransform.getLocation();
-
- // The top of the screen
- final float MIN_VERTICAL_BOUNDS = 0;
- // The width and height of the screen
- float screenX = t.getmScreenSize().x;
- float screenY = t.getmScreenSize().y;
-
- // How far ahead can the alien see?
- float mSeeingDistance = screenX * .5f;
-
- // Where is the alien?
- PointF loc = t.getLocation();
- // How fast is the alien?
- float speed = t.getSpeed();
- // How tall is the alien
- float height = t.getObjectHeight();
-
- // Stop the alien going too far away
- float MAX_VERTICAL_BOUNDS = screenY- height;
- final float MAX_HORIZONTAL_BOUNDS = 2 * screenX;
- final float MIN_HORIZONTAL_BOUNDS = 2 * -screenX;
-
- // Adjust the horizontal speed relative
- // to the player's heading
- // Default is no horizontal speed adjustment
- float horizontalSpeedAdjustmentRelativeToPlayer = 0 ;
- // How much to speed up or slow down relative
- // to player's heading
- float horizontalSpeedAdjustmentModifier = .8f;
-
- // Can the Alien "see" the player? If so make speed relative
- if (Math.abs(loc.x - playerLocation.x)
- < mSeeingDistance) {
- if(playerTransform.getFacingRight()
- != t.getFacingRight()){
-
- // Facing a different way speed up the alien
- horizontalSpeedAdjustmentRelativeToPlayer =
- speed * horizontalSpeedAdjustmentModifier;
- } else{
- // Facing the same way slow it down
- horizontalSpeedAdjustmentRelativeToPlayer =
- -(speed * horizontalSpeedAdjustmentModifier);
- }
- }
-
- // Move horizontally taking into account the speed modification
- if(t.headingLeft()){
- loc.x -= (speed + horizontalSpeedAdjustmentRelativeToPlayer) / fps;
- // Turn the ship around when it reaches the
- // extent of its horizontal patrol area
- if(loc.x < MIN_HORIZONTAL_BOUNDS){
- loc.x = MIN_HORIZONTAL_BOUNDS;
- t.headRight();
- }
- }
- else{
- loc.x += (speed + horizontalSpeedAdjustmentRelativeToPlayer) / fps;
- // Turn the ship around when it reaches the
- // extent of its horizontal patrol area
- if(loc.x > MAX_HORIZONTAL_BOUNDS){
- loc.x = MAX_HORIZONTAL_BOUNDS;
- t.headLeft();
- }
- }
-
- // Vertical speed remains same,
- // Not affected by speed adjustment
- if(t.headingDown()){
- loc.y += (speed) / fps;
- if(loc.y > MAX_VERTICAL_BOUNDS){
- t.headUp();
- }
- }
- else{
- loc.y -= (speed) / fps;
- if(loc.y < MIN_VERTICAL_BOUNDS){
- t.headDown();
- }
- }
- // Update the collider
- t.updateCollider();
-
- // Shoot if the alien within a ships height above,
- // below, or in line with the player?
- // This could be a hit or a miss
- if(mShotRandom.nextInt(SHOT_CHANCE) == TAKE_SHOT) {
- if (Math.abs(playerLocation.y - loc.y) < height) {
- // is the alien facing the right direction
- // and close enough to the player
- if ((t.getFacingRight() && playerLocation.x > loc.x
- || !t.getFacingRight() && playerLocation.x < loc.x)
- && Math.abs(playerLocation.x - loc.x) < screenX) {
- // Fire!
- alienLaserSpawner.spawnAlienLaser(t);
- }
-
- }
- }
-
- return true;
- }
-}
diff --git a/Chapter21/java/AlienPatrolSpec.java b/Chapter21/java/AlienPatrolSpec.java
deleted file mode 100644
index 8c1c289..0000000
--- a/Chapter21/java/AlienPatrolSpec.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-
-class AlienPatrolSpec extends ObjectSpec {
- // This is all the unique specifications
- // for a patrolling alien
- private static final String tag = "Alien";
- private static final String bitmapName = "alien_ship2";
- private static final float speed = 5f;
- private static final PointF relativeScale =
- new PointF(15f, 15f);
-
- private static final String[] components = new String [] {
- "StdGraphicsComponent",
- "AlienPatrolMovementComponent",
- "AlienHorizontalSpawnComponent"};
-
- AlienPatrolSpec(){
- super(tag, bitmapName,
- speed, relativeScale,
- components);
- }
-}
diff --git a/Chapter21/java/AlienVerticalSpawnComponent.java b/Chapter21/java/AlienVerticalSpawnComponent.java
deleted file mode 100644
index 96ee77d..0000000
--- a/Chapter21/java/AlienVerticalSpawnComponent.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import java.util.Random;
-
-class AlienVerticalSpawnComponent implements SpawnComponent {
-
- public void spawn(Transform playerLTransform, Transform t) {
-
- // Spawn just off screen randomly but
- // within the screen width
- Random random = new Random();
- float xPosition = random.nextInt((int)t
- .getmScreenSize().x);
-
- // Set the height to vertically
- // just above the visible game
- float spawnHeight = random
- .nextInt(300) - t.getObjectHeight();
-
- // Spawn the ship
- t.setLocation(xPosition, spawnHeight);
- // Always going dowm
- t.headDown();
- }
-}
diff --git a/Chapter21/java/BackgroundGraphicsComponent.java b/Chapter21/java/BackgroundGraphicsComponent.java
deleted file mode 100644
index d344eb6..0000000
--- a/Chapter21/java/BackgroundGraphicsComponent.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-class BackgroundGraphicsComponent implements GraphicsComponent {
-
- private Bitmap mBitmap;
- private Bitmap mBitmapReversed;
-
- @Override
- public void initialize(Context c, ObjectSpec s, PointF objectSize) {
-
- // Make a resource id out of the string of the file name
- int resID = c.getResources().getIdentifier(s.getBitmapName(),
- "drawable", c.getPackageName());
-
- // Load the bitmap using the id
- mBitmap = BitmapFactory.decodeResource(c.getResources(), resID);
-
- // Resize the bitmap
- mBitmap = Bitmap
- .createScaledBitmap(mBitmap,
- (int)objectSize.x,
- (int)objectSize.y,
- false);
-
- // Create a mirror image of the bitmap
- Matrix matrix = new Matrix();
- matrix.setScale(-1, 1);
- mBitmapReversed = Bitmap
- .createBitmap(mBitmap,
- 0, 0,
- mBitmap.getWidth(),
- mBitmap.getHeight(),
- matrix, true);
- }
-
- @Override
- public void draw(Canvas canvas, Paint paint, Transform t) {
-
- int xClip = t.getXClip();
- int width = mBitmap.getWidth();
- int height = mBitmap.getHeight();
- int startY = 0;
- int endY = (int)t.getmScreenSize().y +20;
-
- // For the regular bitmap
- Rect fromRect1 = new Rect(0, 0, width - xClip, height);
- Rect toRect1 = new Rect(xClip, startY, width, endY);
-
- // For the reversed background
- Rect fromRect2 = new Rect(width - xClip, 0, width, height);
- Rect toRect2 = new Rect(0, startY, xClip, endY);
-
- //draw the two background bitmaps
- if (!t.getReversedFirst()) {
- canvas.drawBitmap(mBitmap, fromRect1, toRect1, paint);
- canvas.drawBitmap(mBitmapReversed, fromRect2, toRect2, paint);
- } else {
- canvas.drawBitmap(mBitmap, fromRect2, toRect2, paint);
- canvas.drawBitmap(mBitmapReversed, fromRect1, toRect1, paint);
- }
-
-
- }
-
-}
diff --git a/Chapter21/java/BackgroundMovementComponent.java b/Chapter21/java/BackgroundMovementComponent.java
deleted file mode 100644
index ecfbe34..0000000
--- a/Chapter21/java/BackgroundMovementComponent.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-class BackgroundMovementComponent implements MovementComponent {
- @Override
- public boolean move(long fps, Transform t, Transform playerTransform) {
-
- int currentXClip = t.getXClip();
-
- if(playerTransform.getFacingRight()) {
- currentXClip -= t.getSpeed() / fps;
- t.setXClip(currentXClip);
- }
- else {
- currentXClip += t.getSpeed() / fps;
- t.setXClip(currentXClip);
- }
-
- if (currentXClip >= t.getSize().x) {
- t.setXClip(0);
- t.flipReversedFirst();
- } else if (currentXClip <= 0) {
- t.setXClip((int)t.getSize().x);
- t.flipReversedFirst();
- }
-
- return true;
- }
-}
diff --git a/Chapter21/java/BackgroundSpawnComponent.java b/Chapter21/java/BackgroundSpawnComponent.java
deleted file mode 100644
index 9acca68..0000000
--- a/Chapter21/java/BackgroundSpawnComponent.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-class BackgroundSpawnComponent implements SpawnComponent {
- @Override
- public void spawn(Transform playerLTransform, Transform t) {
- // Place the background in the top left corner
- t.setLocation(0f,0);
- }
-}
diff --git a/Chapter21/java/BackgroundSpec.java b/Chapter21/java/BackgroundSpec.java
deleted file mode 100644
index a3d082c..0000000
--- a/Chapter21/java/BackgroundSpec.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-
-class BackgroundSpec extends ObjectSpec {
- // This is all the unique specifications
- // for the background
- private static final String tag = "Background";
- private static final String bitmapName = "background";
- private static final float speed = 2f;
- private static final PointF relativeScale =
- new PointF(1f, 1f);
-
- private static final String[] components = new String [] {
- "BackgroundGraphicsComponent",
- "BackgroundMovementComponent",
- "BackgroundSpawnComponent"};
-
- BackgroundSpec() {
- super(tag, bitmapName,
- speed, relativeScale,
- components);
- }
-}
diff --git a/Chapter21/java/GameActivity.java b/Chapter21/java/GameActivity.java
deleted file mode 100644
index 6919703..0000000
--- a/Chapter21/java/GameActivity.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class GameActivity extends Activity {
-
- GameEngine mGameEngine;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Display display = getWindowManager()
- .getDefaultDisplay();
-
- Point size = new Point();
- display.getSize(size);
- mGameEngine = new GameEngine(this, size);
- setContentView(mGameEngine);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mGameEngine.startThread();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mGameEngine.stopThread();
- }
-}
\ No newline at end of file
diff --git a/Chapter21/java/GameEngine.java b/Chapter21/java/GameEngine.java
deleted file mode 100644
index 2a73160..0000000
--- a/Chapter21/java/GameEngine.java
+++ /dev/null
@@ -1,166 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Point;
-import android.graphics.PointF;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceView;
-
-import java.util.ArrayList;
-
-class GameEngine extends SurfaceView
- implements Runnable,
- GameStarter,
- GameEngineBroadcaster,
- PlayerLaserSpawner,
- AlienLaserSpawner {
-
- private Thread mThread = null;
- private long mFPS;
-
- private ArrayList inputObservers = new ArrayList();
- UIController mUIController;
-
- private GameState mGameState;
- private SoundEngine mSoundEngine;
- HUD mHUD;
- Renderer mRenderer;
- ParticleSystem mParticleSystem;
- PhysicsEngine mPhysicsEngine;
- Level mLevel;
-
-
- public GameEngine(Context context, Point size) {
- super(context);
-
- mUIController = new UIController(this);
- mGameState = new GameState(this, context);
- mSoundEngine = new SoundEngine(context);
- mHUD = new HUD(size);
- mRenderer = new Renderer(this);
- mPhysicsEngine = new PhysicsEngine();
-
- mParticleSystem = new ParticleSystem();
- mParticleSystem.init(1000);
-
- mLevel = new Level(context,
- new PointF(size.x, size.y), this);
- }
-
- // For the game engine broadcaster interface
- public void addObserver(InputObserver o) {
-
- inputObservers.add(o);
- }
-
- public void deSpawnReSpawn() {
- // Eventually this will despawn
- // and then respawn all the game objects
- ArrayList objects = mLevel.getGameObjects();
-
- for(GameObject o : objects){
- o.setInactive();
- }
- objects.get(Level.PLAYER_INDEX).spawn(objects.get(Level.PLAYER_INDEX).getTransform());
- objects.get(Level.BACKGROUND_INDEX).spawn(objects.get(Level.PLAYER_INDEX).getTransform());
-
- for (int i = Level.FIRST_ALIEN; i != Level.LAST_ALIEN + 1; i++) {
- objects.get(i).spawn(objects.get(Level.PLAYER_INDEX).getTransform());
- }
-
- }
-
- @Override
- public void run() {
- while (mGameState.getThreadRunning()) {
- long frameStartTime = System.currentTimeMillis();
- ArrayList objects = mLevel.getGameObjects();
-
- if (!mGameState.getPaused()) {
- // Update all the game objects here
- // in a new way
-
- // This call to update will eveolve with the project
- if(mPhysicsEngine.update(mFPS,objects, mGameState, mSoundEngine, mParticleSystem)){
- // Player hit
- deSpawnReSpawn();
- }
- }
-
- // Draw all the game objects here
- // in a new way
- mRenderer.draw(objects, mGameState, mHUD, mParticleSystem);
-
- // Measure the frames per second in the usual way
- long timeThisFrame = System.currentTimeMillis()
- - frameStartTime;
- if (timeThisFrame >= 1) {
- final int MILLIS_IN_SECOND = 1000;
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- // Handle the player's input here
- // But in a new way
- for (InputObserver o : inputObservers) {
- o.handleInput(motionEvent, mGameState, mHUD.getControls());
- }
-
-
-
- return true;
- }
-
- public void stopThread() {
- // New code here soon
- mGameState.stopEverything();
-
- try {
- mThread.join();
- } catch (InterruptedException e) {
- Log.e("Exception","stopThread()" + e.getMessage());
- }
- }
-
- public void startThread() {
- // New code here soon
- mGameState.startThread();
-
- mThread = new Thread(this);
- mThread.start();
- }
-
- @Override
- public boolean spawnPlayerLaser(Transform transform) {
- ArrayList objects = mLevel.getGameObjects();
- if (objects.get(Level.mNextPlayerLaser).spawn(transform)) {
- Level.mNextPlayerLaser++;
- mSoundEngine.playShoot();
- if (Level.mNextPlayerLaser == Level.LAST_PLAYER_LASER + 1) {
- // Just used the last laser
- Level.mNextPlayerLaser = Level.FIRST_PLAYER_LASER;
-
- }
- }
- return true;
- }
-
- public void spawnAlienLaser(Transform transform) {
- ArrayList objects = mLevel.getGameObjects();
- // Shoot laser IF AVAILABLE
- // Pass in the transform of the ship
- // that requested the shot to be fired
- if (objects.get(Level.mNextAlienLaser).spawn(transform)) {
- Level.mNextAlienLaser++;
- mSoundEngine.playShoot();
- if (Level.mNextAlienLaser == Level.LAST_ALIEN_LASER + 1) {
- // Just used the last laser
- Level.mNextAlienLaser = Level.FIRST_ALIEN_LASER;
- }
- }
- }
-}
diff --git a/Chapter21/java/GameEngineBroadcaster.java b/Chapter21/java/GameEngineBroadcaster.java
deleted file mode 100644
index c2ee2d6..0000000
--- a/Chapter21/java/GameEngineBroadcaster.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-interface GameEngineBroadcaster {
-
- void addObserver(InputObserver o);
-}
diff --git a/Chapter21/java/GameObject.java b/Chapter21/java/GameObject.java
deleted file mode 100644
index 82e25bf..0000000
--- a/Chapter21/java/GameObject.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-class GameObject {
-
- private Transform mTransform;
- private boolean isActive = false;
- private String mTag;
-
- private GraphicsComponent graphicsComponent;
- private MovementComponent movementComponent;
- private SpawnComponent spawnComponent;
-
- void setSpawner(SpawnComponent s) {
- spawnComponent = s;
- }
-
- void setGraphics(GraphicsComponent g, Context c,
- ObjectSpec spec, PointF objectSize) {
-
- graphicsComponent = g;
- g.initialize(c, spec, objectSize);
- }
-
- void setMovement(MovementComponent m) {
- movementComponent = m;
- }
-
- void setInput(InputComponent s) {
- s.setTransform(mTransform);
- }
-
- void setmTag(String tag) {
- mTag = tag;
- }
-
- void setTransform(Transform t) {
- mTransform = t;
- }
-
- void draw(Canvas canvas, Paint paint) {
- graphicsComponent.draw(canvas, paint, mTransform);
- }
-
- void update(long fps, Transform playerTransform) {
- if (!(movementComponent.move(fps,
- mTransform, playerTransform))) {
- // Component returned false
- isActive = false;
- }
- }
-
- boolean checkActive() {
- return isActive;
- }
-
- String getTag() {
- return mTag;
- }
-
- void setInactive() {
- isActive = false;
- }
-
- boolean spawn(Transform playerTransform) {
- // Only spawnComponent if not already active
- if (!isActive) {
- spawnComponent.spawn(playerTransform, mTransform);
- isActive = true;
- return true;
- }
- return false;
- }
-
- Transform getTransform() {
- return mTransform;
- }
-}
diff --git a/Chapter21/java/GameObjectFactory.java b/Chapter21/java/GameObjectFactory.java
deleted file mode 100644
index ba148ae..0000000
--- a/Chapter21/java/GameObjectFactory.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.content.Context;
-import android.graphics.PointF;
-
-class GameObjectFactory {
- private Context mContext;
- private PointF mScreenSize;
- private GameEngine mGameEngineReference;
-
- GameObjectFactory(Context c, PointF screenSize,
- GameEngine gameEngine) {
-
- this.mContext = c;
- this.mScreenSize = screenSize;
- mGameEngineReference = gameEngine;
- }
-
- GameObject create(ObjectSpec spec) {
- GameObject object = new GameObject();
-
- int mNumComponents = spec.getComponents().length;
-
- final float HIDDEN = -2000f;
-
- object.setmTag(spec.getTag());
-
- // Configure the speed relative to the screen size
- float mSpeed = mScreenSize.x / spec.getSpeed();
-
- // Configure the object size relative to screen size
- PointF objectSize =
- new PointF(mScreenSize.x / spec.getScale().x,
- mScreenSize.y / spec.getScale().y);
-
- // Set the location to somewhere off-screen
- PointF mLocation = new PointF(HIDDEN, HIDDEN);
-
- object.setTransform(new Transform(mSpeed, objectSize.x,
- objectSize.y, mLocation, mScreenSize));
-
- // Loop through and add/initialize all the components
- for (int i = 0; i < mNumComponents; i++) {
- switch (spec.getComponents()[i]) {
- case "PlayerInputComponent":
- object.setInput(new PlayerInputComponent
- (mGameEngineReference));
- break;
- case "StdGraphicsComponent":
- object.setGraphics(new StdGraphicsComponent(),
- mContext, spec, objectSize);
- break;
- case "PlayerMovementComponent":
- object.setMovement(new PlayerMovementComponent());
- break;
- case "LaserMovementComponent":
- object.setMovement(new LaserMovementComponent());
- break;
- case "PlayerSpawnComponent":
- object.setSpawner(new PlayerSpawnComponent());
- break;
- case "LaserSpawnComponent":
- object.setSpawner(new LaserSpawnComponent());
- break;
- case "BackgroundGraphicsComponent":
- object.setGraphics(new BackgroundGraphicsComponent(),
- mContext, spec, objectSize);
- break;
- case "BackgroundMovementComponent":
- object.setMovement(new BackgroundMovementComponent());
- break;
- case "BackgroundSpawnComponent":
- object.setSpawner(new BackgroundSpawnComponent());
- break;
- case "AlienChaseMovementComponent":
- object.setMovement(
- new AlienChaseMovementComponent(mGameEngineReference));
- break;
- case "AlienPatrolMovementComponent":
- object.setMovement(
- new AlienPatrolMovementComponent(mGameEngineReference));
- break;
- case "AlienDiverMovementComponent":
- object.setMovement(new AlienDiverMovementComponent());
- break;
- case "AlienHorizontalSpawnComponent":
- object.setSpawner(new AlienHorizontalSpawnComponent());
- break;
- case "AlienVerticalSpawnComponent":
- object.setSpawner(new AlienVerticalSpawnComponent());
- break;
-
-
- default:
- // Error unidentified component
- break;
- }
- }
- // Return the completed GameObject to the Level class
- return object;
- }
-}
diff --git a/Chapter21/java/GameStarter.java b/Chapter21/java/GameStarter.java
deleted file mode 100644
index 2bca1bd..0000000
--- a/Chapter21/java/GameStarter.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-interface GameStarter {
- // This allows the State class to
- // spawn and despawn objects via the game engine
- public void deSpawnReSpawn();
-}
diff --git a/Chapter21/java/GameState.java b/Chapter21/java/GameState.java
deleted file mode 100644
index cad3ab7..0000000
--- a/Chapter21/java/GameState.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-
-final class GameState {
- private static volatile boolean mThreadRunning = false;
- private static volatile boolean mPaused = true;
- private static volatile boolean mGameOver = true;
- private static volatile boolean mDrawing = false;
-
- // This object will have access to the deSpawnReSpawn method
- // in GameEngine- once it is initialized
- private static GameStarter gameStarter;
-
- private int mScore;
- private int mHighScore;
- private int mNumShips;
-
- // This is how we will make all the high scores persist
- private SharedPreferences.Editor mEditor;
-
- GameState(GameStarter gs, Context context){
- // This initializes the gameStarter reference
- gameStarter = gs;
-
- // Get the current high score
- SharedPreferences prefs;
- prefs = context.getSharedPreferences("HiScore",
- Context.MODE_PRIVATE);
-
- // Initialize the mEditor ready
- mEditor = prefs.edit();
-
- // Load high score from a entry in the file
- // labeled "hiscore"
- // if not available highscore set to zero 0
- mHighScore = prefs.getInt("hi_score", 0);
- }
-
- private void endGame(){
- mGameOver = true;
- mPaused = true;
- if(mScore > mHighScore){
- mHighScore = mScore;
- // Save high score
- mEditor.putInt("hi_score", mHighScore);
- mEditor.commit();
- }
- }
-
- void startNewGame(){
- mScore = 0;
- mNumShips = 3;
- // Don'mTransform want to be drawing objects while deSpawnReSpawn is
- // clearing ArrayList and filling it up again
- stopDrawing();
- gameStarter.deSpawnReSpawn();
- resume();
-
- // Now we can draw again
- startDrawing();
- }
-
- void loseLife(SoundEngine se){
- mNumShips--;
- se.playPlayerExplode();
- if(mNumShips == 0){
- pause();
- endGame();
- }
- }
-
-
-
- int getNumShips(){
- return mNumShips;
- }
-
- void increaseScore(){
- mScore++;
- }
-
- int getScore(){
- return mScore;
- }
-
- int getHighScore(){
- return mHighScore;
- }
-
- void pause(){
- mPaused = true;
- }
-
- void resume(){
- mGameOver = false;
- mPaused = false;
- }
-
- void stopEverything(){
- mPaused = true;
- mGameOver = true;
- mThreadRunning = false;
- }
-
- boolean getThreadRunning(){
- return mThreadRunning;
- }
-
- void startThread(){
- mThreadRunning = true;
- }
-
- private void stopDrawing(){
- mDrawing = false;
- }
-
- private void startDrawing(){
- mDrawing = true;
- }
-
- boolean getDrawing() {return mDrawing;}
-
- boolean getPaused(){
- return mPaused;
- }
-
- boolean getGameOver(){
- return mGameOver;
- }
-
-}
diff --git a/Chapter21/java/GraphicsComponent.java b/Chapter21/java/GraphicsComponent.java
deleted file mode 100644
index 83d9526..0000000
--- a/Chapter21/java/GraphicsComponent.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-interface GraphicsComponent {
-
- void initialize(Context c,
- ObjectSpec s,
- PointF screensize);
-
- void draw(Canvas canvas,
- Paint paint,
- Transform t);
-}
diff --git a/Chapter21/java/HUD.java b/Chapter21/java/HUD.java
deleted file mode 100644
index 2a4bc5f..0000000
--- a/Chapter21/java/HUD.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.graphics.Rect;
-
-import java.util.ArrayList;
-
-class HUD {
- private int mTextFormatting;
- private int mScreenHeight;
- private int mScreenWidth;
-
- private ArrayList controls;
-
- static int UP = 0;
- static int DOWN = 1;
- static int FLIP = 2;
- static int SHOOT = 3;
- static int PAUSE = 4;
-
- HUD(Point size){
- mScreenHeight = size.y;
- mScreenWidth = size.x;
- mTextFormatting = size.x / 50;
-
- prepareControls();
- }
-
- private void prepareControls(){
- int buttonWidth = mScreenWidth / 14;
- int buttonHeight = mScreenHeight / 12;
- int buttonPadding = mScreenWidth / 90;
-
- Rect up = new Rect(
- buttonPadding,
- mScreenHeight - (buttonHeight * 2) - (buttonPadding * 2),
- buttonWidth + buttonPadding,
- mScreenHeight - buttonHeight - (buttonPadding *2) );
-
- Rect down = new Rect(
- buttonPadding,
- mScreenHeight - buttonHeight - buttonPadding,
- buttonWidth + buttonPadding,
- mScreenHeight - buttonPadding);
-
- Rect flip = new Rect(mScreenWidth - buttonPadding - buttonWidth,
- mScreenHeight - buttonHeight - buttonPadding,
- mScreenWidth - buttonPadding,
- mScreenHeight - buttonPadding
-
- );
-
- Rect shoot = new Rect(mScreenWidth - buttonPadding - buttonWidth,
- mScreenHeight - (buttonHeight * 2) - (buttonPadding * 2),
- mScreenWidth - buttonPadding,
- mScreenHeight - buttonHeight - (buttonPadding *2)
- );
-
- Rect pause = new Rect(
- mScreenWidth - buttonPadding - buttonWidth,
- buttonPadding,
- mScreenWidth - buttonPadding,
- buttonPadding + buttonHeight);
-
- controls = new ArrayList<>();
- controls.add(UP,up);
- controls.add(DOWN,down);
- controls.add(FLIP, flip);
- controls.add(SHOOT, shoot);
- controls.add(PAUSE, pause);
- }
-
- void draw(Canvas c, Paint p, GameState gs){
-
- // Draw the HUD
- p.setColor(Color.argb(255,255,255,255));
- p.setTextSize(mTextFormatting);
- c.drawText("Hi: " + gs.getHighScore(), mTextFormatting,mTextFormatting,p);
- c.drawText("Scrore: " + gs.getScore(), mTextFormatting,mTextFormatting * 2,p);
- c.drawText("Lives: " + gs.getNumShips(), mTextFormatting,mTextFormatting * 3,p);
-
- if(gs.getGameOver()){
- p.setTextSize(mTextFormatting * 5);
- c.drawText("PRESS PLAY", mScreenWidth /4, mScreenHeight /2 ,p);
- }
-
- if(gs.getPaused() && !gs.getGameOver()){
- p.setTextSize(mTextFormatting * 5);
- c.drawText("PAUSED", mScreenWidth /3, mScreenHeight /2 ,p);
- }
- drawControls(c, p);
- }
-
- private void drawControls(Canvas c, Paint p){
- p.setColor(Color.argb(100,255,255,255));
-
- for(Rect r : controls){
- c.drawRect(r.left, r.top, r.right, r.bottom, p);
- }
-
- // Set the colors back
- p.setColor(Color.argb(255,255,255,255));
- }
- ArrayList getControls(){
- return controls;
- }
-}
diff --git a/Chapter21/java/InputComponent.java b/Chapter21/java/InputComponent.java
deleted file mode 100644
index 2c2a210..0000000
--- a/Chapter21/java/InputComponent.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-interface InputComponent {
-
- void setTransform(Transform t);
-}
diff --git a/Chapter21/java/InputObserver.java b/Chapter21/java/InputObserver.java
deleted file mode 100644
index 3b9ebcc..0000000
--- a/Chapter21/java/InputObserver.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-interface InputObserver {
-
- void handleInput(MotionEvent event, GameState gs, ArrayList controls);
-}
diff --git a/Chapter21/java/LaserMovementComponent.java b/Chapter21/java/LaserMovementComponent.java
deleted file mode 100644
index 6fe7386..0000000
--- a/Chapter21/java/LaserMovementComponent.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-
-class LaserMovementComponent implements MovementComponent {
-
- @Override
- public boolean move(long fps, Transform t, Transform playerTransform) {
-
- // Laser can only travel two screen widths
- float range = t.getmScreenSize().x * 2;
-
- // Where is the laser
- PointF location = t.getLocation();
-
- // How fast is it going
- float speed = t.getSpeed();
-
- if(t.headingRight()){
- location.x += speed / fps;
- }
- else if(t.headingLeft()){
- location.x -= speed / fps;
- }
-
- // Has the laser gone out of range
- if(location.x < - range || location.x > range){
- // disable the laser
- return false;
- }
-
- t.updateCollider();
- return true;
- }
-}
diff --git a/Chapter21/java/LaserSpawnComponent.java b/Chapter21/java/LaserSpawnComponent.java
deleted file mode 100644
index 4e9b3d2..0000000
--- a/Chapter21/java/LaserSpawnComponent.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-
-class LaserSpawnComponent implements SpawnComponent {
- @Override
- public void spawn(Transform playerTransform, Transform t) {
-
- PointF startPosition =
- playerTransform.getFiringLocation(t.getSize().x);
-
- t.setLocation((int)startPosition.x, (int)startPosition.y);
-
- if(playerTransform.getFacingRight()){
- t.headRight();
- }
- else{
- t.headLeft();
- }
-
- }
-}
diff --git a/Chapter21/java/Level.java b/Chapter21/java/Level.java
deleted file mode 100644
index 15de821..0000000
--- a/Chapter21/java/Level.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.content.Context;
-import android.graphics.PointF;
-
-import java.util.ArrayList;
-
-class Level {
-
- // Keep track of specific types
- public static final int BACKGROUND_INDEX = 0;
- public static final int PLAYER_INDEX = 1;
- public static final int FIRST_PLAYER_LASER = 2;
- public static final int LAST_PLAYER_LASER = 4;
- public static int mNextPlayerLaser;
- public static final int FIRST_ALIEN = 5;
- public static final int SECOND_ALIEN = 6;
- public static final int THIRD_ALIEN = 7;
- public static final int FOURTH_ALIEN = 8;
- public static final int FIFTH_ALIEN = 9;
- public static final int SIXTH_ALIEN = 10;
- public static final int LAST_ALIEN = 10;
- public static final int FIRST_ALIEN_LASER = 11;
- public static final int LAST_ALIEN_LASER = 15;
- public static int mNextAlienLaser;
-
- // This will hold all the instances of GameObject
- private ArrayList objects;
-
- public Level(Context context,
- PointF mScreenSize,
- GameEngine ge){
-
- objects = new ArrayList<>();
- GameObjectFactory factory = new GameObjectFactory(
- context, mScreenSize, ge);
-
- buildGameObjects(factory);
- }
-
- ArrayList buildGameObjects(
- GameObjectFactory factory){
-
- objects.clear();
- objects.add(BACKGROUND_INDEX, factory.create(new BackgroundSpec()));
- objects.add(PLAYER_INDEX, factory.create(new PlayerSpec()));
-
- // Spawn the player's lasers
- for (int i = FIRST_PLAYER_LASER; i != LAST_PLAYER_LASER + 1; i++) {
- objects.add(i, factory.create(new PlayerLaserSpec()));
- }
-
- mNextPlayerLaser = FIRST_PLAYER_LASER;
-
- // Create some aliens
- objects.add(FIRST_ALIEN, factory
- .create(new AlienChaseSpec()));
- objects.add(SECOND_ALIEN, factory
- .create(new AlienPatrolSpec()));
- objects.add(THIRD_ALIEN, factory
- .create(new AlienPatrolSpec()));
- objects.add(FOURTH_ALIEN, factory
- .create(new AlienChaseSpec()));
- objects.add(FIFTH_ALIEN, factory
- .create(new AlienDiverSpec()));
- objects.add(SIXTH_ALIEN, factory
- .create(new AlienDiverSpec()));
-
- // Create some alien lasers
- for (int i = FIRST_ALIEN_LASER; i != LAST_ALIEN_LASER + 1; i++) {
- objects.add(i, factory
- .create(new AlienLaserSpec()));
- }
- mNextAlienLaser = FIRST_ALIEN_LASER;
-
- return objects;
- }
-
- ArrayList getGameObjects(){
- return objects;
- }
-
-
-}
diff --git a/Chapter21/java/MovementComponent.java b/Chapter21/java/MovementComponent.java
deleted file mode 100644
index e795c46..0000000
--- a/Chapter21/java/MovementComponent.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-interface MovementComponent {
-
- boolean move(long fps,
- Transform t,
- Transform playerTransform);
-}
diff --git a/Chapter21/java/ObjectSpec.java b/Chapter21/java/ObjectSpec.java
deleted file mode 100644
index f2a2f0c..0000000
--- a/Chapter21/java/ObjectSpec.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-
-abstract class ObjectSpec {
- private String mTag;
- private String mBitmapName;
- private float mSpeed;
- private PointF mSizeScale;
- private String[] mComponents;
-
- ObjectSpec(String tag, String bitmapName, float speed, PointF relativeScale, String[] components) {
- mTag = tag;
- mBitmapName = bitmapName;
- mSpeed = speed;
- mSizeScale = relativeScale;
- mComponents = components;
- }
-
- String getTag() {
- return mTag;
- }
-
- String getBitmapName() {
- return mBitmapName;
- }
-
- float getSpeed() {
- return mSpeed;
- }
-
- PointF getScale() {
- return mSizeScale;
- }
-
- String[] getComponents() {
- return mComponents;
- }
-}
diff --git a/Chapter21/java/Particle.java b/Chapter21/java/Particle.java
deleted file mode 100644
index b225559..0000000
--- a/Chapter21/java/Particle.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-
-class Particle {
-
- PointF mVelocity;
- PointF mPosition;
-
- Particle(PointF direction)
- {
- mVelocity = new PointF();
- mPosition = new PointF();
-
- // Determine the direction
- mVelocity.x = direction.x;
- mVelocity.y = direction.y;
- }
-
- void update(float fps)
- {
- // Move the particle
- mPosition.x += mVelocity.x;
- mPosition.y += mVelocity.y;
- }
-
- void setPosition(PointF position)
- {
- mPosition.x = position.x;
- mPosition.y = position.y;
- }
-
- PointF getPosition()
- {
- return mPosition;
- }
-}
diff --git a/Chapter21/java/ParticleSystem.java b/Chapter21/java/ParticleSystem.java
deleted file mode 100644
index 701e4d0..0000000
--- a/Chapter21/java/ParticleSystem.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-import java.util.ArrayList;
-import java.util.Random;
-
-class ParticleSystem {
-
- float mDuration;
-
- ArrayList mParticles;
- Random random = new Random();
- boolean mIsRunning = false;
-
- void init(int numParticles){
-
- mParticles = new ArrayList<>();
- // Create the particles
-
- for (int i = 0; i < numParticles; i++) {
- float angle = (random.nextInt(360)) ;
- angle = angle * 3.14f / 180.f;
- float speed = (random.nextInt(20)+1);
-
- PointF direction;
-
- direction = new PointF((float)Math.cos(angle) * speed,
- (float)Math.sin(angle) * speed);
-
- mParticles.add(new Particle(direction));
- }
- }
-
- void update(long fps){
- mDuration -= (1f/fps);
-
- for(Particle p : mParticles){
- p.update(fps);
- }
-
- if (mDuration < 0)
- {
- mIsRunning = false;
- }
- }
-
- void emitParticles(PointF startPosition){
-
- mIsRunning = true;
- mDuration = 1f;
-
- for(Particle p : mParticles){
- p.setPosition(startPosition);
- }
-
- }
-
- void draw(Canvas canvas, Paint paint){
-
- for (Particle p : mParticles) {
-
- //paint.setARGB(255, random.nextInt(256),
- //random.nextInt(256),
- //random.nextInt(256));
-
- // Uncomment the next line to have plain white particles
- paint.setColor(Color.argb(255,255,255,255));
- canvas.drawRect(p.getPosition().x, p.getPosition().y,
- p.getPosition().x+5,
- p.getPosition().y+5, paint);
- }
- }
-
-
-}
diff --git a/Chapter21/java/PhysicsEngine.java b/Chapter21/java/PhysicsEngine.java
deleted file mode 100644
index 21ae0b6..0000000
--- a/Chapter21/java/PhysicsEngine.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-import android.graphics.RectF;
-
-import java.util.ArrayList;
-
-class PhysicsEngine {
- // This signature and much more will change later in the project
- boolean update(long fps, ArrayList objects,
- GameState gs, SoundEngine se,
- ParticleSystem ps){
-
- // Update all the game objects
- for (GameObject object : objects) {
- if (object.checkActive()) {
- object.update(fps, objects
- .get(Level.PLAYER_INDEX).getTransform());
- }
- }
-
- if(ps.mIsRunning){
- ps.update(fps);
- }
-
- return detectCollisions(gs, objects, se, ps);
- }
-
-
- // Collision detection will go here
- private boolean detectCollisions(GameState mGameState, ArrayList objects, SoundEngine se, ParticleSystem ps ){
- boolean playerHit = false;
- for(GameObject go1 : objects) {
-
- if(go1.checkActive()){
- // The ist object is active so worth checking
-
- for(GameObject go2 : objects) {
-
- if(go2.checkActive()){
-
- // The 2nd object is active so worth checking
- if(RectF.intersects(go1.getTransform().getCollider(), go2.getTransform().getCollider())){
- // There has been a collision - but does it matter
- switch (go1.getTag() + " with " + go2.getTag()){
- case "Player with Alien Laser":
- playerHit = true;
- mGameState.loseLife(se);
-
- break;
-
- case "Player with Alien":
- playerHit = true;
- mGameState.loseLife(se);
-
- break;
-
- case "Player Laser with Alien":
- mGameState.increaseScore();
- // Respawn the alien
- ps.emitParticles(
- new PointF(
- go2.getTransform().getLocation().x,
- go2.getTransform().getLocation().y
-
- )
- );
- go2.setInactive();
- go2.spawn(objects.get(Level.PLAYER_INDEX).getTransform());
- go1.setInactive();
- se.playAlienExplode();
-
- break;
-
- default:
- break;
- }
-
- }
- }
- }
- }
- }
- return playerHit;
- }
-}
diff --git a/Chapter21/java/PlayerInputComponent.java b/Chapter21/java/PlayerInputComponent.java
deleted file mode 100644
index 97b8426..0000000
--- a/Chapter21/java/PlayerInputComponent.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-class PlayerInputComponent implements InputComponent, InputObserver {
-
- private Transform mTransform;
- private PlayerLaserSpawner mPLS;
-
- PlayerInputComponent(GameEngine ger) {
- ger.addObserver(this);
- mPLS = ger;
- }
-
- @Override
- public void setTransform(Transform transform) {
- mTransform = transform;
- }
-
- // Required method of InputObserver interface called from the onTouchEvent method
- @Override
- public void handleInput(MotionEvent event, GameState gameState, ArrayList buttons) {
- // In each MotionEvent object, every active pointer is present. Therefore looping through them all for an event on only one of them is obviously wrong.
- // The getActionIndex returns the index in the array of the pointer that performed/trigged the action/method call. So using getX(i) and getY(i) only gets a true result
- // on the button that was actually pressed/removed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- int i = event.getActionIndex();
- int x = (int) event.getX(i);
- int y = (int) event.getY(i);
-
- switch (event.getAction() & MotionEvent.ACTION_MASK) {
-
- case MotionEvent.ACTION_UP:
- if (buttons.get(HUD.UP).contains(x,y)
- || buttons.get(HUD.DOWN).contains(x,y)) {
-
- // Player has released either up or down
- mTransform.stopVertical();
- }
- break;
-
- case MotionEvent.ACTION_DOWN:
- if (buttons.get(HUD.UP).contains(x,y)) {
- // Player has pressed up
- mTransform.headUp();
- } else if (buttons.get(HUD.DOWN).contains(x,y)) {
- // Player has pressed down
- mTransform.headDown();
- } else if (buttons.get(HUD.FLIP).contains(x,y)) {
- // Player has released the flip button
- mTransform.flip();
- } else if (buttons.get(HUD.SHOOT).contains(x,y)) {
- mPLS.spawnPlayerLaser(mTransform);
- }
- break;
-
- case MotionEvent.ACTION_POINTER_UP:
- if (buttons.get(HUD.UP).contains(x, y)
- || buttons.get(HUD.DOWN).contains(x, y)) {
- // Player has released either up or down
- mTransform.stopVertical();
- }
- break;
-
- case MotionEvent.ACTION_POINTER_DOWN:
- if (buttons.get(HUD.UP).contains(x, y)) {
- // Player has pressed up
- mTransform.headUp();
- } else if (buttons.get(HUD.DOWN).contains(x, y)) {
- // Player has pressed down
- mTransform.headDown();
- } else if (buttons.get(HUD.FLIP).contains(x, y)) {
- // Player has released the flip button
- mTransform.flip();
- } else if (buttons.get(HUD.SHOOT).contains(x, y)) {
- mPLS.spawnPlayerLaser(mTransform);
- }
- break;
- }
- }
-}
diff --git a/Chapter21/java/PlayerLaserSpawner.java b/Chapter21/java/PlayerLaserSpawner.java
deleted file mode 100644
index 5ea1ddb..0000000
--- a/Chapter21/java/PlayerLaserSpawner.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-public interface PlayerLaserSpawner {
- boolean spawnPlayerLaser(Transform transform);
-}
diff --git a/Chapter21/java/PlayerLaserSpec.java b/Chapter21/java/PlayerLaserSpec.java
deleted file mode 100644
index 1d4c47a..0000000
--- a/Chapter21/java/PlayerLaserSpec.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-
-import android.graphics.PointF;
-
-class PlayerLaserSpec extends ObjectSpec {
- // This is all the unique specifications
- // for a player laser
- private static final String tag = "Player Laser";
- private static final String bitmapName = "player_laser";
- private static final float speed = .75f;
- private static final PointF relativeScale =
- new PointF(8f, 160f);
-
- private static final String[] components = new String [] {
- "StdGraphicsComponent",
- "LaserMovementComponent",
- "LaserSpawnComponent"};
-
- PlayerLaserSpec(){
- super(tag, bitmapName,
- speed, relativeScale,
- components);
- }
-}
diff --git a/Chapter21/java/PlayerMovementComponent.java b/Chapter21/java/PlayerMovementComponent.java
deleted file mode 100644
index 41089d6..0000000
--- a/Chapter21/java/PlayerMovementComponent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-
-class PlayerMovementComponent implements MovementComponent {
- public boolean move(long fps, Transform t,
- Transform playerTransform){
-
- // How high is the screen?
- float screenHeight = t.getmScreenSize().y;
- // Where is the player?
- PointF location = t.getLocation();
- // How fast is it going
- float speed = t.getSpeed();
- // How tall is the ship
- float height = t.getObjectHeight();
-
- // Move the ship up or down if required
- if(t.headingDown()){
- location.y += speed / fps;
- }
- else if(t.headingUp()){
- location.y -= speed / fps;
- }
-
- // Make sure the ship can't go off the screen
- if(location.y > screenHeight - height){
- location.y = screenHeight - height;
- }
- else if(location.y < 0){
- location.y = 0;
- }
-
- // Update the collider
- t.updateCollider();
-
- return true;
- }
-}
diff --git a/Chapter21/java/PlayerSpawnComponent.java b/Chapter21/java/PlayerSpawnComponent.java
deleted file mode 100644
index ffb4d84..0000000
--- a/Chapter21/java/PlayerSpawnComponent.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-
-class PlayerSpawnComponent implements SpawnComponent {
- @Override
- public void spawn(Transform playerTransform, Transform t) {
-
- // Spawn in the centre of the screen
- t.setLocation(
- t.getmScreenSize().x/2,
- t.getmScreenSize().y/2);
-
- }
-}
diff --git a/Chapter21/java/PlayerSpec.java b/Chapter21/java/PlayerSpec.java
deleted file mode 100644
index 564df00..0000000
--- a/Chapter21/java/PlayerSpec.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-
-class PlayerSpec extends ObjectSpec {
- // This is all the unique specifications
- // for a player
- private static final String tag = "Player";
- private static final String bitmapName = "player_ship";
- private static final float speed = 1f;
- private static final PointF relativeScale =
- new PointF(15f, 15f);
-
- private static final String[] components = new String [] {
- "PlayerInputComponent",
- "StdGraphicsComponent",
- "PlayerMovementComponent",
- "PlayerSpawnComponent"};
-
- PlayerSpec() {
- super(tag, bitmapName,
- speed, relativeScale,
- components);
- }
-}
diff --git a/Chapter21/java/Renderer.java b/Chapter21/java/Renderer.java
deleted file mode 100644
index 9bff01e..0000000
--- a/Chapter21/java/Renderer.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-import java.util.ArrayList;
-
-class Renderer {
- private Canvas mCanvas;
- private SurfaceHolder mSurfaceHolder;
- private Paint mPaint;
-
- Renderer(SurfaceView sh){
- mSurfaceHolder = sh.getHolder();
- mPaint = new Paint();
- }
-
- void draw(ArrayList objects, GameState gs, HUD hud, ParticleSystem ps) {
- if (mSurfaceHolder.getSurface().isValid()) {
- mCanvas = mSurfaceHolder.lockCanvas();
- mCanvas.drawColor(Color.argb(255, 0, 0, 0));
-
- if (gs.getDrawing()) {
- // Draw all the game objects here
- for (GameObject object : objects) {
- if(object.checkActive()) {
- object.draw(mCanvas, mPaint);
- }
- }
- }
-
- if(gs.getGameOver()) {
- // Draw a background graphic here
- objects.get(Level.BACKGROUND_INDEX).draw(mCanvas, mPaint);
- }
-
- // Draw a particle system explosion here
- if(ps.mIsRunning){
- ps.draw(mCanvas, mPaint);
- }
-
- // Now we draw the HUD on top of everything else
- hud.draw(mCanvas, mPaint, gs);
-
- mSurfaceHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-}
diff --git a/Chapter21/java/SoundEngine.java b/Chapter21/java/SoundEngine.java
deleted file mode 100644
index fe11d6f..0000000
--- a/Chapter21/java/SoundEngine.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-
-import java.io.IOException;
-
-class SoundEngine {
- // for playing sound effects
- private SoundPool mSP;
- private int mShoot_ID = -1;
- private int mAlien_Explode_ID = -1;
- private int mPlayer_explode_ID = -1;
-
-
- SoundEngine(Context c){
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
- try {
- AssetManager assetManager = c.getAssets();
- AssetFileDescriptor descriptor;
-
- // Prepare the sounds in memory
- descriptor = assetManager.openFd("shoot.ogg");
- mShoot_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("alien_explosion.ogg");
- mAlien_Explode_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("player_explosion.ogg");
- mPlayer_explode_ID = mSP.load(descriptor, 0);
-
- } catch (IOException e) {
- // Error
- }
-
- }
-
- void playShoot(){
- mSP.play(mShoot_ID,1, 1, 0, 0, 1);
- }
-
- void playAlienExplode(){
- mSP.play(mAlien_Explode_ID,1, 1, 0, 0, 1);
- }
-
- void playPlayerExplode(){
- mSP.play(mPlayer_explode_ID,1, 1, 0, 0, 1);
- }
-}
diff --git a/Chapter21/java/SpawnComponent.java b/Chapter21/java/SpawnComponent.java
deleted file mode 100644
index 80381d4..0000000
--- a/Chapter21/java/SpawnComponent.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-interface SpawnComponent {
-
- void spawn(Transform playerTransform,
- Transform t);
-}
diff --git a/Chapter21/java/StdGraphicsComponent.java b/Chapter21/java/StdGraphicsComponent.java
deleted file mode 100644
index 1f40f9c..0000000
--- a/Chapter21/java/StdGraphicsComponent.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-class StdGraphicsComponent implements GraphicsComponent {
-
- private Bitmap mBitmap;
- private Bitmap mBitmapReversed;
-
- @Override
- public void initialize(Context context,
- ObjectSpec spec,
- PointF objectSize){
-
- // Make a resource id out of the string of the file name
- int resID = context.getResources()
- .getIdentifier(spec.getBitmapName(),
- "drawable",
- context.getPackageName());
-
- // Load the bitmap using the id
- mBitmap = BitmapFactory.decodeResource(
- context.getResources(), resID);
-
- // Resize the bitmap
- mBitmap = Bitmap
- .createScaledBitmap(mBitmap,
- (int)objectSize.x,
- (int)objectSize.y,
- false);
-
- // Create a mirror image of the bitmap if required
- Matrix matrix = new Matrix();
- matrix.setScale(-1, 1);
- mBitmapReversed = Bitmap.createBitmap(mBitmap,
- 0, 0,
- mBitmap.getWidth(),
- mBitmap.getHeight(),
- matrix, true);
- }
-
- @Override
- public void draw(Canvas canvas, Paint paint, Transform t) {
- if(t.getFacingRight())
- canvas.drawBitmap(mBitmap,
- t.getLocation().x,
- t.getLocation().y,
- paint);
-
- else
- canvas.drawBitmap(mBitmapReversed,
- t.getLocation().x,
- t.getLocation().y,
- paint);
- }
-}
diff --git a/Chapter21/java/Transform.java b/Chapter21/java/Transform.java
deleted file mode 100644
index e9e1a3f..0000000
--- a/Chapter21/java/Transform.java
+++ /dev/null
@@ -1,165 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.PointF;
-import android.graphics.RectF;
-
-class Transform {
-
- // These two members are for scrolling background
- private int mXClip;
- private boolean mReversedFirst = false;
-
- private RectF mCollider;
- private PointF mLocation;
- private boolean mFacingRight = true;
- private boolean mHeadingUp = false;
- private boolean mHeadingDown = false;
- private boolean mHeadingLeft = false;
- private boolean mHeadingRight = false;
- private float mSpeed;
- private float mObjectHeight;
- private float mObjectWidth;
- private static PointF mScreenSize;
-
- Transform(float speed, float objectWidth,
- float objectHeight,
- PointF startingLocation,
- PointF screenSize){
-
- mCollider = new RectF();
- mSpeed = speed;
- mObjectHeight = objectHeight;
- mObjectWidth = objectWidth;
- mLocation = startingLocation;
- mScreenSize = screenSize;
- }
-
- boolean getReversedFirst(){
- return mReversedFirst;
- }
-
- void flipReversedFirst(){
- mReversedFirst = !mReversedFirst;
- }
-
- int getXClip(){
- return mXClip;
- }
-
- void setXClip(int newXClip){
- mXClip = newXClip;
- }
-
- PointF getmScreenSize(){
- return mScreenSize;
- }
-
-
- void headUp(){
- mHeadingUp = true;
- mHeadingDown = false;
-
- }
-
- void headDown(){
- mHeadingDown = true;
- mHeadingUp = false;
- }
-
- void headRight(){
- mHeadingRight = true;
- mHeadingLeft = false;
- mFacingRight = true;
- }
-
- void headLeft(){
- mHeadingLeft = true;
- mHeadingRight = false;
- mFacingRight = false;
- }
-
- boolean headingUp(){
- return mHeadingUp;
- }
-
- boolean headingDown(){
- return mHeadingDown;
- }
-
- boolean headingRight(){
- return mHeadingRight;
- }
-
- boolean headingLeft(){
- return mHeadingLeft;
- }
-
-
- void updateCollider(){
- // Pull the borders in a bit (10%)
- mCollider.top = mLocation.y + (mObjectHeight / 10);
- mCollider.left = mLocation.x + (mObjectWidth /10);
- mCollider.bottom = (mCollider.top + mObjectHeight)
- - mObjectHeight/10;
-
- mCollider.right = (mCollider.left + mObjectWidth)
- - mObjectWidth/10;
- }
-
- float getObjectHeight(){
- return mObjectHeight;
- }
-
- void stopVertical(){
- mHeadingDown = false;
- mHeadingUp = false;
- }
-
- float getSpeed(){
- return mSpeed;
- }
-
- void setLocation(float horizontal, float vertical){
- mLocation = new PointF(horizontal, vertical);
- updateCollider();
- }
-
-
- PointF getLocation() {
-
- return mLocation;
- }
-
- PointF getSize(){
- return new PointF((int)mObjectWidth,
- (int)mObjectHeight);
- }
-
- void flip(){
- mFacingRight = !mFacingRight;
- }
-
- boolean getFacingRight(){
- return mFacingRight;
- }
-
- RectF getCollider(){
- return mCollider;
- }
-
- PointF getFiringLocation(float laserLength){
- PointF mFiringLocation = new PointF();
-
- if(mFacingRight) {
- mFiringLocation.x = mLocation.x
- + (mObjectWidth / 8f);
- }else
- {
- mFiringLocation.x = mLocation.x
- + (mObjectWidth / 8f) - (laserLength);
- }
- // Move the height down a bit of ship height from origin
- mFiringLocation.y = mLocation.y + (mObjectHeight / 1.28f);
- return mFiringLocation;
- }
-}
diff --git a/Chapter21/java/UIController.java b/Chapter21/java/UIController.java
deleted file mode 100644
index 81eaa9e..0000000
--- a/Chapter21/java/UIController.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package com.gamecodeschool.c21scrollingshooter;
-
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-class UIController implements InputObserver {
-
-
- public UIController(GameEngineBroadcaster b){
- b.addObserver(this);
- }
-
- @Override
- public void handleInput(MotionEvent event, GameState gameState, ArrayList buttons) {
-
- int i = event.getActionIndex();
- int x = (int) event.getX(i);
- int y = (int) event.getY(i);
-
- int eventType = event.getAction() & MotionEvent.ACTION_MASK;
-
- if(eventType == MotionEvent.ACTION_UP ||
- eventType == MotionEvent.ACTION_POINTER_UP) {
-
-
- if (buttons.get(HUD.PAUSE).contains(x, y)){
- // Player pressed the pause button
- // Respond differently depending upon the game's state
-
- // If the game is not paused
- if (!gameState.getPaused()) {
- // Pause the game
- gameState.pause();
- }
-
- // If game is over start a new game
- else if (gameState.getGameOver()) {
-
- gameState.startNewGame();
- }
-
- // Paused and not game over
- else if (gameState.getPaused()
- && !gameState.getGameOver()) {
-
- gameState.resume();
- }
- }
-
-
- }
-
- }
-
-}
diff --git a/Chapter22/AndroidManifest.xml b/Chapter22/AndroidManifest.xml
deleted file mode 100644
index 4f41d30..0000000
--- a/Chapter22/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter22/Java/BitmapStore.java b/Chapter22/Java/BitmapStore.java
deleted file mode 100644
index 71920ba..0000000
--- a/Chapter22/Java/BitmapStore.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Matrix;
-import android.graphics.PointF;
-
-import java.util.HashMap;
-import java.util.Map;
-
-class BitmapStore {
- private static Map mBitmapsMap;
- private static Map mBitmapsReversedMap;
- private static BitmapStore mOurInstance;
-
- // Calling this method is the only way to get a BitmapStore
- static BitmapStore getInstance(Context context) {
-
- mOurInstance = new BitmapStore(context);
- return mOurInstance;
- }
-
- // Can't be called using new BitmapStore()
- private BitmapStore(Context c) {
- mBitmapsMap = new HashMap();
- mBitmapsReversedMap = new HashMap();
-
- // Put a default bitmap in each of the maps
- // to return in case a bitmap doesn't exist
- addBitmap(c,
- "death_visible",
- new PointF(1, 1),
- 128,
- true);
- }
-
- static Bitmap getBitmap(String bitmapName) {
-
- if (mBitmapsMap.containsKey(bitmapName)) {
- return mBitmapsMap.get(bitmapName);
- } else {
- return mBitmapsMap.get("death_visible");
- }
- }
-
- static Bitmap getBitmapReversed(String bitmapName) {
-
- if (mBitmapsReversedMap.containsKey(bitmapName)) {
- return mBitmapsReversedMap.get(bitmapName);
- } else {
- return mBitmapsReversedMap.get("death_visible");
- }
- }
-
- static void addBitmap(Context c,
- String bitmapName,
- PointF objectSize,
- int pixelsPerMetre,
- boolean needReversed) {
-
- Bitmap bitmap;
- Bitmap bitmapReversed;
-
- // Make a resource id out of the string of the file name
- int resID = c.getResources().getIdentifier(bitmapName,
- "drawable", c.getPackageName());
-
- // Load the bitmap using the id
- bitmap = BitmapFactory
- .decodeResource(c.getResources(), resID);
-
- // Resize the bitmap
- bitmap = Bitmap.createScaledBitmap(bitmap,
- (int) objectSize.x * pixelsPerMetre,
- (int) objectSize.y * pixelsPerMetre,
- false);
-
- mBitmapsMap.put(bitmapName, bitmap);
-
- if (needReversed) {
- // Create a mirror image of the bitmap
- Matrix matrix = new Matrix();
- matrix.setScale(-1, 1);
- bitmapReversed = Bitmap.createBitmap(
- bitmap,
- 0, 0,
- bitmap.getWidth(),
- bitmap.getHeight(),
- matrix, true);
-
- mBitmapsReversedMap.put(bitmapName, bitmapReversed);
- }
-
- }
-
- static void clearStore() {
- mBitmapsMap.clear();
- mBitmapsReversedMap.clear();
- }
-}
diff --git a/Chapter22/Java/Camera.java b/Chapter22/Java/Camera.java
deleted file mode 100644
index f9da1f2..0000000
--- a/Chapter22/Java/Camera.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-class Camera {
-
- private PointF mCurrentCameraWorldCentre;
- private Rect mConvertedRect;
- private int mPixelsPerMetre;
- private int mScreenCentreX;
- private int mScreenCentreY;
-
- Camera(int screenXResolution, int screenYResolution){
- // Locate the centre of the screen
- mScreenCentreX = screenXResolution / 2;
- mScreenCentreY = screenYResolution / 2;
-
- // How many metres of world space does
- // the screen width show
- // Change this value to zoom in and out
- final int pixelsPerMetreToResolutionRatio = 48;
- mPixelsPerMetre = screenXResolution /
- pixelsPerMetreToResolutionRatio;
-
- mConvertedRect = new Rect();
- mCurrentCameraWorldCentre = new PointF();
- }
-
- int getPixelsPerMetreY(){
- return mPixelsPerMetre;
- }
-
- int getyCentre(){
- return mScreenCentreY;
- }
-
- float getCameraWorldCentreY(){
- return mCurrentCameraWorldCentre.y;
- }
-
- // Set the camera to the player. Called each frame
- void setWorldCentre(PointF worldCentre){
- mCurrentCameraWorldCentre.x = worldCentre.x;
- mCurrentCameraWorldCentre.y = worldCentre.y;
- }
-
- int getPixelsPerMetre(){
- return mPixelsPerMetre;
- }
-
- // Return a Rect of the screen coordinates relative to a world location
- Rect worldToScreen(float objectX,
- float objectY,
- float objectWidth,
- float objectHeight){
-
- int left = (int) (mScreenCentreX -
- ((mCurrentCameraWorldCentre.x - objectX)
- * mPixelsPerMetre));
-
- int top = (int) (mScreenCentreY -
- ((mCurrentCameraWorldCentre.y - objectY)
- * mPixelsPerMetre));
-
- int right = (int) (left + (objectWidth * mPixelsPerMetre));
- int bottom = (int) (top + (objectHeight * mPixelsPerMetre));
- mConvertedRect.set(left, top, right, bottom);
- return mConvertedRect;
- }
-
-}
-
diff --git a/Chapter22/Java/DecorativeBlockUpdateComponent.java b/Chapter22/Java/DecorativeBlockUpdateComponent.java
deleted file mode 100644
index aae9c8e..0000000
--- a/Chapter22/Java/DecorativeBlockUpdateComponent.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-class DecorativeBlockUpdateComponent implements UpdateComponent {
- @Override
- public void update(long fps, Transform t, Transform playerTransform) {
- // Do nothing
- // Not even set a collider
- }
-}
diff --git a/Chapter22/Java/EngineController.java b/Chapter22/Java/EngineController.java
deleted file mode 100644
index 82abebb..0000000
--- a/Chapter22/Java/EngineController.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-interface EngineController {
- // This allows the GameState class to start a new level
- void startNewLevel();
-}
diff --git a/Chapter22/Java/GOSpec/BackgroundCitySpec.java b/Chapter22/Java/GOSpec/BackgroundCitySpec.java
deleted file mode 100644
index 441faa5..0000000
--- a/Chapter22/Java/GOSpec/BackgroundCitySpec.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BackgroundCitySpec extends GameObjectSpec {
- // This is all the unique specifications for the city background
- private static final String tag = "Background";
- private static final String bitmapName = "city";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(100, 70);
- private static final String[] components = new String [] {
- "BackgroundGraphicsComponent","BackgroundUpdateComponent"};
-
- public BackgroundCitySpec() {
- super(tag, bitmapName, speed, size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/BackgroundMountainSpec.java b/Chapter22/Java/GOSpec/BackgroundMountainSpec.java
deleted file mode 100644
index b80e588..0000000
--- a/Chapter22/Java/GOSpec/BackgroundMountainSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BackgroundMountainSpec extends GameObjectSpec {
- // This is all the specifications for the mountain
- private static final String tag = "Background";
- private static final String bitmapName = "mountain";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(100, 70);
- private static final String[] components = new String [] {
- "BackgroundGraphicsComponent",
- "BackgroundUpdateComponent"};
-
- public BackgroundMountainSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/BackgroundUndergroundSpec.java b/Chapter22/Java/GOSpec/BackgroundUndergroundSpec.java
deleted file mode 100644
index 41541ff..0000000
--- a/Chapter22/Java/GOSpec/BackgroundUndergroundSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BackgroundUndergroundSpec extends GameObjectSpec {
- // This is all the specifications for the underground
- private static final String tag = "Background";
- private static final String bitmapName = "underground";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(100, 70f);
- private static final String[] components = new String [] {
- "BackgroundGraphicsComponent",
- "BackgroundUpdateComponent"};
-
- public BackgroundUndergroundSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/BrickTileSpec.java b/Chapter22/Java/GOSpec/BrickTileSpec.java
deleted file mode 100644
index 3a1ecc6..0000000
--- a/Chapter22/Java/GOSpec/BrickTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BrickTileSpec extends GameObjectSpec {
-
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "brick";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public BrickTileSpec() {
- super(tag, bitmapName, speed,
- size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/CartTileSpec.java b/Chapter22/Java/GOSpec/CartTileSpec.java
deleted file mode 100644
index 00c3c5a..0000000
--- a/Chapter22/Java/GOSpec/CartTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class CartTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "cart";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 1f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public CartTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/CoalTileSpec.java b/Chapter22/Java/GOSpec/CoalTileSpec.java
deleted file mode 100644
index b72415c..0000000
--- a/Chapter22/Java/GOSpec/CoalTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class CoalTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "coal";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public CoalTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/CollectibleObjectSpec.java b/Chapter22/Java/GOSpec/CollectibleObjectSpec.java
deleted file mode 100644
index fbf9d79..0000000
--- a/Chapter22/Java/GOSpec/CollectibleObjectSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class CollectibleObjectSpec extends GameObjectSpec {
- private static final String tag = "Collectible";
- private static final String bitmapName = "coin";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public CollectibleObjectSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/ConcreteTileSpec.java b/Chapter22/Java/GOSpec/ConcreteTileSpec.java
deleted file mode 100644
index dff13b5..0000000
--- a/Chapter22/Java/GOSpec/ConcreteTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class ConcreteTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "concrete";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public ConcreteTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/DeadTreeTileSpec.java b/Chapter22/Java/GOSpec/DeadTreeTileSpec.java
deleted file mode 100644
index f1fc83f..0000000
--- a/Chapter22/Java/GOSpec/DeadTreeTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class DeadTreeTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "dead_tree";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 4f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public DeadTreeTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/FireTileSpec.java b/Chapter22/Java/GOSpec/FireTileSpec.java
deleted file mode 100644
index 40d2b90..0000000
--- a/Chapter22/Java/GOSpec/FireTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class FireTileSpec extends GameObjectSpec {
- private static final String tag = "Death";
- private static final String bitmapName = "fire";
- private static final int framesOfAnimation = 3;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String[]{
- "AnimatedGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public FireTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/GameObjectSpec.java b/Chapter22/Java/GOSpec/GameObjectSpec.java
deleted file mode 100644
index 040ba2c..0000000
--- a/Chapter22/Java/GOSpec/GameObjectSpec.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public abstract class GameObjectSpec {
- private String mTag;
- private String mBitmapName;
- private float mSpeed;
- private PointF mSize;
- private String[] mComponents;
- private int mFramesAnimation;
-
- GameObjectSpec(String tag,
- String bitmapName,
- float speed,
- PointF size,
- String[] components,
- int framesAnimation ){
-
- mTag = tag;
- mBitmapName = bitmapName;
- mSpeed = speed;
- mSize = size;
- mComponents = components;
- mFramesAnimation = framesAnimation;
- }
-
- public int getNumFrames(){
- return mFramesAnimation;
- }
-
- public String getTag(){
- return mTag;
- }
-
- public String getBitmapName(){
- return mBitmapName;
- }
-
- public float getSpeed(){
- return mSpeed;
- }
-
- public PointF getSize(){
- return mSize;
- }
-
- public String[] getComponents(){
- return mComponents;
- }
-}
diff --git a/Chapter22/Java/GOSpec/GrassTileSpec.java b/Chapter22/Java/GOSpec/GrassTileSpec.java
deleted file mode 100644
index ceb9034..0000000
--- a/Chapter22/Java/GOSpec/GrassTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class GrassTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "turf";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public GrassTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/InvisibleDeathTenByTenSpec.java b/Chapter22/Java/GOSpec/InvisibleDeathTenByTenSpec.java
deleted file mode 100644
index c51457b..0000000
--- a/Chapter22/Java/GOSpec/InvisibleDeathTenByTenSpec.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-import android.graphics.PointF;
-
-public class InvisibleDeathTenByTenSpec extends GameObjectSpec {
- private static final String tag = "Death";
- private static final String bitmapName = "death_visible";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(10f, 10f);
- private static final String[] components = new String[]{"InanimateBlockGraphicsComponent", "InanimateBlockUpdateComponent"};
-
- public InvisibleDeathTenByTenSpec() {
- super(tag, bitmapName, speed, size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/LamppostTileSpec.java b/Chapter22/Java/GOSpec/LamppostTileSpec.java
deleted file mode 100644
index cb51796..0000000
--- a/Chapter22/Java/GOSpec/LamppostTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class LamppostTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "lamppost";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 4f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public LamppostTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/MoveablePlatformSpec.java b/Chapter22/Java/GOSpec/MoveablePlatformSpec.java
deleted file mode 100644
index 95ced77..0000000
--- a/Chapter22/Java/GOSpec/MoveablePlatformSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class MoveablePlatformSpec extends GameObjectSpec {
- private static final String tag = "Movable Platform";
- private static final String bitmapName = "platform";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(2f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "MovableBlockUpdateComponent"};
-
- public MoveablePlatformSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/ObjectiveTileSpec.java b/Chapter22/Java/GOSpec/ObjectiveTileSpec.java
deleted file mode 100644
index ff0f624..0000000
--- a/Chapter22/Java/GOSpec/ObjectiveTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class ObjectiveTileSpec extends GameObjectSpec {
-
- private static final String tag = "Objective Tile";
- private static final String bitmapName = "objective";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(3f, 3f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public ObjectiveTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/PlayerSpec.java b/Chapter22/Java/GOSpec/PlayerSpec.java
deleted file mode 100644
index 2d6c4b4..0000000
--- a/Chapter22/Java/GOSpec/PlayerSpec.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class PlayerSpec extends GameObjectSpec {
- // This is all the unique specifications for a player
- private static final String tag = "Player";
- private static final String bitmapName = "player";
- private static final int framesOfAnimation = 5;
- private static final float speed = 10f;
- private static final PointF size = new PointF(1f, 2f);
- private static final String[] components = new String [] {
- "PlayerInputComponent",
- "AnimatedGraphicsComponent",
- "PlayerUpdateComponent"};
-
- public PlayerSpec() {
- super(tag, bitmapName, speed,
- size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/ScorchedTileSpec.java b/Chapter22/Java/GOSpec/ScorchedTileSpec.java
deleted file mode 100644
index 271bd79..0000000
--- a/Chapter22/Java/GOSpec/ScorchedTileSpec.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class ScorchedTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "scorched";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public ScorchedTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
-
- }
-}
diff --git a/Chapter22/Java/GOSpec/SnowTileSpec.java b/Chapter22/Java/GOSpec/SnowTileSpec.java
deleted file mode 100644
index 1fbae3b..0000000
--- a/Chapter22/Java/GOSpec/SnowTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class SnowTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "snow";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public SnowTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/SnowyTreeTileSpec.java b/Chapter22/Java/GOSpec/SnowyTreeTileSpec.java
deleted file mode 100644
index a5b2d40..0000000
--- a/Chapter22/Java/GOSpec/SnowyTreeTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class SnowyTreeTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "snowy_tree";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(3f, 6f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public SnowyTreeTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/StalactiteTileSpec.java b/Chapter22/Java/GOSpec/StalactiteTileSpec.java
deleted file mode 100644
index f2bcd0c..0000000
--- a/Chapter22/Java/GOSpec/StalactiteTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class StalactiteTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "stalactite";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 4f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public StalactiteTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/StalagmiteTileSpec.java b/Chapter22/Java/GOSpec/StalagmiteTileSpec.java
deleted file mode 100644
index 537cfa5..0000000
--- a/Chapter22/Java/GOSpec/StalagmiteTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class StalagmiteTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "stalagmite";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 4f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public StalagmiteTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GOSpec/StonePileTileSpec.java b/Chapter22/Java/GOSpec/StonePileTileSpec.java
deleted file mode 100644
index 24003cf..0000000
--- a/Chapter22/Java/GOSpec/StonePileTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c22platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class StonePileTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "stone_pile";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public StonePileTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter22/Java/GameActivity.java b/Chapter22/Java/GameActivity.java
deleted file mode 100644
index 91a1d33..0000000
--- a/Chapter22/Java/GameActivity.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class GameActivity extends Activity {
-
- GameEngine mGameEngine;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Display display = getWindowManager()
- .getDefaultDisplay();
-
- Point size = new Point();
- display.getSize(size);
- mGameEngine = new GameEngine(this, size);
- setContentView(mGameEngine);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mGameEngine.startThread();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mGameEngine.stopThread();
- }
-}
diff --git a/Chapter22/Java/GameEngine.java b/Chapter22/Java/GameEngine.java
deleted file mode 100644
index ec5ba8b..0000000
--- a/Chapter22/Java/GameEngine.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.content.Context;
-import android.graphics.Point;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceView;
-
-import java.util.concurrent.CopyOnWriteArrayList;
-
-class GameEngine extends SurfaceView
- implements Runnable,
- GameEngineBroadcaster,
- EngineController {
-
- private Thread mThread = null;
- private long mFPS;
-
- private GameState mGameState;
- UIController mUIController;
-
- // This ArrayList can be accessed from either thread
- private CopyOnWriteArrayList
- inputObservers = new CopyOnWriteArrayList();
-
- HUD mHUD;
- LevelManager mLevelManager;
- PhysicsEngine mPhysicsEngine;
- Renderer mRenderer;
-
- public GameEngine(Context context, Point size) {
- super(context);
- // Prepare the bitmap store and sound engine
- BitmapStore bs = BitmapStore.getInstance(context);
- SoundEngine se = SoundEngine.getInstance(context);
-
- // Initialize all the significant classes
- // that make the engine work
- mHUD = new HUD(context, size);
- mGameState = new GameState(this, context);
- mUIController = new UIController(this, size);
- mPhysicsEngine = new PhysicsEngine();
- mRenderer = new Renderer(this, size);
- mLevelManager = new LevelManager(context,
- this, mRenderer.getPixelsPerMetre());
-
- }
-
- public void startNewLevel() {
- // Clear the bitmap store
- BitmapStore.clearStore();
- // Clear all the observers and add the UI observer back
- // When we call buildGameObjects the
- // player's observer will be added too
- inputObservers.clear();
- mUIController.addObserver(this);
- mLevelManager.setCurrentLevel(mGameState.getCurrentLevel());
- mLevelManager.buildGameObjects(mGameState);
- }
-
- // For the game engine broadcaster interface
- public void addObserver(InputObserver o) {
- inputObservers.add(o);
- }
-
- @Override
- public void run() {
- while (mGameState.getThreadRunning()) {
-
- long frameStartTime = System.currentTimeMillis();
-
- if (!mGameState.getPaused()) {
- mPhysicsEngine.update(mFPS,
- mLevelManager.getGameObjects(),
- mGameState);
- }
-
- mRenderer.draw(mLevelManager.getGameObjects(),
- mGameState,
- mHUD);
-
- long timeThisFrame = System.currentTimeMillis()
- - frameStartTime;
-
- if (timeThisFrame >= 1) {
- final int MILLIS_IN_SECOND = 1000;
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- for (InputObserver o : inputObservers) {
- o.handleInput(motionEvent,
- mGameState,
- mHUD.getControls());
- }
- return true;
- }
-
- public void stopThread() {
- mGameState.stopEverything();
- mGameState.stopThread();
- try {
- mThread.join();
- } catch (InterruptedException e) {
- Log.e("Exception",
- "stopThread()" + e.getMessage());
- }
- }
-
- public void startThread() {
- mGameState.startThread();
- mThread = new Thread(this);
- mThread.start();
- }
-}
diff --git a/Chapter22/Java/GameEngineBroadcaster.java b/Chapter22/Java/GameEngineBroadcaster.java
deleted file mode 100644
index 3a57271..0000000
--- a/Chapter22/Java/GameEngineBroadcaster.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-interface GameEngineBroadcaster {
-
- // This allows the Player and UI Controller components
- // to add themselves as listeners of the GameEngine class
- void addObserver(InputObserver o);
-}
diff --git a/Chapter22/Java/GameObject.java b/Chapter22/Java/GameObject.java
deleted file mode 100644
index b7715fc..0000000
--- a/Chapter22/Java/GameObject.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-import com.gamecodeschool.c22platformer.GOSpec.GameObjectSpec;
-
-class GameObject {
-
- private Transform mTransform;
-
-
- private boolean mActive = true;
- private String mTag;
-
- private GraphicsComponent mGraphicsComponent;
- private UpdateComponent mUpdateComponent;
-
- void setGraphics(GraphicsComponent g,
- Context c,
- GameObjectSpec spec,
- PointF objectSize,
- int pixelsPerMetre) {
-
- mGraphicsComponent = g;
- g.initialize(c, spec, objectSize, pixelsPerMetre);
- }
-
- void setMovement(UpdateComponent m) {
- mUpdateComponent = m;
- }
-
- /*
- Uncomment this code soon
- void setPlayerInputTransform(PlayerInputComponent s) {
- s.setTransform(mTransform);
- }
- */
-
- void setTransform(Transform t) {
- mTransform = t;
- }
-
- void draw(Canvas canvas, Paint paint, Camera cam) {
- mGraphicsComponent.draw(canvas,
- paint,
- mTransform, cam);
- }
-
- void update(long fps, Transform playerTransform) {
- mUpdateComponent.update(fps,
- mTransform,
- playerTransform);
- }
-
- boolean checkActive() {
- return mActive;
- }
-
- String getTag() {
- return mTag;
- }
-
- void setInactive() {
- mActive = false;
- }
-
- Transform getTransform() {
- return mTransform;
- }
-
- void setTag(String tag) {
- mTag = tag;
- }
-}
diff --git a/Chapter22/Java/GameObjectFactory.java b/Chapter22/Java/GameObjectFactory.java
deleted file mode 100644
index 3b37d60..0000000
--- a/Chapter22/Java/GameObjectFactory.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.content.Context;
-import android.graphics.PointF;
-
-import com.gamecodeschool.c22platformer.GOSpec.GameObjectSpec;
-
-class GameObjectFactory {
- private Context mContext;
- private GameEngine mGameEngineReference;
- private int mPixelsPerMetre;
-
- GameObjectFactory(Context context,
- GameEngine gameEngine,
- int pixelsPerMetre) {
-
- mContext = context;
- mGameEngineReference = gameEngine;
- mPixelsPerMetre = pixelsPerMetre;
- }
-
- GameObject create(GameObjectSpec spec, PointF location) {
- GameObject object = new GameObject();
-
- int mNumComponents = spec.getComponents().length;
- object.setTag(spec.getTag());
-
- // First give the game object the
- // right kind of transform
-
- switch(object.getTag()){
- case "Background":
- // Code coming soon
- break;
-
- case "Player":
- // Code coming soon
- break;
-
- default:// normal transform
- object.setTransform(new Transform(
- spec.getSpeed(),
- spec.getSize().x,
- spec.getSize().y,
- location));
- break;
- }
-
-
- // Loop through and add/initialize all the components
- for (int i = 0; i < mNumComponents; i++) {
- switch (spec.getComponents()[i]) {
- case "PlayerInputComponent":
- // Code coming soon
- break;
- case "AnimatedGraphicsComponent":
- // Code coming soon
- break;
- case "PlayerUpdateComponent":
- // Code coming soon
- break;
- case "InanimateBlockGraphicsComponent":
- object.setGraphics(new
- InanimateBlockGraphicsComponent(),
- mContext, spec, spec.getSize(),
- mPixelsPerMetre);
- break;
- case "InanimateBlockUpdateComponent":
- object.setMovement(new
- InanimateBlockUpdateComponent());
- break;
- case "MovableBlockUpdateComponent":
- // Code coming soon
- break;
- case "DecorativeBlockUpdateComponent":
- object.setMovement(new
- DecorativeBlockUpdateComponent());
- break;
- case "BackgroundGraphicsComponent":
- // Code coming soon
- break;
- case "BackgroundUpdateComponent":
- // Code coming soon
- break;
-
- default:
- // Error unidentified component
- break;
- }
- }
-
- // Return the completed GameObject
- // to the LevelManager class
- return object;
- }
-}
diff --git a/Chapter22/Java/GameState.java b/Chapter22/Java/GameState.java
deleted file mode 100644
index d92f43b..0000000
--- a/Chapter22/Java/GameState.java
+++ /dev/null
@@ -1,185 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-
-final class GameState {
- private static volatile boolean
- mThreadRunning = false;
-
- private static volatile boolean mPaused = true;
- private static volatile boolean mGameOver = true;
- private static volatile boolean mDrawing = false;
- private EngineController engineController;
-
- private int mFastestUnderground;
- private int mFastestMountains;
- private int mFastestCity;
- private long startTimeInMillis;
-
- private int mCoinsAvailable;
- private int coinsCollected;
-
- private SharedPreferences.Editor editor;
-
- private String currentLevel;
-
- GameState(EngineController gs, Context context) {
- engineController = gs;
- SharedPreferences prefs = context
- .getSharedPreferences("HiScore",
- Context.MODE_PRIVATE);
-
- editor = prefs.edit();
- mFastestUnderground = prefs.getInt(
- "fastest_underground_time", 1000);
- mFastestMountains = prefs.getInt(
- "fastest_mountains_time", 1000);
- mFastestCity = prefs.getInt(
- "fastest_city_time", 1000);
- }
-
-
- void coinCollected() {
- coinsCollected++;
- }
-
- int getCoinsRemaining() {
- return mCoinsAvailable - coinsCollected;
- }
-
- void coinAddedToLevel() {
- mCoinsAvailable++;
- }
-
- void resetCoins() {
- mCoinsAvailable = 0;
- coinsCollected = 0;
- }
-
-
- void setCurrentLevel(String level) {
- currentLevel = level;
- }
-
- String getCurrentLevel() {
- return currentLevel;
- }
-
- void objectiveReached() {
- endGame();
- }
-
- int getFastestUnderground() {
- return mFastestUnderground;
- }
-
- int getFastestMountains() {
- return mFastestMountains;
- }
-
- int getFastestCity() {
- return mFastestCity;
- }
-
- void startNewGame() {
- // Don't want to be handling objects while
- // clearing ArrayList and filling it up again
- stopEverything();
- engineController.startNewLevel();
- startEverything();
- startTimeInMillis = System.currentTimeMillis();
- }
-
- int getCurrentTime() {
- long MILLIS_IN_SECOND = 1000;
- return (int) ((System.currentTimeMillis()
- - startTimeInMillis) / MILLIS_IN_SECOND);
- }
-
- void death() {
- stopEverything();
- SoundEngine.playPlayerBurn();
- }
-
- private void endGame() {
-
- stopEverything();
- int totalTime =
- ((mCoinsAvailable - coinsCollected)
- * 10)
- + getCurrentTime();
-
- switch (currentLevel) {
-
- case "underground":
- if (totalTime < mFastestUnderground) {
- mFastestUnderground = totalTime;
- // Save new time
-
- editor.putInt("fastest_underground_time",
- mFastestUnderground);
-
- editor.commit();
- }
- break;
- case "city":
- if (totalTime < mFastestCity) {
- mFastestCity = totalTime;
- // Save new time
- editor.putInt("fastest_city_time",
- mFastestCity);
-
- editor.commit();
- }
- break;
- case "mountains":
- if (totalTime < mFastestMountains) {
- mFastestMountains = totalTime;
- // Save new time
- editor.putInt("fastest_mountains_time",
- mFastestMountains);
-
- editor.commit();
- }
- break;
- }
- }
-
- void stopEverything() {// Except the thread
- mPaused = true;
- mGameOver = true;
- mDrawing = false;
- }
-
- private void startEverything() {
- mPaused = false;
- mGameOver = false;
- mDrawing = true;
- }
-
- void stopThread() {
- mThreadRunning = false;
- }
-
- boolean getThreadRunning() {
- return mThreadRunning;
- }
-
- void startThread() {
- mThreadRunning = true;
- }
-
- boolean getDrawing() {
- return mDrawing;
- }
-
- boolean getPaused() {
- return mPaused;
- }
-
- boolean getGameOver() {
- return mGameOver;
- }
-
-}
diff --git a/Chapter22/Java/GraphicsComponent.java b/Chapter22/Java/GraphicsComponent.java
deleted file mode 100644
index 258a1be..0000000
--- a/Chapter22/Java/GraphicsComponent.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-import com.gamecodeschool.c22platformer.GOSpec.GameObjectSpec;
-
-interface GraphicsComponent {
-
- // Added int mPixelsPerMetre to
- // scale the bitmap to the camera
- void initialize(Context c, GameObjectSpec spec,
- PointF objectSize, int pixelsPerMetre);
-
- // Updated from the last project
- // to take a reference to a Camera
- void draw(Canvas canvas, Paint paint,
- Transform t, Camera cam);
-}
diff --git a/Chapter22/Java/HUD.java b/Chapter22/Java/HUD.java
deleted file mode 100644
index a53c68e..0000000
--- a/Chapter22/Java/HUD.java
+++ /dev/null
@@ -1,179 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.graphics.Rect;
-
-import java.util.ArrayList;
-
-class HUD {
- private Bitmap mMenuBitmap;
-
- private int mTextFormatting;
- private int mScreenHeight;
- private int mScreenWidth;
- final float ONE_THIRD = .33f;
- final float TWO_THIRDS = .66f;
-
- private ArrayList mControls;
-
- static int LEFT = 0;
- static int RIGHT = 1;
- static int JUMP = 2;
-
- HUD(Context context, Point size){
- mScreenHeight = size.y;
- mScreenWidth = size.x;
- mTextFormatting = size.x / 25;
-
- prepareControls();
-
- // Create and scale the bitmaps
- mMenuBitmap = BitmapFactory
- .decodeResource(context.getResources(),
- R.drawable.menu);
-
- mMenuBitmap = Bitmap
- .createScaledBitmap(mMenuBitmap,
- size.x, size.y, false);
-
- }
-
- private void prepareControls(){
- int buttonWidth = mScreenWidth / 14;
- int buttonHeight = mScreenHeight / 12;
- int buttonPadding = mScreenWidth / 90;
-
-
- Rect left = new Rect(
- buttonPadding,
- mScreenHeight - buttonHeight - buttonPadding,
- buttonWidth + buttonPadding,
- mScreenHeight - buttonPadding);
-
- Rect right = new Rect(
- (buttonPadding * 2) + buttonWidth,
- mScreenHeight - buttonHeight - buttonPadding,
- (buttonPadding * 2) + (buttonWidth * 2),
- mScreenHeight - buttonPadding);
-
- Rect jump = new Rect(mScreenWidth - buttonPadding - buttonWidth,
- mScreenHeight - buttonHeight - buttonPadding,
- mScreenWidth - buttonPadding,
- mScreenHeight - buttonPadding);
-
-
- mControls = new ArrayList<>();
- mControls.add(LEFT,left);
- mControls.add(RIGHT,right);
- mControls.add(JUMP, jump);
- }
-
- void draw(Canvas c, Paint p, GameState gs){
-
- if(gs.getGameOver()){
-
- // Draw the mMenuBitmap screen
- c.drawBitmap(mMenuBitmap, 0,0, p);
-
- // draw a rectangle to highlight the text
- p.setColor(Color.argb (100, 26, 128, 182));
- c.drawRect(0,0, mScreenWidth,
- mTextFormatting * 4, p);
-
- // Draw the level names
- p.setColor(Color.argb(255, 255, 255, 255));
- p.setTextSize(mTextFormatting);
- c.drawText("Underground",
- mTextFormatting,
- mTextFormatting * 2,
- p);
-
- c.drawText("Mountains",
- mScreenWidth * ONE_THIRD + (mTextFormatting),
- mTextFormatting * 2,
- p);
-
- c.drawText("City",
- mScreenWidth * TWO_THIRDS + (mTextFormatting),
- mTextFormatting * 2,
- p);
-
- // Draw the fastest times
- p.setTextSize(mTextFormatting/1.8f);
-
- c.drawText("BEST:" + gs.getFastestUnderground()
- +" seconds",
- mTextFormatting,
- mTextFormatting*3,
- p);
-
- c.drawText("BEST:" + gs.getFastestMountains()
- +" seconds", mScreenWidth * ONE_THIRD
- + mTextFormatting,
- mTextFormatting * 3,
- p);
-
- c.drawText("BEST:" + gs.getFastestCity()
- + " seconds",
- mScreenWidth * TWO_THIRDS + mTextFormatting,
- mTextFormatting * 3,
- p);
-
- // draw a rectangle to highlight the large text
- p.setColor(Color.argb (100, 26, 128, 182));
- c.drawRect(0,mScreenHeight - mTextFormatting * 2,
- mScreenWidth,
- mScreenHeight,
- p);
-
- p.setColor(Color.argb(255, 255, 255, 255));
- p.setTextSize(mTextFormatting * 1.5f);
- c.drawText("DOUBLE TAP A LEVEL TO PLAY",
- ONE_THIRD + mTextFormatting * 2,
- mScreenHeight - mTextFormatting/2,
- p);
- }
- else {
- // draw a rectangle to highlight the text
- p.setColor(Color.argb (100, 0, 0, 0));
- c.drawRect(0,0, mScreenWidth,
- mTextFormatting,
- p);
-
- // Draw the HUD text
- p.setTextSize(mTextFormatting/1.5f);
- p.setColor(Color.argb(255, 255, 255, 255));
- c.drawText("Time:" + gs.getCurrentTime()
- + "+" + gs.getCoinsRemaining() * 10,
- mTextFormatting / 4,
- mTextFormatting / 1.5f,
- p);
-
-
- drawControls(c, p);
- }
-
- }
-
- private void drawControls(Canvas c, Paint p){
- p.setColor(Color.argb(100,255,255,255));
-
- for(Rect r : mControls){
- c.drawRect(r.left, r.top, r.right, r.bottom, p);
- }
-
- // Set the colors back
- p.setColor(Color.argb(255,255,255,255));
- }
-
-
- ArrayList getControls(){
- return mControls;
- }
-}
diff --git a/Chapter22/Java/InanimateBlockGraphicsComponent.java b/Chapter22/Java/InanimateBlockGraphicsComponent.java
deleted file mode 100644
index 7ecf4e3..0000000
--- a/Chapter22/Java/InanimateBlockGraphicsComponent.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-import com.gamecodeschool.c22platformer.GOSpec.GameObjectSpec;
-
-class InanimateBlockGraphicsComponent implements GraphicsComponent {
-
- private String mBitmapName;
-
- @Override
- public void initialize(Context context,
- GameObjectSpec spec,
- PointF objectSize,
- int pixelsPerMetre) {
-
- mBitmapName = spec.getBitmapName();
-
- BitmapStore.addBitmap(context,
- mBitmapName, objectSize,
- pixelsPerMetre,
- false);
-
- }
-
-
- @Override
- public void draw(Canvas canvas,
- Paint paint,
- Transform t,
- Camera cam) {
-
- Bitmap bitmap = BitmapStore.getBitmap(mBitmapName);
- // Use the camera to translate the real world
- // coordinates relative to the player-
- // into screen coordinates
- Rect screenCoordinates = cam.worldToScreen(
- t.getLocation().x,
- t.getLocation().y,
- t.getSize().x,
- t.getSize().y);
-
-
- canvas.drawBitmap(
- bitmap,
- screenCoordinates.left,
- screenCoordinates.top,
- paint);
-
-
- }
-}
diff --git a/Chapter22/Java/InanimateBlockUpdateComponent.java b/Chapter22/Java/InanimateBlockUpdateComponent.java
deleted file mode 100644
index 5e03f2b..0000000
--- a/Chapter22/Java/InanimateBlockUpdateComponent.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-class InanimateBlockUpdateComponent implements UpdateComponent {
-
- private boolean mColliderNotSet = true;
-
- @Override
- public void update(long fps,
- Transform t,
- Transform playerTransform) {
-
- // An alternative would be to update
- // the collider just once when it spawns.
- // But this would require spawn components
- // - More code but a bit faster
- if(mColliderNotSet) {
- // Only need to set the collider
- // once because it will never move
- t.updateCollider();
- mColliderNotSet = false;
- }
- }
-}
diff --git a/Chapter22/Java/InputObserver.java b/Chapter22/Java/InputObserver.java
deleted file mode 100644
index dc61369..0000000
--- a/Chapter22/Java/InputObserver.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-
-import android.graphics.Rect;
-import android.view.MotionEvent;
-import java.util.ArrayList;
-
-public interface InputObserver {
-
- // This allows InputObservers to be called by GameEngine to handle input
- void handleInput(MotionEvent event, GameState gs, ArrayList buttons);
-}
diff --git a/Chapter22/Java/LevelManager.java b/Chapter22/Java/LevelManager.java
deleted file mode 100644
index 17cb2e6..0000000
--- a/Chapter22/Java/LevelManager.java
+++ /dev/null
@@ -1,243 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.content.Context;
-import android.graphics.PointF;
-import android.util.Log;
-
-import com.gamecodeschool.c22platformer.GOSpec.*;
-import com.gamecodeschool.c22platformer.Levels.*;
-
-import java.util.ArrayList;
-
-final class LevelManager {
-
- static int PLAYER_INDEX = 0;
- private ArrayList objects;
- private Level currentLevel;
- private GameObjectFactory factory;
-
- LevelManager(Context context,
- GameEngine ge,
- int pixelsPerMetre){
-
- objects = new ArrayList<>();
- factory = new GameObjectFactory(context,
- ge,
- pixelsPerMetre);
- }
-
- void setCurrentLevel(String level){
- switch (level) {
- case "underground":
- currentLevel = new LevelUnderground();
- break;
-
- case "city":
- currentLevel = new LevelCity();
- break;
-
- case "mountains":
- currentLevel = new LevelMountains();
- break;
- }
- }
-
- void buildGameObjects(GameState gs){
- // Backgrounds 1, 2, 3(City, Underground, Mountain...)
- // p = Player
- // g = Grass tile
- // o = Objective
- // m = Movable platform
- // b = Brick tile
- // c = mine Cart
- // s = Stone pile
- // l = coaL
- // n = coNcrete
- // a = lAmpost
- // r = scoRched tile
- // w = snoW tile
- // t = stalacTite
- // i = stalagmIte
- // d = Dead tree
- // e = snowy trEe
- // x = Collectable
- // z = Fire
- // y = invisible death_invisible
-
- gs.resetCoins();
- objects.clear();
- ArrayList levelToLoad = currentLevel.getTiles();
-
- for(int row = 0; row < levelToLoad.size(); row++ )
- {
- for(int column = 0;
- column < levelToLoad.get(row).length();
- column++){
-
- PointF coords = new PointF(column, row);
-
- switch (levelToLoad.get(row)
- .charAt(column)){
-
- case '1':
- //objects.add(factory.create(
- // new BackgroundCitySpec(),
- // coords));
- break;
-
- case '2':
- //objects.add(factory.create(
- // new BackgroundUndergroundSpec(),
- // coords));
- break;
-
- case '3':
- //objects.add(factory.create(
- // new BackgroundMountainSpec(),
- // coords));
- break;
-
- case 'p':
- //objects.add(factory.create(new
- // PlayerSpec(),
- // coords));
- // Remember the location of
- // the player
- //PLAYER_INDEX = objects.size()-1;
- break;
-
- case 'g':
- objects.add(factory.create(
- new GrassTileSpec(),
- coords));
- break;
-
- case 'o':
- objects.add(factory.create(
- new ObjectiveTileSpec(),
- coords));
- break;
-
- case 'm':
- //objects.add(factory.create(
- // new MoveablePlatformSpec(),
- // coords));
- break;
-
- case 'b':
- objects.add(factory.create(
- new BrickTileSpec(),
- coords));
- break;
-
- case 'c':
- objects.add(factory.create(
- new CartTileSpec(),
- coords));
- break;
-
- case 's':
- objects.add(factory.create(
- new StonePileTileSpec(),
- coords));
- break;
-
- case 'l':
- objects.add(factory.create(
- new CoalTileSpec(),
- coords));
- break;
-
- case 'n':
- objects.add(factory.create(
- new ConcreteTileSpec(),
- coords));
- break;
-
- case 'a':
- objects.add(factory.create(
- new LamppostTileSpec(),
- coords));
- break;
-
- case 'r':
- objects.add(factory.create(
- new ScorchedTileSpec(),
- coords));
- break;
-
- case 'w':
- objects.add(factory.create(
- new SnowTileSpec(),
- coords));
- break;
-
- case 't':
- objects.add(factory.create(
- new StalactiteTileSpec(),
- coords));
- break;
-
- case 'i':
- objects.add(factory.create(
- new StalagmiteTileSpec(),
- coords));
- break;
-
- case 'd':
- objects.add(factory.create(
- new DeadTreeTileSpec(),
- coords));
- break;
-
- case 'e':
- objects.add(factory.create(
- new SnowyTreeTileSpec(),
- coords));
- break;
-
- case 'x':
- objects.add(factory.create(
- new CollectibleObjectSpec(),
- coords));
- gs.coinAddedToLevel();
- break;
-
- case 'z':
- //objects.add(factory.create(
- // new FireTileSpec(),
- // coords));
-
- break;
-
- case 'y':
- objects.add(factory.create(
- new InvisibleDeathTenByTenSpec(),
- coords));
-
- break;
-
-
- case '.':
- // Nothing to see here
- break;
-
- default:
- Log.e("Unhandled item in level",
- "row:"+row
- + " column:"+column);
- break;
- }
-
- }
-
- }
-
- }
-
- ArrayList getGameObjects(){
- return objects;
- }
-
-
-}
diff --git a/Chapter22/Java/Levels/Level.java b/Chapter22/Java/Levels/Level.java
deleted file mode 100644
index 0022f46..0000000
--- a/Chapter22/Java/Levels/Level.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.gamecodeschool.c22platformer.Levels;
-
-import java.util.ArrayList;
-
-public abstract class Level {
- // If you want to build a new level then extend this class
- ArrayList tiles;
- public ArrayList getTiles(){
- return tiles;
- }
-}
diff --git a/Chapter22/Java/Levels/LevelCity.java b/Chapter22/Java/Levels/LevelCity.java
deleted file mode 100644
index e45a631..0000000
--- a/Chapter22/Java/Levels/LevelCity.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.gamecodeschool.c25platformer.Levels;
-
-import java.util.ArrayList;
-
-public final class LevelCity extends Level {
- public LevelCity() {
- tiles = new ArrayList();
- tiles.add("1........................................................................................................................................................................................................................................................");
- tiles.add(".........................................................................................................................................................................................................................................................");
- tiles.add(".........................................................................................................................................................................................................................................................");
- tiles.add("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");
- tiles.add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx......................n..........................................................................");
- tiles.add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx......................n..........................................................................");
- tiles.add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx......................n..........................................................................");
- tiles.add("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnm.nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");
- tiles.add("b.x..................................................................................nxxxxx............................................................................................................a.........................a.......................");
- tiles.add("bxxx.................................................................................nxxxxx.......................................................................................................................................................o......");
- tiles.add("bbbbbb...............................................................................nxxxxx..............................................................................................................................................................");
- tiles.add("b......b.............................................................................nnnnnnnnnnnm........................................................................................................................................................");
- tiles.add("b.......b............................................................................n..........x...................................................................................ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg");
- tiles.add("b........b...........................................................................n..........x...................................................................................n....................................................................");
- tiles.add("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbm...nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnm.............n..........x...................................................................................n....................................................................");
- tiles.add("b....................................................................................n..........x...................................................................................nxxxxxxxx............................................................");
- tiles.add("b....................................................................................n..........x...................................................................................nxxxxxxxx............................................................");
- tiles.add("b....................................................................................n..........x...................................................................................nxxxxxxxx............................................................");
- tiles.add("b.................................................................................x..n..........x......................................................................nnnnnn.......n.nnnnnnnn...........................................................");
- tiles.add("bx...............................................................................xxx.n...........................................................m...m...m...m..nnnnnnn.............n........nnnnnnnn....................................................");
- tiles.add("bx.............................................................................bbbbbbn.........................................................m....................................n..............nnnnnnn...............................................");
- tiles.add("bx...............................a.............................a..............b......n.......................................................m......................................n....................nnnnn...........................................");
- tiles.add("bnnn.........................................................................b.......nnnnnnnnnnnnnnnnnnnnnnnm.............................m.........................................n........................nnnn........................................");
- tiles.add("b...................x.......................................................b.......................................................................................................n...........................nnnn.....................................");
- tiles.add("b......b...........xxx.....................................x..x..x..x......b........................................................................................................n..............................nnnnnn...nnnnnnnnnnnnnnnnnnnnnnnnnmx..");
- tiles.add("b......b..m.....bbbbbbbbbbbnnnnnnnnnnnnnnnnnnnnnnm...nnnnnnnnnnnnnnnnnnb............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b............................................b............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b............................................b............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b...........................................xb............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b...........................................xb.....................a......................................a...............................................n.................................................................x..");
- tiles.add("b......b..................b...........................................xb............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b............................................b............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b..........................................m.b.........................................................................nnnnnnnn...........................n.................................................................x..");
- tiles.add("bx.....b..................b............................................b.......m.nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn.......nbbbbbbbbbbbbbbbb..........n..........................................................a.........");
- tiles.add("bx......................x.b...................................m........b.........b........................................................................b...............m.........n...................................................................n");
- tiles.add("bx.....................xxxb............................................b.........b........................................................................b.........................n..................................................................n.");
- tiles.add("bbm....bbbb.bbbbbbbbbbbbbbb.......................b.b..................b.........b.xxxxxxxx...................................bbbbbbbbbbbbbbbbbbbbbbbb..m.b.........................n.........x..m...x................................................n..");
- tiles.add("b......b..................b......................bbbbb......x..........b.........b.xxxxxxxx...............................bbbb............................b.........................n.......x..........x......................................nnnnnnnnnnn");
- tiles.add("b......b..x...........x...b.....................bbbbbbb....xxx.........b.........bbbbbbbbbbb...bbbbb....bbbbbbb....bbbbb..................................b.........................n.......x..........x.....................................n...........");
- tiles.add("b......bbbbbbbb.....bbbbb.b.............bbbbbbbbbbbbbbbbbbbbbb.........b..................................................................................b.........................n.......x..........x....................................n............");
- tiles.add("b......b..................b.............b....................b.........b..................................................................................b.....bbbbbbbb............n.......x..........x...................................n.............");
- tiles.add("b......b................................b....................b.........b..................................................................................bxxx......................n.......x..........x..................................n..............");
- tiles.add("b......b...............x................b....................b.........b..................................................................................bxxx......................n.......x..........x.................................n...............");
- tiles.add("b......b..x...........bbbbb.............b....................b.........b...............d...d...d...d.d.d...d...d..........................................bbbbb.....................n.......x..........x................................n................");
- tiles.add("b......b.xxx.........b....b.............b....................b..............nnnn.........................................................x.........x......b.........................n..................................................n.................");
- tiles.add("b...p..bxxxxx.......b.....b......................x.........................nnnnnn.......................................................xxx.......xxx.....b...........................................................................n..................");
- tiles.add("b......bnnnnnnnnnnnnnnnnnnb.....................xxx.......................nnnnnnnn......s........s.......s.........s....s..............xxxxx.....xxxxx....b..........................................................................n...................");
- tiles.add("ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg");
-
-
- }
-}
diff --git a/Chapter22/Java/Levels/LevelMountains.java b/Chapter22/Java/Levels/LevelMountains.java
deleted file mode 100644
index c9489a2..0000000
--- a/Chapter22/Java/Levels/LevelMountains.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.gamecodeschool.c25platformer.Levels;
-
-import java.util.ArrayList;
-
-public final class LevelMountains extends Level {
- public LevelMountains() {
-
- tiles = new ArrayList();
- tiles.add("3.........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("............................................................x.....e................................................................................................");
- tiles.add("...........................................................xxx.....................................................................................................");
- tiles.add(".........................................................xxxxxxx...................................................................................................");
- tiles.add("...............................................................................................................xxx.................................................");
- tiles.add(".........................................................xxxxxxx...............................................xxx.................................................");
- tiles.add("............................................................................................m.............w....www.................................................");
- tiles.add("........................................................wwwwwwwwwwww..................................x...................x........................................");
- tiles.add("..........................................................................m...........................w...................g......................x.................");
- tiles.add("...............................................................................................................................x.................x..............o..");
- tiles.add("................................................................................................x..............................x.................m.................");
- tiles.add("................................................................................................x..............................x.................x....gggg.........");
- tiles.add("................................................................................................w..............................g.................x.........gggggggg");
- tiles.add(".....................................................................................................................................x...........x.................");
- tiles.add("............................................................................................x.....e..................................x...........x.................");
- tiles.add("........................................e...................................................x........................................g...........x.................");
- tiles.add("............................................................................................w....................................................x.................");
- tiles.add("........................................................................................................................................x........x.................");
- tiles.add(".......................................................................................x................................................x........x.................");
- tiles.add(".........p...........................s........xxx.......................s..............w................................................g........x.................");
- tiles.add(".x..........................wwwwwwwwwwwwwwwwwwwwwwwwwwww..ggggggg...ggggggggggg.....ggggggg....ggggg..........................................x..x.................");
- tiles.add("www.....www...ww....w...w.....................................................................................................................g....................");
- tiles.add("y....y.....y.....y...y........y.....y......y......y.....y....y......y.....y....y......y.....y....y......y....y....y....y.....y....y....y...y....y......y......y....y.....y......y.....y");
-
-
- }
-}
diff --git a/Chapter22/Java/Levels/LevelUnderground.java b/Chapter22/Java/Levels/LevelUnderground.java
deleted file mode 100644
index ce683a3..0000000
--- a/Chapter22/Java/Levels/LevelUnderground.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.gamecodeschool.c25platformer.Levels;
-
-import java.util.ArrayList;
-
-public final class LevelUnderground extends Level {
- public LevelUnderground() {
- tiles = new ArrayList();
- tiles.add("2......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...........x...........................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...........m............m..............................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...................x...................t........................x......................................................................");
- tiles.add("................lzzl............................................ll.....................................................................");
- tiles.add("................lzzl............................................................x.......x..........................o...................");
- tiles.add(".x..............lzzl........................................m....................................x....x................................");
- tiles.add("llllllllllllllllllllllllllll...lll.....llllllllllll...l.................lllllllllllllll...lllllllllllll.....llllllllll.................");
- tiles.add("................................................................ll.....................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("................................................x......ll..............................................................................");
- tiles.add(".........................................x......ll.....................................................................................");
- tiles.add(".........................................ll............................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("..............................x.............xx.........................................................................................");
- tiles.add(".p..........................x...x..........x..x..................................................x.....................................");
- tiles.add("........x.................x.......x......x......x................x.......................x......c..........s...........xxxxxxxxx.......");
- tiles.add("llllllllllllllllllll...lllllllllllllllllll...lllllll...llllllllllllllllll......lllllllllllllllllllllllllllllll........lllllllll........");
- tiles.add("..................................................i..............................................................m.....................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...x...................................................................................................................................");
- tiles.add(".........................................x......ll.....................................................................................");
- tiles.add(".........................................ll............................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("..............................x.............xx.........................................................................................");
- tiles.add("............................x...x..........x..x.....................................................................................x..");
- tiles.add("........x.................x.......x......x......x................x.......................x......c..........s...........xxxxxxxxx.......");
- tiles.add("llllllllllllllllllllzzzlllllzzzzzlllllllll...lllllll...llllllllllllllllll......lllllllllllllllllllllllllllllll........lllllllll........");
- tiles.add("..................................................i....................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("....y......y.......y......y.......y....y......y.......y........y........y........y.........y.........y.........y......y.....y........y.");
-
- }
-}
diff --git a/Chapter22/Java/PhysicsEngine.java b/Chapter22/Java/PhysicsEngine.java
deleted file mode 100644
index e2c6f2f..0000000
--- a/Chapter22/Java/PhysicsEngine.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.graphics.PointF;
-import android.graphics.RectF;
-import java.util.ArrayList;
-
-class PhysicsEngine {
-
- void update(long fps, ArrayList objects, GameState gs) {
- for (GameObject object : objects) {
- object.update(fps,
- objects.get(LevelManager.PLAYER_INDEX)
- .getTransform());
- }
-
- detectCollisions(gs, objects);
- }
-
- private void detectCollisions(GameState gs, ArrayList objects) {
- // More code here soon
- }
-}
diff --git a/Chapter22/Java/Renderer.java b/Chapter22/Java/Renderer.java
deleted file mode 100644
index 95ad52a..0000000
--- a/Chapter22/Java/Renderer.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-import java.util.ArrayList;
-
-class Renderer {
- private Canvas mCanvas;
- private SurfaceHolder mSurfaceHolder;
- private Paint mPaint;
-
- // Here is our new camera
- private Camera mCamera;
-
- Renderer(SurfaceView sh, Point screenSize){
- mSurfaceHolder = sh.getHolder();
- mPaint = new Paint();
-
- // Initialize the camera
- mCamera = new Camera(screenSize.x, screenSize.y);
- }
-
- int getPixelsPerMetre(){
- return mCamera.getPixelsPerMetre();
- }
-
- void draw(ArrayList objects,
- GameState gs,
- HUD hud) {
-
- if (mSurfaceHolder.getSurface().isValid()) {
- mCanvas = mSurfaceHolder.lockCanvas();
- mCanvas.drawColor(Color.argb(255, 0, 0, 0));
-
- if(gs.getDrawing()) {
- // Set the player as the center of the camera
- mCamera.setWorldCentre(
- objects.get(LevelManager.PLAYER_INDEX)
- .getTransform().getLocation());
-
- for (GameObject object : objects) {
- if (object.checkActive()) {
- object.draw(mCanvas, mPaint, mCamera);
- }
- }
- }
-
- hud.draw(mCanvas, mPaint, gs);
-
- mSurfaceHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-
-}
diff --git a/Chapter22/Java/SoundEngine.java b/Chapter22/Java/SoundEngine.java
deleted file mode 100644
index 6e42045..0000000
--- a/Chapter22/Java/SoundEngine.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-
-import java.io.IOException;
-
-class SoundEngine {
- // for playing sound effects
- private static SoundPool mSP;
- private static int mJump_ID = -1;
- private static int mReach_Objective_ID = -1;
- private static int mCoin_Pickup_ID = -1;
- private static int mPlayer_Burn_ID = -1;
-
- private static SoundEngine ourInstance;
-
- public static SoundEngine getInstance(Context context) {
- ourInstance = new SoundEngine(context);
- return ourInstance;
- }
-
- public SoundEngine(Context c){
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
- try {
- AssetManager assetManager = c.getAssets();
- AssetFileDescriptor descriptor;
-
- // Prepare the sounds in memory
- descriptor = assetManager.openFd("jump.ogg");
- mJump_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("reach_objective.ogg");
- mReach_Objective_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("coin_pickup.ogg");
- mCoin_Pickup_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("player_burn.ogg");
- mPlayer_Burn_ID = mSP.load(descriptor, 0);
-
- } catch (IOException e) {
- // Error
- }
-
- }
-
-
- public static void playJump(){
- mSP.play(mJump_ID,1, 1, 0, 0, 1);
- }
-
- public static void playReachObjective(){
- mSP.play(mReach_Objective_ID,1, 1, 0, 0, 1);
- }
-
- public static void playCoinPickup(){
- mSP.play(mCoin_Pickup_ID,1, 1, 0, 0, 1);
- }
-
- public static void playPlayerBurn(){
- mSP.play(mPlayer_Burn_ID,1, 1, 0, 0, 1);
- }
-
-}
diff --git a/Chapter22/Java/Transform.java b/Chapter22/Java/Transform.java
deleted file mode 100644
index 5cc9dcf..0000000
--- a/Chapter22/Java/Transform.java
+++ /dev/null
@@ -1,117 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.graphics.PointF;
-import android.graphics.RectF;
-
-public class Transform {
- RectF mCollider;
- private PointF mLocation;
- private float mSpeed;
- private float mObjectHeight;
- private float mObjectWidth;
- private PointF mStartingPosition;
- private boolean mHeadingUp = false;
- private boolean mHeadingDown = false;
-
- private boolean mFacingRight = true;
- private boolean mHeadingLeft = false;
- private boolean mHeadingRight = false;
-
- Transform(float speed, float objectWidth,
- float objectHeight, PointF startingLocation) {
-
- mCollider = new RectF();
- mSpeed = speed;
- mObjectHeight = objectHeight;
- mObjectWidth = objectWidth;
- mLocation = startingLocation;
-
- // This tells movable blocks their starting position
- mStartingPosition = new PointF(mLocation.x, mLocation.y);
- }
-
-
- public void updateCollider() {
- mCollider.top = mLocation.y;
- mCollider.left = mLocation.x ;
- mCollider.bottom = (mCollider.top + mObjectHeight);
- mCollider.right = (mCollider.left + mObjectWidth);
- }
-
-
- public RectF getCollider() {
- return mCollider;
- }
-
- void headUp() {
- mHeadingUp = true;
- mHeadingDown = false;
- }
-
- void headDown() {
- mHeadingDown = true;
- mHeadingUp = false;
- }
-
- boolean headingUp() {
- return mHeadingUp;
- }
-
- boolean headingDown() {
- return mHeadingDown;
- }
-
- float getSpeed() {
- return mSpeed;
- }
-
- PointF getLocation() {
- return mLocation;
- }
-
- PointF getSize() {
- return new PointF((int) mObjectWidth, (int) mObjectHeight);
- }
-
- void headRight() {
- mHeadingRight = true;
- mHeadingLeft = false;
- mFacingRight = true;
-
- }
-
- void headLeft() {
- mHeadingLeft = true;
- mHeadingRight = false;
- mFacingRight = false;
- }
-
- boolean headingRight() {
- return mHeadingRight;
- }
-
- boolean headingLeft() {
- return mHeadingLeft;
- }
-
- void stopHorizontal() {
- mHeadingLeft = false;
- mHeadingRight = false;
- }
-
- void stopMovingLeft() {
- mHeadingLeft = false;
- }
-
- void stopMovingRight() {
- mHeadingRight = false;
- }
-
- boolean getFacingRight() {
- return mFacingRight;
- }
-
- PointF getStartingPosition(){
- return mStartingPosition;
- }
-}
diff --git a/Chapter22/Java/UIController.java b/Chapter22/Java/UIController.java
deleted file mode 100644
index 75f02f2..0000000
--- a/Chapter22/Java/UIController.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-class UIController implements InputObserver {
-
- private float mThird;
-
- private boolean initialPress = false;
-
- UIController(GameEngineBroadcaster b, Point size) {
- // Add as an observer
- addObserver(b);
-
- mThird = size.x / 3;
- }
-
- // Need to add observer each time a new game is started and the game objects are rebuilt
- // and the observer list is cleared. This method allows us to re-add an observer for this
- // Rather than just add it in the constructor.
- // The Player controller doesn't need it because a new object is created each level
- void addObserver(GameEngineBroadcaster b) {
- b.addObserver(this);
- }
-
- @Override
- public void handleInput(MotionEvent event,
- GameState gameState,
- ArrayList buttons) {
-
- int i = event.getActionIndex();
- int x = (int) event.getX(i);
-
- int eventType = event.getAction()
- & MotionEvent.ACTION_MASK;
-
- if (eventType == MotionEvent.ACTION_UP ||
- eventType == MotionEvent.ACTION_POINTER_UP) {
-
- // If game is over start a new game
- if (gameState.getGameOver() && initialPress) {
-
- if (x < mThird) {
- gameState.setCurrentLevel("underground");
- gameState.startNewGame();
- } else if (x >= mThird && x < mThird * 2) {
- gameState.setCurrentLevel("mountains");
- gameState.startNewGame();
- } else if (x >= mThird * 2) {
- gameState.setCurrentLevel("city");
- gameState.startNewGame();
- }
-
- }
-
- initialPress = !initialPress;
- }
-
- }
-
-}
diff --git a/Chapter22/Java/UpdateComponent.java b/Chapter22/Java/UpdateComponent.java
deleted file mode 100644
index 4653442..0000000
--- a/Chapter22/Java/UpdateComponent.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.gamecodeschool.c22platformer;
-
-interface UpdateComponent {
-
- // Everything has one of these so it can be updated
- // The player's transform could be left out because it is only needed
- // by the background(to see which way the player is moving)
- // However, if we added enemies at a later date they would likely need
- // to know where the player is and what he is doing.
- // So I left it in rather than create a communication between the
- // background and the player
- void update(long fps, Transform t, Transform playerTransform);
-}
diff --git a/Chapter22/README.txt b/Chapter22/README.txt
deleted file mode 100644
index 118565d..0000000
--- a/Chapter22/README.txt
+++ /dev/null
@@ -1 +0,0 @@
-This is all the code and assets covering chapter 22 and chapter 23
\ No newline at end of file
diff --git a/Chapter22/assets/coin_pickup.ogg b/Chapter22/assets/coin_pickup.ogg
deleted file mode 100644
index cfbb1b6..0000000
Binary files a/Chapter22/assets/coin_pickup.ogg and /dev/null differ
diff --git a/Chapter22/assets/jump.ogg b/Chapter22/assets/jump.ogg
deleted file mode 100644
index eb6f8ef..0000000
Binary files a/Chapter22/assets/jump.ogg and /dev/null differ
diff --git a/Chapter22/assets/player_burn.ogg b/Chapter22/assets/player_burn.ogg
deleted file mode 100644
index 62c823b..0000000
Binary files a/Chapter22/assets/player_burn.ogg and /dev/null differ
diff --git a/Chapter22/assets/reach_objective.ogg b/Chapter22/assets/reach_objective.ogg
deleted file mode 100644
index 03d8b79..0000000
Binary files a/Chapter22/assets/reach_objective.ogg and /dev/null differ
diff --git a/Chapter22/drawable/brick.png b/Chapter22/drawable/brick.png
deleted file mode 100644
index ee965c0..0000000
Binary files a/Chapter22/drawable/brick.png and /dev/null differ
diff --git a/Chapter22/drawable/cart.png b/Chapter22/drawable/cart.png
deleted file mode 100644
index 760763f..0000000
Binary files a/Chapter22/drawable/cart.png and /dev/null differ
diff --git a/Chapter22/drawable/city.png b/Chapter22/drawable/city.png
deleted file mode 100644
index 7469d2b..0000000
Binary files a/Chapter22/drawable/city.png and /dev/null differ
diff --git a/Chapter22/drawable/coal.png b/Chapter22/drawable/coal.png
deleted file mode 100644
index 26cdf5f..0000000
Binary files a/Chapter22/drawable/coal.png and /dev/null differ
diff --git a/Chapter22/drawable/coin.png b/Chapter22/drawable/coin.png
deleted file mode 100644
index af753f7..0000000
Binary files a/Chapter22/drawable/coin.png and /dev/null differ
diff --git a/Chapter22/drawable/concrete.png b/Chapter22/drawable/concrete.png
deleted file mode 100644
index 13bbacb..0000000
Binary files a/Chapter22/drawable/concrete.png and /dev/null differ
diff --git a/Chapter22/drawable/dead_tree.png b/Chapter22/drawable/dead_tree.png
deleted file mode 100644
index bfb48ca..0000000
Binary files a/Chapter22/drawable/dead_tree.png and /dev/null differ
diff --git a/Chapter22/drawable/death_invisible.png b/Chapter22/drawable/death_invisible.png
deleted file mode 100644
index f82bcba..0000000
Binary files a/Chapter22/drawable/death_invisible.png and /dev/null differ
diff --git a/Chapter22/drawable/death_visible.png b/Chapter22/drawable/death_visible.png
deleted file mode 100644
index 9652496..0000000
Binary files a/Chapter22/drawable/death_visible.png and /dev/null differ
diff --git a/Chapter22/drawable/fire.png b/Chapter22/drawable/fire.png
deleted file mode 100644
index 0f78395..0000000
Binary files a/Chapter22/drawable/fire.png and /dev/null differ
diff --git a/Chapter22/drawable/grass.png b/Chapter22/drawable/grass.png
deleted file mode 100644
index ecffbc7..0000000
Binary files a/Chapter22/drawable/grass.png and /dev/null differ
diff --git a/Chapter22/drawable/lamppost.png b/Chapter22/drawable/lamppost.png
deleted file mode 100644
index 850f9df..0000000
Binary files a/Chapter22/drawable/lamppost.png and /dev/null differ
diff --git a/Chapter22/drawable/menu.png b/Chapter22/drawable/menu.png
deleted file mode 100644
index ea22c8b..0000000
Binary files a/Chapter22/drawable/menu.png and /dev/null differ
diff --git a/Chapter22/drawable/mountain.png b/Chapter22/drawable/mountain.png
deleted file mode 100644
index 4f2d211..0000000
Binary files a/Chapter22/drawable/mountain.png and /dev/null differ
diff --git a/Chapter22/drawable/objective.png b/Chapter22/drawable/objective.png
deleted file mode 100644
index 493d1b4..0000000
Binary files a/Chapter22/drawable/objective.png and /dev/null differ
diff --git a/Chapter22/drawable/platform.png b/Chapter22/drawable/platform.png
deleted file mode 100644
index c72ada1..0000000
Binary files a/Chapter22/drawable/platform.png and /dev/null differ
diff --git a/Chapter22/drawable/player.png b/Chapter22/drawable/player.png
deleted file mode 100644
index 379b2ed..0000000
Binary files a/Chapter22/drawable/player.png and /dev/null differ
diff --git a/Chapter22/drawable/scorched.png b/Chapter22/drawable/scorched.png
deleted file mode 100644
index 814dfa0..0000000
Binary files a/Chapter22/drawable/scorched.png and /dev/null differ
diff --git a/Chapter22/drawable/snow.png b/Chapter22/drawable/snow.png
deleted file mode 100644
index 4069cfc..0000000
Binary files a/Chapter22/drawable/snow.png and /dev/null differ
diff --git a/Chapter22/drawable/snowy_tree.png b/Chapter22/drawable/snowy_tree.png
deleted file mode 100644
index 6074fab..0000000
Binary files a/Chapter22/drawable/snowy_tree.png and /dev/null differ
diff --git a/Chapter22/drawable/stalactite.png b/Chapter22/drawable/stalactite.png
deleted file mode 100644
index 1afc333..0000000
Binary files a/Chapter22/drawable/stalactite.png and /dev/null differ
diff --git a/Chapter22/drawable/stalagmite.png b/Chapter22/drawable/stalagmite.png
deleted file mode 100644
index a50c974..0000000
Binary files a/Chapter22/drawable/stalagmite.png and /dev/null differ
diff --git a/Chapter22/drawable/stone.png b/Chapter22/drawable/stone.png
deleted file mode 100644
index 327a50b..0000000
Binary files a/Chapter22/drawable/stone.png and /dev/null differ
diff --git a/Chapter22/drawable/stone_pile.png b/Chapter22/drawable/stone_pile.png
deleted file mode 100644
index c0e26b6..0000000
Binary files a/Chapter22/drawable/stone_pile.png and /dev/null differ
diff --git a/Chapter22/drawable/turf.png b/Chapter22/drawable/turf.png
deleted file mode 100644
index e1099ef..0000000
Binary files a/Chapter22/drawable/turf.png and /dev/null differ
diff --git a/Chapter22/drawable/underground.png b/Chapter22/drawable/underground.png
deleted file mode 100644
index df3db7e..0000000
Binary files a/Chapter22/drawable/underground.png and /dev/null differ
diff --git a/Chapter24/AndroidManifest.xml b/Chapter24/AndroidManifest.xml
deleted file mode 100644
index 4f41d30..0000000
--- a/Chapter24/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter24/assets/coin_pickup.ogg b/Chapter24/assets/coin_pickup.ogg
deleted file mode 100644
index cfbb1b6..0000000
Binary files a/Chapter24/assets/coin_pickup.ogg and /dev/null differ
diff --git a/Chapter24/assets/jump.ogg b/Chapter24/assets/jump.ogg
deleted file mode 100644
index eb6f8ef..0000000
Binary files a/Chapter24/assets/jump.ogg and /dev/null differ
diff --git a/Chapter24/assets/player_burn.ogg b/Chapter24/assets/player_burn.ogg
deleted file mode 100644
index 62c823b..0000000
Binary files a/Chapter24/assets/player_burn.ogg and /dev/null differ
diff --git a/Chapter24/assets/reach_objective.ogg b/Chapter24/assets/reach_objective.ogg
deleted file mode 100644
index 03d8b79..0000000
Binary files a/Chapter24/assets/reach_objective.ogg and /dev/null differ
diff --git a/Chapter24/drawable/brick.png b/Chapter24/drawable/brick.png
deleted file mode 100644
index ee965c0..0000000
Binary files a/Chapter24/drawable/brick.png and /dev/null differ
diff --git a/Chapter24/drawable/cart.png b/Chapter24/drawable/cart.png
deleted file mode 100644
index 760763f..0000000
Binary files a/Chapter24/drawable/cart.png and /dev/null differ
diff --git a/Chapter24/drawable/city.png b/Chapter24/drawable/city.png
deleted file mode 100644
index 7469d2b..0000000
Binary files a/Chapter24/drawable/city.png and /dev/null differ
diff --git a/Chapter24/drawable/coal.png b/Chapter24/drawable/coal.png
deleted file mode 100644
index 26cdf5f..0000000
Binary files a/Chapter24/drawable/coal.png and /dev/null differ
diff --git a/Chapter24/drawable/coin.png b/Chapter24/drawable/coin.png
deleted file mode 100644
index af753f7..0000000
Binary files a/Chapter24/drawable/coin.png and /dev/null differ
diff --git a/Chapter24/drawable/concrete.png b/Chapter24/drawable/concrete.png
deleted file mode 100644
index 13bbacb..0000000
Binary files a/Chapter24/drawable/concrete.png and /dev/null differ
diff --git a/Chapter24/drawable/dead_tree.png b/Chapter24/drawable/dead_tree.png
deleted file mode 100644
index bfb48ca..0000000
Binary files a/Chapter24/drawable/dead_tree.png and /dev/null differ
diff --git a/Chapter24/drawable/death_invisible.png b/Chapter24/drawable/death_invisible.png
deleted file mode 100644
index f82bcba..0000000
Binary files a/Chapter24/drawable/death_invisible.png and /dev/null differ
diff --git a/Chapter24/drawable/death_visible.png b/Chapter24/drawable/death_visible.png
deleted file mode 100644
index 9652496..0000000
Binary files a/Chapter24/drawable/death_visible.png and /dev/null differ
diff --git a/Chapter24/drawable/fire.png b/Chapter24/drawable/fire.png
deleted file mode 100644
index 0f78395..0000000
Binary files a/Chapter24/drawable/fire.png and /dev/null differ
diff --git a/Chapter24/drawable/grass.png b/Chapter24/drawable/grass.png
deleted file mode 100644
index ecffbc7..0000000
Binary files a/Chapter24/drawable/grass.png and /dev/null differ
diff --git a/Chapter24/drawable/lamppost.png b/Chapter24/drawable/lamppost.png
deleted file mode 100644
index 850f9df..0000000
Binary files a/Chapter24/drawable/lamppost.png and /dev/null differ
diff --git a/Chapter24/drawable/menu.png b/Chapter24/drawable/menu.png
deleted file mode 100644
index ea22c8b..0000000
Binary files a/Chapter24/drawable/menu.png and /dev/null differ
diff --git a/Chapter24/drawable/mountain.png b/Chapter24/drawable/mountain.png
deleted file mode 100644
index 4f2d211..0000000
Binary files a/Chapter24/drawable/mountain.png and /dev/null differ
diff --git a/Chapter24/drawable/objective.png b/Chapter24/drawable/objective.png
deleted file mode 100644
index 493d1b4..0000000
Binary files a/Chapter24/drawable/objective.png and /dev/null differ
diff --git a/Chapter24/drawable/platform.png b/Chapter24/drawable/platform.png
deleted file mode 100644
index c72ada1..0000000
Binary files a/Chapter24/drawable/platform.png and /dev/null differ
diff --git a/Chapter24/drawable/player.png b/Chapter24/drawable/player.png
deleted file mode 100644
index 379b2ed..0000000
Binary files a/Chapter24/drawable/player.png and /dev/null differ
diff --git a/Chapter24/drawable/scorched.png b/Chapter24/drawable/scorched.png
deleted file mode 100644
index 814dfa0..0000000
Binary files a/Chapter24/drawable/scorched.png and /dev/null differ
diff --git a/Chapter24/drawable/snow.png b/Chapter24/drawable/snow.png
deleted file mode 100644
index 4069cfc..0000000
Binary files a/Chapter24/drawable/snow.png and /dev/null differ
diff --git a/Chapter24/drawable/snowy_tree.png b/Chapter24/drawable/snowy_tree.png
deleted file mode 100644
index 6074fab..0000000
Binary files a/Chapter24/drawable/snowy_tree.png and /dev/null differ
diff --git a/Chapter24/drawable/stalactite.png b/Chapter24/drawable/stalactite.png
deleted file mode 100644
index 1afc333..0000000
Binary files a/Chapter24/drawable/stalactite.png and /dev/null differ
diff --git a/Chapter24/drawable/stalagmite.png b/Chapter24/drawable/stalagmite.png
deleted file mode 100644
index a50c974..0000000
Binary files a/Chapter24/drawable/stalagmite.png and /dev/null differ
diff --git a/Chapter24/drawable/stone.png b/Chapter24/drawable/stone.png
deleted file mode 100644
index 327a50b..0000000
Binary files a/Chapter24/drawable/stone.png and /dev/null differ
diff --git a/Chapter24/drawable/stone_pile.png b/Chapter24/drawable/stone_pile.png
deleted file mode 100644
index c0e26b6..0000000
Binary files a/Chapter24/drawable/stone_pile.png and /dev/null differ
diff --git a/Chapter24/drawable/turf.png b/Chapter24/drawable/turf.png
deleted file mode 100644
index e1099ef..0000000
Binary files a/Chapter24/drawable/turf.png and /dev/null differ
diff --git a/Chapter24/drawable/underground.png b/Chapter24/drawable/underground.png
deleted file mode 100644
index df3db7e..0000000
Binary files a/Chapter24/drawable/underground.png and /dev/null differ
diff --git a/Chapter24/java/AnimatedGraphicsComponent.java b/Chapter24/java/AnimatedGraphicsComponent.java
deleted file mode 100644
index 5a313a3..0000000
--- a/Chapter24/java/AnimatedGraphicsComponent.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-import com.gamecodeschool.c24platformer.GOSpec.GameObjectSpec;
-
-class AnimatedGraphicsComponent implements GraphicsComponent {
-
- private String mBitmapName;
- private Animator mAnimator;
- private Rect mSectionToDraw;
-
- @Override
- public void initialize(Context context,
- GameObjectSpec spec,
- PointF objectSize,
- int pixelsPerMetre) {
-
- // Initialize the animation
- mAnimator = new Animator(
- objectSize.y,
- objectSize.x,
- spec.getNumFrames(),
- pixelsPerMetre);
-
- // stretch the bitmap by the number of frames
- float totalWidth = objectSize.x *
- spec.getNumFrames();
-
- mBitmapName = spec.getBitmapName();
- BitmapStore.addBitmap(context,
- mBitmapName,
- new PointF(totalWidth, objectSize.y),
- pixelsPerMetre, true);
-
- // Get the first frame of animation
- mSectionToDraw = mAnimator.getCurrentFrame(
- System.currentTimeMillis());
- }
-
- @Override
- // Updated to take a reference to a Camera
- public void draw(Canvas canvas,
- Paint paint,
- Transform t,
- Camera cam) {
-
- // Get the section of bitmap to draw
- // when an object is in motion
- // OR if it is a object with
- // zero speed(like a fire tile)
- if (t.headingRight() ||
- t.headingLeft() ||
- t.getSpeed() == 0) {
- // Player is moving so animate/change the frame
- mSectionToDraw = mAnimator.getCurrentFrame(
- System.currentTimeMillis());
- }
-
- // WHere should the bitmap section be drawn?
- Rect screenCoordinates = cam.worldToScreen
- (t.getLocation().x,
- t.getLocation().y,
- t.getSize().x,
- t.getSize().y);
-
- if (t.getFacingRight()) {
- canvas.drawBitmap(
- BitmapStore.getBitmap(mBitmapName),
- mSectionToDraw,
- screenCoordinates,
- paint);
- } else
- canvas.drawBitmap(
- BitmapStore.getBitmapReversed(mBitmapName),
- mSectionToDraw,
- screenCoordinates,
- paint);
- }
-}
-
diff --git a/Chapter24/java/Animator.java b/Chapter24/java/Animator.java
deleted file mode 100644
index a0f8014..0000000
--- a/Chapter24/java/Animator.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.graphics.Rect;
-
-class Animator {
- private Rect mSourceRect;
- private int mFrameCount;
- private int mCurrentFrame;
- private long mFrameTicker;
- private int mFramePeriod;
- private int mFrameWidth;
-
- Animator(float frameHeight,
- float frameWidth,
- int frameCount,
- int pixelsPerMetre) {
-
- final int ANIM_FPS = 10;
-
- this.mCurrentFrame = 0;
- this.mFrameCount = frameCount;
- this.mFrameWidth = (int)frameWidth * pixelsPerMetre;
-
- frameHeight = frameHeight * pixelsPerMetre;
-
- mSourceRect = new Rect(0, 0,
- this.mFrameWidth,
- (int)frameHeight);
-
- mFramePeriod = 1000 / ANIM_FPS;
- mFrameTicker = 0L;
- }
-
- Rect getCurrentFrame(long time) {
- if (time > mFrameTicker + mFramePeriod) {
- mFrameTicker = time;
- mCurrentFrame++;
- if (mCurrentFrame >= mFrameCount) {
- mCurrentFrame = 0;
- }
- }
-
- // Update the left and right values of the source of
- // the next frame on the spritesheet
- this.mSourceRect.left = mCurrentFrame * mFrameWidth;
- this.mSourceRect.right = this.mSourceRect.left
- + mFrameWidth;
-
- return mSourceRect;
- }
-}
diff --git a/Chapter24/java/BackgroundGraphicsComponent.java b/Chapter24/java/BackgroundGraphicsComponent.java
deleted file mode 100644
index 6739133..0000000
--- a/Chapter24/java/BackgroundGraphicsComponent.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-import com.gamecodeschool.c24platformer.GOSpec.GameObjectSpec;
-
-class BackgroundGraphicsComponent implements GraphicsComponent {
-
- private String mBitmapName;
-
- @Override
- public void initialize(Context context,
- GameObjectSpec spec,
- PointF objectSize,
- int pixelsPerMetre) {
-
- mBitmapName = spec.getBitmapName();
-
- BitmapStore.addBitmap(context,
- mBitmapName,
- objectSize,
- pixelsPerMetre,
- true);
- }
-
- @Override
- public void draw(Canvas canvas,
- Paint paint,
- Transform t,
- Camera cam) {
-
- // Cast to a background transform
- BackgroundTransform bt = (BackgroundTransform)t;
-
- Bitmap bitmap = BitmapStore.getBitmap(mBitmapName);
- Bitmap bitmapRevesed = BitmapStore
- .getBitmapReversed(mBitmapName);
-
- int scaledxClip = (int)(bt.getXClip()
- * cam.getPixelsPerMetre());
-
- int width = bitmap.getWidth();
- int height = bitmap.getHeight();
- PointF position = t.getLocation();
-
- float floatstartY = ((cam.getyCentre() -
- ((cam.getCameraWorldCentreY() - position.y) *
- cam.getPixelsPerMetreY())));
-
- int startY = (int) floatstartY;
-
- float floatendY = ((cam.getyCentre() -
- ((cam.getCameraWorldCentreY() -
- position.y - t.getSize().y) *
- cam.getPixelsPerMetreY())));
-
- int endY = (int) floatendY;
-
- // Position the regular bitmap
- Rect fromRect1 = new Rect(0, 0, width - scaledxClip, height);
- Rect toRect1 = new Rect(scaledxClip, startY, width, endY);
-
- // Position the reversed bitmap
- Rect fromRect2 = new Rect(width - scaledxClip, 0, width, height);
- Rect toRect2 = new Rect(0, startY, scaledxClip, endY);
-
- // Draw the two bitmaps
- if (!bt.getReversedFirst()) {
- canvas.drawBitmap(bitmap, fromRect1, toRect1, paint);
- canvas.drawBitmap(bitmapRevesed, fromRect2, toRect2, paint);
- } else {
- canvas.drawBitmap(bitmap, fromRect2, toRect2, paint);
- canvas.drawBitmap(bitmapRevesed, fromRect1, toRect1, paint);
- }
- }
-}
diff --git a/Chapter24/java/BackgroundTransform.java b/Chapter24/java/BackgroundTransform.java
deleted file mode 100644
index 85b0ff5..0000000
--- a/Chapter24/java/BackgroundTransform.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-
-import android.graphics.PointF;
-
-class BackgroundTransform extends Transform {
-
- private float xClip;
- private boolean reversedFirst = false;
-
- public BackgroundTransform(float speed,
- float objectWidth,
- float objectHeight,
- PointF startingLocation) {
-
- super(speed, objectWidth,
- objectHeight,
- startingLocation);
- }
-
- boolean getReversedFirst() {
- return reversedFirst;
- }
-
- void flipReversedFirst() {
- reversedFirst = !reversedFirst;
- }
-
- float getXClip() {
- return xClip;
- }
-
- void setXClip(float newXClip) {
- xClip = newXClip;
- }
-}
diff --git a/Chapter24/java/BackgroundUpdateComponent.java b/Chapter24/java/BackgroundUpdateComponent.java
deleted file mode 100644
index 7d5dd66..0000000
--- a/Chapter24/java/BackgroundUpdateComponent.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-class BackgroundUpdateComponent implements UpdateComponent {
-
- @Override
- public void update(long fps,
- Transform t,
- Transform playerTransform) {
-
- // Cast to background transform
- BackgroundTransform bt =
- (BackgroundTransform) t;
-
- PlayerTransform pt =
- (PlayerTransform) playerTransform;
-
- float currentXClip = bt.getXClip();
-
- // When the player is moving right -
- // update currentXClip to the left
- if (playerTransform.headingRight()) {
- currentXClip -= t.getSpeed() / fps;
- bt.setXClip(currentXClip);
- }
-
- // When the player is heading left -
- // update currentXClip to the right
- else if (playerTransform.headingLeft()) {
- currentXClip += t.getSpeed() / fps;
- bt.setXClip(currentXClip);
- }
-
- // When currentXClip reduces either
- // extreme left or right
- // Flip the order and reset currentXClip
- if (currentXClip >= t.getSize().x) {
- bt.setXClip(0);
- bt.flipReversedFirst();
- } else if (currentXClip <= 0) {
- bt.setXClip((int) t.getSize().x);
- bt.flipReversedFirst();
- }
-
- }
-}
diff --git a/Chapter24/java/BitmapStore.java b/Chapter24/java/BitmapStore.java
deleted file mode 100644
index 4fae940..0000000
--- a/Chapter24/java/BitmapStore.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Matrix;
-import android.graphics.PointF;
-
-import java.util.HashMap;
-import java.util.Map;
-
-class BitmapStore {
- private static Map mBitmapsMap;
- private static Map mBitmapsReversedMap;
- private static BitmapStore mOurInstance;
-
- // Calling this method is the only way to get a BitmapStore
- static BitmapStore getInstance(Context context) {
-
- mOurInstance = new BitmapStore(context);
- return mOurInstance;
- }
-
- // Can't be called using new BitmapStore()
- private BitmapStore(Context c) {
- mBitmapsMap = new HashMap();
- mBitmapsReversedMap = new HashMap();
-
- // Put a default bitmap in each of the maps
- // to return in case a bitmap doesn't exist
- addBitmap(c,
- "death_visible",
- new PointF(1, 1),
- 128,
- true);
- }
-
- static Bitmap getBitmap(String bitmapName) {
-
- if (mBitmapsMap.containsKey(bitmapName)) {
- return mBitmapsMap.get(bitmapName);
- } else {
- return mBitmapsMap.get("death_visible");
- }
- }
-
- static Bitmap getBitmapReversed(String bitmapName) {
-
- if (mBitmapsReversedMap.containsKey(bitmapName)) {
- return mBitmapsReversedMap.get(bitmapName);
- } else {
- return mBitmapsReversedMap.get("death_visible");
- }
- }
-
- static void addBitmap(Context c,
- String bitmapName,
- PointF objectSize,
- int pixelsPerMetre,
- boolean needReversed) {
-
- Bitmap bitmap;
- Bitmap bitmapReversed;
-
- // Make a resource id out of the string of the file name
- int resID = c.getResources().getIdentifier(bitmapName,
- "drawable", c.getPackageName());
-
- // Load the bitmap using the id
- bitmap = BitmapFactory
- .decodeResource(c.getResources(), resID);
-
- // Resize the bitmap
- bitmap = Bitmap.createScaledBitmap(bitmap,
- (int) objectSize.x * pixelsPerMetre,
- (int) objectSize.y * pixelsPerMetre,
- false);
-
- mBitmapsMap.put(bitmapName, bitmap);
-
- if (needReversed) {
- // Create a mirror image of the bitmap
- Matrix matrix = new Matrix();
- matrix.setScale(-1, 1);
- bitmapReversed = Bitmap.createBitmap(
- bitmap,
- 0, 0,
- bitmap.getWidth(),
- bitmap.getHeight(),
- matrix, true);
-
- mBitmapsReversedMap.put(bitmapName, bitmapReversed);
- }
-
- }
-
- static void clearStore() {
- mBitmapsMap.clear();
- mBitmapsReversedMap.clear();
- }
-}
diff --git a/Chapter24/java/Camera.java b/Chapter24/java/Camera.java
deleted file mode 100644
index 0fe630e..0000000
--- a/Chapter24/java/Camera.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-class Camera {
-
- private PointF mCurrentCameraWorldCentre;
- private Rect mConvertedRect;
- private int mPixelsPerMetre;
- private int mScreenCentreX;
- private int mScreenCentreY;
-
- Camera(int screenXResolution, int screenYResolution){
- // Locate the centre of the screen
- mScreenCentreX = screenXResolution / 2;
- mScreenCentreY = screenYResolution / 2;
-
- // How many metres of world space does
- // the screen width show
- // Change this value to zoom in and out
- final int pixelsPerMetreToResolutionRatio = 48;
- mPixelsPerMetre = screenXResolution /
- pixelsPerMetreToResolutionRatio;
-
- mConvertedRect = new Rect();
- mCurrentCameraWorldCentre = new PointF();
- }
-
- int getPixelsPerMetreY(){
- return mPixelsPerMetre;
- }
-
- int getyCentre(){
- return mScreenCentreY;
- }
-
- float getCameraWorldCentreY(){
- return mCurrentCameraWorldCentre.y;
- }
-
- // Set the camera to the player. Called each frame
- void setWorldCentre(PointF worldCentre){
- mCurrentCameraWorldCentre.x = worldCentre.x;
- mCurrentCameraWorldCentre.y = worldCentre.y;
- }
-
- int getPixelsPerMetre(){
- return mPixelsPerMetre;
- }
-
- // Return a Rect of the screen coordinates relative to a world location
- Rect worldToScreen(float objectX,
- float objectY,
- float objectWidth,
- float objectHeight){
-
- int left = (int) (mScreenCentreX -
- ((mCurrentCameraWorldCentre.x - objectX)
- * mPixelsPerMetre));
-
- int top = (int) (mScreenCentreY -
- ((mCurrentCameraWorldCentre.y - objectY)
- * mPixelsPerMetre));
-
- int right = (int) (left + (objectWidth * mPixelsPerMetre));
- int bottom = (int) (top + (objectHeight * mPixelsPerMetre));
- mConvertedRect.set(left, top, right, bottom);
- return mConvertedRect;
- }
-
-}
-
diff --git a/Chapter24/java/DecorativeBlockUpdateComponent.java b/Chapter24/java/DecorativeBlockUpdateComponent.java
deleted file mode 100644
index 8193cf7..0000000
--- a/Chapter24/java/DecorativeBlockUpdateComponent.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-class DecorativeBlockUpdateComponent implements UpdateComponent {
- @Override
- public void update(long fps, Transform t, Transform playerTransform) {
- // Do nothing
- // Not even set a collider
- }
-}
diff --git a/Chapter24/java/EngineController.java b/Chapter24/java/EngineController.java
deleted file mode 100644
index a92e3ff..0000000
--- a/Chapter24/java/EngineController.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-interface EngineController {
- // This allows the GameState class to start a new level
- void startNewLevel();
-}
diff --git a/Chapter24/java/GOSpec/BackgroundCitySpec.java b/Chapter24/java/GOSpec/BackgroundCitySpec.java
deleted file mode 100644
index a640b98..0000000
--- a/Chapter24/java/GOSpec/BackgroundCitySpec.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BackgroundCitySpec extends GameObjectSpec {
- // This is all the unique specifications for the city background
- private static final String tag = "Background";
- private static final String bitmapName = "city";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(100, 70);
- private static final String[] components = new String [] {
- "BackgroundGraphicsComponent","BackgroundUpdateComponent"};
-
- public BackgroundCitySpec() {
- super(tag, bitmapName, speed, size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/BackgroundMountainSpec.java b/Chapter24/java/GOSpec/BackgroundMountainSpec.java
deleted file mode 100644
index 4030271..0000000
--- a/Chapter24/java/GOSpec/BackgroundMountainSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BackgroundMountainSpec extends GameObjectSpec {
- // This is all the specifications for the mountain
- private static final String tag = "Background";
- private static final String bitmapName = "mountain";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(100, 70);
- private static final String[] components = new String [] {
- "BackgroundGraphicsComponent",
- "BackgroundUpdateComponent"};
-
- public BackgroundMountainSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/BackgroundUndergroundSpec.java b/Chapter24/java/GOSpec/BackgroundUndergroundSpec.java
deleted file mode 100644
index e0013cf..0000000
--- a/Chapter24/java/GOSpec/BackgroundUndergroundSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BackgroundUndergroundSpec extends GameObjectSpec {
- // This is all the specifications for the underground
- private static final String tag = "Background";
- private static final String bitmapName = "underground";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(100, 70f);
- private static final String[] components = new String [] {
- "BackgroundGraphicsComponent",
- "BackgroundUpdateComponent"};
-
- public BackgroundUndergroundSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/BrickTileSpec.java b/Chapter24/java/GOSpec/BrickTileSpec.java
deleted file mode 100644
index a42928f..0000000
--- a/Chapter24/java/GOSpec/BrickTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BrickTileSpec extends GameObjectSpec {
-
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "brick";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public BrickTileSpec() {
- super(tag, bitmapName, speed,
- size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/CartTileSpec.java b/Chapter24/java/GOSpec/CartTileSpec.java
deleted file mode 100644
index ecc1790..0000000
--- a/Chapter24/java/GOSpec/CartTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class CartTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "cart";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 1f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public CartTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/CoalTileSpec.java b/Chapter24/java/GOSpec/CoalTileSpec.java
deleted file mode 100644
index d2fe1ea..0000000
--- a/Chapter24/java/GOSpec/CoalTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class CoalTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "coal";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public CoalTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/CollectibleObjectSpec.java b/Chapter24/java/GOSpec/CollectibleObjectSpec.java
deleted file mode 100644
index c6c95a1..0000000
--- a/Chapter24/java/GOSpec/CollectibleObjectSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class CollectibleObjectSpec extends GameObjectSpec {
- private static final String tag = "Collectible";
- private static final String bitmapName = "coin";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public CollectibleObjectSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/ConcreteTileSpec.java b/Chapter24/java/GOSpec/ConcreteTileSpec.java
deleted file mode 100644
index c055d54..0000000
--- a/Chapter24/java/GOSpec/ConcreteTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class ConcreteTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "concrete";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public ConcreteTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/DeadTreeTileSpec.java b/Chapter24/java/GOSpec/DeadTreeTileSpec.java
deleted file mode 100644
index 4dd6956..0000000
--- a/Chapter24/java/GOSpec/DeadTreeTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class DeadTreeTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "dead_tree";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 4f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public DeadTreeTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/FireTileSpec.java b/Chapter24/java/GOSpec/FireTileSpec.java
deleted file mode 100644
index b4325fa..0000000
--- a/Chapter24/java/GOSpec/FireTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class FireTileSpec extends GameObjectSpec {
- private static final String tag = "Death";
- private static final String bitmapName = "fire";
- private static final int framesOfAnimation = 3;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String[]{
- "AnimatedGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public FireTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/GameObjectSpec.java b/Chapter24/java/GOSpec/GameObjectSpec.java
deleted file mode 100644
index d14162c..0000000
--- a/Chapter24/java/GOSpec/GameObjectSpec.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public abstract class GameObjectSpec {
- private String mTag;
- private String mBitmapName;
- private float mSpeed;
- private PointF mSize;
- private String[] mComponents;
- private int mFramesAnimation;
-
- GameObjectSpec(String tag,
- String bitmapName,
- float speed,
- PointF size,
- String[] components,
- int framesAnimation ){
-
- mTag = tag;
- mBitmapName = bitmapName;
- mSpeed = speed;
- mSize = size;
- mComponents = components;
- mFramesAnimation = framesAnimation;
- }
-
- public int getNumFrames(){
- return mFramesAnimation;
- }
-
- public String getTag(){
- return mTag;
- }
-
- public String getBitmapName(){
- return mBitmapName;
- }
-
- public float getSpeed(){
- return mSpeed;
- }
-
- public PointF getSize(){
- return mSize;
- }
-
- public String[] getComponents(){
- return mComponents;
- }
-}
diff --git a/Chapter24/java/GOSpec/GrassTileSpec.java b/Chapter24/java/GOSpec/GrassTileSpec.java
deleted file mode 100644
index cc15127..0000000
--- a/Chapter24/java/GOSpec/GrassTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class GrassTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "turf";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public GrassTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/InvisibleDeathTenByTenSpec.java b/Chapter24/java/GOSpec/InvisibleDeathTenByTenSpec.java
deleted file mode 100644
index 9b4eb2f..0000000
--- a/Chapter24/java/GOSpec/InvisibleDeathTenByTenSpec.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-import android.graphics.PointF;
-
-public class InvisibleDeathTenByTenSpec extends GameObjectSpec {
- private static final String tag = "Death";
- private static final String bitmapName = "death_visible";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(10f, 10f);
- private static final String[] components = new String[]{"InanimateBlockGraphicsComponent", "InanimateBlockUpdateComponent"};
-
- public InvisibleDeathTenByTenSpec() {
- super(tag, bitmapName, speed, size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/LamppostTileSpec.java b/Chapter24/java/GOSpec/LamppostTileSpec.java
deleted file mode 100644
index 63d21eb..0000000
--- a/Chapter24/java/GOSpec/LamppostTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class LamppostTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "lamppost";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 4f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public LamppostTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/MoveablePlatformSpec.java b/Chapter24/java/GOSpec/MoveablePlatformSpec.java
deleted file mode 100644
index d94c5ac..0000000
--- a/Chapter24/java/GOSpec/MoveablePlatformSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class MoveablePlatformSpec extends GameObjectSpec {
- private static final String tag = "Movable Platform";
- private static final String bitmapName = "platform";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(2f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "MovableBlockUpdateComponent"};
-
- public MoveablePlatformSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/ObjectiveTileSpec.java b/Chapter24/java/GOSpec/ObjectiveTileSpec.java
deleted file mode 100644
index 5e04876..0000000
--- a/Chapter24/java/GOSpec/ObjectiveTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class ObjectiveTileSpec extends GameObjectSpec {
-
- private static final String tag = "Objective Tile";
- private static final String bitmapName = "objective";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(3f, 3f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public ObjectiveTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/PlayerSpec.java b/Chapter24/java/GOSpec/PlayerSpec.java
deleted file mode 100644
index b1740f7..0000000
--- a/Chapter24/java/GOSpec/PlayerSpec.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class PlayerSpec extends GameObjectSpec {
- // This is all the unique specifications for a player
- private static final String tag = "Player";
- private static final String bitmapName = "player";
- private static final int framesOfAnimation = 5;
- private static final float speed = 10f;
- private static final PointF size = new PointF(1f, 2f);
- private static final String[] components = new String [] {
- "PlayerInputComponent",
- "AnimatedGraphicsComponent",
- "PlayerUpdateComponent"};
-
- public PlayerSpec() {
- super(tag, bitmapName, speed,
- size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/ScorchedTileSpec.java b/Chapter24/java/GOSpec/ScorchedTileSpec.java
deleted file mode 100644
index 3e4a0b7..0000000
--- a/Chapter24/java/GOSpec/ScorchedTileSpec.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class ScorchedTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "scorched";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public ScorchedTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
-
- }
-}
diff --git a/Chapter24/java/GOSpec/SnowTileSpec.java b/Chapter24/java/GOSpec/SnowTileSpec.java
deleted file mode 100644
index fbc56df..0000000
--- a/Chapter24/java/GOSpec/SnowTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class SnowTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "snow";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public SnowTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/SnowyTreeTileSpec.java b/Chapter24/java/GOSpec/SnowyTreeTileSpec.java
deleted file mode 100644
index 5b13cfb..0000000
--- a/Chapter24/java/GOSpec/SnowyTreeTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class SnowyTreeTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "snowy_tree";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(3f, 6f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public SnowyTreeTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/StalactiteTileSpec.java b/Chapter24/java/GOSpec/StalactiteTileSpec.java
deleted file mode 100644
index ec7ba91..0000000
--- a/Chapter24/java/GOSpec/StalactiteTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class StalactiteTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "stalactite";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 4f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public StalactiteTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/StalagmiteTileSpec.java b/Chapter24/java/GOSpec/StalagmiteTileSpec.java
deleted file mode 100644
index 5196613..0000000
--- a/Chapter24/java/GOSpec/StalagmiteTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class StalagmiteTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "stalagmite";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 4f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public StalagmiteTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GOSpec/StonePileTileSpec.java b/Chapter24/java/GOSpec/StonePileTileSpec.java
deleted file mode 100644
index aa56e44..0000000
--- a/Chapter24/java/GOSpec/StonePileTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c24platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class StonePileTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "stone_pile";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public StonePileTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter24/java/GameActivity.java b/Chapter24/java/GameActivity.java
deleted file mode 100644
index 23bbe08..0000000
--- a/Chapter24/java/GameActivity.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class GameActivity extends Activity {
-
- GameEngine mGameEngine;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Display display = getWindowManager()
- .getDefaultDisplay();
-
- Point size = new Point();
- display.getSize(size);
- mGameEngine = new GameEngine(this, size);
- setContentView(mGameEngine);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mGameEngine.startThread();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mGameEngine.stopThread();
- }
-}
diff --git a/Chapter24/java/GameEngine.java b/Chapter24/java/GameEngine.java
deleted file mode 100644
index 9c7ad1d..0000000
--- a/Chapter24/java/GameEngine.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.content.Context;
-import android.graphics.Point;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceView;
-
-import java.util.concurrent.CopyOnWriteArrayList;
-
-class GameEngine extends SurfaceView
- implements Runnable,
- GameEngineBroadcaster,
- EngineController {
-
- private Thread mThread = null;
- private long mFPS;
-
- private GameState mGameState;
- UIController mUIController;
-
- // This ArrayList can be accessed from either thread
- private CopyOnWriteArrayList
- inputObservers = new CopyOnWriteArrayList();
-
- HUD mHUD;
- LevelManager mLevelManager;
- PhysicsEngine mPhysicsEngine;
- Renderer mRenderer;
-
- public GameEngine(Context context, Point size) {
- super(context);
- // Prepare the bitmap store and sound engine
- BitmapStore bs = BitmapStore.getInstance(context);
- SoundEngine se = SoundEngine.getInstance(context);
-
- // Initialize all the significant classes
- // that make the engine work
- mHUD = new HUD(context, size);
- mGameState = new GameState(this, context);
- mUIController = new UIController(this, size);
- mPhysicsEngine = new PhysicsEngine();
- mRenderer = new Renderer(this, size);
- mLevelManager = new LevelManager(context,
- this, mRenderer.getPixelsPerMetre());
-
- }
-
- public void startNewLevel() {
- // Clear the bitmap store
- BitmapStore.clearStore();
- // Clear all the observers and add the UI observer back
- // When we call buildGameObjects the
- // player's observer will be added too
- inputObservers.clear();
- mUIController.addObserver(this);
- mLevelManager.setCurrentLevel(mGameState.getCurrentLevel());
- mLevelManager.buildGameObjects(mGameState);
- }
-
- // For the game engine broadcaster interface
- public void addObserver(InputObserver o) {
- inputObservers.add(o);
- }
-
- @Override
- public void run() {
- while (mGameState.getThreadRunning()) {
-
- long frameStartTime = System.currentTimeMillis();
-
- if (!mGameState.getPaused()) {
- mPhysicsEngine.update(mFPS,
- mLevelManager.getGameObjects(),
- mGameState);
- }
-
- mRenderer.draw(mLevelManager.getGameObjects(),
- mGameState,
- mHUD);
-
- long timeThisFrame = System.currentTimeMillis()
- - frameStartTime;
-
- if (timeThisFrame >= 1) {
- final int MILLIS_IN_SECOND = 1000;
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- for (InputObserver o : inputObservers) {
- o.handleInput(motionEvent,
- mGameState,
- mHUD.getControls());
- }
- return true;
- }
-
- public void stopThread() {
- mGameState.stopEverything();
- mGameState.stopThread();
- try {
- mThread.join();
- } catch (InterruptedException e) {
- Log.e("Exception",
- "stopThread()" + e.getMessage());
- }
- }
-
- public void startThread() {
- mGameState.startThread();
- mThread = new Thread(this);
- mThread.start();
- }
-}
diff --git a/Chapter24/java/GameEngineBroadcaster.java b/Chapter24/java/GameEngineBroadcaster.java
deleted file mode 100644
index 8d3a29a..0000000
--- a/Chapter24/java/GameEngineBroadcaster.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-interface GameEngineBroadcaster {
-
- // This allows the Player and UI Controller components
- // to add themselves as listeners of the GameEngine class
- void addObserver(InputObserver o);
-}
diff --git a/Chapter24/java/GameObject.java b/Chapter24/java/GameObject.java
deleted file mode 100644
index f2c43db..0000000
--- a/Chapter24/java/GameObject.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-import com.gamecodeschool.c24platformer.GOSpec.GameObjectSpec;
-
-class GameObject {
-
- private Transform mTransform;
-
-
- private boolean mActive = true;
- private String mTag;
-
- private GraphicsComponent mGraphicsComponent;
- private UpdateComponent mUpdateComponent;
-
- void setGraphics(GraphicsComponent g,
- Context c,
- GameObjectSpec spec,
- PointF objectSize,
- int pixelsPerMetre) {
-
- mGraphicsComponent = g;
- g.initialize(c, spec, objectSize, pixelsPerMetre);
- }
-
- void setMovement(UpdateComponent m) {
- mUpdateComponent = m;
- }
-
-
-
- void setPlayerInputTransform(PlayerInputComponent s) {
- s.setTransform(mTransform);
- }
-
-
- void setTransform(Transform t) {
- mTransform = t;
- }
-
- void draw(Canvas canvas, Paint paint, Camera cam) {
- mGraphicsComponent.draw(canvas,
- paint,
- mTransform, cam);
- }
-
- void update(long fps, Transform playerTransform) {
- mUpdateComponent.update(fps,
- mTransform,
- playerTransform);
- }
-
- boolean checkActive() {
- return mActive;
- }
-
- String getTag() {
- return mTag;
- }
-
- void setInactive() {
- mActive = false;
- }
-
- Transform getTransform() {
- return mTransform;
- }
-
- void setTag(String tag) {
- mTag = tag;
- }
-}
diff --git a/Chapter24/java/GameObjectFactory.java b/Chapter24/java/GameObjectFactory.java
deleted file mode 100644
index 61cd163..0000000
--- a/Chapter24/java/GameObjectFactory.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.content.Context;
-import android.graphics.PointF;
-
-import com.gamecodeschool.c24platformer.GOSpec.GameObjectSpec;
-
-class GameObjectFactory {
- private Context mContext;
- private GameEngine mGameEngineReference;
- private int mPixelsPerMetre;
-
- GameObjectFactory(Context context,
- GameEngine gameEngine,
- int pixelsPerMetre) {
-
- mContext = context;
- mGameEngineReference = gameEngine;
- mPixelsPerMetre = pixelsPerMetre;
- }
-
- GameObject create(GameObjectSpec spec, PointF location) {
- GameObject object = new GameObject();
-
- int mNumComponents = spec.getComponents().length;
- object.setTag(spec.getTag());
-
- // First give the game object the
- // right kind of transform
- switch(object.getTag()){
- case "Background":
- // Code coming soon
- object.setTransform(
- new BackgroundTransform(
- spec.getSpeed(),
- spec.getSize().x,
- spec.getSize().y,
- location));
- break;
-
- case "Player":
- // Code coming soon
- object.setTransform(
- new PlayerTransform(spec.getSpeed(),
- spec.getSize().x,
- spec.getSize().y,
- location));
- break;
-
- default:// normal transform
- object.setTransform(new Transform(
- spec.getSpeed(),
- spec.getSize().x,
- spec.getSize().y,
- location));
- break;
- }
-
-
- // Loop through and add/initialize all the components
- for (int i = 0; i < mNumComponents; i++) {
- switch (spec.getComponents()[i]) {
- case "PlayerInputComponent":
- // Code coming soon
- object.setPlayerInputTransform(
- new PlayerInputComponent(
- mGameEngineReference));
- break;
- case "AnimatedGraphicsComponent":
- // Code coming soon
- object.setGraphics(
- new AnimatedGraphicsComponent(),
- mContext, spec, spec.getSize(),
- mPixelsPerMetre);
- break;
- case "PlayerUpdateComponent":
- // Code coming soon
- object.setMovement(new PlayerUpdateComponent());
- break;
- case "InanimateBlockGraphicsComponent":
- object.setGraphics(new
- InanimateBlockGraphicsComponent(),
- mContext, spec, spec.getSize(),
- mPixelsPerMetre);
- break;
- case "InanimateBlockUpdateComponent":
- object.setMovement(new
- InanimateBlockUpdateComponent());
- break;
- case "MovableBlockUpdateComponent":
- // Code coming soon
- break;
- case "DecorativeBlockUpdateComponent":
- object.setMovement(new
- DecorativeBlockUpdateComponent());
- break;
- case "BackgroundGraphicsComponent":
- // Code coming soon
- object.setGraphics(
- new BackgroundGraphicsComponent(),
- mContext, spec, spec.getSize(),
- mPixelsPerMetre);
- break;
- case "BackgroundUpdateComponent":
- // Code coming soon
- object.setMovement(new BackgroundUpdateComponent());
- break;
-
- default:
- // Error unidentified component
- break;
- }
- }
-
- // Return the completed GameObject
- // to the LevelManager class
- return object;
- }
-}
diff --git a/Chapter24/java/GameState.java b/Chapter24/java/GameState.java
deleted file mode 100644
index 3497ba0..0000000
--- a/Chapter24/java/GameState.java
+++ /dev/null
@@ -1,185 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-
-final class GameState {
- private static volatile boolean
- mThreadRunning = false;
-
- private static volatile boolean mPaused = true;
- private static volatile boolean mGameOver = true;
- private static volatile boolean mDrawing = false;
- private EngineController engineController;
-
- private int mFastestUnderground;
- private int mFastestMountains;
- private int mFastestCity;
- private long startTimeInMillis;
-
- private int mCoinsAvailable;
- private int coinsCollected;
-
- private SharedPreferences.Editor editor;
-
- private String currentLevel;
-
- GameState(EngineController gs, Context context) {
- engineController = gs;
- SharedPreferences prefs = context
- .getSharedPreferences("HiScore",
- Context.MODE_PRIVATE);
-
- editor = prefs.edit();
- mFastestUnderground = prefs.getInt(
- "fastest_underground_time", 1000);
- mFastestMountains = prefs.getInt(
- "fastest_mountains_time", 1000);
- mFastestCity = prefs.getInt(
- "fastest_city_time", 1000);
- }
-
-
- void coinCollected() {
- coinsCollected++;
- }
-
- int getCoinsRemaining() {
- return mCoinsAvailable - coinsCollected;
- }
-
- void coinAddedToLevel() {
- mCoinsAvailable++;
- }
-
- void resetCoins() {
- mCoinsAvailable = 0;
- coinsCollected = 0;
- }
-
-
- void setCurrentLevel(String level) {
- currentLevel = level;
- }
-
- String getCurrentLevel() {
- return currentLevel;
- }
-
- void objectiveReached() {
- endGame();
- }
-
- int getFastestUnderground() {
- return mFastestUnderground;
- }
-
- int getFastestMountains() {
- return mFastestMountains;
- }
-
- int getFastestCity() {
- return mFastestCity;
- }
-
- void startNewGame() {
- // Don't want to be handling objects while
- // clearing ArrayList and filling it up again
- stopEverything();
- engineController.startNewLevel();
- startEverything();
- startTimeInMillis = System.currentTimeMillis();
- }
-
- int getCurrentTime() {
- long MILLIS_IN_SECOND = 1000;
- return (int) ((System.currentTimeMillis()
- - startTimeInMillis) / MILLIS_IN_SECOND);
- }
-
- void death() {
- stopEverything();
- SoundEngine.playPlayerBurn();
- }
-
- private void endGame() {
-
- stopEverything();
- int totalTime =
- ((mCoinsAvailable - coinsCollected)
- * 10)
- + getCurrentTime();
-
- switch (currentLevel) {
-
- case "underground":
- if (totalTime < mFastestUnderground) {
- mFastestUnderground = totalTime;
- // Save new time
-
- editor.putInt("fastest_underground_time",
- mFastestUnderground);
-
- editor.commit();
- }
- break;
- case "city":
- if (totalTime < mFastestCity) {
- mFastestCity = totalTime;
- // Save new time
- editor.putInt("fastest_city_time",
- mFastestCity);
-
- editor.commit();
- }
- break;
- case "mountains":
- if (totalTime < mFastestMountains) {
- mFastestMountains = totalTime;
- // Save new time
- editor.putInt("fastest_mountains_time",
- mFastestMountains);
-
- editor.commit();
- }
- break;
- }
- }
-
- void stopEverything() {// Except the thread
- mPaused = true;
- mGameOver = true;
- mDrawing = false;
- }
-
- private void startEverything() {
- mPaused = false;
- mGameOver = false;
- mDrawing = true;
- }
-
- void stopThread() {
- mThreadRunning = false;
- }
-
- boolean getThreadRunning() {
- return mThreadRunning;
- }
-
- void startThread() {
- mThreadRunning = true;
- }
-
- boolean getDrawing() {
- return mDrawing;
- }
-
- boolean getPaused() {
- return mPaused;
- }
-
- boolean getGameOver() {
- return mGameOver;
- }
-
-}
diff --git a/Chapter24/java/GraphicsComponent.java b/Chapter24/java/GraphicsComponent.java
deleted file mode 100644
index d211fae..0000000
--- a/Chapter24/java/GraphicsComponent.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-import com.gamecodeschool.c24platformer.GOSpec.GameObjectSpec;
-
-interface GraphicsComponent {
-
- // Added int mPixelsPerMetre to
- // scale the bitmap to the camera
- void initialize(Context c, GameObjectSpec spec,
- PointF objectSize, int pixelsPerMetre);
-
- // Updated from the last project
- // to take a reference to a Camera
- void draw(Canvas canvas, Paint paint,
- Transform t, Camera cam);
-}
diff --git a/Chapter24/java/HUD.java b/Chapter24/java/HUD.java
deleted file mode 100644
index 99132ff..0000000
--- a/Chapter24/java/HUD.java
+++ /dev/null
@@ -1,179 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.graphics.Rect;
-
-import java.util.ArrayList;
-
-class HUD {
- private Bitmap mMenuBitmap;
-
- private int mTextFormatting;
- private int mScreenHeight;
- private int mScreenWidth;
- final float ONE_THIRD = .33f;
- final float TWO_THIRDS = .66f;
-
- private ArrayList mControls;
-
- static int LEFT = 0;
- static int RIGHT = 1;
- static int JUMP = 2;
-
- HUD(Context context, Point size){
- mScreenHeight = size.y;
- mScreenWidth = size.x;
- mTextFormatting = size.x / 25;
-
- prepareControls();
-
- // Create and scale the bitmaps
- mMenuBitmap = BitmapFactory
- .decodeResource(context.getResources(),
- R.drawable.menu);
-
- mMenuBitmap = Bitmap
- .createScaledBitmap(mMenuBitmap,
- size.x, size.y, false);
-
- }
-
- private void prepareControls(){
- int buttonWidth = mScreenWidth / 14;
- int buttonHeight = mScreenHeight / 12;
- int buttonPadding = mScreenWidth / 90;
-
-
- Rect left = new Rect(
- buttonPadding,
- mScreenHeight - buttonHeight - buttonPadding,
- buttonWidth + buttonPadding,
- mScreenHeight - buttonPadding);
-
- Rect right = new Rect(
- (buttonPadding * 2) + buttonWidth,
- mScreenHeight - buttonHeight - buttonPadding,
- (buttonPadding * 2) + (buttonWidth * 2),
- mScreenHeight - buttonPadding);
-
- Rect jump = new Rect(mScreenWidth - buttonPadding - buttonWidth,
- mScreenHeight - buttonHeight - buttonPadding,
- mScreenWidth - buttonPadding,
- mScreenHeight - buttonPadding);
-
-
- mControls = new ArrayList<>();
- mControls.add(LEFT,left);
- mControls.add(RIGHT,right);
- mControls.add(JUMP, jump);
- }
-
- void draw(Canvas c, Paint p, GameState gs){
-
- if(gs.getGameOver()){
-
- // Draw the mMenuBitmap screen
- c.drawBitmap(mMenuBitmap, 0,0, p);
-
- // draw a rectangle to highlight the text
- p.setColor(Color.argb (100, 26, 128, 182));
- c.drawRect(0,0, mScreenWidth,
- mTextFormatting * 4, p);
-
- // Draw the level names
- p.setColor(Color.argb(255, 255, 255, 255));
- p.setTextSize(mTextFormatting);
- c.drawText("Underground",
- mTextFormatting,
- mTextFormatting * 2,
- p);
-
- c.drawText("Mountains",
- mScreenWidth * ONE_THIRD + (mTextFormatting),
- mTextFormatting * 2,
- p);
-
- c.drawText("City",
- mScreenWidth * TWO_THIRDS + (mTextFormatting),
- mTextFormatting * 2,
- p);
-
- // Draw the fastest times
- p.setTextSize(mTextFormatting/1.8f);
-
- c.drawText("BEST:" + gs.getFastestUnderground()
- +" seconds",
- mTextFormatting,
- mTextFormatting*3,
- p);
-
- c.drawText("BEST:" + gs.getFastestMountains()
- +" seconds", mScreenWidth * ONE_THIRD
- + mTextFormatting,
- mTextFormatting * 3,
- p);
-
- c.drawText("BEST:" + gs.getFastestCity()
- + " seconds",
- mScreenWidth * TWO_THIRDS + mTextFormatting,
- mTextFormatting * 3,
- p);
-
- // draw a rectangle to highlight the large text
- p.setColor(Color.argb (100, 26, 128, 182));
- c.drawRect(0,mScreenHeight - mTextFormatting * 2,
- mScreenWidth,
- mScreenHeight,
- p);
-
- p.setColor(Color.argb(255, 255, 255, 255));
- p.setTextSize(mTextFormatting * 1.5f);
- c.drawText("DOUBLE TAP A LEVEL TO PLAY",
- ONE_THIRD + mTextFormatting * 2,
- mScreenHeight - mTextFormatting/2,
- p);
- }
- else {
- // draw a rectangle to highlight the text
- p.setColor(Color.argb (100, 0, 0, 0));
- c.drawRect(0,0, mScreenWidth,
- mTextFormatting,
- p);
-
- // Draw the HUD text
- p.setTextSize(mTextFormatting/1.5f);
- p.setColor(Color.argb(255, 255, 255, 255));
- c.drawText("Time:" + gs.getCurrentTime()
- + "+" + gs.getCoinsRemaining() * 10,
- mTextFormatting / 4,
- mTextFormatting / 1.5f,
- p);
-
-
- drawControls(c, p);
- }
-
- }
-
- private void drawControls(Canvas c, Paint p){
- p.setColor(Color.argb(100,255,255,255));
-
- for(Rect r : mControls){
- c.drawRect(r.left, r.top, r.right, r.bottom, p);
- }
-
- // Set the colors back
- p.setColor(Color.argb(255,255,255,255));
- }
-
-
- ArrayList getControls(){
- return mControls;
- }
-}
diff --git a/Chapter24/java/InanimateBlockGraphicsComponent.java b/Chapter24/java/InanimateBlockGraphicsComponent.java
deleted file mode 100644
index d78ee66..0000000
--- a/Chapter24/java/InanimateBlockGraphicsComponent.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-import com.gamecodeschool.c24platformer.GOSpec.GameObjectSpec;
-
-class InanimateBlockGraphicsComponent implements GraphicsComponent {
-
- private String mBitmapName;
-
- @Override
- public void initialize(Context context,
- GameObjectSpec spec,
- PointF objectSize,
- int pixelsPerMetre) {
-
- mBitmapName = spec.getBitmapName();
-
- BitmapStore.addBitmap(context,
- mBitmapName, objectSize,
- pixelsPerMetre,
- false);
-
- }
-
-
- @Override
- public void draw(Canvas canvas,
- Paint paint,
- Transform t,
- Camera cam) {
-
- Bitmap bitmap = BitmapStore.getBitmap(mBitmapName);
- // Use the camera to translate the real world
- // coordinates relative to the player-
- // into screen coordinates
- Rect screenCoordinates = cam.worldToScreen(
- t.getLocation().x,
- t.getLocation().y,
- t.getSize().x,
- t.getSize().y);
-
-
- canvas.drawBitmap(
- bitmap,
- screenCoordinates.left,
- screenCoordinates.top,
- paint);
-
-
- }
-}
diff --git a/Chapter24/java/InanimateBlockUpdateComponent.java b/Chapter24/java/InanimateBlockUpdateComponent.java
deleted file mode 100644
index b0210e4..0000000
--- a/Chapter24/java/InanimateBlockUpdateComponent.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-class InanimateBlockUpdateComponent implements UpdateComponent {
-
- private boolean mColliderNotSet = true;
-
- @Override
- public void update(long fps,
- Transform t,
- Transform playerTransform) {
-
- // An alternative would be to update
- // the collider just once when it spawns.
- // But this would require spawn components
- // - More code but a bit faster
- if(mColliderNotSet) {
- // Only need to set the collider
- // once because it will never move
- t.updateCollider();
- mColliderNotSet = false;
- }
- }
-}
diff --git a/Chapter24/java/InputObserver.java b/Chapter24/java/InputObserver.java
deleted file mode 100644
index c62201c..0000000
--- a/Chapter24/java/InputObserver.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-public interface InputObserver {
-
- // This allows InputObservers to be called by GameEngine to handle input
- void handleInput(MotionEvent event, GameState gs, ArrayList buttons);
-}
diff --git a/Chapter24/java/LevelManager.java b/Chapter24/java/LevelManager.java
deleted file mode 100644
index f9d0711..0000000
--- a/Chapter24/java/LevelManager.java
+++ /dev/null
@@ -1,243 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.content.Context;
-import android.graphics.PointF;
-import android.util.Log;
-
-import com.gamecodeschool.c24platformer.GOSpec.*;
-import com.gamecodeschool.c24platformer.Levels.*;
-
-import java.util.ArrayList;
-
-final class LevelManager {
-
- static int PLAYER_INDEX = 0;
- private ArrayList objects;
- private Level currentLevel;
- private GameObjectFactory factory;
-
- LevelManager(Context context,
- GameEngine ge,
- int pixelsPerMetre){
-
- objects = new ArrayList<>();
- factory = new GameObjectFactory(context,
- ge,
- pixelsPerMetre);
- }
-
- void setCurrentLevel(String level){
- switch (level) {
- case "underground":
- currentLevel = new LevelUnderground();
- break;
-
- case "city":
- currentLevel = new LevelCity();
- break;
-
- case "mountains":
- currentLevel = new LevelMountains();
- break;
- }
- }
-
- void buildGameObjects(GameState gs){
- // Backgrounds 1, 2, 3(City, Underground, Mountain...)
- // p = Player
- // g = Grass tile
- // o = Objective
- // m = Movable platform
- // b = Brick tile
- // c = mine Cart
- // s = Stone pile
- // l = coaL
- // n = coNcrete
- // a = lAmpost
- // r = scoRched tile
- // w = snoW tile
- // t = stalacTite
- // i = stalagmIte
- // d = Dead tree
- // e = snowy trEe
- // x = Collectable
- // z = Fire
- // y = invisible death_invisible
-
- gs.resetCoins();
- objects.clear();
- ArrayList levelToLoad = currentLevel.getTiles();
-
- for(int row = 0; row < levelToLoad.size(); row++ )
- {
- for(int column = 0;
- column < levelToLoad.get(row).length();
- column++){
-
- PointF coords = new PointF(column, row);
-
- switch (levelToLoad.get(row)
- .charAt(column)){
-
- case '1':
- objects.add(factory.create(
- new BackgroundCitySpec(),
- coords));
- break;
-
- case '2':
- objects.add(factory.create(
- new BackgroundUndergroundSpec(),
- coords));
- break;
-
- case '3':
- objects.add(factory.create(
- new BackgroundMountainSpec(),
- coords));
- break;
-
- case 'p':
- objects.add(factory.create(new
- PlayerSpec(),
- coords));
- // Remember the location of
- // the player
- PLAYER_INDEX = objects.size()-1;
- break;
-
- case 'g':
- objects.add(factory.create(
- new GrassTileSpec(),
- coords));
- break;
-
- case 'o':
- objects.add(factory.create(
- new ObjectiveTileSpec(),
- coords));
- break;
-
- case 'm':
- //objects.add(factory.create(
- // new MoveablePlatformSpec(),
- // coords));
- break;
-
- case 'b':
- objects.add(factory.create(
- new BrickTileSpec(),
- coords));
- break;
-
- case 'c':
- objects.add(factory.create(
- new CartTileSpec(),
- coords));
- break;
-
- case 's':
- objects.add(factory.create(
- new StonePileTileSpec(),
- coords));
- break;
-
- case 'l':
- objects.add(factory.create(
- new CoalTileSpec(),
- coords));
- break;
-
- case 'n':
- objects.add(factory.create(
- new ConcreteTileSpec(),
- coords));
- break;
-
- case 'a':
- objects.add(factory.create(
- new LamppostTileSpec(),
- coords));
- break;
-
- case 'r':
- objects.add(factory.create(
- new ScorchedTileSpec(),
- coords));
- break;
-
- case 'w':
- objects.add(factory.create(
- new SnowTileSpec(),
- coords));
- break;
-
- case 't':
- objects.add(factory.create(
- new StalactiteTileSpec(),
- coords));
- break;
-
- case 'i':
- objects.add(factory.create(
- new StalagmiteTileSpec(),
- coords));
- break;
-
- case 'd':
- objects.add(factory.create(
- new DeadTreeTileSpec(),
- coords));
- break;
-
- case 'e':
- objects.add(factory.create(
- new SnowyTreeTileSpec(),
- coords));
- break;
-
- case 'x':
- objects.add(factory.create(
- new CollectibleObjectSpec(),
- coords));
- gs.coinAddedToLevel();
- break;
-
- case 'z':
- objects.add(factory.create(
- new FireTileSpec(),
- coords));
-
- break;
-
- case 'y':
- objects.add(factory.create(
- new InvisibleDeathTenByTenSpec(),
- coords));
-
- break;
-
-
- case '.':
- // Nothing to see here
- break;
-
- default:
- Log.e("Unhandled item in level",
- "row:"+row
- + " column:"+column);
- break;
- }
-
- }
-
- }
-
- }
-
- ArrayList getGameObjects(){
- return objects;
- }
-
-
-}
diff --git a/Chapter24/java/Levels/Level.java b/Chapter24/java/Levels/Level.java
deleted file mode 100644
index 4fcf895..0000000
--- a/Chapter24/java/Levels/Level.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.gamecodeschool.c24platformer.Levels;
-
-import java.util.ArrayList;
-
-public abstract class Level {
- // If you want to build a new level then extend this class
- ArrayList tiles;
- public ArrayList getTiles(){
- return tiles;
- }
-}
diff --git a/Chapter24/java/Levels/LevelCity.java b/Chapter24/java/Levels/LevelCity.java
deleted file mode 100644
index e45a631..0000000
--- a/Chapter24/java/Levels/LevelCity.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.gamecodeschool.c25platformer.Levels;
-
-import java.util.ArrayList;
-
-public final class LevelCity extends Level {
- public LevelCity() {
- tiles = new ArrayList();
- tiles.add("1........................................................................................................................................................................................................................................................");
- tiles.add(".........................................................................................................................................................................................................................................................");
- tiles.add(".........................................................................................................................................................................................................................................................");
- tiles.add("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");
- tiles.add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx......................n..........................................................................");
- tiles.add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx......................n..........................................................................");
- tiles.add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx......................n..........................................................................");
- tiles.add("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnm.nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");
- tiles.add("b.x..................................................................................nxxxxx............................................................................................................a.........................a.......................");
- tiles.add("bxxx.................................................................................nxxxxx.......................................................................................................................................................o......");
- tiles.add("bbbbbb...............................................................................nxxxxx..............................................................................................................................................................");
- tiles.add("b......b.............................................................................nnnnnnnnnnnm........................................................................................................................................................");
- tiles.add("b.......b............................................................................n..........x...................................................................................ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg");
- tiles.add("b........b...........................................................................n..........x...................................................................................n....................................................................");
- tiles.add("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbm...nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnm.............n..........x...................................................................................n....................................................................");
- tiles.add("b....................................................................................n..........x...................................................................................nxxxxxxxx............................................................");
- tiles.add("b....................................................................................n..........x...................................................................................nxxxxxxxx............................................................");
- tiles.add("b....................................................................................n..........x...................................................................................nxxxxxxxx............................................................");
- tiles.add("b.................................................................................x..n..........x......................................................................nnnnnn.......n.nnnnnnnn...........................................................");
- tiles.add("bx...............................................................................xxx.n...........................................................m...m...m...m..nnnnnnn.............n........nnnnnnnn....................................................");
- tiles.add("bx.............................................................................bbbbbbn.........................................................m....................................n..............nnnnnnn...............................................");
- tiles.add("bx...............................a.............................a..............b......n.......................................................m......................................n....................nnnnn...........................................");
- tiles.add("bnnn.........................................................................b.......nnnnnnnnnnnnnnnnnnnnnnnm.............................m.........................................n........................nnnn........................................");
- tiles.add("b...................x.......................................................b.......................................................................................................n...........................nnnn.....................................");
- tiles.add("b......b...........xxx.....................................x..x..x..x......b........................................................................................................n..............................nnnnnn...nnnnnnnnnnnnnnnnnnnnnnnnnmx..");
- tiles.add("b......b..m.....bbbbbbbbbbbnnnnnnnnnnnnnnnnnnnnnnm...nnnnnnnnnnnnnnnnnnb............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b............................................b............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b............................................b............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b...........................................xb............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b...........................................xb.....................a......................................a...............................................n.................................................................x..");
- tiles.add("b......b..................b...........................................xb............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b............................................b............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b..........................................m.b.........................................................................nnnnnnnn...........................n.................................................................x..");
- tiles.add("bx.....b..................b............................................b.......m.nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn.......nbbbbbbbbbbbbbbbb..........n..........................................................a.........");
- tiles.add("bx......................x.b...................................m........b.........b........................................................................b...............m.........n...................................................................n");
- tiles.add("bx.....................xxxb............................................b.........b........................................................................b.........................n..................................................................n.");
- tiles.add("bbm....bbbb.bbbbbbbbbbbbbbb.......................b.b..................b.........b.xxxxxxxx...................................bbbbbbbbbbbbbbbbbbbbbbbb..m.b.........................n.........x..m...x................................................n..");
- tiles.add("b......b..................b......................bbbbb......x..........b.........b.xxxxxxxx...............................bbbb............................b.........................n.......x..........x......................................nnnnnnnnnnn");
- tiles.add("b......b..x...........x...b.....................bbbbbbb....xxx.........b.........bbbbbbbbbbb...bbbbb....bbbbbbb....bbbbb..................................b.........................n.......x..........x.....................................n...........");
- tiles.add("b......bbbbbbbb.....bbbbb.b.............bbbbbbbbbbbbbbbbbbbbbb.........b..................................................................................b.........................n.......x..........x....................................n............");
- tiles.add("b......b..................b.............b....................b.........b..................................................................................b.....bbbbbbbb............n.......x..........x...................................n.............");
- tiles.add("b......b................................b....................b.........b..................................................................................bxxx......................n.......x..........x..................................n..............");
- tiles.add("b......b...............x................b....................b.........b..................................................................................bxxx......................n.......x..........x.................................n...............");
- tiles.add("b......b..x...........bbbbb.............b....................b.........b...............d...d...d...d.d.d...d...d..........................................bbbbb.....................n.......x..........x................................n................");
- tiles.add("b......b.xxx.........b....b.............b....................b..............nnnn.........................................................x.........x......b.........................n..................................................n.................");
- tiles.add("b...p..bxxxxx.......b.....b......................x.........................nnnnnn.......................................................xxx.......xxx.....b...........................................................................n..................");
- tiles.add("b......bnnnnnnnnnnnnnnnnnnb.....................xxx.......................nnnnnnnn......s........s.......s.........s....s..............xxxxx.....xxxxx....b..........................................................................n...................");
- tiles.add("ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg");
-
-
- }
-}
diff --git a/Chapter24/java/Levels/LevelMountains.java b/Chapter24/java/Levels/LevelMountains.java
deleted file mode 100644
index c9489a2..0000000
--- a/Chapter24/java/Levels/LevelMountains.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.gamecodeschool.c25platformer.Levels;
-
-import java.util.ArrayList;
-
-public final class LevelMountains extends Level {
- public LevelMountains() {
-
- tiles = new ArrayList();
- tiles.add("3.........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("............................................................x.....e................................................................................................");
- tiles.add("...........................................................xxx.....................................................................................................");
- tiles.add(".........................................................xxxxxxx...................................................................................................");
- tiles.add("...............................................................................................................xxx.................................................");
- tiles.add(".........................................................xxxxxxx...............................................xxx.................................................");
- tiles.add("............................................................................................m.............w....www.................................................");
- tiles.add("........................................................wwwwwwwwwwww..................................x...................x........................................");
- tiles.add("..........................................................................m...........................w...................g......................x.................");
- tiles.add("...............................................................................................................................x.................x..............o..");
- tiles.add("................................................................................................x..............................x.................m.................");
- tiles.add("................................................................................................x..............................x.................x....gggg.........");
- tiles.add("................................................................................................w..............................g.................x.........gggggggg");
- tiles.add(".....................................................................................................................................x...........x.................");
- tiles.add("............................................................................................x.....e..................................x...........x.................");
- tiles.add("........................................e...................................................x........................................g...........x.................");
- tiles.add("............................................................................................w....................................................x.................");
- tiles.add("........................................................................................................................................x........x.................");
- tiles.add(".......................................................................................x................................................x........x.................");
- tiles.add(".........p...........................s........xxx.......................s..............w................................................g........x.................");
- tiles.add(".x..........................wwwwwwwwwwwwwwwwwwwwwwwwwwww..ggggggg...ggggggggggg.....ggggggg....ggggg..........................................x..x.................");
- tiles.add("www.....www...ww....w...w.....................................................................................................................g....................");
- tiles.add("y....y.....y.....y...y........y.....y......y......y.....y....y......y.....y....y......y.....y....y......y....y....y....y.....y....y....y...y....y......y......y....y.....y......y.....y");
-
-
- }
-}
diff --git a/Chapter24/java/Levels/LevelUnderground.java b/Chapter24/java/Levels/LevelUnderground.java
deleted file mode 100644
index ce683a3..0000000
--- a/Chapter24/java/Levels/LevelUnderground.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.gamecodeschool.c25platformer.Levels;
-
-import java.util.ArrayList;
-
-public final class LevelUnderground extends Level {
- public LevelUnderground() {
- tiles = new ArrayList();
- tiles.add("2......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...........x...........................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...........m............m..............................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...................x...................t........................x......................................................................");
- tiles.add("................lzzl............................................ll.....................................................................");
- tiles.add("................lzzl............................................................x.......x..........................o...................");
- tiles.add(".x..............lzzl........................................m....................................x....x................................");
- tiles.add("llllllllllllllllllllllllllll...lll.....llllllllllll...l.................lllllllllllllll...lllllllllllll.....llllllllll.................");
- tiles.add("................................................................ll.....................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("................................................x......ll..............................................................................");
- tiles.add(".........................................x......ll.....................................................................................");
- tiles.add(".........................................ll............................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("..............................x.............xx.........................................................................................");
- tiles.add(".p..........................x...x..........x..x..................................................x.....................................");
- tiles.add("........x.................x.......x......x......x................x.......................x......c..........s...........xxxxxxxxx.......");
- tiles.add("llllllllllllllllllll...lllllllllllllllllll...lllllll...llllllllllllllllll......lllllllllllllllllllllllllllllll........lllllllll........");
- tiles.add("..................................................i..............................................................m.....................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...x...................................................................................................................................");
- tiles.add(".........................................x......ll.....................................................................................");
- tiles.add(".........................................ll............................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("..............................x.............xx.........................................................................................");
- tiles.add("............................x...x..........x..x.....................................................................................x..");
- tiles.add("........x.................x.......x......x......x................x.......................x......c..........s...........xxxxxxxxx.......");
- tiles.add("llllllllllllllllllllzzzlllllzzzzzlllllllll...lllllll...llllllllllllllllll......lllllllllllllllllllllllllllllll........lllllllll........");
- tiles.add("..................................................i....................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("....y......y.......y......y.......y....y......y.......y........y........y........y.........y.........y.........y......y.....y........y.");
-
- }
-}
diff --git a/Chapter24/java/PhysicsEngine.java b/Chapter24/java/PhysicsEngine.java
deleted file mode 100644
index 923cc9b..0000000
--- a/Chapter24/java/PhysicsEngine.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import java.util.ArrayList;
-
-class PhysicsEngine {
-
- void update(long fps, ArrayList objects, GameState gs) {
- for (GameObject object : objects) {
- object.update(fps,
- objects.get(LevelManager.PLAYER_INDEX)
- .getTransform());
- }
-
- detectCollisions(gs, objects);
- }
-
- private void detectCollisions(GameState gs, ArrayList objects) {
- // More code here soon
- }
-}
diff --git a/Chapter24/java/PlayerInputComponent.java b/Chapter24/java/PlayerInputComponent.java
deleted file mode 100644
index a8d984b..0000000
--- a/Chapter24/java/PlayerInputComponent.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-class PlayerInputComponent implements InputObserver {
-
- private Transform mPlayersTransform;
- private PlayerTransform mPlayersPlayerTransform;
-
- PlayerInputComponent(GameEngine ger) {
- ger.addObserver(this);
- }
-
- public void setTransform(Transform transform) {
- mPlayersTransform = transform;
- mPlayersPlayerTransform =
- (PlayerTransform) mPlayersTransform;
- }
-
- // Required method of InputObserver interface
- // called from the onTouchEvent method
- public void handleInput(MotionEvent event,
- GameState gameState,
- ArrayList buttons) {
-
- int i = event.getActionIndex();
- int x = (int) event.getX(i);
- int y = (int) event.getY(i);
-
- if(!gameState.getPaused()) {
- switch (event.getAction() & MotionEvent.ACTION_MASK) {
-
- case MotionEvent.ACTION_UP:
- if (buttons.get(HUD.LEFT).contains(x, y)
- || buttons.get(HUD.RIGHT)
- .contains(x, y)) {
- // Player has released either left or right
- mPlayersTransform.stopHorizontal();
- }
- break;
-
- case MotionEvent.ACTION_DOWN:
- if (buttons.get(HUD.LEFT).contains(x, y)) {
- // Player has pressed left
- mPlayersTransform.headLeft();
- } else if (buttons.get(HUD.RIGHT).contains(x, y)) {
- // Player has pressed right
- mPlayersTransform.headRight();
- } else if (buttons.get(HUD.JUMP).contains(x, y)) {
- // Player has released the jump button
- mPlayersPlayerTransform.triggerJump();
- }
- break;
-
- case MotionEvent.ACTION_POINTER_UP:
- if (buttons.get(HUD.LEFT).contains(x, y)
- || buttons.get(HUD.RIGHT).contains(x, y)) {
- // Player has released either up or down
- mPlayersTransform.stopHorizontal();
- }
- break;
-
- case MotionEvent.ACTION_POINTER_DOWN:
- if (buttons.get(HUD.LEFT).contains(x, y)) {
- // Player has pressed left
- mPlayersTransform.headLeft();
- } else if (buttons.get(HUD.RIGHT).contains(x, y)) {
- // Player has pressed right
- mPlayersTransform.headRight();
- } else if (buttons.get(HUD.JUMP).contains(x, y)) {
- // Player has released the jump button
- mPlayersPlayerTransform.triggerJump();
- }
- break;
- }
- }
- }
-}
diff --git a/Chapter24/java/PlayerTransform.java b/Chapter24/java/PlayerTransform.java
deleted file mode 100644
index 3eebd21..0000000
--- a/Chapter24/java/PlayerTransform.java
+++ /dev/null
@@ -1,157 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.graphics.PointF;
-import android.graphics.RectF;
-
-import java.util.ArrayList;
-
-class PlayerTransform extends Transform {
-
- private ArrayList mColliders;
-
- private final float TENTH = .1f;
- private final float HALF = .5f;
- private final float THIRD = .3f;
- private final float FIFTH = .2f;
- private final float FEET_PROTRUSION = 1.2f;
-
- private RectF mHeadRectF = new RectF();
- private RectF mRightRectF = new RectF();
- private RectF mFeetRectF = new RectF();
- private RectF mLeftRectF = new RectF();
-
- private boolean mJumpTriggered = false;
- private boolean mBumpedHeadTriggered = false;
-
- private boolean mGrounded;
-
- PlayerTransform(float speed,
- float objectWidth,
- float objectHeight,
- PointF startingLocation) {
-
- super(speed, objectWidth,
- objectHeight,
- startingLocation);
-
- mColliders = new ArrayList();
- // Load up the colliders ArrayList with
- // player specific colliders
- mColliders.add(mFeetRectF);
- mColliders.add(mHeadRectF);
- mColliders.add(mRightRectF);
- mColliders.add(mLeftRectF);
- }
-
- public ArrayList getColliders(){
- updateColliders();
- return mColliders;
- }
-
- public void updateColliders(){
-
- PointF location = getLocation();
- float objectHeight = getSize().y;
- float objectWidth = getSize().x;
-
- // Feet
- mColliders.get(0).left = location.x
- + (objectWidth * THIRD);
-
- mColliders.get(0).top = location.y
- + objectHeight - (objectHeight
- * TENTH);
-
- mColliders.get(0).right = location.x
- + objectWidth - (objectWidth
- * THIRD);
-
- mColliders.get(0).bottom = location.y
- + objectHeight + (objectHeight
- * FEET_PROTRUSION);
-
- // Head
- mColliders.get(1).left = location.x
- + ((objectWidth * THIRD));
-
- mColliders.get(1).top = location.y;
- mColliders.get(1).right = location.x
- +objectWidth - (objectWidth
- * THIRD);
-
- mColliders.get(1).bottom = location.y
- + (objectHeight * TENTH);
-
- // Right
- mColliders.get(2).left = location.x
- + objectWidth - (objectWidth
- * TENTH);
-
- mColliders.get(2).top = location.y
- + (objectHeight * THIRD);
- mColliders.get(2).right = location.x
- + objectWidth;
-
- mColliders.get(2).bottom = location.y
- + (objectHeight - (objectHeight
- * HALF));
-
- // Left
- mColliders.get(3).left = location.x;
- mColliders.get(3).top = location.y
- + (objectHeight * FIFTH);
- mColliders.get(3).right = location.x
- + (objectWidth * TENTH);
-
- mColliders.get(3).bottom = location.y
- + (objectHeight - (objectHeight
- * FIFTH));
- }
-
- // Called by handle input component to
- // let us know a jump has been triggered
- void triggerJump() {
- mJumpTriggered = true;
- }
-
- // Called by movement component to let transform
- // know that movement component is aware
- // jump was triggered
- void handlingJump() {
- mJumpTriggered = false;
- }
-
- // Used by movement component to find
- // out if jump has been triggered
- boolean jumpTriggered() {
- return mJumpTriggered;
- }
-
- void setNotGrounded(){
- mGrounded=false;
- }
-
- void triggerBumpedHead() {
- mBumpedHeadTriggered = true;
- }
-
- void handlingBumpedHead() {
- mBumpedHeadTriggered = false;
- }
-
- boolean bumpedHead() {
- return mBumpedHeadTriggered;
- }
-
- void notGrounded() {
- mGrounded = false;
- }
-
- void grounded() {
- mGrounded = true;
- }
-
- boolean isGrounded() {
- return mGrounded;
- }
-}
diff --git a/Chapter24/java/PlayerUpdateComponent.java b/Chapter24/java/PlayerUpdateComponent.java
deleted file mode 100644
index f103c0e..0000000
--- a/Chapter24/java/PlayerUpdateComponent.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.graphics.PointF;
-
-class PlayerUpdateComponent implements UpdateComponent {
-
- private boolean mIsJumping = false;
- private long mJumpStartTime;
-
- // How long a jump lasts
- // Further subdivided into up time and down time, later
- private final long MAX_JUMP_TIME = 400;
- private final float GRAVITY = 6;
-
- public void update(long fps,
- Transform t,
- Transform playerTransform) {
-
- // cast to player transform
- PlayerTransform pt = (PlayerTransform) t;
-
- // Where is the player?
- PointF location = t.getLocation();
- // How fast is it going
- float speed = t.getSpeed();
-
- if (t.headingLeft()) {
- location.x -= speed / fps;
- } else if (t.headingRight()) {
- location.x += speed / fps;
- }
-
- // Has the player bumped there head
- if (pt.bumpedHead()) {
- mIsJumping = false;
- pt.handlingBumpedHead();
- }
-
- // Check if jump was triggered by player
- // and if player
- // is NOT ALREADY jumping or falling
- // Don't want jumping in mid air
- // If you want double jump (or triple etc.)
- // allow the jump when not grounded,
- // and count the number of non-grounded
- // jumps and disallow jump when
- // your preferred limit is reached
- if (pt.jumpTriggered()
- && !mIsJumping
- && pt.isGrounded()) {
-
- SoundEngine.playJump();
- mIsJumping = true;
- pt.handlingJump();
- // Thanks for the notification
- // I'll take it from here
- mJumpStartTime = System.currentTimeMillis();
- }
-
- // Gravity
- if (!mIsJumping) {
- // Player is not jumping apply GRAVITY
- location.y += GRAVITY / fps;
- } else if (mIsJumping) {
- // Player is jumping
- pt.setNotGrounded();
-
- // Still in upward (first part) phase of the jump
- if (System.currentTimeMillis()
- < mJumpStartTime + (MAX_JUMP_TIME / 1.5)) {
- // keep going up
- location.y -= (GRAVITY * 1.8) / fps;
- }
- // In second (downward) phase of jump
- else if (System.currentTimeMillis()
- < mJumpStartTime + MAX_JUMP_TIME) {
- // Come back down
- location.y += (GRAVITY) / fps;
- }
- // Has the jump ended
- else if (System.currentTimeMillis()
- > mJumpStartTime + MAX_JUMP_TIME) {
-
- // Time to end the jump
- mIsJumping = false;
- }
- }
-
- // Let the colliders know the new position
- t.updateCollider();
- }
-}
diff --git a/Chapter24/java/Renderer.java b/Chapter24/java/Renderer.java
deleted file mode 100644
index bb6fef0..0000000
--- a/Chapter24/java/Renderer.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-import java.util.ArrayList;
-
-class Renderer {
- private Canvas mCanvas;
- private SurfaceHolder mSurfaceHolder;
- private Paint mPaint;
-
- // Here is our new camera
- private Camera mCamera;
-
- Renderer(SurfaceView sh, Point screenSize){
- mSurfaceHolder = sh.getHolder();
- mPaint = new Paint();
-
- // Initialize the camera
- mCamera = new Camera(screenSize.x, screenSize.y);
- }
-
- int getPixelsPerMetre(){
- return mCamera.getPixelsPerMetre();
- }
-
- void draw(ArrayList objects,
- GameState gs,
- HUD hud) {
-
- if (mSurfaceHolder.getSurface().isValid()) {
- mCanvas = mSurfaceHolder.lockCanvas();
- mCanvas.drawColor(Color.argb(255, 0, 0, 0));
-
- if(gs.getDrawing()) {
- // Set the player as the center of the camera
- mCamera.setWorldCentre(
- objects.get(LevelManager.PLAYER_INDEX)
- .getTransform().getLocation());
-
- for (GameObject object : objects) {
- if (object.checkActive()) {
- object.draw(mCanvas, mPaint, mCamera);
- }
- }
- }
-
- hud.draw(mCanvas, mPaint, gs);
-
- mSurfaceHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-
-}
diff --git a/Chapter24/java/SoundEngine.java b/Chapter24/java/SoundEngine.java
deleted file mode 100644
index 21259a1..0000000
--- a/Chapter24/java/SoundEngine.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-
-import java.io.IOException;
-
-class SoundEngine {
- // for playing sound effects
- private static SoundPool mSP;
- private static int mJump_ID = -1;
- private static int mReach_Objective_ID = -1;
- private static int mCoin_Pickup_ID = -1;
- private static int mPlayer_Burn_ID = -1;
-
- private static SoundEngine ourInstance;
-
- public static SoundEngine getInstance(Context context) {
- ourInstance = new SoundEngine(context);
- return ourInstance;
- }
-
- public SoundEngine(Context c){
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
- try {
- AssetManager assetManager = c.getAssets();
- AssetFileDescriptor descriptor;
-
- // Prepare the sounds in memory
- descriptor = assetManager.openFd("jump.ogg");
- mJump_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("reach_objective.ogg");
- mReach_Objective_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("coin_pickup.ogg");
- mCoin_Pickup_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("player_burn.ogg");
- mPlayer_Burn_ID = mSP.load(descriptor, 0);
-
- } catch (IOException e) {
- // Error
- }
-
- }
-
-
- public static void playJump(){
- mSP.play(mJump_ID,1, 1, 0, 0, 1);
- }
-
- public static void playReachObjective(){
- mSP.play(mReach_Objective_ID,1, 1, 0, 0, 1);
- }
-
- public static void playCoinPickup(){
- mSP.play(mCoin_Pickup_ID,1, 1, 0, 0, 1);
- }
-
- public static void playPlayerBurn(){
- mSP.play(mPlayer_Burn_ID,1, 1, 0, 0, 1);
- }
-
-}
diff --git a/Chapter24/java/Transform.java b/Chapter24/java/Transform.java
deleted file mode 100644
index 45f8ac9..0000000
--- a/Chapter24/java/Transform.java
+++ /dev/null
@@ -1,117 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.graphics.PointF;
-import android.graphics.RectF;
-
-public class Transform {
- RectF mCollider;
- private PointF mLocation;
- private float mSpeed;
- private float mObjectHeight;
- private float mObjectWidth;
- private PointF mStartingPosition;
- private boolean mHeadingUp = false;
- private boolean mHeadingDown = false;
-
- private boolean mFacingRight = true;
- private boolean mHeadingLeft = false;
- private boolean mHeadingRight = false;
-
- Transform(float speed, float objectWidth,
- float objectHeight, PointF startingLocation) {
-
- mCollider = new RectF();
- mSpeed = speed;
- mObjectHeight = objectHeight;
- mObjectWidth = objectWidth;
- mLocation = startingLocation;
-
- // This tells movable blocks their starting position
- mStartingPosition = new PointF(mLocation.x, mLocation.y);
- }
-
-
- public void updateCollider() {
- mCollider.top = mLocation.y;
- mCollider.left = mLocation.x ;
- mCollider.bottom = (mCollider.top + mObjectHeight);
- mCollider.right = (mCollider.left + mObjectWidth);
- }
-
-
- public RectF getCollider() {
- return mCollider;
- }
-
- void headUp() {
- mHeadingUp = true;
- mHeadingDown = false;
- }
-
- void headDown() {
- mHeadingDown = true;
- mHeadingUp = false;
- }
-
- boolean headingUp() {
- return mHeadingUp;
- }
-
- boolean headingDown() {
- return mHeadingDown;
- }
-
- float getSpeed() {
- return mSpeed;
- }
-
- PointF getLocation() {
- return mLocation;
- }
-
- PointF getSize() {
- return new PointF((int) mObjectWidth, (int) mObjectHeight);
- }
-
- void headRight() {
- mHeadingRight = true;
- mHeadingLeft = false;
- mFacingRight = true;
-
- }
-
- void headLeft() {
- mHeadingLeft = true;
- mHeadingRight = false;
- mFacingRight = false;
- }
-
- boolean headingRight() {
- return mHeadingRight;
- }
-
- boolean headingLeft() {
- return mHeadingLeft;
- }
-
- void stopHorizontal() {
- mHeadingLeft = false;
- mHeadingRight = false;
- }
-
- void stopMovingLeft() {
- mHeadingLeft = false;
- }
-
- void stopMovingRight() {
- mHeadingRight = false;
- }
-
- boolean getFacingRight() {
- return mFacingRight;
- }
-
- PointF getStartingPosition(){
- return mStartingPosition;
- }
-}
diff --git a/Chapter24/java/UIController.java b/Chapter24/java/UIController.java
deleted file mode 100644
index 9f1dc93..0000000
--- a/Chapter24/java/UIController.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-class UIController implements InputObserver {
-
- private float mThird;
-
- private boolean initialPress = false;
-
- UIController(GameEngineBroadcaster b, Point size) {
- // Add as an observer
- addObserver(b);
-
- mThird = size.x / 3;
- }
-
- // Need to add observer each time a new game is started and the game objects are rebuilt
- // and the observer list is cleared. This method allows us to re-add an observer for this
- // Rather than just add it in the constructor.
- // The Player controller doesn't need it because a new object is created each level
- void addObserver(GameEngineBroadcaster b) {
- b.addObserver(this);
- }
-
- @Override
- public void handleInput(MotionEvent event,
- GameState gameState,
- ArrayList buttons) {
-
- int i = event.getActionIndex();
- int x = (int) event.getX(i);
-
- int eventType = event.getAction()
- & MotionEvent.ACTION_MASK;
-
- if (eventType == MotionEvent.ACTION_UP ||
- eventType == MotionEvent.ACTION_POINTER_UP) {
-
- // If game is over start a new game
- if (gameState.getGameOver() && initialPress) {
-
- if (x < mThird) {
- gameState.setCurrentLevel("underground");
- gameState.startNewGame();
- } else if (x >= mThird && x < mThird * 2) {
- gameState.setCurrentLevel("mountains");
- gameState.startNewGame();
- } else if (x >= mThird * 2) {
- gameState.setCurrentLevel("city");
- gameState.startNewGame();
- }
-
- }
-
- initialPress = !initialPress;
- }
-
- }
-
-}
diff --git a/Chapter24/java/UpdateComponent.java b/Chapter24/java/UpdateComponent.java
deleted file mode 100644
index 897675b..0000000
--- a/Chapter24/java/UpdateComponent.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.gamecodeschool.c24platformer;
-
-interface UpdateComponent {
-
- // Everything has one of these so it can be updated
- // The player's transform could be left out because it is only needed
- // by the background(to see which way the player is moving)
- // However, if we added enemies at a later date they would likely need
- // to know where the player is and what he is doing.
- // So I left it in rather than create a communication between the
- // background and the player
- void update(long fps, Transform t, Transform playerTransform);
-}
diff --git a/Chapter25/AndroidManifest.xml b/Chapter25/AndroidManifest.xml
deleted file mode 100644
index 4f41d30..0000000
--- a/Chapter25/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Chapter25/assets/coin_pickup.ogg b/Chapter25/assets/coin_pickup.ogg
deleted file mode 100644
index cfbb1b6..0000000
Binary files a/Chapter25/assets/coin_pickup.ogg and /dev/null differ
diff --git a/Chapter25/assets/jump.ogg b/Chapter25/assets/jump.ogg
deleted file mode 100644
index eb6f8ef..0000000
Binary files a/Chapter25/assets/jump.ogg and /dev/null differ
diff --git a/Chapter25/assets/player_burn.ogg b/Chapter25/assets/player_burn.ogg
deleted file mode 100644
index 62c823b..0000000
Binary files a/Chapter25/assets/player_burn.ogg and /dev/null differ
diff --git a/Chapter25/assets/reach_objective.ogg b/Chapter25/assets/reach_objective.ogg
deleted file mode 100644
index 03d8b79..0000000
Binary files a/Chapter25/assets/reach_objective.ogg and /dev/null differ
diff --git a/Chapter25/drawable/brick.png b/Chapter25/drawable/brick.png
deleted file mode 100644
index ee965c0..0000000
Binary files a/Chapter25/drawable/brick.png and /dev/null differ
diff --git a/Chapter25/drawable/cart.png b/Chapter25/drawable/cart.png
deleted file mode 100644
index 760763f..0000000
Binary files a/Chapter25/drawable/cart.png and /dev/null differ
diff --git a/Chapter25/drawable/city.png b/Chapter25/drawable/city.png
deleted file mode 100644
index 7469d2b..0000000
Binary files a/Chapter25/drawable/city.png and /dev/null differ
diff --git a/Chapter25/drawable/coal.png b/Chapter25/drawable/coal.png
deleted file mode 100644
index 26cdf5f..0000000
Binary files a/Chapter25/drawable/coal.png and /dev/null differ
diff --git a/Chapter25/drawable/coin.png b/Chapter25/drawable/coin.png
deleted file mode 100644
index af753f7..0000000
Binary files a/Chapter25/drawable/coin.png and /dev/null differ
diff --git a/Chapter25/drawable/concrete.png b/Chapter25/drawable/concrete.png
deleted file mode 100644
index 13bbacb..0000000
Binary files a/Chapter25/drawable/concrete.png and /dev/null differ
diff --git a/Chapter25/drawable/dead_tree.png b/Chapter25/drawable/dead_tree.png
deleted file mode 100644
index bfb48ca..0000000
Binary files a/Chapter25/drawable/dead_tree.png and /dev/null differ
diff --git a/Chapter25/drawable/death_invisible.png b/Chapter25/drawable/death_invisible.png
deleted file mode 100644
index f82bcba..0000000
Binary files a/Chapter25/drawable/death_invisible.png and /dev/null differ
diff --git a/Chapter25/drawable/death_visible.png b/Chapter25/drawable/death_visible.png
deleted file mode 100644
index 9652496..0000000
Binary files a/Chapter25/drawable/death_visible.png and /dev/null differ
diff --git a/Chapter25/drawable/fire.png b/Chapter25/drawable/fire.png
deleted file mode 100644
index 0f78395..0000000
Binary files a/Chapter25/drawable/fire.png and /dev/null differ
diff --git a/Chapter25/drawable/grass.png b/Chapter25/drawable/grass.png
deleted file mode 100644
index ecffbc7..0000000
Binary files a/Chapter25/drawable/grass.png and /dev/null differ
diff --git a/Chapter25/drawable/lamppost.png b/Chapter25/drawable/lamppost.png
deleted file mode 100644
index 850f9df..0000000
Binary files a/Chapter25/drawable/lamppost.png and /dev/null differ
diff --git a/Chapter25/drawable/menu.png b/Chapter25/drawable/menu.png
deleted file mode 100644
index ea22c8b..0000000
Binary files a/Chapter25/drawable/menu.png and /dev/null differ
diff --git a/Chapter25/drawable/mountain.png b/Chapter25/drawable/mountain.png
deleted file mode 100644
index 4f2d211..0000000
Binary files a/Chapter25/drawable/mountain.png and /dev/null differ
diff --git a/Chapter25/drawable/objective.png b/Chapter25/drawable/objective.png
deleted file mode 100644
index 493d1b4..0000000
Binary files a/Chapter25/drawable/objective.png and /dev/null differ
diff --git a/Chapter25/drawable/platform.png b/Chapter25/drawable/platform.png
deleted file mode 100644
index c72ada1..0000000
Binary files a/Chapter25/drawable/platform.png and /dev/null differ
diff --git a/Chapter25/drawable/player.png b/Chapter25/drawable/player.png
deleted file mode 100644
index 379b2ed..0000000
Binary files a/Chapter25/drawable/player.png and /dev/null differ
diff --git a/Chapter25/drawable/scorched.png b/Chapter25/drawable/scorched.png
deleted file mode 100644
index 814dfa0..0000000
Binary files a/Chapter25/drawable/scorched.png and /dev/null differ
diff --git a/Chapter25/drawable/snow.png b/Chapter25/drawable/snow.png
deleted file mode 100644
index 4069cfc..0000000
Binary files a/Chapter25/drawable/snow.png and /dev/null differ
diff --git a/Chapter25/drawable/snowy_tree.png b/Chapter25/drawable/snowy_tree.png
deleted file mode 100644
index 6074fab..0000000
Binary files a/Chapter25/drawable/snowy_tree.png and /dev/null differ
diff --git a/Chapter25/drawable/stalactite.png b/Chapter25/drawable/stalactite.png
deleted file mode 100644
index 1afc333..0000000
Binary files a/Chapter25/drawable/stalactite.png and /dev/null differ
diff --git a/Chapter25/drawable/stalagmite.png b/Chapter25/drawable/stalagmite.png
deleted file mode 100644
index a50c974..0000000
Binary files a/Chapter25/drawable/stalagmite.png and /dev/null differ
diff --git a/Chapter25/drawable/stone.png b/Chapter25/drawable/stone.png
deleted file mode 100644
index 327a50b..0000000
Binary files a/Chapter25/drawable/stone.png and /dev/null differ
diff --git a/Chapter25/drawable/stone_pile.png b/Chapter25/drawable/stone_pile.png
deleted file mode 100644
index c0e26b6..0000000
Binary files a/Chapter25/drawable/stone_pile.png and /dev/null differ
diff --git a/Chapter25/drawable/turf.png b/Chapter25/drawable/turf.png
deleted file mode 100644
index e1099ef..0000000
Binary files a/Chapter25/drawable/turf.png and /dev/null differ
diff --git a/Chapter25/drawable/underground.png b/Chapter25/drawable/underground.png
deleted file mode 100644
index df3db7e..0000000
Binary files a/Chapter25/drawable/underground.png and /dev/null differ
diff --git a/Chapter25/java/AnimatedGraphicsComponent.java b/Chapter25/java/AnimatedGraphicsComponent.java
deleted file mode 100644
index dcfd2e4..0000000
--- a/Chapter25/java/AnimatedGraphicsComponent.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-import com.gamecodeschool.c25platformer.GOSpec.GameObjectSpec;
-
-class AnimatedGraphicsComponent implements GraphicsComponent {
-
- private String mBitmapName;
- private Animator mAnimator;
- private Rect mSectionToDraw;
-
- @Override
- public void initialize(Context context,
- GameObjectSpec spec,
- PointF objectSize,
- int pixelsPerMetre) {
-
- // Initialize the animation
- mAnimator = new Animator(
- objectSize.y,
- objectSize.x,
- spec.getNumFrames(),
- pixelsPerMetre);
-
- // stretch the bitmap by the number of frames
- float totalWidth = objectSize.x *
- spec.getNumFrames();
-
- mBitmapName = spec.getBitmapName();
- BitmapStore.addBitmap(context,
- mBitmapName,
- new PointF(totalWidth, objectSize.y),
- pixelsPerMetre, true);
-
- // Get the first frame of animation
- mSectionToDraw = mAnimator.getCurrentFrame(
- System.currentTimeMillis());
- }
-
- @Override
- // Updated to take a reference to a Camera
- public void draw(Canvas canvas,
- Paint paint,
- Transform t,
- Camera cam) {
-
- // Get the section of bitmap to draw
- // when an object is in motion
- // OR if it is a object with
- // zero speed(like a fire tile)
- if (t.headingRight() ||
- t.headingLeft() ||
- t.getSpeed() == 0) {
- // Player is moving so animate/change the frame
- mSectionToDraw = mAnimator.getCurrentFrame(
- System.currentTimeMillis());
- }
-
- // WHere should the bitmap section be drawn?
- Rect screenCoordinates = cam.worldToScreen
- (t.getLocation().x,
- t.getLocation().y,
- t.getSize().x,
- t.getSize().y);
-
- if (t.getFacingRight()) {
- canvas.drawBitmap(
- BitmapStore.getBitmap(mBitmapName),
- mSectionToDraw,
- screenCoordinates,
- paint);
- } else
- canvas.drawBitmap(
- BitmapStore.getBitmapReversed(mBitmapName),
- mSectionToDraw,
- screenCoordinates,
- paint);
- }
-}
-
diff --git a/Chapter25/java/Animator.java b/Chapter25/java/Animator.java
deleted file mode 100644
index fd91cc6..0000000
--- a/Chapter25/java/Animator.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.graphics.Rect;
-
-class Animator {
- private Rect mSourceRect;
- private int mFrameCount;
- private int mCurrentFrame;
- private long mFrameTicker;
- private int mFramePeriod;
- private int mFrameWidth;
-
- Animator(float frameHeight,
- float frameWidth,
- int frameCount,
- int pixelsPerMetre) {
-
- final int ANIM_FPS = 10;
-
- this.mCurrentFrame = 0;
- this.mFrameCount = frameCount;
- this.mFrameWidth = (int)frameWidth * pixelsPerMetre;
-
- frameHeight = frameHeight * pixelsPerMetre;
-
- mSourceRect = new Rect(0, 0,
- this.mFrameWidth,
- (int)frameHeight);
-
- mFramePeriod = 1000 / ANIM_FPS;
- mFrameTicker = 0L;
- }
-
- Rect getCurrentFrame(long time) {
- if (time > mFrameTicker + mFramePeriod) {
- mFrameTicker = time;
- mCurrentFrame++;
- if (mCurrentFrame >= mFrameCount) {
- mCurrentFrame = 0;
- }
- }
-
- // Update the left and right values of the source of
- // the next frame on the spritesheet
- this.mSourceRect.left = mCurrentFrame * mFrameWidth;
- this.mSourceRect.right = this.mSourceRect.left
- + mFrameWidth;
-
- return mSourceRect;
- }
-}
diff --git a/Chapter25/java/BackgroundGraphicsComponent.java b/Chapter25/java/BackgroundGraphicsComponent.java
deleted file mode 100644
index 6cf0aab..0000000
--- a/Chapter25/java/BackgroundGraphicsComponent.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-import com.gamecodeschool.c25platformer.GOSpec.GameObjectSpec;
-
-class BackgroundGraphicsComponent implements GraphicsComponent {
-
- private String mBitmapName;
-
- @Override
- public void initialize(Context context,
- GameObjectSpec spec,
- PointF objectSize,
- int pixelsPerMetre) {
-
- mBitmapName = spec.getBitmapName();
-
- BitmapStore.addBitmap(context,
- mBitmapName,
- objectSize,
- pixelsPerMetre,
- true);
- }
-
- @Override
- public void draw(Canvas canvas,
- Paint paint,
- Transform t,
- Camera cam) {
-
- // Cast to a background transform
- BackgroundTransform bt = (BackgroundTransform)t;
-
- Bitmap bitmap = BitmapStore.getBitmap(mBitmapName);
- Bitmap bitmapRevesed = BitmapStore
- .getBitmapReversed(mBitmapName);
-
- int scaledxClip = (int)(bt.getXClip()
- * cam.getPixelsPerMetre());
-
- int width = bitmap.getWidth();
- int height = bitmap.getHeight();
- PointF position = t.getLocation();
-
- float floatstartY = ((cam.getyCentre() -
- ((cam.getCameraWorldCentreY() - position.y) *
- cam.getPixelsPerMetreY())));
-
- int startY = (int) floatstartY;
-
- float floatendY = ((cam.getyCentre() -
- ((cam.getCameraWorldCentreY() -
- position.y - t.getSize().y) *
- cam.getPixelsPerMetreY())));
-
- int endY = (int) floatendY;
-
- // Position the regular bitmap
- Rect fromRect1 = new Rect(0, 0, width - scaledxClip, height);
- Rect toRect1 = new Rect(scaledxClip, startY, width, endY);
-
- // Position the reversed bitmap
- Rect fromRect2 = new Rect(width - scaledxClip, 0, width, height);
- Rect toRect2 = new Rect(0, startY, scaledxClip, endY);
-
- // Draw the two bitmaps
- if (!bt.getReversedFirst()) {
- canvas.drawBitmap(bitmap, fromRect1, toRect1, paint);
- canvas.drawBitmap(bitmapRevesed, fromRect2, toRect2, paint);
- } else {
- canvas.drawBitmap(bitmap, fromRect2, toRect2, paint);
- canvas.drawBitmap(bitmapRevesed, fromRect1, toRect1, paint);
- }
- }
-}
diff --git a/Chapter25/java/BackgroundTransform.java b/Chapter25/java/BackgroundTransform.java
deleted file mode 100644
index 947b951..0000000
--- a/Chapter25/java/BackgroundTransform.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-
-import android.graphics.PointF;
-
-class BackgroundTransform extends Transform {
-
- private float xClip;
- private boolean reversedFirst = false;
-
- public BackgroundTransform(float speed,
- float objectWidth,
- float objectHeight,
- PointF startingLocation) {
-
- super(speed, objectWidth,
- objectHeight,
- startingLocation);
- }
-
- boolean getReversedFirst() {
- return reversedFirst;
- }
-
- void flipReversedFirst() {
- reversedFirst = !reversedFirst;
- }
-
- float getXClip() {
- return xClip;
- }
-
- void setXClip(float newXClip) {
- xClip = newXClip;
- }
-}
diff --git a/Chapter25/java/BackgroundUpdateComponent.java b/Chapter25/java/BackgroundUpdateComponent.java
deleted file mode 100644
index 879da72..0000000
--- a/Chapter25/java/BackgroundUpdateComponent.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-class BackgroundUpdateComponent implements UpdateComponent {
-
- @Override
- public void update(long fps,
- Transform t,
- Transform playerTransform) {
-
- // Cast to background transform
- BackgroundTransform bt =
- (BackgroundTransform) t;
-
- PlayerTransform pt =
- (PlayerTransform) playerTransform;
-
- float currentXClip = bt.getXClip();
-
- // When the player is moving right -
- // update currentXClip to the left
- if (playerTransform.headingRight()) {
- currentXClip -= t.getSpeed() / fps;
- bt.setXClip(currentXClip);
- }
-
- // When the player is heading left -
- // update currentXClip to the right
- else if (playerTransform.headingLeft()) {
- currentXClip += t.getSpeed() / fps;
- bt.setXClip(currentXClip);
- }
-
- // When currentXClip reduces either
- // extreme left or right
- // Flip the order and reset currentXClip
- if (currentXClip >= t.getSize().x) {
- bt.setXClip(0);
- bt.flipReversedFirst();
- } else if (currentXClip <= 0) {
- bt.setXClip((int) t.getSize().x);
- bt.flipReversedFirst();
- }
-
- }
-}
diff --git a/Chapter25/java/BitmapStore.java b/Chapter25/java/BitmapStore.java
deleted file mode 100644
index 1bfa006..0000000
--- a/Chapter25/java/BitmapStore.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Matrix;
-import android.graphics.PointF;
-
-import java.util.HashMap;
-import java.util.Map;
-
-class BitmapStore {
- private static Map mBitmapsMap;
- private static Map mBitmapsReversedMap;
- private static BitmapStore mOurInstance;
-
- // Calling this method is the only way to get a BitmapStore
- static BitmapStore getInstance(Context context) {
-
- mOurInstance = new BitmapStore(context);
- return mOurInstance;
- }
-
- // Can't be called using new BitmapStore()
- private BitmapStore(Context c) {
- mBitmapsMap = new HashMap();
- mBitmapsReversedMap = new HashMap();
-
- // Put a default bitmap in each of the maps
- // to return in case a bitmap doesn't exist
- addBitmap(c,
- "death_visible",
- new PointF(1, 1),
- 128,
- true);
- }
-
- static Bitmap getBitmap(String bitmapName) {
-
- if (mBitmapsMap.containsKey(bitmapName)) {
- return mBitmapsMap.get(bitmapName);
- } else {
- return mBitmapsMap.get("death_visible");
- }
- }
-
- static Bitmap getBitmapReversed(String bitmapName) {
-
- if (mBitmapsReversedMap.containsKey(bitmapName)) {
- return mBitmapsReversedMap.get(bitmapName);
- } else {
- return mBitmapsReversedMap.get("death_visible");
- }
- }
-
- static void addBitmap(Context c,
- String bitmapName,
- PointF objectSize,
- int pixelsPerMetre,
- boolean needReversed) {
-
- Bitmap bitmap;
- Bitmap bitmapReversed;
-
- // Make a resource id out of the string of the file name
- int resID = c.getResources().getIdentifier(bitmapName,
- "drawable", c.getPackageName());
-
- // Load the bitmap using the id
- bitmap = BitmapFactory
- .decodeResource(c.getResources(), resID);
-
- // Resize the bitmap
- bitmap = Bitmap.createScaledBitmap(bitmap,
- (int) objectSize.x * pixelsPerMetre,
- (int) objectSize.y * pixelsPerMetre,
- false);
-
- mBitmapsMap.put(bitmapName, bitmap);
-
- if (needReversed) {
- // Create a mirror image of the bitmap
- Matrix matrix = new Matrix();
- matrix.setScale(-1, 1);
- bitmapReversed = Bitmap.createBitmap(
- bitmap,
- 0, 0,
- bitmap.getWidth(),
- bitmap.getHeight(),
- matrix, true);
-
- mBitmapsReversedMap.put(bitmapName, bitmapReversed);
- }
-
- }
-
- static void clearStore() {
- mBitmapsMap.clear();
- mBitmapsReversedMap.clear();
- }
-}
diff --git a/Chapter25/java/Camera.java b/Chapter25/java/Camera.java
deleted file mode 100644
index a029c6d..0000000
--- a/Chapter25/java/Camera.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-class Camera {
-
- private PointF mCurrentCameraWorldCentre;
- private Rect mConvertedRect;
- private int mPixelsPerMetre;
- private int mScreenCentreX;
- private int mScreenCentreY;
-
- Camera(int screenXResolution, int screenYResolution){
- // Locate the centre of the screen
- mScreenCentreX = screenXResolution / 2;
- mScreenCentreY = screenYResolution / 2;
-
- // How many metres of world space does
- // the screen width show
- // Change this value to zoom in and out
- final int pixelsPerMetreToResolutionRatio = 48;
- mPixelsPerMetre = screenXResolution /
- pixelsPerMetreToResolutionRatio;
-
- mConvertedRect = new Rect();
- mCurrentCameraWorldCentre = new PointF();
- }
-
- int getPixelsPerMetreY(){
- return mPixelsPerMetre;
- }
-
- int getyCentre(){
- return mScreenCentreY;
- }
-
- float getCameraWorldCentreY(){
- return mCurrentCameraWorldCentre.y;
- }
-
- // Set the camera to the player. Called each frame
- void setWorldCentre(PointF worldCentre){
- mCurrentCameraWorldCentre.x = worldCentre.x;
- mCurrentCameraWorldCentre.y = worldCentre.y;
- }
-
- int getPixelsPerMetre(){
- return mPixelsPerMetre;
- }
-
- // Return a Rect of the screen coordinates relative to a world location
- Rect worldToScreen(float objectX,
- float objectY,
- float objectWidth,
- float objectHeight){
-
- int left = (int) (mScreenCentreX -
- ((mCurrentCameraWorldCentre.x - objectX)
- * mPixelsPerMetre));
-
- int top = (int) (mScreenCentreY -
- ((mCurrentCameraWorldCentre.y - objectY)
- * mPixelsPerMetre));
-
- int right = (int) (left + (objectWidth * mPixelsPerMetre));
- int bottom = (int) (top + (objectHeight * mPixelsPerMetre));
- mConvertedRect.set(left, top, right, bottom);
- return mConvertedRect;
- }
-
-}
-
diff --git a/Chapter25/java/DecorativeBlockUpdateComponent.java b/Chapter25/java/DecorativeBlockUpdateComponent.java
deleted file mode 100644
index d479b4e..0000000
--- a/Chapter25/java/DecorativeBlockUpdateComponent.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-class DecorativeBlockUpdateComponent implements UpdateComponent {
- @Override
- public void update(long fps, Transform t, Transform playerTransform) {
- // Do nothing
- // Not even set a collider
- }
-}
diff --git a/Chapter25/java/EngineController.java b/Chapter25/java/EngineController.java
deleted file mode 100644
index 9bbb0e0..0000000
--- a/Chapter25/java/EngineController.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-interface EngineController {
- // This allows the GameState class to start a new level
- void startNewLevel();
-}
diff --git a/Chapter25/java/GOSpec/BackgroundCitySpec.java b/Chapter25/java/GOSpec/BackgroundCitySpec.java
deleted file mode 100644
index 3c5b8d7..0000000
--- a/Chapter25/java/GOSpec/BackgroundCitySpec.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BackgroundCitySpec extends GameObjectSpec {
- // This is all the unique specifications for the city background
- private static final String tag = "Background";
- private static final String bitmapName = "city";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(100, 70);
- private static final String[] components = new String [] {
- "BackgroundGraphicsComponent","BackgroundUpdateComponent"};
-
- public BackgroundCitySpec() {
- super(tag, bitmapName, speed, size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/BackgroundMountainSpec.java b/Chapter25/java/GOSpec/BackgroundMountainSpec.java
deleted file mode 100644
index 2c38672..0000000
--- a/Chapter25/java/GOSpec/BackgroundMountainSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BackgroundMountainSpec extends GameObjectSpec {
- // This is all the specifications for the mountain
- private static final String tag = "Background";
- private static final String bitmapName = "mountain";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(100, 70);
- private static final String[] components = new String [] {
- "BackgroundGraphicsComponent",
- "BackgroundUpdateComponent"};
-
- public BackgroundMountainSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/BackgroundUndergroundSpec.java b/Chapter25/java/GOSpec/BackgroundUndergroundSpec.java
deleted file mode 100644
index 9a77ec9..0000000
--- a/Chapter25/java/GOSpec/BackgroundUndergroundSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BackgroundUndergroundSpec extends GameObjectSpec {
- // This is all the specifications for the underground
- private static final String tag = "Background";
- private static final String bitmapName = "underground";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(100, 70f);
- private static final String[] components = new String [] {
- "BackgroundGraphicsComponent",
- "BackgroundUpdateComponent"};
-
- public BackgroundUndergroundSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/BrickTileSpec.java b/Chapter25/java/GOSpec/BrickTileSpec.java
deleted file mode 100644
index dcfcde5..0000000
--- a/Chapter25/java/GOSpec/BrickTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class BrickTileSpec extends GameObjectSpec {
-
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "brick";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public BrickTileSpec() {
- super(tag, bitmapName, speed,
- size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/CartTileSpec.java b/Chapter25/java/GOSpec/CartTileSpec.java
deleted file mode 100644
index 5928445..0000000
--- a/Chapter25/java/GOSpec/CartTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class CartTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "cart";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 1f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public CartTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/CoalTileSpec.java b/Chapter25/java/GOSpec/CoalTileSpec.java
deleted file mode 100644
index 2051a3b..0000000
--- a/Chapter25/java/GOSpec/CoalTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class CoalTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "coal";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public CoalTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/CollectibleObjectSpec.java b/Chapter25/java/GOSpec/CollectibleObjectSpec.java
deleted file mode 100644
index 2c78126..0000000
--- a/Chapter25/java/GOSpec/CollectibleObjectSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class CollectibleObjectSpec extends GameObjectSpec {
- private static final String tag = "Collectible";
- private static final String bitmapName = "coin";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public CollectibleObjectSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/ConcreteTileSpec.java b/Chapter25/java/GOSpec/ConcreteTileSpec.java
deleted file mode 100644
index 0cc9bfd..0000000
--- a/Chapter25/java/GOSpec/ConcreteTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class ConcreteTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "concrete";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public ConcreteTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/DeadTreeTileSpec.java b/Chapter25/java/GOSpec/DeadTreeTileSpec.java
deleted file mode 100644
index 405bbb0..0000000
--- a/Chapter25/java/GOSpec/DeadTreeTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class DeadTreeTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "dead_tree";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 4f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public DeadTreeTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/FireTileSpec.java b/Chapter25/java/GOSpec/FireTileSpec.java
deleted file mode 100644
index d1bb6b5..0000000
--- a/Chapter25/java/GOSpec/FireTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class FireTileSpec extends GameObjectSpec {
- private static final String tag = "Death";
- private static final String bitmapName = "fire";
- private static final int framesOfAnimation = 3;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String[]{
- "AnimatedGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public FireTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/GameObjectSpec.java b/Chapter25/java/GOSpec/GameObjectSpec.java
deleted file mode 100644
index b901ead..0000000
--- a/Chapter25/java/GOSpec/GameObjectSpec.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public abstract class GameObjectSpec {
- private String mTag;
- private String mBitmapName;
- private float mSpeed;
- private PointF mSize;
- private String[] mComponents;
- private int mFramesAnimation;
-
- GameObjectSpec(String tag,
- String bitmapName,
- float speed,
- PointF size,
- String[] components,
- int framesAnimation ){
-
- mTag = tag;
- mBitmapName = bitmapName;
- mSpeed = speed;
- mSize = size;
- mComponents = components;
- mFramesAnimation = framesAnimation;
- }
-
- public int getNumFrames(){
- return mFramesAnimation;
- }
-
- public String getTag(){
- return mTag;
- }
-
- public String getBitmapName(){
- return mBitmapName;
- }
-
- public float getSpeed(){
- return mSpeed;
- }
-
- public PointF getSize(){
- return mSize;
- }
-
- public String[] getComponents(){
- return mComponents;
- }
-}
diff --git a/Chapter25/java/GOSpec/GrassTileSpec.java b/Chapter25/java/GOSpec/GrassTileSpec.java
deleted file mode 100644
index 9be7611..0000000
--- a/Chapter25/java/GOSpec/GrassTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class GrassTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "turf";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public GrassTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/InvisibleDeathTenByTenSpec.java b/Chapter25/java/GOSpec/InvisibleDeathTenByTenSpec.java
deleted file mode 100644
index 2a99c34..0000000
--- a/Chapter25/java/GOSpec/InvisibleDeathTenByTenSpec.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-import android.graphics.PointF;
-
-public class InvisibleDeathTenByTenSpec extends GameObjectSpec {
- private static final String tag = "Death";
- private static final String bitmapName = "death_visible";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(10f, 10f);
- private static final String[] components = new String[]{"InanimateBlockGraphicsComponent", "InanimateBlockUpdateComponent"};
-
- public InvisibleDeathTenByTenSpec() {
- super(tag, bitmapName, speed, size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/LamppostTileSpec.java b/Chapter25/java/GOSpec/LamppostTileSpec.java
deleted file mode 100644
index 3219904..0000000
--- a/Chapter25/java/GOSpec/LamppostTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class LamppostTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "lamppost";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 4f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public LamppostTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/MoveablePlatformSpec.java b/Chapter25/java/GOSpec/MoveablePlatformSpec.java
deleted file mode 100644
index 42a5a7b..0000000
--- a/Chapter25/java/GOSpec/MoveablePlatformSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class MoveablePlatformSpec extends GameObjectSpec {
- private static final String tag = "Movable Platform";
- private static final String bitmapName = "platform";
- private static final int framesOfAnimation = 1;
- private static final float speed = 3f;
- private static final PointF size = new PointF(2f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "MovableBlockUpdateComponent"};
-
- public MoveablePlatformSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/ObjectiveTileSpec.java b/Chapter25/java/GOSpec/ObjectiveTileSpec.java
deleted file mode 100644
index ac6bf2a..0000000
--- a/Chapter25/java/GOSpec/ObjectiveTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class ObjectiveTileSpec extends GameObjectSpec {
-
- private static final String tag = "Objective Tile";
- private static final String bitmapName = "objective";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(3f, 3f);
- private static final String[] components = new String[]{
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public ObjectiveTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/PlayerSpec.java b/Chapter25/java/GOSpec/PlayerSpec.java
deleted file mode 100644
index 2791bbb..0000000
--- a/Chapter25/java/GOSpec/PlayerSpec.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class PlayerSpec extends GameObjectSpec {
- // This is all the unique specifications for a player
- private static final String tag = "Player";
- private static final String bitmapName = "player";
- private static final int framesOfAnimation = 5;
- private static final float speed = 10f;
- private static final PointF size = new PointF(1f, 2f);
- private static final String[] components = new String [] {
- "PlayerInputComponent",
- "AnimatedGraphicsComponent",
- "PlayerUpdateComponent"};
-
- public PlayerSpec() {
- super(tag, bitmapName, speed,
- size, components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/ScorchedTileSpec.java b/Chapter25/java/GOSpec/ScorchedTileSpec.java
deleted file mode 100644
index 327747b..0000000
--- a/Chapter25/java/GOSpec/ScorchedTileSpec.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class ScorchedTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "scorched";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public ScorchedTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
-
- }
-}
diff --git a/Chapter25/java/GOSpec/SnowTileSpec.java b/Chapter25/java/GOSpec/SnowTileSpec.java
deleted file mode 100644
index 580bfb6..0000000
--- a/Chapter25/java/GOSpec/SnowTileSpec.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-
-import android.graphics.PointF;
-
-public class SnowTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "snow";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(1f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public SnowTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/SnowyTreeTileSpec.java b/Chapter25/java/GOSpec/SnowyTreeTileSpec.java
deleted file mode 100644
index 121f343..0000000
--- a/Chapter25/java/GOSpec/SnowyTreeTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class SnowyTreeTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "snowy_tree";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(3f, 6f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public SnowyTreeTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/StalactiteTileSpec.java b/Chapter25/java/GOSpec/StalactiteTileSpec.java
deleted file mode 100644
index 0416607..0000000
--- a/Chapter25/java/GOSpec/StalactiteTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class StalactiteTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "stalactite";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 4f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public StalactiteTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/StalagmiteTileSpec.java b/Chapter25/java/GOSpec/StalagmiteTileSpec.java
deleted file mode 100644
index f75e8ce..0000000
--- a/Chapter25/java/GOSpec/StalagmiteTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class StalagmiteTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "stalagmite";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 4f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "DecorativeBlockUpdateComponent"};
-
- public StalagmiteTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GOSpec/StonePileTileSpec.java b/Chapter25/java/GOSpec/StonePileTileSpec.java
deleted file mode 100644
index f947f8f..0000000
--- a/Chapter25/java/GOSpec/StonePileTileSpec.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.gamecodeschool.c25platformer.GOSpec;
-
-import android.graphics.PointF;
-
-public class StonePileTileSpec extends GameObjectSpec {
- private static final String tag = "Inert Tile";
- private static final String bitmapName = "stone_pile";
- private static final int framesOfAnimation = 1;
- private static final float speed = 0f;
- private static final PointF size = new PointF(2f, 1f);
- private static final String[] components = new String [] {
- "InanimateBlockGraphicsComponent",
- "InanimateBlockUpdateComponent"};
-
- public StonePileTileSpec() {
- super(tag, bitmapName, speed, size,
- components, framesOfAnimation);
- }
-}
diff --git a/Chapter25/java/GameActivity.java b/Chapter25/java/GameActivity.java
deleted file mode 100644
index 7b807e8..0000000
--- a/Chapter25/java/GameActivity.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.app.Activity;
-import android.graphics.Point;
-import android.os.Bundle;
-import android.view.Display;
-
-public class GameActivity extends Activity {
-
- GameEngine mGameEngine;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Display display = getWindowManager()
- .getDefaultDisplay();
-
- Point size = new Point();
- display.getSize(size);
- mGameEngine = new GameEngine(this, size);
- setContentView(mGameEngine);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mGameEngine.startThread();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mGameEngine.stopThread();
- }
-}
diff --git a/Chapter25/java/GameEngine.java b/Chapter25/java/GameEngine.java
deleted file mode 100644
index 0e67182..0000000
--- a/Chapter25/java/GameEngine.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.content.Context;
-import android.graphics.Point;
-import android.util.Log;
-import android.view.MotionEvent;
-import android.view.SurfaceView;
-
-import java.util.concurrent.CopyOnWriteArrayList;
-
-class GameEngine extends SurfaceView
- implements Runnable,
- GameEngineBroadcaster,
- EngineController {
-
- private Thread mThread = null;
- private long mFPS;
-
- private GameState mGameState;
- UIController mUIController;
-
- // This ArrayList can be accessed from either thread
- private CopyOnWriteArrayList
- inputObservers = new CopyOnWriteArrayList();
-
- HUD mHUD;
- LevelManager mLevelManager;
- PhysicsEngine mPhysicsEngine;
- Renderer mRenderer;
-
- public GameEngine(Context context, Point size) {
- super(context);
- // Prepare the bitmap store and sound engine
- BitmapStore bs = BitmapStore.getInstance(context);
- SoundEngine se = SoundEngine.getInstance(context);
-
- // Initialize all the significant classes
- // that make the engine work
- mHUD = new HUD(context, size);
- mGameState = new GameState(this, context);
- mUIController = new UIController(this, size);
- mPhysicsEngine = new PhysicsEngine();
- mRenderer = new Renderer(this, size);
- mLevelManager = new LevelManager(context,
- this, mRenderer.getPixelsPerMetre());
-
- }
-
- public void startNewLevel() {
- // Clear the bitmap store
- BitmapStore.clearStore();
- // Clear all the observers and add the UI observer back
- // When we call buildGameObjects the
- // player's observer will be added too
- inputObservers.clear();
- mUIController.addObserver(this);
- mLevelManager.setCurrentLevel(mGameState.getCurrentLevel());
- mLevelManager.buildGameObjects(mGameState);
- }
-
- // For the game engine broadcaster interface
- public void addObserver(InputObserver o) {
- inputObservers.add(o);
- }
-
- @Override
- public void run() {
- while (mGameState.getThreadRunning()) {
-
- long frameStartTime = System.currentTimeMillis();
-
- if (!mGameState.getPaused()) {
- mPhysicsEngine.update(mFPS,
- mLevelManager.getGameObjects(),
- mGameState);
- }
-
- mRenderer.draw(mLevelManager.getGameObjects(),
- mGameState,
- mHUD);
-
- long timeThisFrame = System.currentTimeMillis()
- - frameStartTime;
-
- if (timeThisFrame >= 1) {
- final int MILLIS_IN_SECOND = 1000;
- mFPS = MILLIS_IN_SECOND / timeThisFrame;
- }
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent motionEvent) {
- for (InputObserver o : inputObservers) {
- o.handleInput(motionEvent,
- mGameState,
- mHUD.getControls());
- }
- return true;
- }
-
- public void stopThread() {
- mGameState.stopEverything();
- mGameState.stopThread();
- try {
- mThread.join();
- } catch (InterruptedException e) {
- Log.e("Exception",
- "stopThread()" + e.getMessage());
- }
- }
-
- public void startThread() {
- mGameState.startThread();
- mThread = new Thread(this);
- mThread.start();
- }
-}
diff --git a/Chapter25/java/GameEngineBroadcaster.java b/Chapter25/java/GameEngineBroadcaster.java
deleted file mode 100644
index e7319f0..0000000
--- a/Chapter25/java/GameEngineBroadcaster.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-interface GameEngineBroadcaster {
-
- // This allows the Player and UI Controller components
- // to add themselves as listeners of the GameEngine class
- void addObserver(InputObserver o);
-}
diff --git a/Chapter25/java/GameObject.java b/Chapter25/java/GameObject.java
deleted file mode 100644
index 573e2df..0000000
--- a/Chapter25/java/GameObject.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-import com.gamecodeschool.c25platformer.GOSpec.GameObjectSpec;
-
-class GameObject {
-
- private Transform mTransform;
-
-
- private boolean mActive = true;
- private String mTag;
-
- private GraphicsComponent mGraphicsComponent;
- private UpdateComponent mUpdateComponent;
-
- void setGraphics(GraphicsComponent g,
- Context c,
- GameObjectSpec spec,
- PointF objectSize,
- int pixelsPerMetre) {
-
- mGraphicsComponent = g;
- g.initialize(c, spec, objectSize, pixelsPerMetre);
- }
-
- void setMovement(UpdateComponent m) {
- mUpdateComponent = m;
- }
-
-
-
- void setPlayerInputTransform(PlayerInputComponent s) {
- s.setTransform(mTransform);
- }
-
-
- void setTransform(Transform t) {
- mTransform = t;
- }
-
- void draw(Canvas canvas, Paint paint, Camera cam) {
- mGraphicsComponent.draw(canvas,
- paint,
- mTransform, cam);
- }
-
- void update(long fps, Transform playerTransform) {
- mUpdateComponent.update(fps,
- mTransform,
- playerTransform);
- }
-
- boolean checkActive() {
- return mActive;
- }
-
- String getTag() {
- return mTag;
- }
-
- void setInactive() {
- mActive = false;
- }
-
- Transform getTransform() {
- return mTransform;
- }
-
- void setTag(String tag) {
- mTag = tag;
- }
-}
diff --git a/Chapter25/java/GameObjectFactory.java b/Chapter25/java/GameObjectFactory.java
deleted file mode 100644
index 5b61e81..0000000
--- a/Chapter25/java/GameObjectFactory.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.content.Context;
-import android.graphics.PointF;
-
-import com.gamecodeschool.c25platformer.GOSpec.GameObjectSpec;
-
-class GameObjectFactory {
- private Context mContext;
- private GameEngine mGameEngineReference;
- private int mPixelsPerMetre;
-
- GameObjectFactory(Context context,
- GameEngine gameEngine,
- int pixelsPerMetre) {
-
- mContext = context;
- mGameEngineReference = gameEngine;
- mPixelsPerMetre = pixelsPerMetre;
- }
-
- GameObject create(GameObjectSpec spec, PointF location) {
- GameObject object = new GameObject();
-
- int mNumComponents = spec.getComponents().length;
- object.setTag(spec.getTag());
-
- // First give the game object the
- // right kind of transform
- switch(object.getTag()){
- case "Background":
- // Code coming soon
- object.setTransform(
- new BackgroundTransform(
- spec.getSpeed(),
- spec.getSize().x,
- spec.getSize().y,
- location));
- break;
-
- case "Player":
- // Code coming soon
- object.setTransform(
- new PlayerTransform(spec.getSpeed(),
- spec.getSize().x,
- spec.getSize().y,
- location));
- break;
-
- default:// normal transform
- object.setTransform(new Transform(
- spec.getSpeed(),
- spec.getSize().x,
- spec.getSize().y,
- location));
- break;
- }
-
-
- // Loop through and add/initialize all the components
- for (int i = 0; i < mNumComponents; i++) {
- switch (spec.getComponents()[i]) {
- case "PlayerInputComponent":
- // Code coming soon
- object.setPlayerInputTransform(
- new PlayerInputComponent(
- mGameEngineReference));
- break;
- case "AnimatedGraphicsComponent":
- // Code coming soon
- object.setGraphics(
- new AnimatedGraphicsComponent(),
- mContext, spec, spec.getSize(),
- mPixelsPerMetre);
- break;
- case "PlayerUpdateComponent":
- // Code coming soon
- object.setMovement(new PlayerUpdateComponent());
- break;
- case "InanimateBlockGraphicsComponent":
- object.setGraphics(new
- InanimateBlockGraphicsComponent(),
- mContext, spec, spec.getSize(),
- mPixelsPerMetre);
- break;
- case "InanimateBlockUpdateComponent":
- object.setMovement(new
- InanimateBlockUpdateComponent());
- break;
- case "MovableBlockUpdateComponent":
- // Code coming soon
- object.setMovement(new
- MovableBlockUpdateComponent());
- break;
- case "DecorativeBlockUpdateComponent":
- object.setMovement(new
- DecorativeBlockUpdateComponent());
- break;
- case "BackgroundGraphicsComponent":
- // Code coming soon
- object.setGraphics(
- new BackgroundGraphicsComponent(),
- mContext, spec, spec.getSize(),
- mPixelsPerMetre);
- break;
- case "BackgroundUpdateComponent":
- // Code coming soon
- object.setMovement(new BackgroundUpdateComponent());
- break;
-
- default:
- // Error unidentified component
- break;
- }
- }
-
- // Return the completed GameObject
- // to the LevelManager class
- return object;
- }
-}
diff --git a/Chapter25/java/GameState.java b/Chapter25/java/GameState.java
deleted file mode 100644
index 1c05b03..0000000
--- a/Chapter25/java/GameState.java
+++ /dev/null
@@ -1,185 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-
-final class GameState {
- private static volatile boolean
- mThreadRunning = false;
-
- private static volatile boolean mPaused = true;
- private static volatile boolean mGameOver = true;
- private static volatile boolean mDrawing = false;
- private EngineController engineController;
-
- private int mFastestUnderground;
- private int mFastestMountains;
- private int mFastestCity;
- private long startTimeInMillis;
-
- private int mCoinsAvailable;
- private int coinsCollected;
-
- private SharedPreferences.Editor editor;
-
- private String currentLevel;
-
- GameState(EngineController gs, Context context) {
- engineController = gs;
- SharedPreferences prefs = context
- .getSharedPreferences("HiScore",
- Context.MODE_PRIVATE);
-
- editor = prefs.edit();
- mFastestUnderground = prefs.getInt(
- "fastest_underground_time", 1000);
- mFastestMountains = prefs.getInt(
- "fastest_mountains_time", 1000);
- mFastestCity = prefs.getInt(
- "fastest_city_time", 1000);
- }
-
-
- void coinCollected() {
- coinsCollected++;
- }
-
- int getCoinsRemaining() {
- return mCoinsAvailable - coinsCollected;
- }
-
- void coinAddedToLevel() {
- mCoinsAvailable++;
- }
-
- void resetCoins() {
- mCoinsAvailable = 0;
- coinsCollected = 0;
- }
-
-
- void setCurrentLevel(String level) {
- currentLevel = level;
- }
-
- String getCurrentLevel() {
- return currentLevel;
- }
-
- void objectiveReached() {
- endGame();
- }
-
- int getFastestUnderground() {
- return mFastestUnderground;
- }
-
- int getFastestMountains() {
- return mFastestMountains;
- }
-
- int getFastestCity() {
- return mFastestCity;
- }
-
- void startNewGame() {
- // Don't want to be handling objects while
- // clearing ArrayList and filling it up again
- stopEverything();
- engineController.startNewLevel();
- startEverything();
- startTimeInMillis = System.currentTimeMillis();
- }
-
- int getCurrentTime() {
- long MILLIS_IN_SECOND = 1000;
- return (int) ((System.currentTimeMillis()
- - startTimeInMillis) / MILLIS_IN_SECOND);
- }
-
- void death() {
- stopEverything();
- SoundEngine.playPlayerBurn();
- }
-
- private void endGame() {
-
- stopEverything();
- int totalTime =
- ((mCoinsAvailable - coinsCollected)
- * 10)
- + getCurrentTime();
-
- switch (currentLevel) {
-
- case "underground":
- if (totalTime < mFastestUnderground) {
- mFastestUnderground = totalTime;
- // Save new time
-
- editor.putInt("fastest_underground_time",
- mFastestUnderground);
-
- editor.commit();
- }
- break;
- case "city":
- if (totalTime < mFastestCity) {
- mFastestCity = totalTime;
- // Save new time
- editor.putInt("fastest_city_time",
- mFastestCity);
-
- editor.commit();
- }
- break;
- case "mountains":
- if (totalTime < mFastestMountains) {
- mFastestMountains = totalTime;
- // Save new time
- editor.putInt("fastest_mountains_time",
- mFastestMountains);
-
- editor.commit();
- }
- break;
- }
- }
-
- void stopEverything() {// Except the thread
- mPaused = true;
- mGameOver = true;
- mDrawing = false;
- }
-
- private void startEverything() {
- mPaused = false;
- mGameOver = false;
- mDrawing = true;
- }
-
- void stopThread() {
- mThreadRunning = false;
- }
-
- boolean getThreadRunning() {
- return mThreadRunning;
- }
-
- void startThread() {
- mThreadRunning = true;
- }
-
- boolean getDrawing() {
- return mDrawing;
- }
-
- boolean getPaused() {
- return mPaused;
- }
-
- boolean getGameOver() {
- return mGameOver;
- }
-
-}
diff --git a/Chapter25/java/GraphicsComponent.java b/Chapter25/java/GraphicsComponent.java
deleted file mode 100644
index a4dd395..0000000
--- a/Chapter25/java/GraphicsComponent.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-
-import com.gamecodeschool.c25platformer.GOSpec.GameObjectSpec;
-
-interface GraphicsComponent {
-
- // Added int mPixelsPerMetre to
- // scale the bitmap to the camera
- void initialize(Context c, GameObjectSpec spec,
- PointF objectSize, int pixelsPerMetre);
-
- // Updated from the last project
- // to take a reference to a Camera
- void draw(Canvas canvas, Paint paint,
- Transform t, Camera cam);
-}
diff --git a/Chapter25/java/HUD.java b/Chapter25/java/HUD.java
deleted file mode 100644
index de9b6b2..0000000
--- a/Chapter25/java/HUD.java
+++ /dev/null
@@ -1,179 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.graphics.Rect;
-
-import java.util.ArrayList;
-
-class HUD {
- private Bitmap mMenuBitmap;
-
- private int mTextFormatting;
- private int mScreenHeight;
- private int mScreenWidth;
- final float ONE_THIRD = .33f;
- final float TWO_THIRDS = .66f;
-
- private ArrayList mControls;
-
- static int LEFT = 0;
- static int RIGHT = 1;
- static int JUMP = 2;
-
- HUD(Context context, Point size){
- mScreenHeight = size.y;
- mScreenWidth = size.x;
- mTextFormatting = size.x / 25;
-
- prepareControls();
-
- // Create and scale the bitmaps
- mMenuBitmap = BitmapFactory
- .decodeResource(context.getResources(),
- R.drawable.menu);
-
- mMenuBitmap = Bitmap
- .createScaledBitmap(mMenuBitmap,
- size.x, size.y, false);
-
- }
-
- private void prepareControls(){
- int buttonWidth = mScreenWidth / 14;
- int buttonHeight = mScreenHeight / 12;
- int buttonPadding = mScreenWidth / 90;
-
-
- Rect left = new Rect(
- buttonPadding,
- mScreenHeight - buttonHeight - buttonPadding,
- buttonWidth + buttonPadding,
- mScreenHeight - buttonPadding);
-
- Rect right = new Rect(
- (buttonPadding * 2) + buttonWidth,
- mScreenHeight - buttonHeight - buttonPadding,
- (buttonPadding * 2) + (buttonWidth * 2),
- mScreenHeight - buttonPadding);
-
- Rect jump = new Rect(mScreenWidth - buttonPadding - buttonWidth,
- mScreenHeight - buttonHeight - buttonPadding,
- mScreenWidth - buttonPadding,
- mScreenHeight - buttonPadding);
-
-
- mControls = new ArrayList<>();
- mControls.add(LEFT,left);
- mControls.add(RIGHT,right);
- mControls.add(JUMP, jump);
- }
-
- void draw(Canvas c, Paint p, GameState gs){
-
- if(gs.getGameOver()){
-
- // Draw the mMenuBitmap screen
- c.drawBitmap(mMenuBitmap, 0,0, p);
-
- // draw a rectangle to highlight the text
- p.setColor(Color.argb (100, 26, 128, 182));
- c.drawRect(0,0, mScreenWidth,
- mTextFormatting * 4, p);
-
- // Draw the level names
- p.setColor(Color.argb(255, 255, 255, 255));
- p.setTextSize(mTextFormatting);
- c.drawText("Underground",
- mTextFormatting,
- mTextFormatting * 2,
- p);
-
- c.drawText("Mountains",
- mScreenWidth * ONE_THIRD + (mTextFormatting),
- mTextFormatting * 2,
- p);
-
- c.drawText("City",
- mScreenWidth * TWO_THIRDS + (mTextFormatting),
- mTextFormatting * 2,
- p);
-
- // Draw the fastest times
- p.setTextSize(mTextFormatting/1.8f);
-
- c.drawText("BEST:" + gs.getFastestUnderground()
- +" seconds",
- mTextFormatting,
- mTextFormatting*3,
- p);
-
- c.drawText("BEST:" + gs.getFastestMountains()
- +" seconds", mScreenWidth * ONE_THIRD
- + mTextFormatting,
- mTextFormatting * 3,
- p);
-
- c.drawText("BEST:" + gs.getFastestCity()
- + " seconds",
- mScreenWidth * TWO_THIRDS + mTextFormatting,
- mTextFormatting * 3,
- p);
-
- // draw a rectangle to highlight the large text
- p.setColor(Color.argb (100, 26, 128, 182));
- c.drawRect(0,mScreenHeight - mTextFormatting * 2,
- mScreenWidth,
- mScreenHeight,
- p);
-
- p.setColor(Color.argb(255, 255, 255, 255));
- p.setTextSize(mTextFormatting * 1.5f);
- c.drawText("DOUBLE TAP A LEVEL TO PLAY",
- ONE_THIRD + mTextFormatting * 2,
- mScreenHeight - mTextFormatting/2,
- p);
- }
- else {
- // draw a rectangle to highlight the text
- p.setColor(Color.argb (100, 0, 0, 0));
- c.drawRect(0,0, mScreenWidth,
- mTextFormatting,
- p);
-
- // Draw the HUD text
- p.setTextSize(mTextFormatting/1.5f);
- p.setColor(Color.argb(255, 255, 255, 255));
- c.drawText("Time:" + gs.getCurrentTime()
- + "+" + gs.getCoinsRemaining() * 10,
- mTextFormatting / 4,
- mTextFormatting / 1.5f,
- p);
-
-
- drawControls(c, p);
- }
-
- }
-
- private void drawControls(Canvas c, Paint p){
- p.setColor(Color.argb(100,255,255,255));
-
- for(Rect r : mControls){
- c.drawRect(r.left, r.top, r.right, r.bottom, p);
- }
-
- // Set the colors back
- p.setColor(Color.argb(255,255,255,255));
- }
-
-
- ArrayList getControls(){
- return mControls;
- }
-}
diff --git a/Chapter25/java/InanimateBlockGraphicsComponent.java b/Chapter25/java/InanimateBlockGraphicsComponent.java
deleted file mode 100644
index 9377830..0000000
--- a/Chapter25/java/InanimateBlockGraphicsComponent.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PointF;
-import android.graphics.Rect;
-
-import com.gamecodeschool.c25platformer.GOSpec.GameObjectSpec;
-
-class InanimateBlockGraphicsComponent implements GraphicsComponent {
-
- private String mBitmapName;
-
- @Override
- public void initialize(Context context,
- GameObjectSpec spec,
- PointF objectSize,
- int pixelsPerMetre) {
-
- mBitmapName = spec.getBitmapName();
-
- BitmapStore.addBitmap(context,
- mBitmapName, objectSize,
- pixelsPerMetre,
- false);
-
- }
-
-
- @Override
- public void draw(Canvas canvas,
- Paint paint,
- Transform t,
- Camera cam) {
-
- Bitmap bitmap = BitmapStore.getBitmap(mBitmapName);
- // Use the camera to translate the real world
- // coordinates relative to the player-
- // into screen coordinates
- Rect screenCoordinates = cam.worldToScreen(
- t.getLocation().x,
- t.getLocation().y,
- t.getSize().x,
- t.getSize().y);
-
-
- canvas.drawBitmap(
- bitmap,
- screenCoordinates.left,
- screenCoordinates.top,
- paint);
-
-
- }
-}
diff --git a/Chapter25/java/InanimateBlockUpdateComponent.java b/Chapter25/java/InanimateBlockUpdateComponent.java
deleted file mode 100644
index 354965c..0000000
--- a/Chapter25/java/InanimateBlockUpdateComponent.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-class InanimateBlockUpdateComponent implements UpdateComponent {
-
- private boolean mColliderNotSet = true;
-
- @Override
- public void update(long fps,
- Transform t,
- Transform playerTransform) {
-
- // An alternative would be to update
- // the collider just once when it spawns.
- // But this would require spawn components
- // - More code but a bit faster
- if(mColliderNotSet) {
- // Only need to set the collider
- // once because it will never move
- t.updateCollider();
- mColliderNotSet = false;
- }
- }
-}
diff --git a/Chapter25/java/InputObserver.java b/Chapter25/java/InputObserver.java
deleted file mode 100644
index 79fd8ed..0000000
--- a/Chapter25/java/InputObserver.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-public interface InputObserver {
-
- // This allows InputObservers to be called by GameEngine to handle input
- void handleInput(MotionEvent event, GameState gs, ArrayList buttons);
-}
diff --git a/Chapter25/java/LevelManager.java b/Chapter25/java/LevelManager.java
deleted file mode 100644
index 3eab0ca..0000000
--- a/Chapter25/java/LevelManager.java
+++ /dev/null
@@ -1,243 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.content.Context;
-import android.graphics.PointF;
-import android.util.Log;
-
-import com.gamecodeschool.c25platformer.GOSpec.*;
-import com.gamecodeschool.c25platformer.Levels.*;
-
-import java.util.ArrayList;
-
-final class LevelManager {
-
- static int PLAYER_INDEX = 0;
- private ArrayList objects;
- private Level currentLevel;
- private GameObjectFactory factory;
-
- LevelManager(Context context,
- GameEngine ge,
- int pixelsPerMetre){
-
- objects = new ArrayList<>();
- factory = new GameObjectFactory(context,
- ge,
- pixelsPerMetre);
- }
-
- void setCurrentLevel(String level){
- switch (level) {
- case "underground":
- currentLevel = new LevelUnderground();
- break;
-
- case "city":
- currentLevel = new LevelCity();
- break;
-
- case "mountains":
- currentLevel = new LevelMountains();
- break;
- }
- }
-
- void buildGameObjects(GameState gs){
- // Backgrounds 1, 2, 3(City, Underground, Mountain...)
- // p = Player
- // g = Grass tile
- // o = Objective
- // m = Movable platform
- // b = Brick tile
- // c = mine Cart
- // s = Stone pile
- // l = coaL
- // n = coNcrete
- // a = lAmpost
- // r = scoRched tile
- // w = snoW tile
- // t = stalacTite
- // i = stalagmIte
- // d = Dead tree
- // e = snowy trEe
- // x = Collectable
- // z = Fire
- // y = invisible death_invisible
-
- gs.resetCoins();
- objects.clear();
- ArrayList levelToLoad = currentLevel.getTiles();
-
- for(int row = 0; row < levelToLoad.size(); row++ )
- {
- for(int column = 0;
- column < levelToLoad.get(row).length();
- column++){
-
- PointF coords = new PointF(column, row);
-
- switch (levelToLoad.get(row)
- .charAt(column)){
-
- case '1':
- objects.add(factory.create(
- new BackgroundCitySpec(),
- coords));
- break;
-
- case '2':
- objects.add(factory.create(
- new BackgroundUndergroundSpec(),
- coords));
- break;
-
- case '3':
- objects.add(factory.create(
- new BackgroundMountainSpec(),
- coords));
- break;
-
- case 'p':
- objects.add(factory.create(new
- PlayerSpec(),
- coords));
- // Remember the location of
- // the player
- PLAYER_INDEX = objects.size()-1;
- break;
-
- case 'g':
- objects.add(factory.create(
- new GrassTileSpec(),
- coords));
- break;
-
- case 'o':
- objects.add(factory.create(
- new ObjectiveTileSpec(),
- coords));
- break;
-
- case 'm':
- objects.add(factory.create(
- new MoveablePlatformSpec(),
- coords));
- break;
-
- case 'b':
- objects.add(factory.create(
- new BrickTileSpec(),
- coords));
- break;
-
- case 'c':
- objects.add(factory.create(
- new CartTileSpec(),
- coords));
- break;
-
- case 's':
- objects.add(factory.create(
- new StonePileTileSpec(),
- coords));
- break;
-
- case 'l':
- objects.add(factory.create(
- new CoalTileSpec(),
- coords));
- break;
-
- case 'n':
- objects.add(factory.create(
- new ConcreteTileSpec(),
- coords));
- break;
-
- case 'a':
- objects.add(factory.create(
- new LamppostTileSpec(),
- coords));
- break;
-
- case 'r':
- objects.add(factory.create(
- new ScorchedTileSpec(),
- coords));
- break;
-
- case 'w':
- objects.add(factory.create(
- new SnowTileSpec(),
- coords));
- break;
-
- case 't':
- objects.add(factory.create(
- new StalactiteTileSpec(),
- coords));
- break;
-
- case 'i':
- objects.add(factory.create(
- new StalagmiteTileSpec(),
- coords));
- break;
-
- case 'd':
- objects.add(factory.create(
- new DeadTreeTileSpec(),
- coords));
- break;
-
- case 'e':
- objects.add(factory.create(
- new SnowyTreeTileSpec(),
- coords));
- break;
-
- case 'x':
- objects.add(factory.create(
- new CollectibleObjectSpec(),
- coords));
- gs.coinAddedToLevel();
- break;
-
- case 'z':
- objects.add(factory.create(
- new FireTileSpec(),
- coords));
-
- break;
-
- case 'y':
- objects.add(factory.create(
- new InvisibleDeathTenByTenSpec(),
- coords));
-
- break;
-
-
- case '.':
- // Nothing to see here
- break;
-
- default:
- Log.e("Unhandled item in level",
- "row:"+row
- + " column:"+column);
- break;
- }
-
- }
-
- }
-
- }
-
- ArrayList getGameObjects(){
- return objects;
- }
-
-
-}
diff --git a/Chapter25/java/Levels/Level.java b/Chapter25/java/Levels/Level.java
deleted file mode 100644
index 8730b46..0000000
--- a/Chapter25/java/Levels/Level.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.gamecodeschool.c25platformer.Levels;
-
-import java.util.ArrayList;
-
-public abstract class Level {
- // If you want to build a new level then extend this class
- ArrayList tiles;
- public ArrayList getTiles(){
- return tiles;
- }
-}
diff --git a/Chapter25/java/Levels/LevelCity.java b/Chapter25/java/Levels/LevelCity.java
deleted file mode 100644
index e45a631..0000000
--- a/Chapter25/java/Levels/LevelCity.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.gamecodeschool.c25platformer.Levels;
-
-import java.util.ArrayList;
-
-public final class LevelCity extends Level {
- public LevelCity() {
- tiles = new ArrayList();
- tiles.add("1........................................................................................................................................................................................................................................................");
- tiles.add(".........................................................................................................................................................................................................................................................");
- tiles.add(".........................................................................................................................................................................................................................................................");
- tiles.add("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");
- tiles.add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx......................n..........................................................................");
- tiles.add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx......................n..........................................................................");
- tiles.add("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx......................n..........................................................................");
- tiles.add("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnm.nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");
- tiles.add("b.x..................................................................................nxxxxx............................................................................................................a.........................a.......................");
- tiles.add("bxxx.................................................................................nxxxxx.......................................................................................................................................................o......");
- tiles.add("bbbbbb...............................................................................nxxxxx..............................................................................................................................................................");
- tiles.add("b......b.............................................................................nnnnnnnnnnnm........................................................................................................................................................");
- tiles.add("b.......b............................................................................n..........x...................................................................................ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg");
- tiles.add("b........b...........................................................................n..........x...................................................................................n....................................................................");
- tiles.add("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbm...nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnm.............n..........x...................................................................................n....................................................................");
- tiles.add("b....................................................................................n..........x...................................................................................nxxxxxxxx............................................................");
- tiles.add("b....................................................................................n..........x...................................................................................nxxxxxxxx............................................................");
- tiles.add("b....................................................................................n..........x...................................................................................nxxxxxxxx............................................................");
- tiles.add("b.................................................................................x..n..........x......................................................................nnnnnn.......n.nnnnnnnn...........................................................");
- tiles.add("bx...............................................................................xxx.n...........................................................m...m...m...m..nnnnnnn.............n........nnnnnnnn....................................................");
- tiles.add("bx.............................................................................bbbbbbn.........................................................m....................................n..............nnnnnnn...............................................");
- tiles.add("bx...............................a.............................a..............b......n.......................................................m......................................n....................nnnnn...........................................");
- tiles.add("bnnn.........................................................................b.......nnnnnnnnnnnnnnnnnnnnnnnm.............................m.........................................n........................nnnn........................................");
- tiles.add("b...................x.......................................................b.......................................................................................................n...........................nnnn.....................................");
- tiles.add("b......b...........xxx.....................................x..x..x..x......b........................................................................................................n..............................nnnnnn...nnnnnnnnnnnnnnnnnnnnnnnnnmx..");
- tiles.add("b......b..m.....bbbbbbbbbbbnnnnnnnnnnnnnnnnnnnnnnm...nnnnnnnnnnnnnnnnnnb............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b............................................b............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b............................................b............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b...........................................xb............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b...........................................xb.....................a......................................a...............................................n.................................................................x..");
- tiles.add("b......b..................b...........................................xb............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b............................................b............................................................................................................n.................................................................x..");
- tiles.add("b......b..................b..........................................m.b.........................................................................nnnnnnnn...........................n.................................................................x..");
- tiles.add("bx.....b..................b............................................b.......m.nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn.......nbbbbbbbbbbbbbbbb..........n..........................................................a.........");
- tiles.add("bx......................x.b...................................m........b.........b........................................................................b...............m.........n...................................................................n");
- tiles.add("bx.....................xxxb............................................b.........b........................................................................b.........................n..................................................................n.");
- tiles.add("bbm....bbbb.bbbbbbbbbbbbbbb.......................b.b..................b.........b.xxxxxxxx...................................bbbbbbbbbbbbbbbbbbbbbbbb..m.b.........................n.........x..m...x................................................n..");
- tiles.add("b......b..................b......................bbbbb......x..........b.........b.xxxxxxxx...............................bbbb............................b.........................n.......x..........x......................................nnnnnnnnnnn");
- tiles.add("b......b..x...........x...b.....................bbbbbbb....xxx.........b.........bbbbbbbbbbb...bbbbb....bbbbbbb....bbbbb..................................b.........................n.......x..........x.....................................n...........");
- tiles.add("b......bbbbbbbb.....bbbbb.b.............bbbbbbbbbbbbbbbbbbbbbb.........b..................................................................................b.........................n.......x..........x....................................n............");
- tiles.add("b......b..................b.............b....................b.........b..................................................................................b.....bbbbbbbb............n.......x..........x...................................n.............");
- tiles.add("b......b................................b....................b.........b..................................................................................bxxx......................n.......x..........x..................................n..............");
- tiles.add("b......b...............x................b....................b.........b..................................................................................bxxx......................n.......x..........x.................................n...............");
- tiles.add("b......b..x...........bbbbb.............b....................b.........b...............d...d...d...d.d.d...d...d..........................................bbbbb.....................n.......x..........x................................n................");
- tiles.add("b......b.xxx.........b....b.............b....................b..............nnnn.........................................................x.........x......b.........................n..................................................n.................");
- tiles.add("b...p..bxxxxx.......b.....b......................x.........................nnnnnn.......................................................xxx.......xxx.....b...........................................................................n..................");
- tiles.add("b......bnnnnnnnnnnnnnnnnnnb.....................xxx.......................nnnnnnnn......s........s.......s.........s....s..............xxxxx.....xxxxx....b..........................................................................n...................");
- tiles.add("ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg");
-
-
- }
-}
diff --git a/Chapter25/java/Levels/LevelMountains.java b/Chapter25/java/Levels/LevelMountains.java
deleted file mode 100644
index c9489a2..0000000
--- a/Chapter25/java/Levels/LevelMountains.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.gamecodeschool.c25platformer.Levels;
-
-import java.util.ArrayList;
-
-public final class LevelMountains extends Level {
- public LevelMountains() {
-
- tiles = new ArrayList();
- tiles.add("3.........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("..........................");
- tiles.add("............................................................x.....e................................................................................................");
- tiles.add("...........................................................xxx.....................................................................................................");
- tiles.add(".........................................................xxxxxxx...................................................................................................");
- tiles.add("...............................................................................................................xxx.................................................");
- tiles.add(".........................................................xxxxxxx...............................................xxx.................................................");
- tiles.add("............................................................................................m.............w....www.................................................");
- tiles.add("........................................................wwwwwwwwwwww..................................x...................x........................................");
- tiles.add("..........................................................................m...........................w...................g......................x.................");
- tiles.add("...............................................................................................................................x.................x..............o..");
- tiles.add("................................................................................................x..............................x.................m.................");
- tiles.add("................................................................................................x..............................x.................x....gggg.........");
- tiles.add("................................................................................................w..............................g.................x.........gggggggg");
- tiles.add(".....................................................................................................................................x...........x.................");
- tiles.add("............................................................................................x.....e..................................x...........x.................");
- tiles.add("........................................e...................................................x........................................g...........x.................");
- tiles.add("............................................................................................w....................................................x.................");
- tiles.add("........................................................................................................................................x........x.................");
- tiles.add(".......................................................................................x................................................x........x.................");
- tiles.add(".........p...........................s........xxx.......................s..............w................................................g........x.................");
- tiles.add(".x..........................wwwwwwwwwwwwwwwwwwwwwwwwwwww..ggggggg...ggggggggggg.....ggggggg....ggggg..........................................x..x.................");
- tiles.add("www.....www...ww....w...w.....................................................................................................................g....................");
- tiles.add("y....y.....y.....y...y........y.....y......y......y.....y....y......y.....y....y......y.....y....y......y....y....y....y.....y....y....y...y....y......y......y....y.....y......y.....y");
-
-
- }
-}
diff --git a/Chapter25/java/Levels/LevelUnderground.java b/Chapter25/java/Levels/LevelUnderground.java
deleted file mode 100644
index ce683a3..0000000
--- a/Chapter25/java/Levels/LevelUnderground.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.gamecodeschool.c25platformer.Levels;
-
-import java.util.ArrayList;
-
-public final class LevelUnderground extends Level {
- public LevelUnderground() {
- tiles = new ArrayList();
- tiles.add("2......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...........x...........................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...........m............m..............................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...................x...................t........................x......................................................................");
- tiles.add("................lzzl............................................ll.....................................................................");
- tiles.add("................lzzl............................................................x.......x..........................o...................");
- tiles.add(".x..............lzzl........................................m....................................x....x................................");
- tiles.add("llllllllllllllllllllllllllll...lll.....llllllllllll...l.................lllllllllllllll...lllllllllllll.....llllllllll.................");
- tiles.add("................................................................ll.....................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("................................................x......ll..............................................................................");
- tiles.add(".........................................x......ll.....................................................................................");
- tiles.add(".........................................ll............................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("..............................x.............xx.........................................................................................");
- tiles.add(".p..........................x...x..........x..x..................................................x.....................................");
- tiles.add("........x.................x.......x......x......x................x.......................x......c..........s...........xxxxxxxxx.......");
- tiles.add("llllllllllllllllllll...lllllllllllllllllll...lllllll...llllllllllllllllll......lllllllllllllllllllllllllllllll........lllllllll........");
- tiles.add("..................................................i..............................................................m.....................");
- tiles.add(".......................................................................................................................................");
- tiles.add("...x...................................................................................................................................");
- tiles.add(".........................................x......ll.....................................................................................");
- tiles.add(".........................................ll............................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("..............................x.............xx.........................................................................................");
- tiles.add("............................x...x..........x..x.....................................................................................x..");
- tiles.add("........x.................x.......x......x......x................x.......................x......c..........s...........xxxxxxxxx.......");
- tiles.add("llllllllllllllllllllzzzlllllzzzzzlllllllll...lllllll...llllllllllllllllll......lllllllllllllllllllllllllllllll........lllllllll........");
- tiles.add("..................................................i....................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add(".......................................................................................................................................");
- tiles.add("....y......y.......y......y.......y....y......y.......y........y........y........y.........y.........y.........y......y.....y........y.");
-
- }
-}
diff --git a/Chapter25/java/MovableBlockUpdateComponent.java b/Chapter25/java/MovableBlockUpdateComponent.java
deleted file mode 100644
index dfa8ea4..0000000
--- a/Chapter25/java/MovableBlockUpdateComponent.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.graphics.PointF;
-
-class MovableBlockUpdateComponent implements UpdateComponent {
-
- @Override
- public void update(long fps,
- Transform t,
- Transform playerTransform) {
-
- PointF location = t.getLocation();
- if (t.headingUp()) {
- location.y -= t.getSpeed() / fps;
- } else if (t.headingDown()) {
- location.y += t.getSpeed() / fps;
- } else {
- // Must be first update of the game
- // so start with going down
- t.headDown();
- }
-
- // Check if the platform needs
- // to change direction
- if (t.headingUp() && location.y <=
- t.getStartingPosition().y) {
- // Back at the start
- t.headDown();
- } else if (t.headingDown() && location.y >=
- (t.getStartingPosition().y
- + t.getSize().y * 10)) {
- // Moved ten times the height downwards
- t.headUp();
- }
-
- // Update the colliders with the new position
- t.updateCollider();
- }
-}
diff --git a/Chapter25/java/PhysicsEngine.java b/Chapter25/java/PhysicsEngine.java
deleted file mode 100644
index 76b51fc..0000000
--- a/Chapter25/java/PhysicsEngine.java
+++ /dev/null
@@ -1,163 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.graphics.PointF;
-import android.graphics.RectF;
-
-import java.util.ArrayList;
-
-class PhysicsEngine {
-
- void update(long fps, ArrayList objects, GameState gs) {
- for (GameObject object : objects) {
- object.update(fps,
- objects.get(LevelManager.PLAYER_INDEX)
- .getTransform());
- }
-
- detectCollisions(gs, objects);
- }
-
- private void detectCollisions(GameState gs,
- ArrayList objects) {
- // More code here soon
- boolean collisionOccurred = false;
-
- // Something collides with some part of
- // the player most frames
- // so lets make some handy references
- // Get a reference to the players position
- // as we will probably need to update it
- Transform playersTransform =
- objects.get(LevelManager.PLAYER_INDEX)
- .getTransform();
-
- PlayerTransform playersPlayerTransform =
- (PlayerTransform) playersTransform;
-
- // Get the players extra colliders
- // from the cast object
- ArrayList playerColliders =
- playersPlayerTransform.getColliders();
-
- PointF playersLocation =
- playersTransform.getLocation();
-
- for (GameObject go : objects) {
- // Just need to check player collisions
- // with everything else
- if (go.checkActive()) {
- // Object is active so check for collision
- // with player - anywhere at all
- if (RectF.intersects(go.getTransform()
- .getCollider(),
- playersTransform.getCollider())) {
-
- // A collision of some kind has occurred
- // so lets dig a little deeper
- collisionOccurred = true;
- // Get a reference to the current (being tested)
- // object's transform and location
- Transform testedTransform = go.getTransform();
- PointF testedLocation = testedTransform.getLocation();
- // Don't check the player against itself
- if (objects.indexOf(go) != LevelManager.PLAYER_INDEX) {
- // Where was the player hit?
- for (int i = 0; i < playerColliders.size(); i++) {
- if (RectF.intersects(testedTransform.getCollider(),
- playerColliders.get(i))) {
-
- // React to the collision based on the
- // body part and object type
- switch (go.getTag() + " with " + "" + i) {
- // Test feet first to avoid the
- // player sinking in to a tile
- // and unnecessarily triggering
- // right and left as well
- case "Movable Platform with 0":// Feet
- playersPlayerTransform.grounded();
- playersLocation.y =
- (testedTransform.getLocation().y)
- - (playersTransform.getSize().y);
- break;
-
- case "Death with 0":// Feet
- gs.death();
- break;
-
- case "Inert Tile with 0":// Feet
- playersPlayerTransform.grounded();
- playersLocation.y =
- (testedTransform.getLocation().y)
- - (playersTransform.getSize().y);
- break;
-
- case "Inert Tile with 1":// Head
- // Just update the player to a suitable height
- // but allow any jumps to continue
- playersLocation.y = testedLocation.y
- + testedTransform.getSize().y;
-
- playersPlayerTransform.triggerBumpedHead();
- break;
-
- case "Collectible with 2":// Right
- SoundEngine.playCoinPickup();
- // Switch off coin
- go.setInactive();
- // Tell the game state a coin has been found
- gs.coinCollected();
- break;
-
- case "Inert Tile with 2":// Right
- // Stop the player moving right
- playersTransform.stopMovingRight();
- // Move the player to the left of the tile
- playersLocation.x = (testedTransform
- .getLocation().x)
- - playersTransform.getSize().x;
- break;
-
- case "Collectible with 3":// Left
- SoundEngine.playCoinPickup();
- // Switch off coin
- go.setInactive();
- // Tell the game state a coin has been found
- gs.coinCollected();
- break;
-
- case "Inert Tile with 3":// Left
- playersTransform.stopMovingLeft();
- // Move the player to the right of the tile
- playersLocation.x =
- testedLocation.x
- + testedTransform.getSize().x;
- break;
-
- // Handle the player's feet reaching
- // the objective tile
- case "Objective Tile with 0":
- SoundEngine.playReachObjective();
- gs.objectiveReached();
- break;
-
- default:
-
- break;
- }
- }
-
- }
- }
- }
-
- }
-
- }
-
- if (!collisionOccurred) {
- // No connection with main player collider so not grounded
- playersPlayerTransform.notGrounded();
-
- }
- }
-}
diff --git a/Chapter25/java/PlayerInputComponent.java b/Chapter25/java/PlayerInputComponent.java
deleted file mode 100644
index 6be433e..0000000
--- a/Chapter25/java/PlayerInputComponent.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-class PlayerInputComponent implements InputObserver {
-
- private Transform mPlayersTransform;
- private PlayerTransform mPlayersPlayerTransform;
-
- PlayerInputComponent(GameEngine ger) {
- ger.addObserver(this);
- }
-
- public void setTransform(Transform transform) {
- mPlayersTransform = transform;
- mPlayersPlayerTransform =
- (PlayerTransform) mPlayersTransform;
- }
-
- // Required method of InputObserver interface
- // called from the onTouchEvent method
- public void handleInput(MotionEvent event,
- GameState gameState,
- ArrayList buttons) {
-
- int i = event.getActionIndex();
- int x = (int) event.getX(i);
- int y = (int) event.getY(i);
-
- if(!gameState.getPaused()) {
- switch (event.getAction() & MotionEvent.ACTION_MASK) {
-
- case MotionEvent.ACTION_UP:
- if (buttons.get(HUD.LEFT).contains(x, y)
- || buttons.get(HUD.RIGHT)
- .contains(x, y)) {
- // Player has released either left or right
- mPlayersTransform.stopHorizontal();
- }
- break;
-
- case MotionEvent.ACTION_DOWN:
- if (buttons.get(HUD.LEFT).contains(x, y)) {
- // Player has pressed left
- mPlayersTransform.headLeft();
- } else if (buttons.get(HUD.RIGHT).contains(x, y)) {
- // Player has pressed right
- mPlayersTransform.headRight();
- } else if (buttons.get(HUD.JUMP).contains(x, y)) {
- // Player has released the jump button
- mPlayersPlayerTransform.triggerJump();
- }
- break;
-
- case MotionEvent.ACTION_POINTER_UP:
- if (buttons.get(HUD.LEFT).contains(x, y)
- || buttons.get(HUD.RIGHT).contains(x, y)) {
- // Player has released either up or down
- mPlayersTransform.stopHorizontal();
- }
- break;
-
- case MotionEvent.ACTION_POINTER_DOWN:
- if (buttons.get(HUD.LEFT).contains(x, y)) {
- // Player has pressed left
- mPlayersTransform.headLeft();
- } else if (buttons.get(HUD.RIGHT).contains(x, y)) {
- // Player has pressed right
- mPlayersTransform.headRight();
- } else if (buttons.get(HUD.JUMP).contains(x, y)) {
- // Player has released the jump button
- mPlayersPlayerTransform.triggerJump();
- }
- break;
- }
- }
- }
-}
diff --git a/Chapter25/java/PlayerTransform.java b/Chapter25/java/PlayerTransform.java
deleted file mode 100644
index 350761e..0000000
--- a/Chapter25/java/PlayerTransform.java
+++ /dev/null
@@ -1,157 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.graphics.PointF;
-import android.graphics.RectF;
-
-import java.util.ArrayList;
-
-class PlayerTransform extends Transform {
-
- private ArrayList mColliders;
-
- private final float TENTH = .1f;
- private final float HALF = .5f;
- private final float THIRD = .3f;
- private final float FIFTH = .2f;
- private final float FEET_PROTRUSION = 1.2f;
-
- private RectF mHeadRectF = new RectF();
- private RectF mRightRectF = new RectF();
- private RectF mFeetRectF = new RectF();
- private RectF mLeftRectF = new RectF();
-
- private boolean mJumpTriggered = false;
- private boolean mBumpedHeadTriggered = false;
-
- private boolean mGrounded;
-
- PlayerTransform(float speed,
- float objectWidth,
- float objectHeight,
- PointF startingLocation) {
-
- super(speed, objectWidth,
- objectHeight,
- startingLocation);
-
- mColliders = new ArrayList();
- // Load up the colliders ArrayList with
- // player specific colliders
- mColliders.add(mFeetRectF);
- mColliders.add(mHeadRectF);
- mColliders.add(mRightRectF);
- mColliders.add(mLeftRectF);
- }
-
- public ArrayList getColliders(){
- updateColliders();
- return mColliders;
- }
-
- public void updateColliders(){
-
- PointF location = getLocation();
- float objectHeight = getSize().y;
- float objectWidth = getSize().x;
-
- // Feet
- mColliders.get(0).left = location.x
- + (objectWidth * THIRD);
-
- mColliders.get(0).top = location.y
- + objectHeight - (objectHeight
- * TENTH);
-
- mColliders.get(0).right = location.x
- + objectWidth - (objectWidth
- * THIRD);
-
- mColliders.get(0).bottom = location.y
- + objectHeight + (objectHeight
- * FEET_PROTRUSION);
-
- // Head
- mColliders.get(1).left = location.x
- + ((objectWidth * THIRD));
-
- mColliders.get(1).top = location.y;
- mColliders.get(1).right = location.x
- +objectWidth - (objectWidth
- * THIRD);
-
- mColliders.get(1).bottom = location.y
- + (objectHeight * TENTH);
-
- // Right
- mColliders.get(2).left = location.x
- + objectWidth - (objectWidth
- * TENTH);
-
- mColliders.get(2).top = location.y
- + (objectHeight * THIRD);
- mColliders.get(2).right = location.x
- + objectWidth;
-
- mColliders.get(2).bottom = location.y
- + (objectHeight - (objectHeight
- * HALF));
-
- // Left
- mColliders.get(3).left = location.x;
- mColliders.get(3).top = location.y
- + (objectHeight * FIFTH);
- mColliders.get(3).right = location.x
- + (objectWidth * TENTH);
-
- mColliders.get(3).bottom = location.y
- + (objectHeight - (objectHeight
- * FIFTH));
- }
-
- // Called by handle input component to
- // let us know a jump has been triggered
- void triggerJump() {
- mJumpTriggered = true;
- }
-
- // Called by movement component to let transform
- // know that movement component is aware
- // jump was triggered
- void handlingJump() {
- mJumpTriggered = false;
- }
-
- // Used by movement component to find
- // out if jump has been triggered
- boolean jumpTriggered() {
- return mJumpTriggered;
- }
-
- void setNotGrounded(){
- mGrounded=false;
- }
-
- void triggerBumpedHead() {
- mBumpedHeadTriggered = true;
- }
-
- void handlingBumpedHead() {
- mBumpedHeadTriggered = false;
- }
-
- boolean bumpedHead() {
- return mBumpedHeadTriggered;
- }
-
- void notGrounded() {
- mGrounded = false;
- }
-
- void grounded() {
- mGrounded = true;
- }
-
- boolean isGrounded() {
- return mGrounded;
- }
-}
diff --git a/Chapter25/java/PlayerUpdateComponent.java b/Chapter25/java/PlayerUpdateComponent.java
deleted file mode 100644
index cd5ce8e..0000000
--- a/Chapter25/java/PlayerUpdateComponent.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.graphics.PointF;
-
-class PlayerUpdateComponent implements UpdateComponent {
-
- private boolean mIsJumping = false;
- private long mJumpStartTime;
-
- // How long a jump lasts
- // Further subdivided into up time and down time, later
- private final long MAX_JUMP_TIME = 400;
- private final float GRAVITY = 6;
-
- public void update(long fps,
- Transform t,
- Transform playerTransform) {
-
- // cast to player transform
- PlayerTransform pt = (PlayerTransform) t;
-
- // Where is the player?
- PointF location = t.getLocation();
- // How fast is it going
- float speed = t.getSpeed();
-
- if (t.headingLeft()) {
- location.x -= speed / fps;
- } else if (t.headingRight()) {
- location.x += speed / fps;
- }
-
- // Has the player bumped there head
- if (pt.bumpedHead()) {
- mIsJumping = false;
- pt.handlingBumpedHead();
- }
-
- // Check if jump was triggered by player
- // and if player
- // is NOT ALREADY jumping or falling
- // Don't want jumping in mid air
- // If you want double jump (or triple etc.)
- // allow the jump when not grounded,
- // and count the number of non-grounded
- // jumps and disallow jump when
- // your preferred limit is reached
- if (pt.jumpTriggered()
- && !mIsJumping
- && pt.isGrounded()) {
-
- SoundEngine.playJump();
- mIsJumping = true;
- pt.handlingJump();
- // Thanks for the notification
- // I'll take it from here
- mJumpStartTime = System.currentTimeMillis();
- }
-
- // Gravity
- if (!mIsJumping) {
- // Player is not jumping apply GRAVITY
- location.y += GRAVITY / fps;
- } else if (mIsJumping) {
- // Player is jumping
- pt.setNotGrounded();
-
- // Still in upward (first part) phase of the jump
- if (System.currentTimeMillis()
- < mJumpStartTime + (MAX_JUMP_TIME / 1.5)) {
- // keep going up
- location.y -= (GRAVITY * 1.8) / fps;
- }
- // In second (downward) phase of jump
- else if (System.currentTimeMillis()
- < mJumpStartTime + MAX_JUMP_TIME) {
- // Come back down
- location.y += (GRAVITY) / fps;
- }
- // Has the jump ended
- else if (System.currentTimeMillis()
- > mJumpStartTime + MAX_JUMP_TIME) {
-
- // Time to end the jump
- mIsJumping = false;
- }
- }
-
- // Let the colliders know the new position
- t.updateCollider();
- }
-}
diff --git a/Chapter25/java/Renderer.java b/Chapter25/java/Renderer.java
deleted file mode 100644
index 6d69b7e..0000000
--- a/Chapter25/java/Renderer.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Point;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-
-import java.util.ArrayList;
-
-class Renderer {
- private Canvas mCanvas;
- private SurfaceHolder mSurfaceHolder;
- private Paint mPaint;
-
- // Here is our new camera
- private Camera mCamera;
-
- Renderer(SurfaceView sh, Point screenSize){
- mSurfaceHolder = sh.getHolder();
- mPaint = new Paint();
-
- // Initialize the camera
- mCamera = new Camera(screenSize.x, screenSize.y);
- }
-
- int getPixelsPerMetre(){
- return mCamera.getPixelsPerMetre();
- }
-
- void draw(ArrayList objects,
- GameState gs,
- HUD hud) {
-
- if (mSurfaceHolder.getSurface().isValid()) {
- mCanvas = mSurfaceHolder.lockCanvas();
- mCanvas.drawColor(Color.argb(255, 0, 0, 0));
-
- if(gs.getDrawing()) {
- // Set the player as the center of the camera
- mCamera.setWorldCentre(
- objects.get(LevelManager.PLAYER_INDEX)
- .getTransform().getLocation());
-
- for (GameObject object : objects) {
- if (object.checkActive()) {
- object.draw(mCanvas, mPaint, mCamera);
- }
- }
- }
-
- hud.draw(mCanvas, mPaint, gs);
-
- mSurfaceHolder.unlockCanvasAndPost(mCanvas);
- }
- }
-
-}
diff --git a/Chapter25/java/SoundEngine.java b/Chapter25/java/SoundEngine.java
deleted file mode 100644
index a5d7820..0000000
--- a/Chapter25/java/SoundEngine.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.content.res.AssetManager;
-import android.media.AudioAttributes;
-import android.media.AudioManager;
-import android.media.SoundPool;
-import android.os.Build;
-
-import java.io.IOException;
-
-class SoundEngine {
- // for playing sound effects
- private static SoundPool mSP;
- private static int mJump_ID = -1;
- private static int mReach_Objective_ID = -1;
- private static int mCoin_Pickup_ID = -1;
- private static int mPlayer_Burn_ID = -1;
-
- private static SoundEngine ourInstance;
-
- public static SoundEngine getInstance(Context context) {
- ourInstance = new SoundEngine(context);
- return ourInstance;
- }
-
- public SoundEngine(Context c){
- // Initialize the SoundPool
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes = new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
-
- mSP = new SoundPool.Builder()
- .setMaxStreams(5)
- .setAudioAttributes(audioAttributes)
- .build();
- } else {
- mSP = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
- }
- try {
- AssetManager assetManager = c.getAssets();
- AssetFileDescriptor descriptor;
-
- // Prepare the sounds in memory
- descriptor = assetManager.openFd("jump.ogg");
- mJump_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("reach_objective.ogg");
- mReach_Objective_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("coin_pickup.ogg");
- mCoin_Pickup_ID = mSP.load(descriptor, 0);
-
- descriptor = assetManager.openFd("player_burn.ogg");
- mPlayer_Burn_ID = mSP.load(descriptor, 0);
-
- } catch (IOException e) {
- // Error
- }
-
- }
-
-
- public static void playJump(){
- mSP.play(mJump_ID,1, 1, 0, 0, 1);
- }
-
- public static void playReachObjective(){
- mSP.play(mReach_Objective_ID,1, 1, 0, 0, 1);
- }
-
- public static void playCoinPickup(){
- mSP.play(mCoin_Pickup_ID,1, 1, 0, 0, 1);
- }
-
- public static void playPlayerBurn(){
- mSP.play(mPlayer_Burn_ID,1, 1, 0, 0, 1);
- }
-
-}
diff --git a/Chapter25/java/Transform.java b/Chapter25/java/Transform.java
deleted file mode 100644
index 29fd95f..0000000
--- a/Chapter25/java/Transform.java
+++ /dev/null
@@ -1,117 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.graphics.PointF;
-import android.graphics.RectF;
-
-public class Transform {
- RectF mCollider;
- private PointF mLocation;
- private float mSpeed;
- private float mObjectHeight;
- private float mObjectWidth;
- private PointF mStartingPosition;
- private boolean mHeadingUp = false;
- private boolean mHeadingDown = false;
-
- private boolean mFacingRight = true;
- private boolean mHeadingLeft = false;
- private boolean mHeadingRight = false;
-
- Transform(float speed, float objectWidth,
- float objectHeight, PointF startingLocation) {
-
- mCollider = new RectF();
- mSpeed = speed;
- mObjectHeight = objectHeight;
- mObjectWidth = objectWidth;
- mLocation = startingLocation;
-
- // This tells movable blocks their starting position
- mStartingPosition = new PointF(mLocation.x, mLocation.y);
- }
-
-
- public void updateCollider() {
- mCollider.top = mLocation.y;
- mCollider.left = mLocation.x ;
- mCollider.bottom = (mCollider.top + mObjectHeight);
- mCollider.right = (mCollider.left + mObjectWidth);
- }
-
-
- public RectF getCollider() {
- return mCollider;
- }
-
- void headUp() {
- mHeadingUp = true;
- mHeadingDown = false;
- }
-
- void headDown() {
- mHeadingDown = true;
- mHeadingUp = false;
- }
-
- boolean headingUp() {
- return mHeadingUp;
- }
-
- boolean headingDown() {
- return mHeadingDown;
- }
-
- float getSpeed() {
- return mSpeed;
- }
-
- PointF getLocation() {
- return mLocation;
- }
-
- PointF getSize() {
- return new PointF((int) mObjectWidth, (int) mObjectHeight);
- }
-
- void headRight() {
- mHeadingRight = true;
- mHeadingLeft = false;
- mFacingRight = true;
-
- }
-
- void headLeft() {
- mHeadingLeft = true;
- mHeadingRight = false;
- mFacingRight = false;
- }
-
- boolean headingRight() {
- return mHeadingRight;
- }
-
- boolean headingLeft() {
- return mHeadingLeft;
- }
-
- void stopHorizontal() {
- mHeadingLeft = false;
- mHeadingRight = false;
- }
-
- void stopMovingLeft() {
- mHeadingLeft = false;
- }
-
- void stopMovingRight() {
- mHeadingRight = false;
- }
-
- boolean getFacingRight() {
- return mFacingRight;
- }
-
- PointF getStartingPosition(){
- return mStartingPosition;
- }
-}
diff --git a/Chapter25/java/UIController.java b/Chapter25/java/UIController.java
deleted file mode 100644
index 6ec7d5b..0000000
--- a/Chapter25/java/UIController.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-
-class UIController implements InputObserver {
-
- private float mThird;
-
- private boolean initialPress = false;
-
- UIController(GameEngineBroadcaster b, Point size) {
- // Add as an observer
- addObserver(b);
-
- mThird = size.x / 3;
- }
-
- // Need to add observer each time a new game is started and the game objects are rebuilt
- // and the observer list is cleared. This method allows us to re-add an observer for this
- // Rather than just add it in the constructor.
- // The Player controller doesn't need it because a new object is created each level
- void addObserver(GameEngineBroadcaster b) {
- b.addObserver(this);
- }
-
- @Override
- public void handleInput(MotionEvent event,
- GameState gameState,
- ArrayList buttons) {
-
- int i = event.getActionIndex();
- int x = (int) event.getX(i);
-
- int eventType = event.getAction()
- & MotionEvent.ACTION_MASK;
-
- if (eventType == MotionEvent.ACTION_UP ||
- eventType == MotionEvent.ACTION_POINTER_UP) {
-
- // If game is over start a new game
- if (gameState.getGameOver() && initialPress) {
-
- if (x < mThird) {
- gameState.setCurrentLevel("underground");
- gameState.startNewGame();
- } else if (x >= mThird && x < mThird * 2) {
- gameState.setCurrentLevel("mountains");
- gameState.startNewGame();
- } else if (x >= mThird * 2) {
- gameState.setCurrentLevel("city");
- gameState.startNewGame();
- }
-
- }
-
- initialPress = !initialPress;
- }
-
- }
-
-}
diff --git a/Chapter25/java/UpdateComponent.java b/Chapter25/java/UpdateComponent.java
deleted file mode 100644
index 0981c41..0000000
--- a/Chapter25/java/UpdateComponent.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.gamecodeschool.c25platformer;
-
-interface UpdateComponent {
-
- // Everything has one of these so it can be updated
- // The player's transform could be left out because it is only needed
- // by the background(to see which way the player is moving)
- // However, if we added enemies at a later date they would likely need
- // to know where the player is and what he is doing.
- // So I left it in rather than create a communication between the
- // background and the player
- void update(long fps, Transform t, Transform playerTransform);
-}
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 4f1ec73..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2018 Packt
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/README.md b/README.md
index ec91c3d..7e5e300 100644
--- a/README.md
+++ b/README.md
@@ -1,74 +1 @@
-# Learning Java by Building Android Games
-
-
-
-This is the code repository for [Learning Java by Building Android Games](https://www.packtpub.com/game-development/learning-java-9-building-android-games-second-edition), published by Packt.
-
-**Learn Java and Android from scratch by building six exciting games**
-
-## What is this book about?
-Android is one of the most popular mobile operating systems presently. It uses the most popular programming language, Java, as the primary language for building apps of all types. However, this book is unlike other Android books in that it doesn’t assume that you already have Java proficiency.
-
-This book covers the following exciting features:
-* Set up a game development environment in Android Studio
-
-* Implement screen locking, screen rotation, pixel graphics, and play sound effects
-
-* Respond to a player’s touch, and program intelligent enemies who challenge the player in different ways
-
-* Learn game development concepts, such as collision detection, animating sprite sheets, simple tracking and following, AI, parallax backgrounds, and particle explosions
-
-* Animate objects at 60 frames per second (FPS) and manage multiple independent objects using Object-Oriented Programming (OOP)
-
-If you feel this book is for you, get your [copy](https://www.amazon.com/dp/1788839153) today!
-
-
-
-
-## Instructions and Navigations
-All of the code is organized into folders. For example, Chapter02.
-
-The code will look like the following:
-```
-if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- AudioAttributes audioAttributes =
- new AudioAttributes.Builder()
- .setUsage(AudioAttributes.USAGE_MEDIA)
-```
-
-**Following is what you need for this book:**
-Learning Java by Building Android Games is for you if you are completely new to Java, Android, or game programming and want to make Android games. This book also acts as a refresher for those who already have experience of using Java on Android or any other platform without game development experience.
-
-With the following software and hardware list you can run all code files present in the book (Chapter 1-15).
-
-### Software and Hardware List
-
-| Chapter | Software required | OS required |
-| -------- | ------------------------------------| -----------------------------------|
-| 1-26 | Android Studio | Windows, Linux, Mac (Specific |
-| | | instructions given for Windows. |
-| | | Minor interpretation needed for |
-| | | Mac or Linux) |
-
-We also provide a PDF file that has color images of the screenshots/diagrams used in this book. [Click here to download it](Graphics Bundle Link).
-
-### Related products
-* Mastering Firebase for Android Development [[Packt]](https://www.packtpub.com/web-development/mastering-firebase) [[Amazon]](https://www.amazon.com/dp/1788624718)
-
-* Android Design Patterns and Best Practice [[Packt]](https://www.packtpub.com/web-development/android-design-patterns-and-best-practice) [[Amazon]](https://www.amazon.com/dp/1786467216)
-
-## Get to Know the Author
-**Author Name**
-John Horton
-
-**Author Name**
-John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
-
-
-## Other books by the authors
-* [Beginning C++ Game Programming - Part 2 [Video]](https://www.packtpub.com/game-development/beginning-c-game-programming-part-2-video)
-* [Android: Game Programming](https://www.packtpub.com/game-development/android-game-programming)
-
-### Suggestions and Feedback
-[Click here](https://docs.google.com/forms/d/e/1FAIpQLSdy7dATC6QmEL81FIUuymZ0Wy9vH1jHkvpY57OiMeKGqib_Ow/viewform) if you have any feedback or suggestions.
+CSC 133 Final Project