Tag Archives: Mobile Game

How to detect shake motion on Android phone

When I was implementing the shake-to-shuffle feature in Pair-Up game, I googled for a similar code-snippet but didn’t have much luck. Eventually I came across this hidden code in Android Developer Guide which talks about using the phone motion sensor to program:
http://developer.android.com/guide/samples/ApiDemos/src/com/example/android/apis/os/Sensors.html
Alas! It can be done! But I just need a very simple function to detect if there’s a shake action. So my actual code is a lot simpler:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

// Need to implement SensorListener
public class ShakeActivity extends Activity implements SensorListener {
// For shake motion detection.
private SensorManager sensorMgr;
private long lastUpdate = -1;
private float x, y, z;
private float last_x, last_y, last_z;
private static final int SHAKE_THRESHOLD = 800;
 
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
…… // other initializations
// start motion …

A Series of Upgrades

Things has been a bit hectic the past few days with the post-launch upgrades.
Pair Up v1.0 was launch 4 days ago, and I had 4 upgrades since then, which makes the current version 1.4 — a quite iterative launch. . I have to book-keeping the launches here or I will forgot what has been done when:

v1.0 (3/25/09): First launch. Got several comments saying the image tile is way too small.
v1.1 (3/26/09): Increased image tile size from 40×40 to 45×45. Well, seems that’s not big enough though, but I’m reluctant to compromise the number of tiles given the limited display size.
v1.2 (3/26/09): Moved hint/shuffle buttons to options menu. Heard user’s complain on these two small buttons. This alternative worked pretty well. Thanks!
v1.3 (3/27/09): Shake to shuffle! This is a long-planned feature, and my personal favorite one: makes the game much more fun compared to its PC alternative.
v1.4 (3/28/09): Increased game …

Pair Up Launched!

It was officially launched midnight Mar 25th, 2009. Hooray!
Within one minute of the launch there was comment left, a rather encouraging one! The next morning I woke up, it was already downloaded 100+ times with an average rating of 60% — not bad!
Most of the complains are about small tile size: not fat-finger-Americans friendly . I took immediate action of increasing the image tile size from 40×40 to 45×45, and the update was released before noon of Mar 26th. As of now (3pm), the number of downloads is more than 300. Someone left a comment saying looking forward to more updates — Great! I DO have a list of fun features to implement.
But now, most importantly, a detailed help page is very much needed. I read one comment saying that the time progress bar hinders — actually that was intended: if you had tiles eliminated, the time stopped for …