Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 05 May 2013
Offline Last Active Oct 27 2014 10:32 AM

Topics I've Started

Saving a persistent .txt file

31 March 2014 - 07:16 PM

I'm trying to save the player's top score so that It will be available after the process of the game is terminated.  It seems like I got my write to work but whenever I try to read the file I get a <code>FileNotFoundException</code>.  Wondering if one of you guys can see what I'm doing wrong.

//The method that saves the file.
public void saveGame(int score){
		BufferedWriter outputStream;
			outputStream = new BufferedWriter(new FileWriter(new
		} catch (Exception e){
			Log.d("outputStream Exception", e.getMessage());
		Log.d("", "saved to file");
        //The method that reads the file.
	public int readScores(){
		String read;
		StringBuilder builder = new StringBuilder("");
		BufferedReader buffread;
		try {
			buffread = new BufferedReader(new FileReader(new 
		} catch (FileNotFoundException e1) {
			Log.d("here 0", e1.getMessage());
			return -1;

		try {
			while ((read = buffread.readLine()) != null)
		} catch (IOException e1) {

		try {
		} catch (IOException e) {
		Log.d("", builder.toString());
		return Integer.parseInt(builder.toString());

Just released my first game

11 October 2013 - 03:51 PM

Made my first release to the google play store today. Hoping to get some feedback from the people that made it possible. It does have issues running on phones with lower specs, which I'm still working to get resolved.  Let me know what you think.


download it here: https://play.google.com/store/apps/details?id=com.rjava.turretgame


It's available for all android phones 4.0 and newer. Free to download.

Tiny Turret Beta, looking for some feedback.

31 August 2013 - 07:59 PM

Hey guys and gals.  I've been working on a basic turret shooter for android that I'm getting pretty close to releasing.  It will be free to download and ad free. I posted the beta apk file on mediafire.  You can dowload it here




I have only been able to test it on high end phones and tablets so I'm not sure how well it will work on older phones.  Any feedback is welcome. Hope you like it.

making projectiles travel at a fixed velocity

21 July 2013 - 06:52 AM

I'm having trouble making projectiles travel at the same speed. Right now I'm generating a bullet at a fixed point toward the bottom of the screen in response to a TouchEvent.  Using the coordinates of the touch and starting position of the bullet I'm calculating a vector to make the bullet travel on the correct path. Currently the accuracy is dead on, but depending on the location of the touch the bullet will travel faster or slower.  Right now I'm calculating what percent the touchEvent's y value is of a fixed value, and then multiplying the vector's x value by that number.  It works pretty well except for when the vector's y value gets close to zero.  Wondering if someone can see what I'm doing wrong, or steer me in the direction of the proper technique.


This is the code that populates the bullet object;

if (touchEvents.size() > 0) {
			for (int i = 0; i < touchEvents.size(); i++) {

				turretTickTimer += deltaTime;

				storeXBullet = touchEvents.get(i).x;
				storeYBullet = touchEvents.get(i).y;
				inputCode = touchEvents.get(i).type;

				if (touchEvents.get(i).y < 950
						&& turretTickTimer >= TURRET_TIMER) {
					bullets.add(new Bullet(Assets.bullet,
							((storeXBullet) - TURRET_X_POSITION),
							((TURRET_Y_POSITION - storeYBullet))));
					turretTickTimer = 0;
		} else {
			turretTickTimer += deltaTime;
			if (turretTickTimer >= TURRET_TIMER && inputCode != 1
					&& storeYBullet < 950) {
				bullets.add(new Bullet(Assets.bullet,
						((storeXBullet) - TURRET_X_POSITION),
						((TURRET_Y_POSITION - storeYBullet))));
				turretTickTimer = 0;

This is the bullet class.

package com.turretgame.sprites;

import java.util.Vector;

import android.graphics.Rect;
import android.util.Log;

import com.example.gamedevchapter3.Graphics;
import com.example.gamedevchapter3.Pixmap;
import com.turretgame.mainpackage.Assets;

public class Bullet {
	final int TURRET_Y_POSITION = 1040 + (Assets.turret.getHeight() / 2);
	final int TURRET_X_POSITION = 360 + (Assets.turret.getWidth() / 2);

	final float VELOCITY = 1f;
	Pixmap pixmap;
	public Rect intersectRect;
	float xpos, ypos;
	float velocityAdjustment = 0;
	float movementVectorX, movementVectorY = 0;
	public Bullet(Pixmap pixmap, float moveX, float moveY){
		this.pixmap = pixmap;
		velocityAdjustment = (float)(10.0f / moveY);
		this.movementVectorX = moveX * velocityAdjustment;
		this.movementVectorY = 10;//moveY;
		intersectRect = new Rect((int)xpos, (int)ypos, (int)xpos + 5, (int)ypos+ 5);
	public void update(){
		xpos += (movementVectorX * VELOCITY);
		ypos -= (movementVectorY * VELOCITY);
		intersectRect.set((int)xpos, (int)ypos, (int)xpos + 5, (int)ypos+ 5);
	public void draw(Graphics g){
		g.drawPixmap(pixmap, (int)xpos, (int)ypos);
	public float getY(){
		return ypos;
	public float getX(){
		return xpos;


Any help is appreciated.

Rotating an image to face a point

28 June 2013 - 03:10 PM


     I have a class which is supposed to except a touchEvent in its update method, and then rotate a bitmap to face the location of that touchEvent.        

For some reason the way I have it written now the image just continues to rotate in the direction of the touchEvent. I've tried just about everything, wondering if someone could help.

package com.turretgame.mainpackage;

import android.graphics.Color;
import android.graphics.Matrix;
import android.util.Log;

import com.example.gamedevchapter3.Input.TouchEvent;
import com.example.gamedevchapter3.Pixmap;
import com.example.gamedevchapter3.Graphics;

public class Turret {

	Pixmap turretImage;
	Matrix matrix;

	float direction, tempDirection = 0;
	int xpos, ypos = 100;
	float eventSlope = 0;
	int screenWidth, screenHeight;

	public Turret(Pixmap image, int x, int y, int worldWidth, int worldHeight) {
		turretImage = image;

		matrix = new Matrix();

		xpos = 360;
		ypos = 1040;
		matrix.postTranslate(360, 1040);

	public void update(TouchEvent event, float deltaTime) {

		event.x -= 360;
		eventSlope = (((float) event.x) / ((float) event.y));

		if (eventSlope != 0) {
			tempDirection = ((float) (Math.atan2((double)1 / (double)eventSlope, 0)));
		} else {
			eventSlope = 0;
		Log.d("direction", Float.toString(direction));
		direction = direction + tempDirection;
		matrix.postRotate(direction, xpos + 8, ypos + 20);
		direction = tempDirection;

	public void draw(Graphics g) {

		g.drawPixmap(turretImage, matrix);