Permalink
Browse files

Done

  • Loading branch information...
0 parents commit ee5c9964a8c1a3d0163dec40b8a667da4fbc3df9 @mihaimaruseac committed Feb 2, 2011
8 .classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="lib" path="/data/prg/discontinued/ipw/sensorsimulator-1.1.0-rc1/lib/sensorsimulator-lib-1.1.0-rc1.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
33 .project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>KamikazeRace</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>
19 AndroidManifest.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="mm.kamikaze"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <activity android:name=".Kamikaze"
+ 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>
+
+
+<uses-permission android:name="android.permission.INTERNET"></uses-permission>
+</manifest>
13 README
@@ -0,0 +1,13 @@
+Mihai Maruseac, 341C3
+Kamikaze Race
+
+Aplicația presupune că jucătorul este un șofer de mașină cam nenorocos: este pe
+autostradă în plin trafic cu accelerația la maxim și fără frâne. Ajută șoferul
+să supraviețuiască cât mai mult.
+
+Aplicația folosește senzorul de orientare, contând valoarea lui roll
+(dreapta-stânga). Dacă testați pe calculator (singurul lor unde a fost testată)
+trebie să folosiți simulatorul de la open intents.
+
+Pentru restart, se ține click lung pe ecran. Funcționează doar la game-over.
+
BIN bin/KamikazeRace.apk
Binary file not shown.
BIN bin/classes.dex
Binary file not shown.
BIN bin/mm/kamikaze/Car.class
Binary file not shown.
BIN bin/mm/kamikaze/Draw.class
Binary file not shown.
BIN bin/mm/kamikaze/Kamikaze$1.class
Binary file not shown.
BIN bin/mm/kamikaze/Kamikaze.class
Binary file not shown.
BIN bin/mm/kamikaze/R$attr.class
Binary file not shown.
BIN bin/mm/kamikaze/R$drawable.class
Binary file not shown.
BIN bin/mm/kamikaze/R$id.class
Binary file not shown.
BIN bin/mm/kamikaze/R$layout.class
Binary file not shown.
BIN bin/mm/kamikaze/R$string.class
Binary file not shown.
BIN bin/mm/kamikaze/R.class
Binary file not shown.
BIN bin/resources.ap_
Binary file not shown.
11 default.properties
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-8
28 gen/mm/kamikaze/R.java
@@ -0,0 +1,28 @@
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package mm.kamikaze;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int hiscar=0x7f020000;
+ public static final int icon=0x7f020001;
+ public static final int mycar=0x7f020002;
+ }
+ public static final class id {
+ public static final int canvas=0x7f050000;
+ }
+ public static final class layout {
+ public static final int main=0x7f030000;
+ }
+ public static final class string {
+ public static final int app_name=0x7f040001;
+ public static final int hello=0x7f040000;
+ }
+}
BIN res/drawable-hdpi/hiscar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-hdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-hdpi/mycar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-ldpi/hiscar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-ldpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-ldpi/mycar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-mdpi/hiscar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-mdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-mdpi/mycar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 res/layout/main.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:id="@+id/canvas"
+ />
+</LinearLayout>
5 res/values/strings.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Hello World, Kamikaze!</string>
+ <string name="app_name">Kamikaze Race</string>
+</resources>
19 src/mm/kamikaze/Car.java
@@ -0,0 +1,19 @@
+package mm.kamikaze;
+
+public class Car {
+ public int x, y, sp;
+ public int h;
+ public boolean active;
+
+ public Car() {
+ defaultSettings();
+ }
+
+ private void defaultSettings(){
+ x = 0;
+ y = 0;
+ h = 20;
+ sp = 0;
+ active = false;
+ }
+}
216 src/mm/kamikaze/Draw.java
@@ -0,0 +1,216 @@
+package mm.kamikaze;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.Paint.Style;
+import android.view.View;
+import android.widget.Toast;
+
+public class Draw extends View{
+ private static final int PAD = 10;
+ private static final int SCOREPAD = 32;
+ private Context context;
+ private int w, h;
+ private int xs, ys, xe, ye;
+
+ /* Road geometry */
+ private static final int STRIPELEN = 20;
+ private static final int STRIPETOT = 56;
+ private static final int STRIPEWID = 2;
+ private static final int BLEN = 30;
+ private int STRIPESTART = 0;
+ private static final int STRIPES = 10;
+
+ /* Car geometry */
+ private final int HWCAR = 10;
+ private final int HHCAR = 33;
+ private final int YCAR = 325;
+ private int XCAR = 295;
+ private static final int XCARMAX = 295;
+ private static final int XCARMIN = 25;
+
+ /* Speed values */
+ private final int STRIPSPEED = 1;
+ private final int MAXSPEED = STRIPES * STRIPSPEED;
+ private double sp = 0.5;
+ private int BEHIND = 500;
+
+ /* random values */
+ private double CAR = .2;
+
+ /* cars */
+ private final int MAXCARS = 10;
+ private Car []cars;
+ private int activeCars = 0;
+ private boolean gameover = false;
+ private Bitmap mycar;
+ private Bitmap hiscar;
+
+ public Draw(Context context) {
+ super(context);
+ this.context = context;
+
+ cars = new Car[MAXCARS];
+ for (int i = 0; i < MAXCARS; i++)
+ cars[i] = new Car();
+
+ Resources res = getResources();
+ mycar = BitmapFactory.decodeResource(res, R.drawable.mycar);
+ hiscar = BitmapFactory.decodeResource(res, R.drawable.hiscar);
+ }
+
+ public void reset(){
+ if (!gameover) return;
+ sp = .5;
+ activeCars = 0;
+ XCAR = XCARMAX;
+ gameover = false;
+ postInvalidate();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas){
+ int x, y, ytmp;
+
+ w = this.getWidth();
+ h = this.getHeight();
+
+ xs = PAD;
+ ys = PAD + SCOREPAD;
+ xe = w - PAD;
+ ye = h - PAD;
+
+ /* draw text */
+ Paint textp = new Paint();
+ textp.setColor(Color.MAGENTA);
+ canvas.drawText("Score: " + (int)Math.round(10 * sp), xs + 12, ys - 12, textp);
+
+ /* draw border around terrain */
+ Paint bp = new Paint();
+ bp.setColor(Color.YELLOW);
+ bp.setStyle(Style.STROKE);
+ canvas.drawRect(xs, ys, xe, ye, bp);
+
+ /* draw marks on the road */
+ Paint sp = new Paint();
+ sp.setColor(Color.LTGRAY);
+ x = xs + BLEN - STRIPEWID / 2;
+ while (x < xe - 5){
+ y = ys + STRIPESTART;
+ while (y < ye){
+ ytmp = y + STRIPELEN;
+ if (ytmp > ye){
+ ytmp = ye;
+ canvas.drawRect(x, y, x + STRIPEWID, ytmp, sp);
+ break;
+ }
+ canvas.drawRect(x, y, x + STRIPEWID, ytmp, sp);
+ y += STRIPETOT;
+ }
+ x += BLEN;
+ }
+
+ /* draw my car */
+ canvas.drawBitmap(mycar, XCAR - HWCAR, YCAR - HHCAR, null);
+
+ /* draw other cars */
+ if (gameover){
+ Toast.makeText(context, "Game Over", Toast.LENGTH_SHORT).show();
+ }
+
+ canvas.clipRect(xs, ys, xe, ye);
+ for (int i = 0; i < activeCars; i++){
+ Car c = cars[i];
+ canvas.drawBitmap(hiscar, c.x - HWCAR, c.y - c.h, null);
+ }
+ }
+
+ public void run() {
+ if (gameover) return;
+
+ STRIPESTART = (int)Math.round(STRIPESTART + sp) % STRIPETOT;
+ sp += .05;
+
+ /* car moves */
+ for (int i = 0; i < activeCars; i++){
+ cars[i].y -= (cars[i].sp - sp);
+ }
+
+ for (int i = 0; i < activeCars; i++){
+ if (cars[i].y > BEHIND){
+ Car tmp = cars[(activeCars--)-1];
+ cars[activeCars] = cars[i];
+ cars[i--] = tmp;
+ }
+ }
+
+ /* check colision */
+ for (int i = 0; i < activeCars; i++){
+ if (Math.abs(XCAR - cars[i].x) < 2 * HWCAR){
+ if (Math.abs(YCAR - cars[i].y) < 2 * HHCAR){
+ gameover = true;
+ }
+ }
+ }
+
+ /* get a new car */
+ if (activeCars < MAXCARS){
+ double x = Math.random();
+ if (x < CAR){
+ int speed = (int) Math.round(Math.random() * MAXSPEED);
+ int band;
+
+ for (band = 0; band < STRIPES; band++){
+ if (speed < band * STRIPSPEED){
+ break;
+ }
+ }
+ band--;
+
+ cars[activeCars].active = true;
+ cars[activeCars].x = XCARMAX - band * BLEN;
+ int s = 0, count = 0;
+ for (int j = 0; j < activeCars; j++){
+ if (cars[j].x == cars[activeCars].x){
+ s += cars[j].sp;
+ count++;
+ }
+ }
+ if (count != 0){
+ speed = (int) Math.round((float)s/count);
+ }
+ if (speed > sp)
+ cars[activeCars].y = BEHIND - 10;
+ else
+ cars[activeCars].y = 0;
+ for (int j = 0; j < activeCars; j++){
+ if (cars[j].x == cars[activeCars].x && Math.abs(cars[activeCars].y - cars[j].y) <= 3*HHCAR){
+ cars[activeCars].active = false;
+ break;
+ }
+ }
+ if (cars[activeCars].active){
+ cars[activeCars].sp = speed;
+ activeCars++;
+ }
+ }
+ }
+
+ CAR += .05;
+ postInvalidate();
+ }
+
+ public void moveLeft(int dx){
+ if (XCAR > XCARMIN) XCAR-=dx;
+ }
+
+ public void moveRight(int dx){
+ if (XCAR < XCARMAX) XCAR+=dx;
+ }
+}
93 src/mm/kamikaze/Kamikaze.java
@@ -0,0 +1,93 @@
+package mm.kamikaze;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnLongClickListener;
+import android.view.ViewGroup.LayoutParams;
+import android.widget.LinearLayout;
+import android.hardware.SensorManager;
+
+/* MM: Warning!! The following imports will work only when simulating on emulator!! */
+import org.openintents.sensorsimulator.hardware.Sensor;
+import org.openintents.sensorsimulator.hardware.SensorEvent;
+import org.openintents.sensorsimulator.hardware.SensorEventListener;
+import org.openintents.sensorsimulator.hardware.SensorManagerSimulator;
+
+public class Kamikaze extends Activity implements SensorEventListener, Runnable {
+ private final static int CHANGE = 30;
+
+ LinearLayout screen;
+ private Draw d;
+ private Thread t;
+ private SensorManagerSimulator sensorManager;
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ /** MM: Not in real life, only in emulator */
+ sensorManager = SensorManagerSimulator.getSystemService(this, SENSOR_SERVICE);
+ sensorManager.connectSimulator();
+
+ /** MM: prepare the interface */
+ screen = (LinearLayout)findViewById(R.id.canvas);
+ d = new Draw(screen.getContext());
+ d.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
+ d.setOnLongClickListener(new OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ d.reset();
+ return false;
+ }
+ });
+ screen.addView(d);
+ t = new Thread(this);
+ t.start();
+ }
+
+ @Override
+ protected void onResume(){
+ super.onResume();
+ sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_GAME);
+ }
+
+ @Override
+ protected void onStop(){
+ sensorManager.unregisterListener(this);
+ super.onStop();
+ }
+
+ @Override
+ public void onAccuracyChanged(Sensor arg0, int arg1) {}
+
+ @Override
+ public void onSensorChanged(SensorEvent event) {
+ int sensor = event.type;
+ float[] values = event.values;
+ int _z;
+ _z = (int) values[2];
+ switch (sensor){
+ case Sensor.TYPE_ORIENTATION:
+ if (Math.abs(_z) > CHANGE){
+ if (_z < 0) d.moveLeft(Math.abs(_z)/CHANGE);
+ else d.moveRight(Math.abs(_z)/CHANGE);
+ }
+ break;
+ }
+ }
+
+ @Override
+ public void run() {
+ while (true){
+ try {
+ Thread.sleep(100);
+ d.run();
+ //d.invalidate();
+ } catch (InterruptedException e) {}
+ }
+ }
+}

0 comments on commit ee5c996

Please sign in to comment.