5/29/2009

Shop guy


Some art done for the store guy. His arm kinda looks weird..

店のおやじの絵描いたで。腕変になってんちゃうますのん〜。

5/28/2009

Custom icon in UITableViewCell

Added icons by the items to indicate the item category such as weapons, armors, items, etc.
API made it really easy to do this.

アイテムの左側にアイテムジャンル(武器、防具など)を表示するアイコンを設置。ものすごく簡単にできる。

Inside this method in your UITableViewController:


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


...put this:


UIImage *aIconImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"some_image" ofType:@"png"]];
cell.imageView.image = aIconImage;

5/27/2009

UIImageViewController


Getting images from your photo library is as easy as about... 10 lines of code. I was pretty impressed how the API made it so easy. I'm putting in some player profile picture feature in there.

写真アルバムから写真をゲットすんのにめちゃくちゃ簡単なことにびっくり。
ステータスに自分の写真を入れれるようにした。


@interface StatusViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {



- (IBAction)showImagePicker:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate = self;
imagePickerController.allowsImageEditing = YES;
[self presentModalViewController:imagePickerController animated:YES];
[imagePickerController release];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissModalViewControllerAnimated:YES];
}

Getting things done...

Just did a little today, just getting little detailed things done like coming up with standard button size for the entire game, etc. I'm also going to add image picker for player's character, so the player can shoot and choose their own character's picture.

今日はちょっとだけ進んだ。ボタンのサイズを統一など、細かいところを修正。プレイヤーが写真アルバムから自分のキャラクターを選べるようにするリサーチを。めっちゃ簡単にできるみたい。

5/26/2009

Rest, treasure chest, etc.

Tons of little things done. Now resting is possible in an empty room, and there's chances you'll find a treasure chest. Still only know about 90% of the retain, copy, release business.

いっぱいできた。空の部屋で休むことが可能。宝箱も見つかることもあるかも。またメモリー関係の自分のバグで足を止められる。retain, copy, releaseがまだ90%しかわかってないかな。

5/25/2009

Some math for the first time!

I've never had to use more than arithmetic in before, but today I had to use arc cosine for the first time.
I'm drawing a line that from point A to point B, and below is the equation I had to use. Awesome stuff.

今日生まれて初めてプログラミングでコサインを使った。線をかくのに必要。


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.view];
float deltaX2 = originalPoint.x - currentTouchPosition.x;
float deltaY2 = fabsf(originalPoint.y - currentTouchPosition.y);
float c = sqrt( pow(deltaY2,2) + pow(deltaX2,2));
float radian = acos( (deltaX2 / c ) );
if(originalPoint.y < currentTouchPosition.y) radian = -radian;
CGAffineTransform transformRadian = CGAffineTransformMakeRotation(radian);
theSlash.transform = transformRadian;

...

5/24/2009

Run button working

Now I can run away from the monsters. Also, depending on which floor and room you are on, the encounter situation changes to battle, shop, NPC, empty room, etc. I have yet to implement the NPC part.

モンスターから逃げれるようになった。フロアと部屋によって違うエンカウンターあり。宝の山の部屋とかあれば嬉しいな。

5/23/2009

Next floor...

Now I can go to next floor, but the buttons and the stairs image won't disappear. I need to removeFromSuperview somewhere.

次のフロアへ行けるようになった。階段の絵とボタンが消えないのでどこかでremoveFromSuperviewを呼ばないと。

5/22/2009

Added system button

Now all the buttons on the bottom, Item, Status, System, are placed appropriately. I might add Skill/Magic or something like that later on. I found a bug where a subclassed UITextView does not receive the touchesEnded method. The bug has been filed by other guy at the developer's forum.

アイテム、ステータス、の二つのボタンに一つ追加したのがシステムボタン。戦闘中メッセージスピードの調節をしたりメニューに戻れるようにする。メニューに戻った際にはmemory leakが大変。UITextViewをサブクラスしたときにtouchesEndedが呼ばれないバグを発見。デベロッパーフォーラムで誰かがバグをリポートしてた。バグってまだまだあるんやねぇ。

Object allocations / memory leak


I've been fighting this almost all day today. It seems like it's not deallocating my game object correctly. After every battle, my game allocates extra 1MB as you can see in the picture. My allocation is like a stairway. How do I fix this...

一日中苦戦。戦闘の1ラウンド終わるたんびに1MB分ぐらいのオブジェクトが階段のごとくallocateされてる。もはやこれまでかー!何があかんのかなぁ。

UIImage cache or not to cache

There are different ways to display images. Cached or not cached. Apple employee at the forum said NOT to use the cache way, which is the + (UIImage *)imageNamed:(NSString *)name method in UIImage.
UIImageで絵をロードする時はキャッシュするやり方、 (UIImage *)imageNamed:(NSString *)name 、よりしないやり方のほうがいいらしい。

NSString *aFilePath = [[NSBundle mainBundle] pathForResource:@"mypicture" ofType:@"png"];
UIImage *aImage = [UIImage imageWithContentsOfFile:aFilePath];
UIImageView *aImageView = [[UIImageView alloc] initWithImage:aImage];

5/21/2009

Testing on device

This is my first time testing this app on my iPhone. I've waited because I was afraid I wouldn't be able to use the apps that I had on my iPhone OS 2.2.1, I couldn't downgrade. I had to upgrade my SDK to the latest beta, which caused a little change but fixed it in 15 minutes. It's working nicely on my iPhone now, it looks good.

iPhoneにインストールしてテスト。iPhone 2.2.1にダウングレードできないためちょっとためらいがあったけど、とりあえずはうまくいってるようなので一安心。間違って今まで撮ってた写真を全部消去してしまい、オウマイガ。はっはっは、笑ってすませようやないかぁ。

5/20/2009

Bug found in Cocoa Touch

I can use Potion after battle now. Fixed two bugs.
In UITableView, when you swipe a row, the "Delete" comes up. But then you can't select any of the rows afterwards. The code below fixes the problem. Forums and Google is always my friend. :)
戦闘後でもポーションが使えるようになった。2つのバグ修正。UITableViewで行をスワイプすると「解除」ボタンが表れる。その後にビューがまったく反応しなくなる。解決は下。フォーラムとグーグル様々です。m(_ _ )m


myTableView.alwaysBounceVertical = NO;
myTableView.scrollEnabled = YES;

5/19/2009

Problem solved...

The problem I had last night was solved in like 5 minutes today. I guess you can't think right when you are tired. Eat well, play well, work well, sleep well.
昨日悩んでた問題が5分ぐらいで解けた。なんじゃいー。やっぱり疲れてると集中力や思考能力が下がる。よく食べてよく遊んでよく働いてよく寝よう。

Battle: Item usage

Items can be used during battle, but you cannot change equipment. I'm having problem using up the turn when the player uses the item. It sounds like a simple thing! UIAlertView is so handy. I wish I could customize the design though.
戦闘中のアイテムの使用はできるようになったけど、ターン終了がうまくいかない。UIAlertViewは使えるがデザインをカスタマイズできないのが残念。

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"This is UIAlertView" delegate:nil cancelButtonTitle:@"OKotherButtonTitles:nil];
[alert show];
[alert release];

5/17/2009

This page is so narrow..

I was looking for a simple design like this but with more width template than this one. I don't have time to make my own template.
Update: Ended up fixing it myself. I might have wasted my time.. This area was only 435px, so small!
もっと幅のあるテンプレートないんすかね。こういうシンプルなデザインがいいんやけど。
更新:やっぱり自分で幅を変えた、と。いらん時間ついやしたな。。

5/16/2009

Battle, base done

Now I can attack monsters, defeat them, and move on to next room. No concept of rooms yet though. Players are still gods, can't die. XP and gold obtained after battle. I put some dummy sounds and music. Sure adds flavor to the game.
一通り攻撃だけでバトルができるようになった。敵は倒せるがプレイヤーはまだ無敵。アイテムも使えるように準備。XPとGoldゲット。音量コントロールもできるようにした。ダミーのサウンドと音楽も設置。

5/15/2009

LanguageManager class

So I ended up writing my custom class called LanguageManager, which just holds all the strings that need to be translated and returns the strings.


LanguageManagerというクラスでlocalizationをすることに決定。オプションメニューでスイッチできるようにしたいので、アップルの自動的に認知するやつは使えなかった。


[LanguageManager translate:@"Start"];



+ (NSString *)translate:(NSString *)aString {
Settings *gameSettings = [Settings getInstance];
if (gameSettings.languageSettings == 0) return aString; // if user setting is English
if (gameSettings.languageSettings == 1){ //if user setting is Japanese
if(aString == @"Start") return @"スタート";
if(aString == @"Continue") return @"コンティニュー";
...


I wonder if there's any better way...
これでいいんかいな。

5/14/2009

Localization research

I've figured out how to do localization for the game before, but I wanted it so users (or me) can switch the language on the fly instead of going to the iPhone Settings.
完璧にlocalizationをする方法をサーチ。iPhoneの設定でやるより自分のアプリ内でやりたいしね〜。ほぼ自分のため。iPhone自体は英語で使いたくて、ゲームは日本語でしたいのです。

Some helpful links:

http://www.iphonesdkarticles.com/2008/11/localizing-iphone-apps.html

http://www.bdunagan.com/2009/03/15/ibtool-localization-made-easy/

http://developer.apple.com/documentation/MacOSX/Conceptual/BPInternational/Articles/InternatAndLocaliz.html#//apple_ref/doc/uid/20000277


To get what language the user is using:
ユーザーが何語を使ってるか:


NSArray *languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
NSString *currentLanguage = [languages objectAtIndex:0];
NSLog(@"Current Locale: %@", [[NSLocale currentLocale] localeIdentifier]);
NSLog(@"Current language: %@", currentLanguage);
NSLog(@"Welcome Text: %@", NSLocalizedString(@"TitleKey", @""));

5/13/2009

Battle coding...

I think the battle system is working OK even though the code is very ugly... The more agility you have, the more attack you do.
バトルのコードはきれいじゃないけど、うまくいってる気がする。Agilityを100を超すとアタック。1ラウンドで100を超すと何回も攻撃するorされるシステム。素早さが命になるときもある。

This code would've saved me a million times if I knew this earlier... Often times, I need to execute something after X seconds.
これをもっと早くに知ってればどんだけ助かったことか。。X秒後に何か命令させるのを今までNSTimerでやってました。はっはっは。(T▽T)

[self performSelector:@selector(battle02:) withObject:NO afterDelay:1];

5/12/2009

NSThread, NSTimer

I need a good way to display these battle messages with little delay like 1 second. NSThread and NSTimer were my options. It seems to be working.
NSThreadとか見てみるけど、「◯◯の攻撃!」「◯○のダメージ!」というふうに1秒の間を作ってみる。NSTimerでやってみた。うまくいきそう。


NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSThread sleepForTimeInterval:0.3];
// do stuff here
[self performSelectorOnMainThread:@selector(addToBattleTextView:) withObject:aString waitUntilDone:NO];
[pool release];

5/11/2009

Battle system

Brainstorming for battle system. How should it decide who attacks first. When one reaches 100 agility.
Agilityが100を超すと、攻撃ができるというシステムにしてみる。

5/10/2009

Battle message: UITextView

Using UITextView for displaying battle message that scrolls. "Encountered enemies!" is the first one.
スクロールする戦闘メッセージにUITextViewを設置。「モンスターがあわられた!」が出てくるようになった。

5/09/2009

1 to 7 monsters

Successfully chose and displayed the 1 through 7 monsters, skipping 5.
5匹の時はスキップして、1から7匹うまく出てきた。

5/07/2009

Monster array

I guess I was having trouble displaying them on the screen with arbitrary numbers.
1から7匹出てくるモンスターをうまく画面に表示させるロジックが思いつかない。

More monsters

I forgot what I worked on about monsters haha.
何やったか忘れた。はっはっは。

5/06/2009

Monster encounter!

Now the player encounters monsters! But can't do anything yet...
モンスター出現!でもまだ闘えず。。

5/05/2009

NSKeyedUnarchiver

Using NSKeyedUnarchiver to save player data and item data as an alternative to NSUserDefaults. I've read that NSUserDefaults isn't the best for storing huge amounts of data. Actually, the reason I migrated to NSKeyedUnarchiver is because I couldn't save some object or an array using NSUserDefaults. Now I can save the items I've purchased from the store. Learned how to use enum.
プレイヤーデータ、アイテムデータなどはNSUserDefaultsじゃなくてArchiverでセーブ。買ったアイテムをセーブできるようになった。enumの使い方もおぼえた。



theData = [NSData dataWithContentsOfFile:dataFilePath];
decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:theData];
Player *tempPlayer = [decoder decodeObjectForKey:@"playerData"];


- (void)savePlayerStateBeforeTerminate {
Player *player = [Player getInstance];
Player *tempPlayer = [[Player alloc] init];
tempPlayer = player;
NSMutableData *theData;
NSKeyedArchiver *encoder;
theData = [NSMutableData data];
encoder = [[NSKeyedArchiver alloc] initForWritingWithMutableData:theData];
[encoder encodeObject:tempPlayer forKey:@"playerData"];
[encoder finishEncoding];
[theData writeToFile:dataFilePath atomically:YES];
[encoder release];
}


Player.m

- (id)initWithCoder:(NSCoder *)decoder
{
playerLevel = [decoder decodeIntegerForKey:@"playerLevel"];
playerFloor = [decoder decodeIntegerForKey:@"playerFloor"];
playerRoom = [decoder decodeIntegerForKey:@"playerRoom"];
...
return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {
//[super encodeWithCoder:coder];
[coder encodeInt:playerLevel forKey:@"playerLevel"];
[coder encodeInt:playerFloor forKey:@"playerFloor"];
...
}

5/03/2009

Shop and Item window done

They are located in the bottom screen, it slides up smoothly when you tap it. You can sort and delete the list also with the now familiar user interface Apple came up with. Weapon and armor now equippable.
ショップとアイテム画面が完成。アイテム画面ではsort/deleteもできる。武器と防具の装備も設置。

5/01/2009

UITableViewController and copy, hooray!

Managed to use UITableViewController alright. I understood the concept of the copy method. I needed to copy the object with a new pointer from the items list. Before, I was just copying the pointer. It took me 3 hours of research how to copy object properly.
UITableViewControllerうまくいった。newItem = [aItem copy]しないとだめと気づく&リサーチで3時間ぐらいかかった。


- (id)copyWithZone:(NSZone *)zone {
id aCopy = [[[self class] alloc] init];
[aCopy setItemAbundancyPercent:[self itemAbundancyPercent]];
[aCopy setItemPrice:[self itemPrice]];
[aCopy setItemCategory:[self itemCategory]];
[aCopy setItemName:[self itemName]];
[aCopy setItemWeapon:[self itemWeapon]];
[aCopy setEffectPower:[self effectPower]];
[aCopy setItemAttributeNumber:[self itemAttributeNumber]];
[aCopy setItemDescription:[self itemDescription]];
[aCopy setIsEquipped:[self isEquipped]];
return aCopy;
}