Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Tuesday, 23 April 2013

New Problem

I found a problem which occurred at the exit part of the application. The application did not fully exit when I pressed the back button, and when I pressed back to the app, it displayed the previous page when I exit the application. Therefore, I found a script online and it worked well to solve the problem. I had tested this on my phone as well.


Script
if(Capabilities.cpuArchitecture==”ARM”){
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true); NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true); NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
}
function handleActivate(event:Event):void
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
function handleDeactivate(event:Event):void
{
NativeApplication.nativeApplication.exit();
}
function handleKeys(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.BACK) {
NativeApplication.nativeApplication.exit();
}
}

Sunday, 21 April 2013

Game Development 2 - Pair Game

I found a new script for the matching card game, and it worked well on the frame after a little bit of tweaking the code. However, there is still an error when I tried clicking back to the previous page with the game on page 4 displayed, but cannot be disabled when going back to the previous page or the next page. Since the problem still occurs, therefore I keep going back to the old script to make the tile disappear when the same tiles are matched. I put the solution behind the game after the game is played. I put in a movieclip to show the arranged new duty roles for each characters. 

I still try my best to solve the problem although I had plan B for it.

Thursday, 18 April 2013

Animation and Coding

I am currently working on the animation and game coding. I keep testing it on my phone when I am half done with it so that I can find any bugs or problems and fix them earlier. I found out that there is a minor error which is fortunately easy to solve. While doing this, I went to hunt for background music to suit my ebook and some sound effects to go together with the animation and games.

The first game went well, but the problems lie in the second game. This is because the second card game uses OOP and Actionscript file to call into my file. But it appeared in every frame, while it only needs to be on a certain frame. So I went online to look for the solution and hope that it will work out well. I tried very hard but to no avail, even trying different ways to solve the problem but nothing worked out. So I resorted to another script which is shown below:


Matching Card Game

Script


package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class color_match extends Sprite {
private var first_tile:colors;
private var second_tile:colors;
private var pause_timer:Timer;
var colordeck:Array = new Array(1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8);
public function color_match() {
for (x=1; x<=4; x++) {
for (y=1; y<=4; y++) {
var random_card = Math.floor(Math.random()*colordeck.length);
var tile:colors = new colors();
tile.col = colordeck[random_card];
colordeck.splice(random_card,1);
tile.gotoAndStop(9);
tile.x = (x-1)*82;
tile.y = (y-1)*82;
tile.addEventListener(MouseEvent.CLICK,tile_clicked);
addChild(tile);
}
}
}
public function tile_clicked(event:MouseEvent) {
var clicked:colors = (event.currentTarget as colors);
if (first_tile == null) {
first_tile = clicked;
first_tile.gotoAndStop(clicked.col);
}
else if (second_tile == null && first_tile != clicked) {
second_tile = clicked;
second_tile.gotoAndStop(clicked.col);
if (first_tile.col == second_tile.col) {
pause_timer = new Timer(1000,1);
pause_timer.addEventListener(TimerEvent.TIMER_COMPLETE,remove_tiles);
pause_timer.start();
}
else {
pause_timer = new Timer(1000,1);
pause_timer.addEventListener(TimerEvent.TIMER_COMPLETE,reset_tiles);
pause_timer.start();
}
}
}
public function reset_tiles(event:TimerEvent) {
first_tile.gotoAndStop(9);
second_tile.gotoAndStop(9);
first_tile = null;
second_tile = null;
pause_timer.removeEventListener(TimerEvent.TIMER_COMPLETE,reset_tiles);
}
public function remove_tiles(event:TimerEvent) {
removeChild(first_tile);
removeChild(second_tile);
first_tile = null;
second_tile = null;
pause_timer.removeEventListener(TimerEvent.TIMER_COMPLETE,remove_tiles);
}
}
}

This source is found online :http://www.emanueleferonato.com/2008/05/02/creation-of-a-matching-game-with-flash-and-as3/


Although it is an Actionscript file, it is much easier to refined compared to the previous version I had.