cocos2d-iphone之魔塔20层第五部分
这一章我们就要开始在Game01.m文件中canMoveTo: 方法中的if循环中添加相应的事件了,我在制作地图时图块都设置了其属性如图:
这里我就要获取其属性值
[html]
NSDictionary *props = [self.curtitleMap propertiesForGID:enemy_tileGid];
NSString *value = [props valueForKey:@"enemy"];
int type = [value intValue];
通过获取到的属性值来判断是那一类怪物,这里还得再添加两个类Enemy 和 Monster
为了有重点的讲解这里我就先不介绍这两个类了。代码如下:
Enemy.h代码
[html]
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@inte易做图ce Enemy : CCSprite<NSCopying>
{
}
//怪物编号
@property (nonatomic,assign) int enemyID;
//怪物名
@property (nonatomic,retain) NSString *name;
//血量
@property (nonatomic,assign) int HP;
//攻击
@property (nonatomic,assign) int Attack;
//防御
@property (nonatomic,assign) int Defense;
//金币
@property (nonatomic,assign) int Coin;
//经验
@property (nonatomic,assign) int Experience;
//怪物行走动画
@property (nonatomic,retain) CCAnimation *walkAction;
-(Enemy*) initWithEmeny:(Enemy*) copyform;
@end
Enemy.m代码
[html]
#import "Enemy.h"
@implementation Enemy
@synthesize enemyID;
@synthesize name;
@synthesize HP;
@synthesize Attack;
@synthesize Defense;
@synthesize Coin;
@synthesize Experience;
@synthesize walkAction;
-(id) copyWithZone:(NSZone *)zone
{
Enemy *copy = [[[self class] allocWithZone:zone] initWithEmeny:self];
return copy;
}
-(Enemy*) initWithEmeny:(Enemy *)copyform
{
if ((self = [super init]))
{
self.enemyID = copyform.enemyID;
self.name = copyform.name;
self.HP = copyform.HP;
self.Attack = copyform.Attack;
self.Defense = copyform.Defense;
self.Coin = copyform.Coin;
self.Experience = copyform.Experience;
self.walkAction = copyform.walkAction;
}
return self;
}
@end
Monster.h代码
[html]
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "Enemy.h"
@inte易做图ce Monster : Enemy
+(id)initWith:(int)typeID;
@end
Monster.m代码
[html]
#import "Monster.h"
@implementation Monster
+(id)initWith:(int)typeID
{
CGRect Rect;
Rect = CGRectMake(0, typeID*32, 32, 32);
Monster *enemy = nil;
NSString *name;
int HP,Attack,Defense,Coin,Experience;
if ((enemy = [[[super alloc] initWithFile:@"enemy.png" rect:Rect] autorelease]))
{
switch (typeID)
{
case 0:
name = @"骷髅兵1";
HP = 110;
Attack = 25;
Defense = 5;
Coin = 5;
Experience = 4;
break;
case 1:
name = @"骷髅兵2";
HP = 150;
Attack = 40;
Defense = 20;
Coin = 8;
Experience = 6;
break;
case 2:
name = @"骷髅队长";
HP = 400;
Attack = 90;
Defense = 50;
Coin = 15;
Experience = 12;
break;
case 3:
name = @"冥队长";
HP = 3500;
Attack = 1280;
Defense = 1000;
Coin = 112;
Experience = 100;
break;
case 4:
name = @"小蝙蝠";
HP = 100;
Attack = 20;
Defense = 5;
Coin = 3;
Experience = 3;
break;
case 5:
nam
补充:移动开发 , 其他 ,
- 更多wap疑问解答:
- 新人求助QPainter
- 为什么程序都退出了还可以收到推送?如果大多设备都可以推送那运营商怎么办?
- qt 4.7 sqlserver2000 存储过程调用
- 关于ANDROID4.0.1编译问题!
- Android FrameBuffer读屏幕30秒后mmap失败
- 联通粗定位用java程序如何来请求和接受数据
- 为什么QT运行Android平台的程序时,mouseMoveEvent事件响应的间隔时间很长??????????
- android与PC蓝牙通讯
- 指定大小的label 内容可变,如果内容超出label的宽度,将未能显示的部分显示在另一个label上
- Android调试
- android如何通过wifi连接无线打印机
- 运行程序,release目录下产生一个乱码文件夹
- 分享个某机构最新安卓资料,自己验证了
- service启动不起来,掉不了service connection
- 求助:QT5.0 没有QPrinter吗