Jump to content
  • Advertisement

tmccolgan88

Member
  • Content Count

    32
  • Joined

  • Last visited

Everything posted by tmccolgan88

  1. 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; try{ outputStream = new BufferedWriter(new FileWriter(new File(getFilesDir()+File.separator+"scores.txt"))); outputStream.write(Integer.toString(score)); outputStream.close(); } 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 File(getFilesDir()+File.separator+"scores.txt"))); } catch (FileNotFoundException e1) { Log.d("here 0", e1.getMessage()); return -1; } try { while ((read = buffread.readLine()) != null) builder.append(read); } catch (IOException e1) { e1.printStackTrace(); } try { buffread.close(); } catch (IOException e) { e.printStackTrace(); } Log.d("", builder.toString()); return Integer.parseInt(builder.toString()); }
  2. tmccolgan88

    Saving a persistent .txt file

    Yup. My if that called the function in true was wrong.
  3. tmccolgan88

    Saving a persistent .txt file

    For some reason my code is always returning the fail safe number. I just noticed that it wasn't actually working correctly. public int readScores(){ SharedPreferences data = getSharedPreferences("LIFETIME_GAME_DATA_2", Activity.MODE_PRIVATE); int bestScore = data.getInt("BEST_SCORE", 3); Log.d("Best Score", String.valueOf(bestScore)); return bestScore; } public void saveGame(int score){ SharedPreferences data = getSharedPreferences("LIFETIME_GAME_DATA_2", Activity.MODE_PRIVATE); if (score > readScores()) data.edit().putInt("BEST_SCORE", score).apply(); } This is how my code looks now. I can't seem to figure out what I'm doing wrong.
  4. tmccolgan88

    Saving a persistent .txt file

    Hello TechnoGoth. Ive read the link you posted a few times but it didn't seem to help.  The SharedPreferences  class seems to work perfectly though. 
  5. tmccolgan88

    Saving a persistent .txt file

      Hey frob. All the documentation that I can find says that when saving to internal storage you don't need to declare permissions. I went ahead and tried the code with and without perms when it wouldn't work though.
  6. tmccolgan88

    Is gaming on console dying?

    Well, except maybe BlackBerry OS as a gaming platform...     This made me laugh.
  7. tmccolgan88

    Will you upgrade to windows 8.1?

    I'm still on 7. Haven't seen a reason to change.
  8. tmccolgan88

    Fixing your own problems

    Happens to me quite a bit. I end up analyzing every piece of code to make sure I'm not making a thread for a stupid problem.  Sometimes that's exactly what's happening
  9. tmccolgan88

    Is gaming on console dying?

    No gaming platform is dying.
  10. I wind up doing this with most pieces of code I write that require more than a little bit of thought.  My first pass I code with the sole goal of getting whatever I'm trying to do working. Usually by the time it does work the eloquent, or at least not awful, solution presents itself.
  11. tmccolgan88

    Just released my first game

    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.
  12. Why not just create different virtual machines of different specs to test it?
  13. 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   http://www.mediafire.com/download/kgkia9aef5hm9ms/TurretGame.apk .    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.
  14. tmccolgan88

    Need feedback for my Android game

    It looks pretty fun. Iv'e always been a big fan of the twin stick shooter.  It's hard to to tell for sure without being able to actually try it out but to me it looked like the camera is a little too close.  Maybe test out pulling it up a little bit and showing a greater area to the player.
  15. Neither will make you "better".  Some people even think that IDE's hinder learning, and say that you should begin programming in a terminal. That is kind of overkill though.  If you want to be a better programmer just make sure you understand what is happening in your code, and research it if you don't.
  16. Trying to get motivated after going over the "god damn I've been working on this project for a long time" hump
  17. Thanks Shazen, works perfectly now. 
  18. 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; xpos = TURRET_X_POSITION; ypos = TURRET_Y_POSITION; 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.
  19. Great article. When I first started making my own games my biggest issue was establishing a project scope. I would add every idea that popped into my head. Probably goes without saying I didn't finish the first 4 or 5 projects I started.
  20. Hello,      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); } }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!