ScoreString exists to prevent calls to {@link String#format(String, Object...)} as this seems to be rather
17 | * profligate at allocating memory, which in turns leads to garbage collection. Given that we can't manage that directly we do our
18 | * own thing.
19 | *
20 | * @author Rod */
21 | public class ScoreString implements CharSequence {
22 |
23 | public static final int DEFAULT_CHARS = 6;
24 |
25 | private final char[] score;
26 | private final int start;
27 |
28 | public ScoreString () {
29 | this(DEFAULT_CHARS);
30 | }
31 |
32 | public ScoreString (int numChars) {
33 | score = new char[numChars];
34 | int n = 1;
35 | for (int i = 0; i < numChars - 1; i++) {
36 | n *= 10;
37 | }
38 | start = n;
39 | }
40 |
41 | @Override
42 | public char charAt (int index) {
43 | return score[index];
44 | }
45 |
46 | @Override
47 | public int length () {
48 | return score.length;
49 | }
50 |
51 | @Override
52 | public CharSequence subSequence (int start, int end) {
53 | // Don't care. Call at your own risk.
54 | return null;
55 | }
56 |
57 | /** Sets this ScoreString to hold the given integer value.
58 | *
59 | * @param v the value that the ScoreString will hold. */
60 | public void setScore (int v) {
61 | for (int n = start, i = 0; i < score.length; n /= 10, i++) {
62 | int j = (v / n) % 10;
63 | score[i] = (char)('0' + j);
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/core/src/com/badlydrawngames/general/Particle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Rod Hyde (rod@badlydrawngames.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
10 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
11 | * governing permissions and limitations under the License.
12 | */
13 |
14 | package com.badlydrawngames.general;
15 |
16 | import com.badlogic.gdx.graphics.Color;
17 |
18 | import static com.badlogic.gdx.math.MathUtils.*;
19 | import static com.badlydrawngames.general.MathUtils.*;
20 |
21 | public class Particle {
22 |
23 | private final float MIN_SPEED = 3.125f;
24 | private final float MAX_SPEED = 6.25f;
25 | private final float DECAY = 2.0f;
26 |
27 | public boolean active;
28 | public float x;
29 | public float y;
30 | public Color color;
31 | public final float size;
32 | final float halfSize;
33 | float dx;
34 | float dy;
35 | float r;
36 | float g;
37 | float b;
38 | float a;
39 |
40 | public Particle (float size) {
41 | this.color = new Color();
42 | this.size = size;
43 | this.halfSize = size / 2;
44 | }
45 |
46 | public void spawn (Color c, float x, float y) {
47 | this.active = true;
48 | this.x = x - halfSize;
49 | this.y = y - halfSize;
50 | color.set(c);
51 | r = c.r;
52 | g = c.g;
53 | b = c.b;
54 | a = 3.0f;
55 | float direction = random((float)-PI, PI);
56 | float speed = random(MIN_SPEED, MAX_SPEED);
57 | dx = cos(direction) * speed;
58 | dy = sin(direction) * speed;
59 | }
60 |
61 | public void update (float delta) {
62 | x += dx * delta;
63 | y += dy * delta;
64 | dx *= (1.0 - DECAY * delta * 0.5f);
65 | dy *= (1.0 - DECAY * delta * 0.5f);
66 | a *= (1.0 - DECAY * delta);
67 | color.a = min(1.0f, a);
68 | color.r = min(1.0f, r + max(0, (a - 1.0f)));
69 | color.g = min(1.0f, g + max(0, (a - 1.0f)));
70 | color.b = min(1.0f, b + max(0, (a - 1.0f)));
71 | active = active && a > 0.1f;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/core/src/com/badlydrawngames/general/Config.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Rod Hyde (rod@badlydrawngames.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
10 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
11 | * governing permissions and limitations under the License.
12 | */
13 |
14 | package com.badlydrawngames.general;
15 |
16 | import java.io.IOException;
17 | import java.io.InputStream;
18 | import java.util.Properties;
19 |
20 | import com.badlogic.gdx.Gdx;
21 | import com.badlogic.gdx.files.FileHandle;
22 |
23 | /** Provides a simple way to tweak the game configuration via attributes. Ideally this would be backed with a
24 | * ConfigProvider or similar.
25 | * @author Rod */
26 | public class Config {
27 |
28 | private static final String PROPERTIES_FILE = "data/veryangryrobots.properties";
29 | private static Properties properties;
30 |
31 | private Config () {
32 | }
33 |
34 | private static Properties instance () {
35 | if (null == properties) {
36 | properties = new Properties();
37 | FileHandle fh = Gdx.files.internal(PROPERTIES_FILE);
38 | InputStream inStream = fh.read();
39 | try {
40 | properties.load(inStream);
41 | inStream.close();
42 | } catch (IOException e) {
43 | if (inStream != null) {
44 | try {
45 | inStream.close();
46 | } catch (IOException ex) {
47 | }
48 | }
49 | }
50 | }
51 | return properties;
52 | }
53 |
54 | public static int asInt (String name, int fallback) {
55 | String v = instance().getProperty(name);
56 | if (v == null) return fallback;
57 | return Integer.parseInt(v);
58 | }
59 |
60 | public static float asFloat (String name, float fallback) {
61 | String v = instance().getProperty(name);
62 | if (v == null) return fallback;
63 | return Float.parseFloat(v);
64 | }
65 |
66 | public static String asString (String name, String fallback) {
67 | String v = instance().getProperty(name);
68 | if (v == null) return fallback;
69 | return v;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/core/src/com/badlydrawngames/veryangryrobots/VeryAngryRobotsGame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Rod Hyde (rod@badlydrawngames.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
10 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
11 | * governing permissions and limitations under the License.
12 | */
13 |
14 | package com.badlydrawngames.veryangryrobots;
15 |
16 | import com.badlogic.gdx.Game;
17 | import com.badlogic.gdx.Screen;
18 | import com.badlydrawngames.veryangryrobots.StatusManager.Achievements;
19 |
20 | public class VeryAngryRobotsGame extends Game implements AchievementsListener {
21 |
22 | Screen mainMenuScreen;
23 | Screen playingScreen;
24 | ScoresScreen scoresScreen;
25 | IShowScores scoreDisplayer;
26 | ISubmitScores scoreSubmitter;
27 | AchievementsListener achievementsListener;
28 |
29 | /** Creates all the screens that the game will need, then switches to the main menu. */
30 | @Override
31 | public void create () {
32 | Assets.load();
33 | mainMenuScreen = new MainMenuScreen(this);
34 | playingScreen = new WorldPresenter(this);
35 | scoresScreen = new ScoresScreen(this);
36 | setScreen(mainMenuScreen);
37 | }
38 |
39 | public void submitScore (int score) {
40 | if (scoreSubmitter != null) {
41 | scoreSubmitter.submitScore(score);
42 | }
43 | }
44 |
45 | public void showScores () {
46 | if (scoreDisplayer != null) {
47 | scoreDisplayer.showScores();
48 | }
49 | }
50 |
51 | @Override
52 | public void onAttained (Achievements achievement) {
53 | if (achievementsListener != null) {
54 | achievementsListener.onAttained(achievement);
55 | }
56 | }
57 |
58 | public void setScoreDisplayer (IShowScores scoreDisplayer) {
59 | this.scoreDisplayer = scoreDisplayer;
60 | }
61 |
62 | public void setScoreSubmitter (ISubmitScores scoreSubmitter) {
63 | this.scoreSubmitter = scoreSubmitter;
64 | }
65 |
66 | public void setAchievementsListener (AchievementsListener listener) {
67 | this.achievementsListener = listener;
68 | }
69 |
70 | public boolean canShowScores () {
71 | return scoreDisplayer != null;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/core/src/com/badlydrawngames/veryangryrobots/mobiles/Captain.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Rod Hyde (rod@badlydrawngames.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
10 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
11 | * governing permissions and limitations under the License.
12 | */
13 |
14 | package com.badlydrawngames.veryangryrobots.mobiles;
15 |
16 | import com.badlydrawngames.general.Config;
17 | import com.badlydrawngames.veryangryrobots.Assets;
18 |
19 | import static com.badlogic.gdx.math.MathUtils.*;
20 |
21 | public class Captain extends GameObject {
22 |
23 | public static final int LURKING = INACTIVE + 1;
24 | public static final int CHASING = LURKING + 1;
25 |
26 | private static final float SPEED = Config.asFloat("Captain.speed", 3.75f);
27 | private static final float BOUNCE_SIZE = Config.asFloat("Captain.bounceSize", 5.625f);
28 | private static final float BOUNCE_FREQUENCY = Config.asFloat("Captain.bounceFrequency", 10.0f);
29 |
30 | private float activateTime;
31 | private Player player;
32 | private float speed;
33 | private float t;
34 |
35 | public Captain () {
36 | width = Assets.captainWidth;
37 | height = Assets.captainHeight;
38 | geometry = Assets.captainGeometry;
39 | setState(INACTIVE);
40 | speed = SPEED;
41 | }
42 |
43 | @Override
44 | public void update (float delta) {
45 | stateTime += delta;
46 | if (state == LURKING) {
47 | updateLurking(delta);
48 | } else if (state == CHASING) {
49 | updateChasing(delta);
50 | }
51 | }
52 |
53 | public void activateAfter (float interval) {
54 | activateTime = stateTime + interval;
55 | }
56 |
57 | public void setPlayer (Player player) {
58 | this.player = player;
59 | }
60 |
61 | private void updateLurking (float delta) {
62 | if (stateTime >= activateTime) {
63 | setState(Captain.CHASING);
64 | }
65 | }
66 |
67 | private void updateChasing (float delta) {
68 | float dx = player.x - x;
69 | float dy = player.y - y;
70 | float angle = atan2(dy, dx);
71 | float sd = speed * delta;
72 | x += cos(angle) * sd;
73 | y += sin(angle) * sd;
74 | if (sin(t) > 0) {
75 | y += BOUNCE_SIZE * delta;
76 | } else {
77 | y -= BOUNCE_SIZE * delta;
78 | }
79 | t += delta * BOUNCE_FREQUENCY;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/core/data/veryangryrobots.properties:
--------------------------------------------------------------------------------
1 | # Game window dimensions in virtual coordinates.
2 | Global.screenWidth = 480
3 | Global.screenHeight = 320
4 | Global.statusAreaHeight = 24
5 |
6 | # Fonts.
7 | Global.scoreFont = wellbutrin.fnt
8 | Global.flyupFont = ocr_a_small.fnt
9 | Global.textFont = ocr_a.fnt
10 |
11 | # Robot numbers.
12 | Global.initialRobots = 6
13 | Global.maxRobots = 12
14 |
15 | # Timings.
16 | Global.deadTime = 2.0
17 | Global.amnestyTime = 2.0
18 | Global.roomTransitionTime = 0.333
19 |
20 | # Level progression.
21 | Level.robotIncrement = 3
22 | Level.0.robotShots = 0
23 | Level.0.score = 0
24 | Level.1.robotShots = 1
25 | Level.1.score = 300
26 | Level.2.robotShots = 2
27 | Level.2.score = 1000
28 | Level.3.robotShots = 3
29 | Level.3.score = 2000
30 | Level.4.robotShots = 4
31 | Level.4.score = 4000
32 | Level.5.robotShots = 5
33 | Level.5.score = 5000
34 | Level.6.robotShots = 1
35 | Level.6.score = 6000
36 | Level.7.robotShots = 2
37 | Level.7.score = 8000
38 | Level.8.robotShots = 3
39 | Level.8.score = 10000
40 | Level.9.robotShots = 4
41 | Level.9.score = 12500
42 | Level.10.robotShots = 5
43 | Level.10.score = 15000
44 | Level.11.robotShots = 6
45 | Level.11.score = 20000
46 |
47 | # Player attributes.
48 | Player.borderWidthPercent = 25.0
49 | Player.borderHeightPercent = 6.7
50 | Player.frameDuration = 0.2
51 | Player.speed = 12.5
52 | Player.maxShots = 4
53 | Player.lives = 3
54 | Player.firingInterval = 0.25
55 | Player.firstExtraLife = 10000
56 | Player.secondExtraLife = 50000
57 |
58 | # Captain attributes.
59 | Captain.borderWidthPercent = 16.7
60 | Captain.borderHeightPercent = 16.7
61 | Captain.frameDuration = 0.5
62 | Captain.speed = 3.75
63 | Captain.bounceSize = 5.625
64 | Captain.bounceFrequency = 10.0
65 | Captain.minLurkTime = 2.0
66 | Captain.lurkMultiplier = 2.0
67 |
68 | # Robot attributes.
69 | Robot.frameDuration = 0.1
70 | Robot.speed = 1.25
71 | Robot.maxShots = 6
72 | Robot.score = 50
73 | Robot.bonusScore = 100
74 |
75 | # PlayerShot attributes.
76 | PlayerShot.speed = 31.25
77 |
78 | # RobotShot attributes.
79 | RobotShot.slowSpeed = 4.6875
80 | RobotShot.fastSpeed = 6.0
81 |
82 | # Maze attributes.
83 | Maze.hCells = 5
84 | Maze.vCells = 3
85 |
86 | # Achievements.
87 | achievements.cleanRoomsForPerfectionist = 10
88 | achievements.robotsForRobocide = 50
89 | achievements.roomsForLuckyJim = 10
90 | achievements.roomsForChicken = 5
91 | achievements.gamesForAddict = 10
92 | achievements.daredevilSeconds = 10
93 |
94 | # Status display.
95 | status.achievementDisplayTime = 5.0
96 | status.achievementFlashCycleLength = 0.5
97 | status.achievementFlashOnPercent = 50
98 |
99 | # Flyups.
100 | flyup.lifetime = 1.0
101 | flyup.speed = 1.5625
102 |
103 | # Particles.
104 | particle.size = 0.1875
105 |
--------------------------------------------------------------------------------
/core/src/com/badlydrawngames/general/Grid.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Rod Hyde (rod@badlydrawngames.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
10 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
11 | * governing permissions and limitations under the License.
12 | */
13 |
14 | package com.badlydrawngames.general;
15 |
16 | import com.badlogic.gdx.math.Rectangle;
17 | import com.badlogic.gdx.utils.Array;
18 |
19 | import static com.badlydrawngames.general.MathUtils.*;
20 |
21 | public class Grid {
22 |
23 | private final int cols;
24 | private final int rows;
25 | private final float cellWidth;
26 | private final float cellHeight;
27 | private final ArrayGameObject. Different behaviours are specified by overriding
21 | * {@link GameObject#update}.
22 | *
23 | * @author Rod */
24 | public class GameObject {
25 |
26 | /** The default state for any new game object. */
27 | public static final int INACTIVE = -1;
28 |
29 | /** This game object's x coordinate in world space. */
30 | public float x;
31 |
32 | /** This game object's y coordinate in world space. */
33 | public float y;
34 |
35 | /** This game object's width in world units. */
36 | public float width;
37 |
38 | /** This game object's height in world units. */
39 | public float height;
40 |
41 | /** This game object's collision geometry (if it has any) in local coordinates. */
42 | public CollisionGeometry geometry;
43 |
44 | /** This game object's current state. */
45 | public int state;
46 |
47 | /** How long this game object has been in its current state (in seconds). */
48 | public float stateTime;
49 |
50 | /** Will be true if this game object is in collision. */
51 | public boolean inCollision;
52 |
53 | // Holds this game object's bounding rectangle in world space.
54 | private final Rectangle bounds;
55 |
56 | public GameObject () {
57 | stateTime = 0.0f;
58 | inCollision = false;
59 | bounds = new Rectangle();
60 | }
61 |
62 | /** Assigns collision geometry to this GameObject.
63 | * @param geometry the new collision geometry. */
64 | public void setGeometry (CollisionGeometry geometry) {
65 | this.geometry = geometry;
66 | }
67 |
68 | /** Returns this GameObject's bounding rectangle.
69 | * @return the bounding rectangle. */
70 | public Rectangle bounds () {
71 | bounds.x = x;
72 | bounds.y = y;
73 | bounds.width = width;
74 | bounds.height = height;
75 | return bounds;
76 | }
77 |
78 | /** Switches this game object into a new state and resets {@link #stateTime}.
79 | * @param state the new state. */
80 | public void setState (int state) {
81 | this.state = state;
82 | stateTime = 0.0f;
83 | }
84 |
85 | /** Returns true if this game object's bounds intersect with the given rectangle.
86 | *
87 | * @param r the rectangle to intersect.
88 | * @return true if the bounds intersect. */
89 | public boolean boundsIntersect (Rectangle r) {
90 | return Colliders.intersects(bounds(), r);
91 | }
92 |
93 | /** Returns true if this game object's bounds intersect with the given game object.
94 | *
95 | * @param go the other game object.
96 | * @return true if the bounds intersect. */
97 | public boolean boundsIntersect (GameObject go) {
98 | return Colliders.intersects(bounds(), go.bounds());
99 | }
100 |
101 | /** Returns true if this game object's collision geometry intersects with the given rectangle.
102 | *
103 | * @param r the rectangle to intersect.
104 | * @return true if the geometry intersects with the rectangle. */
105 | public boolean geometryIntersects (Rectangle r) {
106 | return geometry.intersects(r, x, y);
107 | }
108 |
109 | /** Returns true if this game object's collision geometry intersects with another game object's collision geometry.
110 | *
111 | * @param go the other game object.
112 | * @return true if the geometries intersect. */
113 | public boolean geometryIntersects (GameObject go) {
114 | return geometry.intersects(x, y, go.geometry, go.x, go.y);
115 | }
116 |
117 | /** Returns true if this game object is in collision with a rectangle. It first does a simple box test against this game
118 | * object's bounds, then, if that's true, tests its collision geometry against the rectangle.
119 | *
120 | * @param r the rectangle to intersect.
121 | * @return true if this game object intersects the rectangle. */
122 | public boolean intersects (Rectangle r) {
123 | return boundsIntersect(r) && (geometry == null || geometryIntersects(r));
124 | }
125 |
126 | /** Returns true if this game object is in collision with another game object. It first does a bounds test, then, if that's
127 | * true, tests its collision geometry against the other game object's collision geometry. */
128 | public boolean intersects (GameObject go) {
129 | if (!boundsIntersect(go)) {
130 | return false;
131 | }
132 | if (geometry == null) {
133 | return go.geometry == null || go.geometryIntersects(bounds());
134 | } else if (go.geometry == null) {
135 | return geometryIntersects(go.bounds());
136 | }
137 | return geometryIntersects(go);
138 | }
139 |
140 | /** Updates this game object. Typically you would override this to create interesting behaviour.
141 | *
142 | * @param delta time in seconds since the last update. */
143 | public void update (float delta) {
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/core/src/com/badlydrawngames/veryangryrobots/WorldPresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Rod Hyde (rod@badlydrawngames.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
10 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
11 | * governing permissions and limitations under the License.
12 | */
13 |
14 | package com.badlydrawngames.veryangryrobots;
15 |
16 | import com.badlogic.gdx.Gdx;
17 | import com.badlogic.gdx.Input;
18 | import com.badlogic.gdx.graphics.GL20;
19 | import com.badlydrawngames.general.GameScreen;
20 | import com.badlydrawngames.veryangryrobots.WorldView.Presenter;
21 | import com.badlydrawngames.veryangryrobots.mobiles.Player;
22 |
23 | /**
24 | * It is the role of the WorldPresenter to glue together the {@link World} and the {@link WorldView}. It passes on
25 | * information from the controls in the WorldView to the World, updates it, then asks the WorldView to draw everything on its
26 | * behalf. The {@link WorldView} tells this WorldPresenter what to do via the methods provided by the
27 | * {@link Presenter} interface.
28 | *
render was called. */
95 | @Override
96 | public void render (float delta) {
97 | // Update time.
98 | if (delta >= MAX_DELTA) delta = MAX_DELTA;
99 |
100 | // Ask the view to update the controls.
101 | worldView.updateControls(delta);
102 |
103 | // If we're not paused then update the world and the subsystems.
104 | world.update(delta);
105 | if (!world.isPaused()) {
106 | statusManager.update(delta);
107 | worldView.update(delta);
108 | soundManager.update(delta);
109 | }
110 |
111 | // Clear the screen and draw the views.
112 | Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
113 | Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
114 | worldView.render(delta);
115 | statusView.render(delta);
116 |
117 | if (isDead && world.getState() == World.PLAYING) {
118 | game.submitScore(score);
119 | game.setScreen(game.scoresScreen);
120 | game.scoresScreen.setScore(score);
121 | }
122 | boolean isBackPressed = Gdx.input.isKeyPressed(Input.Keys.BACK);
123 | if (!wasBackPressed && isBackPressed) {
124 | if (!world.isPaused()) {
125 | world.pause();
126 | } else {
127 | game.setScreen(game.mainMenuScreen);
128 | }
129 | }
130 | wasBackPressed = isBackPressed;
131 | }
132 |
133 | /** Called by the {@link WorldView} when the player wants to move.
134 | *
135 | * @param x the x value of the controller.
136 | * @param y the y value of the controller. */
137 | @Override
138 | public void setController (float x, float y) {
139 | Player player = world.getPlayer();
140 | player.setController(x, y);
141 | }
142 |
143 | /** Called by the {@link WorldView} when the player wants to fire.
144 | *
145 | * @param x the x value of the controller.
146 | * @param y the y value of the controller. */
147 | @Override
148 | public void setFiringController (float x, float y) {
149 | Player player = world.getPlayer();
150 | world.firePlayerShot.fire(player, x, y);
151 | }
152 |
153 | @Override
154 | public void onScoreChanged (int score) {
155 | this.score = score;
156 | }
157 |
158 | @Override
159 | public void onLivesChanged (int lives) {
160 | isDead = (lives == 0);
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/core/src/com/badlydrawngames/veryangryrobots/RoomBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Rod Hyde (rod@badlydrawngames.com)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 | * License. You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
10 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
11 | * governing permissions and limitations under the License.
12 | */
13 |
14 | package com.badlydrawngames.veryangryrobots;
15 |
16 | import com.badlogic.gdx.math.Rectangle;
17 | import com.badlogic.gdx.utils.Array;
18 | import com.badlogic.gdx.utils.IntArray;
19 | import com.badlogic.gdx.utils.Pool;
20 | import com.badlydrawngames.general.Pools;
21 |
22 | public class RoomBuilder {
23 | private static final float WALL_WIDTH = World.WALL_WIDTH;
24 | private static final float WALL_HEIGHT = World.WALL_HEIGHT;
25 | private static final float HALF_HEIGHT = WALL_HEIGHT / 2;
26 | private static final float ADJUSTMENT = World.OUTER_WALL_ADJUST;
27 | private static final int MAX_RECTANGLES = 256;
28 | private static final int MAX_DOORS = 4;
29 | private static final int MAX_WALLS = MAX_RECTANGLES - MAX_DOORS;
30 |
31 | private final MazeGenerator mazeGenerator;
32 | private final Pool