Re: [SCORCHED] SF.net SVN: scorched:[15] spikes/trunk/TerrainSpike
Status: Planning
Brought to you by:
zkunath
|
From: Scott W. <swe...@gm...> - 2009-02-06 17:23:48
|
This looks pretty good. I don't quite understand the algorithm you're using-- do you think you could explain it at the meeting today? Scott On Fri, Feb 6, 2009 at 10:39 AM, <as...@us...> wrote: > Revision: 15 > http://scorched.svn.sourceforge.net/scorched/?rev=15&view=rev > Author: asittwo > Date: 2009-02-06 16:39:25 +0000 (Fri, 06 Feb 2009) > > Log Message: > ----------- > > > Added Paths: > ----------- > spikes/trunk/TerrainSpike/.classpath > spikes/trunk/TerrainSpike/.project > spikes/trunk/TerrainSpike/AndroidManifest.xml > spikes/trunk/TerrainSpike/assets/ > spikes/trunk/TerrainSpike/res/ > spikes/trunk/TerrainSpike/res/drawable/ > spikes/trunk/TerrainSpike/res/drawable/icon.png > spikes/trunk/TerrainSpike/res/drawable/snowflake.png > spikes/trunk/TerrainSpike/res/layout/ > spikes/trunk/TerrainSpike/res/layout/main.xml > spikes/trunk/TerrainSpike/res/values/ > spikes/trunk/TerrainSpike/res/values/strings.xml > spikes/trunk/TerrainSpike/src/ > spikes/trunk/TerrainSpike/src/eu/ > spikes/trunk/TerrainSpike/src/eu/MrSnowflake/ > spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/ > spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/ > spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/GameTemplate.java > spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/GameView.java > spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/Terrain.java > spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/storage.java > > Added: spikes/trunk/TerrainSpike/.classpath > =================================================================== > --- spikes/trunk/TerrainSpike/.classpath (rev 0) > +++ spikes/trunk/TerrainSpike/.classpath 2009-02-06 16:39:25 UTC (rev 15) > @@ -0,0 +1,6 @@ > +<?xml version="1.0" encoding="UTF-8"?> > +<classpath> > + <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> > + <classpathentry excluding="eu/MrSnowflake/android/gametemplate/storage.java" kind="src" path="src"/> > + <classpathentry kind="output" path="bin"/> > +</classpath> > > > Property changes on: spikes/trunk/TerrainSpike/.classpath > ___________________________________________________________________ > Added: svn:mime-type > + text/plain > > Added: spikes/trunk/TerrainSpike/.project > =================================================================== > --- spikes/trunk/TerrainSpike/.project (rev 0) > +++ spikes/trunk/TerrainSpike/.project 2009-02-06 16:39:25 UTC (rev 15) > @@ -0,0 +1,33 @@ > +<?xml version="1.0" encoding="UTF-8"?> > +<projectDescription> > + <name>TerrainSpike</name> > + <comment></comment> > + <projects> > + </projects> > + <buildSpec> > + <buildCommand> > + <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name> > + <arguments> > + </arguments> > + </buildCommand> > + <buildCommand> > + <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name> > + <arguments> > + </arguments> > + </buildCommand> > + <buildCommand> > + <name>org.eclipse.jdt.core.javabuilder</name> > + <arguments> > + </arguments> > + </buildCommand> > + <buildCommand> > + <name>com.android.ide.eclipse.adt.ApkBuilder</name> > + <arguments> > + </arguments> > + </buildCommand> > + </buildSpec> > + <natures> > + <nature>com.android.ide.eclipse.adt.AndroidNature</nature> > + <nature>org.eclipse.jdt.core.javanature</nature> > + </natures> > +</projectDescription> > > > Property changes on: spikes/trunk/TerrainSpike/.project > ___________________________________________________________________ > Added: svn:mime-type > + text/plain > > Added: spikes/trunk/TerrainSpike/AndroidManifest.xml > =================================================================== > --- spikes/trunk/TerrainSpike/AndroidManifest.xml (rev 0) > +++ spikes/trunk/TerrainSpike/AndroidManifest.xml 2009-02-06 16:39:25 UTC (rev 15) > @@ -0,0 +1,15 @@ > +<?xml version="1.0" encoding="utf-8"?> > +<manifest xmlns:android="http://schemas.android.com/apk/res/android" > + package="eu.MrSnowflake.android.gametemplate" > + android:versionCode="1" > + android:versionName="1.0.0"> > + <application android:icon="@drawable/icon" android:label="@string/app_name"> > + <activity android:name=".GameTemplate" > + android:label="@string/app_name"> > + <intent-filter> > + <action android:name="android.intent.action.MAIN" /> > + <category android:name="android.intent.category.LAUNCHER" /> > + </intent-filter> > + </activity> > + </application> > +</manifest> > \ No newline at end of file > > > Property changes on: spikes/trunk/TerrainSpike/AndroidManifest.xml > ___________________________________________________________________ > Added: svn:mime-type > + text/plain > > Added: spikes/trunk/TerrainSpike/res/drawable/icon.png > =================================================================== > (Binary files differ) > > > Property changes on: spikes/trunk/TerrainSpike/res/drawable/icon.png > ___________________________________________________________________ > Added: svn:mime-type > + application/octet-stream > > Added: spikes/trunk/TerrainSpike/res/drawable/snowflake.png > =================================================================== > (Binary files differ) > > > Property changes on: spikes/trunk/TerrainSpike/res/drawable/snowflake.png > ___________________________________________________________________ > Added: svn:mime-type > + application/octet-stream > > Added: spikes/trunk/TerrainSpike/res/layout/main.xml > =================================================================== > --- spikes/trunk/TerrainSpike/res/layout/main.xml (rev 0) > +++ spikes/trunk/TerrainSpike/res/layout/main.xml 2009-02-06 16:39:25 UTC (rev 15) > @@ -0,0 +1,10 @@ > +<?xml version="1.0" encoding="utf-8"?> > +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" > + android:layout_width="fill_parent" > + android:layout_height="fill_parent"> > + > + <eu.MrSnowflake.android.gametemplate.GameView > + android:id="@+id/game" > + android:layout_width="fill_parent" > + android:layout_height="fill_parent"/> > +</FrameLayout> > > > Property changes on: spikes/trunk/TerrainSpike/res/layout/main.xml > ___________________________________________________________________ > Added: svn:mime-type > + text/plain > > Added: spikes/trunk/TerrainSpike/res/values/strings.xml > =================================================================== > --- spikes/trunk/TerrainSpike/res/values/strings.xml (rev 0) > +++ spikes/trunk/TerrainSpike/res/values/strings.xml 2009-02-06 16:39:25 UTC (rev 15) > @@ -0,0 +1,9 @@ > +<?xml version="1.0" encoding="utf-8"?> > +<resources> > + <string name="app_name">GameTemplate</string> > + > + <string name="menu_start">Start</string> > + <string name="menu_stop">Stop</string> > + <string name="menu_pause">Pause</string> > + <string name="menu_resume">Resume</string> > +</resources> > > > Property changes on: spikes/trunk/TerrainSpike/res/values/strings.xml > ___________________________________________________________________ > Added: svn:mime-type > + text/plain > > Added: spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/GameTemplate.java > =================================================================== > --- spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/GameTemplate.java (rev 0) > +++ spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/GameTemplate.java 2009-02-06 16:39:25 UTC (rev 15) > @@ -0,0 +1,104 @@ > +package eu.MrSnowflake.android.gametemplate; > + > +import android.app.Activity; > +import android.os.Bundle; > +import android.util.Log; > +import android.view.Menu; > +import android.view.MenuItem; > +import android.view.Window; > +import eu.MrSnowflake.android.gametemplate.GameView.GameThread; > + > +public class GameTemplate extends Activity { > + private static final int MENU_PAUSE = Menu.FIRST; > + > + private static final int MENU_RESUME = Menu.FIRST + 1; > + > + private static final int MENU_START = Menu.FIRST + 2; > + > + private static final int MENU_STOP = Menu.FIRST + 3; > + > + /** A handle to the thread that's actually running the animation. */ > + private GameThread mGameThread; > + > + /** A handle to the View in which the game is running. */ > + private GameView mGameView; > + > + /** > + * Invoked during init to give the Activity a chance to set up its Menu. > + * > + * @param menu the Menu to which entries may be added > + * @return true > + */ > + @Override > + public boolean onCreateOptionsMenu(Menu menu) { > + super.onCreateOptionsMenu(menu); > + > + menu.add(0, MENU_START, 0, R.string.menu_start); > + menu.add(0, MENU_STOP, 0, R.string.menu_stop); > + menu.add(0, MENU_PAUSE, 0, R.string.menu_pause); > + menu.add(0, MENU_RESUME, 0, R.string.menu_resume); > + > + return true; > + } > + > + /** > + * Invoked when the user selects an item from the Menu. > + * > + * @param item the Menu entry which was selected > + * @return true if the Menu item was legit (and we consumed it), false > + * otherwise > + */ > + @Override > + public boolean onOptionsItemSelected(MenuItem item) { > + switch (item.getItemId()) { > + case MENU_START: > + mGameThread.doStart(); > + return true; > + case MENU_STOP: > + mGameThread.setState(GameThread.STATE_LOSE); > + return true; > + case MENU_PAUSE: > + mGameThread.pause(); > + return true; > + case MENU_RESUME: > + mGameThread.unpause(); > + return true; > + } > + > + return false; > + } > + > + /** > + * Invoked when the Activity is created. > + * > + * @param savedInstanceState a Bundle containing state saved from a previous > + * execution, or null if this is a new execution > + */ > + @Override > + protected void onCreate(Bundle savedInstanceState) { > + super.onCreate(savedInstanceState); > + > + // turn off the window's title bar > + requestWindowFeature(Window.FEATURE_NO_TITLE); > + > + // tell system to use the layout defined in our XML file > + setContentView(R.layout.main); > + > + // get handles to the LunarView from XML, and its LunarThread > + mGameView = (GameView) findViewById(R.id.game); > + mGameThread = mGameView.getThread(); > + > + // set up a new game > + mGameThread.setState(GameThread.STATE_RUNNING);//(GameThread.STATE_READY); > + Log.w(this.getClass().getName(), "SIS is null"); > + } > + > + /** > + * Invoked when the Activity loses user focus. > + */ > + @Override > + protected void onPause() { > + super.onPause(); > + mGameView.getThread().pause(); // pause game when Activity pauses > + } > +} > > > Property changes on: spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/GameTemplate.java > ___________________________________________________________________ > Added: svn:mime-type > + text/plain > > Added: spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/GameView.java > =================================================================== > --- spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/GameView.java (rev 0) > +++ spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/GameView.java 2009-02-06 16:39:25 UTC (rev 15) > @@ -0,0 +1,440 @@ > +package eu.MrSnowflake.android.gametemplate; > + > +import java.util.ArrayList; > +import java.util.Random; > + > +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.PointF; > +import android.os.Handler; > +import android.os.Message; > +import android.util.AttributeSet; > +import android.util.Log; > +import android.view.KeyEvent; > +import android.view.SurfaceHolder; > +import android.view.SurfaceView; > + > +/** > + * View that draws, takes keystrokes, etc. for a simple LunarLander game. > + * > + * Has a mode which RUNNING, PAUSED, etc. Has a x, y, dx, dy, ... capturing the > + * current ship physics. All x/y etc. are measured with (0,0) at the lower left. > + * updatePhysics() advances the physics based on realtime. draw() renders the > + * ship, and does an invalidate() to prompt another draw() as soon as possible > + * by the system. > + */ > +class GameView extends SurfaceView implements SurfaceHolder.Callback { > + class GameThread extends Thread { > + /* > + * State-tracking constants > + */ > + public static final int STATE_LOSE = 1; > + public static final int STATE_PAUSE = 2; > + public static final int STATE_READY = 3; > + public static final int STATE_RUNNING = 4; > + public static final int STATE_WIN = 5; > + > + private float x; > + private float y; > + > + private Terrain land; > + ArrayList<PointF> arr; > + > + > + PointF snowflake1; > + PointF snowflake2; > + > + private static final int SPEED = 100; > + private boolean dRight; > + private boolean dLeft; > + private boolean dUp; > + private boolean dDown; > + > + private int mCanvasWidth; > + private int mCanvasHeight; > + > + private long mLastTime; > + private Bitmap mSnowflake; > + > + /** Message handler used by thread to post stuff back to the GameView */ > + private Handler mHandler; > + > + /** The state of the game. One of READY, RUNNING, PAUSE, LOSE, or WIN */ > + private int mMode; > + /** Indicate whether the surface has been created & is ready to draw */ > + private boolean mRun = false; > + /** Handle to the surface manager object we interact with */ > + private SurfaceHolder mSurfaceHolder; > + > + public GameThread(SurfaceHolder surfaceHolder, Context context, > + Handler handler) { > + // get handles to some important objects > + mSurfaceHolder = surfaceHolder; > + mHandler = handler; > + mContext = context; > + > + x = 10; > + y = 10; > + > + mSnowflake = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.snowflake); > + } > + > + /** > + * Starts the game, setting parameters for the current difficulty. > + */ > + public void doStart() { > + synchronized (mSurfaceHolder) { > + // Initialize game here! > + > + x = 10; > + y = 10; > + > + mLastTime = System.currentTimeMillis() + 100; > + setState(STATE_RUNNING); > + > + } > + } > + > + /** > + * Pauses the physics update & animation. > + */ > + public void pause() { > + synchronized (mSurfaceHolder) { > + if (mMode == STATE_RUNNING) > + setState(STATE_PAUSE); > + } > + } > + > + @Override > + public void run() { > + Log.w("SETTING UP TERRAIN", "width = " + getWidth() + ", height = " + getHeight()); > + land = new Terrain(getWidth(), getHeight()); > + land.generateNewMap(); > + Log.w("FINISHED SETTING UP TERRAIN", "width = " + getWidth() + ", height = " + getHeight()); > + > + arr = land.getArray(); > + Log.w("FINISHED GETTING TERRAIN", "width = " + getWidth() + ", height = " + getHeight()); > + Random rand = new Random(); > + int snow1 = rand.nextInt(arr.size()); > + int snow2 = rand.nextInt(arr.size()); > + Log.w("FINISHED GETTING 2 RANDOM NUMBERS", "width = " + snow1 + ", height = " + snow2); > + snowflake1 = arr.get(snow1); > + snowflake2 = arr.get(snow2); > + Log.w("FINISHED GETTING 2 RANDOM POINTS", "width = " + snowflake1.x + ", height = " + snowflake1.y); > + Log.w("FINISHED GETTING 2 RANDOM POINTS", "width = " + snowflake2.x + ", height = " + snowflake2.y); > + > + while (mRun) { > + Canvas c = null; > + try { > + c = mSurfaceHolder.lockCanvas(null); > + synchronized (mSurfaceHolder) { > + if (mMode == STATE_RUNNING) > + updateGame(); > + doDraw(c); > + } > + } finally { > + // do this in a finally so that if an exception is thrown > + // during the above, we don't leave the Surface in an > + // inconsistent state > + if (c != null) { > + mSurfaceHolder.unlockCanvasAndPost(c); > + } > + } > + } > + } > + > + /** > + * Used to signal the thread whether it should be running or not. > + * Passing true allows the thread to run; passing false will shut it > + * down if it's already running. Calling start() after this was most > + * recently called with false will result in an immediate shutdown. > + * > + * @param b true to run, false to shut down > + */ > + public void setRunning(boolean b) { > + mRun = b; > + } > + > + /** > + * Sets the game mode. That is, whether we are running, paused, in the > + * failure state, in the victory state, etc. > + * > + * @see #setState(int, CharSequence) > + * @param mode one of the STATE_* constants > + */ > + public void setState(int mode) { > + synchronized (mSurfaceHolder) { > + setState(mode, null); > + } > + } > + > + /** > + * Sets the game mode. That is, whether we are running, paused, in the > + * failure state, in the victory state, etc. > + * > + * @param mode one of the STATE_* constants > + * @param message string to add to screen or null > + */ > + public void setState(int mode, CharSequence message) { > + synchronized (mSurfaceHolder) { > + mMode = mode; > + } > + } > + > + /* Callback invoked when the surface dimensions change. */ > + public void setSurfaceSize(int width, int height) { > + // synchronized to make sure these all change atomically > + synchronized (mSurfaceHolder) { > + mCanvasWidth = width; > + mCanvasHeight = height; > + } > + } > + > + /** > + * Resumes from a pause. > + */ > + public void unpause() { > + // Move the real time clock up to now > + synchronized (mSurfaceHolder) { > + mLastTime = System.currentTimeMillis() + 100; > + } > + setState(STATE_RUNNING); > + } > + > + /** > + * Handles a key-down event. > + * > + * @param keyCode the key that was pressed > + * @param msg the original event object > + * @return true > + */ > + boolean doKeyDown(int keyCode, KeyEvent msg) { > + boolean handled = false; > + synchronized (mSurfaceHolder) { > + if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT){ > + dRight = true; > + handled = true; > + } > + if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT){ > + dLeft = true; > + handled = true; > + } > + if (keyCode == KeyEvent.KEYCODE_DPAD_UP){ > + dUp = true; > + handled = true; > + } > + if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN){ > + dDown = true; > + handled = true; > + } > + return handled; > + } > + } > + > + /** > + * Handles a key-up event. > + * > + * @param keyCode the key that was pressed > + * @param msg the original event object > + * @return true if the key was handled and consumed, or else false > + */ > + boolean doKeyUp(int keyCode, KeyEvent msg) { > + boolean handled = false; > + synchronized (mSurfaceHolder) { > + if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT){ > + dRight = false; > + handled = true; > + } > + if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT){ > + dLeft = false; > + handled = true; > + } > + if (keyCode == KeyEvent.KEYCODE_DPAD_UP){ > + dUp = false; > + handled = true; > + } > + if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN){ > + dDown = false; > + handled = true; > + } > + return handled; > + } > + } > + > + /** > + * Draws the ship, fuel/speed bars, and background to the provided > + * Canvas. > + */ > + private void doDraw(Canvas canvas) { > + // empty canvas > + canvas.drawARGB(255, 0, 0, 0); > + > +// land.generateNewMap(); > + > + Paint paint = new Paint(); > + paint.setColor(Color.RED); > + paint.setStrokeWidth(0); > + > + //Log.w("GENERATING MAP", "asdasdasdasdasdasdasdasdasd"); > + //float[] pts = land.getMap(); > + > + for(int i = 0; i < arr.size(); i++) > + { > + canvas.drawLine((float)0, arr.get(i).y, arr.get(i).x, arr.get(i).y, paint); > + } > + > +// for(int i = 0; i < pts.length; i++) > +// { > +// Log.w("Point " + i, "" + pts[i]); > +// } > + > +// canvas.drawPoints(pts, paint); > + //canvas.drawLine((float)50.0, (float)50.0, (float)200.0, (float)200.0, paint); > + //canvas.drawBitmap(mSnowflake, snowflake1.x, snowflake1.y, new Paint()); > + //canvas.drawBitmap(mSnowflake, snowflake2.x, snowflake2.y, new Paint()); > + Log.w("FLAKE", "" + snowflake1.x); > + Log.w("FLAKE", "" + snowflake2.x); > + } > + > + /** > + * Updates the game. > + */ > + private void updateGame() { > + //// <DoNotRemove> > + long now = System.currentTimeMillis(); > + // Do nothing if mLastTime is in the future. > + // This allows the game-start to delay the start of the physics > + // by 100ms or whatever. > + if (mLastTime > now) > + return; > + double elapsed = (now - mLastTime) / 1000.0; > + mLastTime = now; > + //// </DoNotRemove> > + > + /* > + * Why use mLastTime, now and elapsed? > + * Well, because the frame rate isn't always constant, it could happen your normal frame rate is 25fps > + * then your char will walk at a steady pace, but when your frame rate drops to say 12fps, without elapsed > + * your character will only walk half as fast as at the 25fps frame rate. Elapsed lets you manage the slowdowns > + * and speedups! > + */ > + > + if (dUp) > + y -= elapsed * SPEED; > + if (dDown) > + y += elapsed * SPEED; > + if (y < 0) > + y = 0; > + else if (y >= mCanvasHeight - mSnowflake.getHeight()) > + y = mCanvasHeight - mSnowflake.getHeight(); > + if (dLeft) > + x -= elapsed * SPEED; > + if (dRight) > + x += elapsed * SPEED; > + if (x < 0) > + x = 0; > + else if (x >= mCanvasWidth - mSnowflake.getWidth()) > + x = mCanvasWidth - mSnowflake.getWidth(); > + } > + } > + > + /** Handle to the application context, used to e.g. fetch Drawables. */ > + private Context mContext; > + > + /** The thread that actually draws the animation */ > + private GameThread thread; > + > + public GameView(Context context, AttributeSet attrs) { > + super(context, attrs); > + > + // register our interest in hearing about changes to our surface > + SurfaceHolder holder = getHolder(); > + holder.addCallback(this); > + > + // create thread only; it's started in surfaceCreated() > + thread = new GameThread(holder, context, new Handler() { > + @Override > + public void handleMessage(Message m) { > + // Use for pushing back messages. > + } > + }); > + > + setFocusable(true); // make sure we get key events > + } > + > + /** > + * Fetches the animation thread corresponding to this LunarView. > + * > + * @return the animation thread > + */ > + public GameThread getThread() { > + return thread; > + } > + > + /** > + * Standard override to get key-press events. > + */ > + @Override > + public boolean onKeyDown(int keyCode, KeyEvent msg) { > + return thread.doKeyDown(keyCode, msg); > + } > + > + /** > + * Standard override for key-up. We actually care about these, so we can > + * turn off the engine or stop rotating. > + */ > + @Override > + public boolean onKeyUp(int keyCode, KeyEvent msg) { > + return thread.doKeyUp(keyCode, msg); > + } > + > + /** > + * Standard window-focus override. Notice focus lost so we can pause on > + * focus lost. e.g. user switches to take a call. > + */ > + @Override > + public void onWindowFocusChanged(boolean hasWindowFocus) { > + if (!hasWindowFocus) > + thread.pause(); > + } > + > + /* Callback invoked when the surface dimensions change. */ > + public void surfaceChanged(SurfaceHolder holder, int format, int width, > + int height) { > + thread.setSurfaceSize(width, height); > + } > + > + /* > + * Callback invoked when the Surface has been created and is ready to be > + * used. > + */ > + public void surfaceCreated(SurfaceHolder holder) { > + // start the thread here so that we don't busy-wait in run() > + // waiting for the surface to be created > + thread.setRunning(true); > + thread.start(); > + } > + > + /* > + * Callback invoked when the Surface has been destroyed and must no longer > + * be touched. WARNING: after this method returns, the Surface/Canvas must > + * never be touched again! > + */ > + public void surfaceDestroyed(SurfaceHolder holder) { > + // we have to tell thread to shut down & wait for it to finish, or else > + // it might touch the Surface after we return and explode > + boolean retry = true; > + thread.setRunning(false); > + while (retry) { > + try { > + thread.join(); > + retry = false; > + } catch (InterruptedException e) { > + } > + } > + } > +} > > > Property changes on: spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/GameView.java > ___________________________________________________________________ > Added: svn:mime-type > + text/plain > > Added: spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/Terrain.java > =================================================================== > --- spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/Terrain.java (rev 0) > +++ spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/Terrain.java 2009-02-06 16:39:25 UTC (rev 15) > @@ -0,0 +1,128 @@ > +package eu.MrSnowflake.android.gametemplate; > + > +import java.util.ArrayList; > +import java.util.Random; > + > +import android.graphics.PointF; > + > +public class Terrain > +{ > + int PixelWidth; > + int PixelHeight; > + > + int PlateauFactor = 10; > + //int SectorFactor = 3; > + int BaseHeight = PixelWidth/3; > + //float PerturbationFactor = 1/4; > + > + ArrayList<PointF> BitMapping; > + float[] PointArray; > + //float[] SectorMarks; > + > +// public TerrainGenerator() > +// { > +// PixelHeight = pixelHeight; > +// PixelWidth = pixelWidth; > +// > +// BitMapping = new Boolean[pixelWidth][pixelHeight]; > +// } > + > + public Terrain(int pixelWidth, int pixelHeight) > + { > + PixelHeight = pixelHeight; > + PixelWidth = pixelWidth; > + //PixelHeight = 200; > + //PixelWidth = 200; > + > + BitMapping = new ArrayList<PointF>(); > + } > + > + public void generateNewMap() > + { > + BitMapping.clear(); > + > + int last = BaseHeight; > + int plateauFactor = 0; > + > + Random rand = new Random(); > + > + for(int y = 0; y < PixelHeight; y++) > + { > +// for(int l = 0; l < SectorFactor; l++) > +// { > +// if(y == SectorMarks[l]) > +// last = BaseHeight; > +// } > + > + int perturbation; > + > + if(plateauFactor > 0) > + { > + perturbation = rand.nextInt(4); > + plateauFactor--; > + } > + else > + { > + perturbation = rand.nextInt(PixelWidth/4); > + plateauFactor = PlateauFactor + rand.nextInt(PlateauFactor); > + } > + > + // Decide whether offset is negative or positive. > + perturbation = (rand.nextBoolean() ? perturbation : -1 * perturbation); > + > + int x = last + perturbation; > + > + // Make sure all points are on valid screen real estate. > + if(x < 0) > + { > + x = 0 + rand.nextInt(2); > + } > + else if(x > PixelWidth * 3/4) > + { > + x = PixelWidth * 3/4 + rand.nextInt(2); > + } > + > + // Store the last point chosen, so that the next random point will be > + // within an offset of it. Introduces some smoothness to the terrain. > + last = x; > + > + BitMapping.add(new PointF(x, y)); > + } > + > + //convertMap(); > + } > + > + public void convertMap() > + { > + for(int i = 0; i < BitMapping.size(); i++) > + { > + PointF p = BitMapping.get(i); > + > + for(int j = 0; j < p.x; j++) > + { > + BitMapping.add(new PointF(j, p.y)); > + } > + } > + > + int k = 0; > + int count = 0; > + PointArray = new float[BitMapping.size() * 2]; > + > + while(k < BitMapping.size()) > + { > + PointArray[count++] = BitMapping.get(k).x; > + PointArray[count++] = BitMapping.get(k).y; > + k++; > + } > + } > + > + public ArrayList<PointF> getArray() > + { > + return BitMapping; > + } > + > + public float[] getMap() > + { > + return PointArray; > + } > +} > > > Property changes on: spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/Terrain.java > ___________________________________________________________________ > Added: svn:mime-type > + text/plain > > Added: spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/storage.java > =================================================================== > --- spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/storage.java (rev 0) > +++ spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/storage.java 2009-02-06 16:39:25 UTC (rev 15) > @@ -0,0 +1,135 @@ > +package eu.MrSnowflake.android.gametemplate; > + > +import java.util.ArrayList; > +import java.util.Random; > + > +import android.graphics.PointF; > + > +public class Terrain > +{ > + int PixelWidth; > + int PixelHeight; > + > + int PlateauFactor = 10; > + int SectorFactor = 3; > + int BaseHeight = PixelWidth/3; > + //float PerturbationFactor = 1/4; > + > + ArrayList<PointF> BitMapping; > + float[] PointArray; > + float[] SectorMarks; > + > +// public TerrainGenerator() > +// { > +// PixelHeight = pixelHeight; > +// PixelWidth = pixelWidth; > +// > +// BitMapping = new Boolean[pixelWidth][pixelHeight]; > +// } > + > + public Terrain(int pixelWidth, int pixelHeight) > + { > + PixelHeight = pixelHeight; > + PixelWidth = pixelWidth; > + //PixelHeight = 200; > + //PixelWidth = 200; > + > + float[] sectorMarks = new float[SectorFactor]; > + > + for(int i = 0; i < SectorFactor; i++) > + { > + sectorMarks[i] = (i+1) * PixelHeight / SectorFactor; > + } > + > + BitMapping = new ArrayList<PointF>(); > + } > + > + public void generateNewMap() > + { > + BitMapping.clear(); > + > + int last = BaseHeight; > + int plateauFactor = 0; > + > + Random rand = new Random(); > + > + for(int y = 0; y < PixelHeight; y++) > + { > + for(int l = 0; l < SectorFactor; l++) > + { > + if(y == SectorMarks[l]) > + last = BaseHeight; > + } > + > + int perturbation; > + > + if(plateauFactor > 0) > + { > + perturbation = rand.nextInt(3); > + plateauFactor--; > + } > + else > + { > + perturbation = rand.nextInt(PixelWidth/4); > + plateauFactor = PlateauFactor; > + } > + > + // Decide whether offset is negative or positive. > + perturbation = (rand.nextBoolean() ? perturbation : -1 * perturbation); > + > + int x = last + perturbation; > + > + // Make sure all points are on valid screen real estate. > + if(x < 0) > + { > + x = 0 + rand.nextInt(2); > + } > + else if(x > PixelWidth * 3/4) > + { > + x = PixelWidth * 3/4 + rand.nextInt(2); > + } > + > + // Store the last point chosen, so that the next random point will be > + // within an offset of it. Introduces some smoothness to the terrain. > + last = x; > + > + BitMapping.add(new PointF(x, y)); > + } > + > + //convertMap(); > + } > + > + public void convertMap() > + { > + for(int i = 0; i < BitMapping.size(); i++) > + { > + PointF p = BitMapping.get(i); > + > + for(int j = 0; j < p.x; j++) > + { > + BitMapping.add(new PointF(j, p.y)); > + } > + } > + > + int k = 0; > + int count = 0; > + PointArray = new float[BitMapping.size() * 2]; > + > + while(k < BitMapping.size()) > + { > + PointArray[count++] = BitMapping.get(k).x; > + PointArray[count++] = BitMapping.get(k).y; > + k++; > + } > + } > + > + public ArrayList<PointF> getArray() > + { > + return BitMapping; > + } > + > + public float[] getMap() > + { > + return PointArray; > + } > +} > > > Property changes on: spikes/trunk/TerrainSpike/src/eu/MrSnowflake/android/gametemplate/storage.java > ___________________________________________________________________ > Added: svn:mime-type > + text/plain > > > This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. > > ------------------------------------------------------------------------------ > Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing skills and code to > build responsive, highly engaging applications that combine the power of local > resources and data with the reach of the web. Download the Adobe AIR SDK and > Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com > _______________________________________________ > scorched-devel mailing list > sco...@li... > https://lists.sourceforge.net/lists/listinfo/scorched-devel > |