Android Open Source - DroidRunJump Road






From Project

Back to project page DroidRunJump.

License

The source code is released under:

"Droid-Run-Jump" Copyright (c) 2011 Donald E. Llopis <machinezilla@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentati...

If you think the Android project DroidRunJump listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.android.sofla.drj;
//from  w  ww.  jav  a 2s .com
import android.content.SharedPreferences;
import android.graphics.Canvas;

public class Road {
  
  Game game;
  float y;
    
  final int MAX_DIVIDERS = 11;
  float [] dividerX;
    
  public Road(Game game) {
    this.game = game;
    y = game.groundY;
    
    dividerX = new float[MAX_DIVIDERS];    
  }
  
  public void reset() {
    float xOffset = 0.0f;    
    for (int i=0; i<MAX_DIVIDERS; i++) {
      dividerX[i] = xOffset;
      xOffset += 80.0f;       
    }    
  }
  
  public void update() {
    for (int i=0; i<MAX_DIVIDERS; i++) {
      dividerX[i] -= 10.0f;
      if (dividerX[i] < -60.0f) {
        dividerX[i] = game.width + 10.0f;        
      }
    }
  }
  
  public void draw(Canvas canvas) {
    canvas.drawBitmap(game.roadImage, 0, y, game.emptyPaint);
    
    for (int i=0; i<MAX_DIVIDERS; i++) {      
      canvas.drawBitmap(game.dividerImage, dividerX[i], y+10.0f, game.emptyPaint);      
    }    
  }
  
  public void restore(SharedPreferences savedState) {    
    for (int i=0; i<MAX_DIVIDERS; i++) {
      dividerX[i] = savedState.getFloat("road_div_" + i + "_x", 0);
    }
  }
  
  public void save(SharedPreferences.Editor map) {
    for (int i=0; i<MAX_DIVIDERS; i++) {
      map.putFloat("road_div_" + i + "_x", dividerX[i]);
    }
  }  
}




Java Source Code List

com.android.sofla.drj.DroidRunJumpActivity.java
com.android.sofla.drj.DroidRunJumpView.java
com.android.sofla.drj.Droid.java
com.android.sofla.drj.Game.java
com.android.sofla.drj.Pastry.java
com.android.sofla.drj.Pothole.java
com.android.sofla.drj.Road.java