Updated readme, fixes for playing the game on device
This commit is contained in:
@@ -7,6 +7,12 @@ SDL_JAVA_PACKAGE_PATH := de_schwardtnet_alienblaster
|
||||
# Typically /sdcard/alienblaster
|
||||
# Or /data/data/de.schwardtnet.alienblaster/files if you're planning to unpack data in application private folder
|
||||
# Your application will just set current directory there
|
||||
SDL_CURDIR_PATH := /sdcard/alienblaster
|
||||
SDL_CURDIR_PATH := /data/data/de.schwardtnet.alienblaster/files
|
||||
|
||||
# Android Dev Phone G1 has trackball instead of cursor keys, and
|
||||
# sends trackball movement events as rapid KeyDown/KeyUp events,
|
||||
# this will make Up/Down/Left/Right key up events with X frames delay,
|
||||
# so if application expects you to press and hold button it will process the event correctly.
|
||||
SDL_TRACKBALL_KEYUP_DELAY := 4
|
||||
|
||||
include $(call all-subdir-makefiles)
|
||||
|
||||
@@ -15,9 +15,9 @@ LOCAL_CFLAGS := $(foreach D, $(CG_SUBDIRS), -I$(CG_SRCDIR)/$(D)) \
|
||||
-I$(LOCAL_PATH)/../stlport/stlport \
|
||||
|
||||
#Change C++ file extension as appropriate
|
||||
LOCAL_CPP_EXTENSION := .cpp
|
||||
LOCAL_CPP_EXTENSION := .cc
|
||||
|
||||
LOCAL_SRC_FILES := $(foreach F, $(CG_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.cpp))))
|
||||
LOCAL_SRC_FILES := $(foreach F, $(CG_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.cc))))
|
||||
# Uncomment to also add C sources
|
||||
LOCAL_SRC_FILES += $(foreach F, $(CG_SUBDIRS), $(addprefix $(F)/,$(notdir $(wildcard $(LOCAL_PATH)/$(F)/*.c))))
|
||||
|
||||
|
||||
@@ -8,7 +8,11 @@ ifndef SDL_JAVA_PACKAGE_PATH
|
||||
$(error Please define SDL_JAVA_PACKAGE_PATH to the path of your Java package with dots replaced with underscores, for example "com_example_SanAngeles")
|
||||
endif
|
||||
|
||||
LOCAL_CFLAGS := -I$(LOCAL_PATH)/include -DSDL_JAVA_PACKAGE_PATH=$(SDL_JAVA_PACKAGE_PATH) -DSDL_CURDIR_PATH=\"$(SDL_CURDIR_PATH)\"
|
||||
LOCAL_CFLAGS := -I$(LOCAL_PATH)/include \
|
||||
-DSDL_JAVA_PACKAGE_PATH=$(SDL_JAVA_PACKAGE_PATH) \
|
||||
-DSDL_CURDIR_PATH=\"$(SDL_CURDIR_PATH)\" \
|
||||
-DSDL_TRACKBALL_KEYUP_DELAY=$(SDL_TRACKBALL_KEYUP_DELAY) \
|
||||
|
||||
|
||||
SDL_SRCS := \
|
||||
src/*.c \
|
||||
|
||||
@@ -95,6 +95,8 @@ static GLuint texture = 0;
|
||||
|
||||
static SDLKey keymap[KEYCODE_LAST+1];
|
||||
|
||||
static int processAndroidTrackballKeyDelays( int key, int action );
|
||||
|
||||
/* ANDROID driver bootstrap functions */
|
||||
|
||||
static int ANDROID_Available(void)
|
||||
@@ -380,6 +382,8 @@ static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface)
|
||||
surface->pixels = memBuffer;
|
||||
|
||||
SDL_mutexV(WaitForNativeRender);
|
||||
|
||||
processAndroidTrackballKeyDelays( -1, 0 );
|
||||
|
||||
return(0);
|
||||
};
|
||||
@@ -467,12 +471,82 @@ static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
|
||||
return(keysym);
|
||||
}
|
||||
|
||||
static int AndroidTrackballKeyDelays[4] = {0,0,0,0};
|
||||
|
||||
// Key = -1 if we want to send KeyUp events from main loop
|
||||
static int processAndroidTrackballKeyDelays( int key, int action )
|
||||
{
|
||||
#if ! defined(SDL_TRACKBALL_KEYUP_DELAY) || (SDL_TRACKBALL_KEYUP_DELAY == 0)
|
||||
return 0;
|
||||
#else
|
||||
// Send Directional Pad Up events with a delay, so app wil lthink we're holding the key a bit
|
||||
static const int KeysMapping[4] = {KEYCODE_DPAD_UP, KEYCODE_DPAD_DOWN, KEYCODE_DPAD_LEFT, KEYCODE_DPAD_RIGHT};
|
||||
int idx;
|
||||
SDL_keysym keysym;
|
||||
|
||||
if( key < 0 )
|
||||
{
|
||||
for( idx = 0; idx < 4; idx ++ )
|
||||
{
|
||||
if( AndroidTrackballKeyDelays[idx] > 0 )
|
||||
{
|
||||
AndroidTrackballKeyDelays[idx] --;
|
||||
if( AndroidTrackballKeyDelays[idx] == 0 )
|
||||
SDL_PrivateKeyboard( SDL_RELEASED, TranslateKey(KeysMapping[idx], &keysym) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
idx = -1;
|
||||
// Too lazy to do switch or function
|
||||
if( key == KEYCODE_DPAD_UP )
|
||||
idx = 0;
|
||||
else if( key == KEYCODE_DPAD_DOWN )
|
||||
idx = 1;
|
||||
else if( key == KEYCODE_DPAD_LEFT )
|
||||
idx = 2;
|
||||
else if( key == KEYCODE_DPAD_RIGHT )
|
||||
idx = 3;
|
||||
if( idx >= 0 )
|
||||
{
|
||||
if( action && AndroidTrackballKeyDelays[idx] == 0 )
|
||||
{
|
||||
// User pressed key for the first time
|
||||
SDL_PrivateKeyboard( SDL_PRESSED, TranslateKey(key, &keysym) );
|
||||
}
|
||||
else if( !action && AndroidTrackballKeyDelays[idx] == 0 )
|
||||
{
|
||||
// User released key - make a delay, do not send event
|
||||
AndroidTrackballKeyDelays[idx] = SDL_TRACKBALL_KEYUP_DELAY;
|
||||
}
|
||||
/*
|
||||
else if( !action && AndroidTrackballKeyDelays[idx] > 0 )
|
||||
{
|
||||
// User released key after we fired delay (should not happen)
|
||||
SDL_PrivateKeyboard( SDL_RELEASED, TranslateKey(key, &keysym) );
|
||||
delays[idx] = SDL_TRACKBALL_KEYUP_DELAY;
|
||||
}
|
||||
else if( action && AndroidTrackballKeyDelays[idx] > 0 )
|
||||
{
|
||||
// User pressed key another time - do nothing
|
||||
}
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jint key, jint action )
|
||||
{
|
||||
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "key event %i %s", key, action ? "down" : "up");
|
||||
SDL_keysym keysym;
|
||||
SDL_PrivateKeyboard( action ? SDL_PRESSED : SDL_RELEASED, TranslateKey(key, &keysym) );
|
||||
if( ! processAndroidTrackballKeyDelays(key, action) )
|
||||
SDL_PrivateKeyboard( action ? SDL_PRESSED : SDL_RELEASED, TranslateKey(key, &keysym) );
|
||||
}
|
||||
|
||||
/* Call to render the next GL frame */
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
This is Alien Blaster game ported to Google Android.
|
||||
I did not change anything in Alien Blaster sources, except for SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT and BIT_DEPTH constants in global.h.
|
||||
|
||||
This should be compiled with Android 1.6 SDK and NDK - google for them and install them as described in their docs.
|
||||
You'll need to install Eclipse or Ant too
|
||||
@@ -16,9 +19,21 @@ That will create file project/bin/DemoActivity-debug.apk - use "adb install" to
|
||||
|
||||
Alien Blaster data can be downloaded from http://www.schwardtnet.de/alienblaster/ -
|
||||
download alienblaster-1.1.0.tgz, unpack it and execute
|
||||
adb push alienblaster /sdcard/alienblaster
|
||||
adb shell
|
||||
<in adb shell>:
|
||||
su
|
||||
mkdir /data/data/de.schwardtnet.alienblaster/files
|
||||
exit
|
||||
adb push alienblaster /data/data/de.schwardtnet.alienblaster/files
|
||||
Then you can test it by launching Alien Blaster icon from Android applications menu.
|
||||
It's designed for 640x480, but with bit of luck you can redefine your keys and play the game a bit.
|
||||
It's designed for 640x480, but with bit of luck you can play the game a bit.
|
||||
Note: You should play it with vertical screen orientation (keyboard is closed)
|
||||
Fire key is Call key, redefine Choose Weapon to Enter key through (trackball click)
|
||||
Other keys like Home, Back and End Call will force application quit, and because
|
||||
the app itself does not handle SDL_QUIT event correctly (asks for confirmation),
|
||||
it will stay in memory until you reboot device. The same will happen if the phone
|
||||
goes to sleep, so hit keyboard often plz.
|
||||
To exit correctly press Menu key - it's redirected to Escape.
|
||||
|
||||
When porting you own app, replace "alienblaster" and "de.schwardtnet.alienblaster" with
|
||||
the name of your application and your reversed webpage address everywhere:
|
||||
@@ -29,7 +44,9 @@ the name of your application and your reversed webpage address everywhere:
|
||||
project/res/values/strings.xml:3
|
||||
(that's all, maybe I forgot something)
|
||||
|
||||
Make directory project/jni/<yourapp>, copy there file project/jni/alienblaster/Android.mk and edit it
|
||||
Make directory project/jni/<yourapp>, copy there file project/jni/alienblaster/Android.mk and edit it -
|
||||
rename all "alienblaster" strings to your app name, add subdirs of your app under "CG_SUBDIRS := src"
|
||||
and change "LOCAL_CPP_EXTENSION := .cc" to an extension your C++ files are using
|
||||
Then repeat steps:
|
||||
make APP=<yourapp> V=1
|
||||
ant debug
|
||||
@@ -43,4 +60,3 @@ If you'll add new libs add them to project/jni/, copy Android.mk from existing l
|
||||
add libname to Application.mk and project/jni/<yourapp>/Android.mk
|
||||
|
||||
Note that there's still no sound in SDL, only video and keyboard/mouse
|
||||
|
||||
|
||||
Reference in New Issue
Block a user