Thursday 28 June 2012

Useful Stage Reached

I've now done all the Menu items as follows:
Quit : finishes the game
Music On/Off : tweaks the music flag, though no music is currently implemented
Inventory: enters the Inventory scene (which cannot be saved)
User Save/Restore : uses 4 possible local files to save/restore any position
 also:
Android Save/Restore :  to deal with situations where Android OS does something outside the game's control - e.g. Change orientation; Pull a different Activity into foreground; Destroy game for lack of resources.
In this case,  the game saves its current position with the Android's own memory of the game, and restores it when the game is restarted.

All tested on both the PC-based emulator and on a Xoom device.

Thursday 21 June 2012

Save and Restore

I think I've done all the necessary stuff for life-cycle save and restore. Tests so far are encouraging, but there are a number of life-cycle incidents I'm not able readily to reproduce on the emulator. It'll take a test on real hardware to make me comfortable.

Next task is doing the user save / restore options. Then I'll implement the QUIT function.

Thursday 14 June 2012

The GUI

Now implemented the skeleton of the "Settings" menu. The Pause/Restart works, as do the Inventory entry/exit and Music on/off.



Still to do in Settings - Save, Restore.

Tuesday 12 June 2012

Scale, Flip and Mirror on Sprites

Wow! That was easy.

The following snatch of code takes image im and transforms it to scaledbitmap.
 scale (x and y values) are based on 100 as full size.
flip x and y values are either 1 or -1.
 1,1 means as original bitmap
-1, 1 means mirrored in the y axis
1, -1 means flipped on the x-axis
-1, -1 means mirrored on both axes - i.e. inverted
 
// scale image before return
Matrix matrix = new Matrix();
// scale and flip
matrix.postScale((float)flip.x*scale.x/100, (float)flip.y*scale.y/100);
// create a new bitmap from the original using the matrix to transform the result
Bitmap scaledbitmap = Bitmap.createBitmap(im , 0, 0,
           im.getWidth(), im.getHeight(), matrix, true);
return scaledbitmap;  

Monday 11 June 2012

The GUI

Having further considered the matter of the GUI, I've decided to base it all on sprites, rather than a special screen. It is probably neater, and certainly more efficient. So another carefully designed backdrop hits the wastebin.



So, what's still to do?
  • Scale, flip and mirror on sprites;
  • Cursor;
  • More detailed touch control;
  • Pick-up and drop;
  • The save / restore for Android OS operations. The game has to be revivable if it is re-oriented, de-focussed etc. by the user.  It's an Android preoccupation;
  • Similarly, and, I hope, using the same compression technology, the user save / restore;
  • Music,which I hope to implement by using the built-in MP3 player;
  • The Jade game itself, for which I have a lot of scenery and virtually no plot;
  • The various delivery activities to get it to Beta Test and Android Market.
In short, still a lot to do, but the worst is over, I think. Actually getting a limp-mode game on screen has been an achievement. This time, as opposed to the original applet-based software, I've compartmentalised the code so that it will be easy to expand the game, or even base another game on the same engine.

Saturday 9 June 2012

Progress to Date

Well, where am I?
  •  Scaling for whatever size of playfield is available works perfectly.
  • After pestering with invalidateRect() for weeks to deal with the "dirty" rectangles on the screen, and finding it doesn't work the way I expected, I now just repaint the whole playfield (the image part of the View) every tick. In tests, both on emulator and Xoom, it's fast enough, even with a couple of active sprites. My ticks are approximately 18/second;
  • I can detect a touch in various aspects;
  • I can click a sprite and change screen, I've dealt with the problem of re-entrant popscreens;
  • I'm wrestling with the GUI concept. Basically, there's an icon on every screen, which, if clicked, takes you to an options screen where you can choose to select the inventory screen, quit, save, restore or switch the music on and off (the music is not yet incorporated);
  • I can display moving sprites (the gulls in the illustration below) with multiple (24, in this case) images.

Tuesday 29 May 2012

Scaling and Displacement

Scaling and displacement are tricky areas. The old browser-based Java engine could use absolute values for background and sprite size. Everything was based on a 640 x 480 playfield starting at position 0,0, with appropriately sized sprites, and sprite / zone positions locked to the 640 x 480 setup.

With the multi-platform Android version, any given game background size need not be based on 640 x 480, but may take any rectangular size. In addition, the eventual playfields can be many sizes and usually will not not start at position 0, 0. Sprites will be scaled and their position on the screen scaled appropriately. Touch positions will be similarly displaced.


All collisions, zone effects, sprite movements and other screen events will be computed in the program on a game model which is at the basic background dimensions.

So, for drawing and detection of user touch, all positions, including background, sprite positions, dirty rectangle positions and touch positions, we have to make a transformation.

Rule 1. All images are pre-transformed to the correct scale. (This to save processing time during animation)

Rule 2. All position calculations are initially made on the base dimensions of the background playfield and proportionate sprite positions, and are only resized and displaced at draw time.

Rule 3  All touch co-ordinates are similarly transformed to base positions (by rescaling in reverse and subtracting the displacement) before being applied to the base model.

For example, the background. In any given scene, the background image does not vary. It is efficient to scale the image at the outset of the scene. Once scaled, and its displacement from position 0,0 determined, it can be drawn, in whole or in part, without having to scale the bitmap every time.


Similarly, sprite images will be resized, but all dimensions and positions will be reported to the base game model on the (in this case) 640x480 basis.

The actual placement and size of the sprite will be deternined in the draw stage.

There is a slight complication. Sprites can be scaled, flipped and mirrored , and this is done prior to the general scaling transformation.

It's not really so complex. Is it?


Sunday 20 May 2012

A Little More Progress

I can't see very much more that needs to be saved - the current scene is the major factor.

Just mopping up some of the display manager functions, and checking out thread behaviour for the timer.

Saturday 19 May 2012

More Struggle

Google is keen to get to know me and help out. Perhaps they could improve their user interface on this Xoom.

Anyway, I've made a little progress with the game but I don't want to go too far without testing my changes on the emulator which I can't do right now.

re. Bundle management

For simplicity, it's best if the game restore string for orientation is the same structure as the optional game save file that's stored locally.

Therefore, I am not going to make use of the Key:value pair structure in the Bundle except to label the whole save string.

In addition, since the game may be updated/altered, the save string must always be forwards/backwards compatible.

Must watch out for possible duplicate keywords e.g. spritename/scenename both called "pause"; imagenames will often be the same as sprite/scene names. Partially identical names in the savestring could also be problem, as we search it for spritenames among other things. Perhaps all keywords in the string should be uppercase and preceded by a type letter. e.g. S for sprite, R for scene(room), G for general state markers.

re. Scene alteration

Mostly, changed or additional zones with new destinations. Occasionally, delete zone. Sometimes, different image(s) or music.

So, for any alteration - like an open door with a new exit, we just have a key in the save string that causes us, on restore, to call a method in JadeData which makes the alteration.

Thursday 3 May 2012

Unecessary Struggle

I found that all the menu items on this blog had been rendered into Greek, and simultaneously my bluetooth keyboard malfunctioned, so wasted some time, but the good news is that I made useful inroads into Save and Restore both for users and for Androidy purposes.

Wednesday 25 April 2012

A Few More Topics


Coding:
  • Background transitions: It should be easy to slide one background over another, one doDraw() at a time.
  • Sprite scale, flip and mirror: Must do some experiments with this, but it looks as if a single bitmapFactory call with a suitable matrix could do the whole modification on a Sprite  image.
  • onPause and onResume: A save string could be attached to the Bundle, just to restore the current state. The deliberate saves (by User) would use the same save string format, but stored in a local file.
Game:
  • Lighting the Rocket: A candle in a cave.

Monday 23 April 2012

More Design

Showing the limp mode version to a friend yesterday alerted me to the fact that I ought to centralise the image in the view. No problem. Just a displacement in the x or y axis of the destination.

There will also be a need for cutting off a portion of any sprite that strays across the background boundary.

Both of these can be handled in the doDraw portion of the code.


--------------------------

Some scenes will be labelled "no popscene", eg Inventory, save, limbo.

---------------------------

Design suggestion: So that we don't need to use text to label the various saves, icons of jade Chinese horoscope characters  (eg dragon, tiger, ox, monkey) will be used.

Sunday 22 April 2012

Quick Design Points

Decision 1:

Sprite images will be collected full size. On scale change in the sprite, they will be re-scaled in the sprite's image list.

Decision 2:

View scaling will be done at doDraw time. After all, it's only one rescale per sprite.

Thursday 19 April 2012

Some Decisons

Wrestling with the Rect (x1, y1, x2, y2) versus Rectangle (x1, y1, width, height), I eventually decided there'd be less code wasted by going over to the Rect as standard, particularly appropriate for Zones, and making the position (x1, y1) and size (width, height) of the Sprite as Points.

Another decision is that Sprite position will be the position of the Sprite centre.

When to scale the Sprite image(s) for screen size? This should be done at scene change, not "just in time".

There is also a scale factor for Sprites which is independent of screen size, and can happen during a scene. This should be done "just in time".

The new Pause facility will act like an Inventory scene, with all the features previously supplied by Javascript buttons - music, save/restore, Inventory.

Wednesday 18 April 2012

Optimism

Really making progress with Jade now. After a successful limp mode with background and moving partially transparent sprite, which readjusted and restarted on orientation, I was confident enough to bring in a lot of the Bridge code. A few matters giving me grief right now:
  • The difference between Android Java's Rect class and the Java Rectangle class;
  • The fact that the cursor is going to have to be a sprite;
  • How to implement flip and mirror- will Android Java accept a back-to-front or upside-down Rect as a parameter in canvas.drawBitmap? To be tested.

Thursday 12 April 2012

Breakthrough

After remaining baffled for a while that I couldn't get my Android Jade app to display anything, I discovered:
  • by a roundabout route, without ever finding out what had been wrong, how to display and change a background of a different size to the original image;
  • how to move a sprite over it (with transparency);
  • how to detect touches and flings on the touch screen;
  • how to detect and compensate for changes in orientation;
  • how to superimpose a diagnostic display.
I now, therefore, have a framework on which to build the various functions from Bridge. The apk (application package) even works on the Xoom.

Wednesday 4 April 2012

Still Struggling

I am now seriously planning Jade, as the Android version of Bridge will be called, and here are a few of the considerations I've been working with.

Contrary to my previous assumption, I think quite a lot of Bridge code will transfer across to Jade.

It appears that most graphics Android apps consist of a kind of basic Activity, and a separate Class, a subclass of View, for the work and the display. I'm currently wondering whether I should do the same, and include all the Sprite / Scene / Data Management etc. classes within the View subclass. I'm revising scoping rules etc.

I was originally planning to put the initialise data in an xml file, but I now feel that my BridgeData class is actually more efficient, involving less iteration and parsing at startup and restart.

I found the Vector class very handy in Bridge, but I guess it's time to use these smart list classes.

I shall retain the off-screen buffer model from Bridge, do all the original artwork at full size, do vector movement etc. off-screen, then blit it into the View canvas when it's done. So at each screen size and each orientation, I'll calculate suitable View dimensions. Then I'll leave it to Java to scale the OSB to the actual screen. This is instead of doing the screen construction inside a Thread.

As for the GUI, there will be a "Jade" button (actually a Sprite) on every screen. Touching it will pause the game and allow the user to make various choices (it will actually be a virtual scene, like Inventory and Limbo). Choices include music, save, restore.

There will be differences in the cursor and carrying GUI, due to touch rather than mouse screens.

I think I can retain the cookie format of save data.

Tuesday 6 March 2012

Getting started with Android

It's hard to find a really appropriate example on which to base Jade, but I today managed to write a tiny program that draws one of my backgrounds.

Thursday 1 March 2012

Is it REALLY eight months?

It's not that I haven't done anything since last July. For a month or so, I built scenes for the Junk voyage. But then... I discovered Android, in the form of a Motorola Xoom, and I'm looking seriously at mounting the adventure on an Android base.

A development system and three books downstream, I still haven't written a line of code. Actually, although Android coding is mostly in Java, there's very little of the existing code that I'll be able to use.