public virtual JumpObject AddJumpObject(float x, float y, float w, float h, Animation a) { JumpObject o = null; if (indexTile != null) { o = new JumpObject(x, y, w, h, a, indexTile); } else if (tiles.Count > 0) { o = new JumpObject(x, y, w, h, a, tiles[0]); } else { return(null); } Add(o); return(o); }
public virtual JumpObject AddJumpObject(float x, float y, float w, float h, Animation a) { JumpObject o = null; if (indexTile != null) { o = new JumpObject(x, y, w, h, a, indexTile); } else if (tiles.Count > 0) { o = new JumpObject(x, y, w, h, a, tiles[0]); } else { return null; } Add(o); return o; }
public void Use(JumpObject hero) { hero.SetJumperTwo(true); }
public override void Create() { // 以指定图片创建动画 this.coinAnimation = Animation.GetDefaultAnimation("assets/coin.png", 32, 32, 200); this.enemyAnimation = Animation.GetDefaultAnimation("assets/enemy.gif", 32, 32, 200, LColor.black); this.accelAnimation = Animation.GetDefaultAnimation( "assets/accelerator.gif", 32, 32, 200); this.jumpertwoAnimation = Animation.GetDefaultAnimation( "assets/jumper_two.gif", 32, 32, 200); // 注销Screen时释放下列资源 PutReleases(coinAnimation, enemyAnimation, accelAnimation, jumpertwoAnimation, hero); // 加载一张由字符串形成的地图(如果不使用此方式加载,则默认使用标准的数组地图) TileMap indexMap = TileMap.LoadCharsMap("assets/map.chr", 32, 32); // 如果有配置好的LTexturePack文件,可于此注入 // indexMap.setImagePack(file); // 设定无法穿越的区域(如果不设置此项,所有索引不等于"-1"的区域都可以穿越) indexMap.SetLimit(new int[] { 'B', 'C', 'i', 'c' }); indexMap.PutTile('B', "assets/block.png"); int imgId = indexMap.PutTile('C', "assets/coin_block.gif"); // 因为两块瓦片对应同一地图字符,所以此处使用了已载入的图片索引 indexMap.PutTile('i', imgId); indexMap.PutTile('c', "assets/coin_block2.gif"); // 加载此地图到窗体中 putTileMap(indexMap); // 获得地图对应的二维数组 int[][] maps = indexMap.GetMap(); int w = indexMap.GetRow(); int h = indexMap.GetCol(); // 遍历二维数组地图,并以此为基础添加角色到窗体之上 for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { switch (maps[j][i]) { case 'o': Coin coin = new Coin(indexMap.TilesToPixelsX(i), indexMap.TilesToPixelsY(j), new Animation( coinAnimation), indexMap); AddTileObject(coin); break; case 'k': Enemy enemy = new Enemy(indexMap.TilesToPixelsX(i), indexMap.TilesToPixelsY(j), new Animation( enemyAnimation), indexMap); AddTileObject(enemy); break; case 'a': Accelerator accelerator = new Accelerator( indexMap.TilesToPixelsX(i), indexMap.TilesToPixelsY(j), new Animation( accelAnimation), indexMap); AddTileObject(accelerator); break; case 'j': JumperTwo jump = new JumperTwo(indexMap.TilesToPixelsX(i), indexMap.TilesToPixelsY(j), new Animation( jumpertwoAnimation), indexMap); AddTileObject(jump); break; } } } // 获得主角动作图 Animation animation = Animation.GetDefaultAnimation("assets/hero.png", 20, 20, 150, LColor.black); // 在像素坐标位置(192,32)放置角色,大小为32x32,动画为针对hero.png的分解图 hero = AddJumpObject(192, 32, 32, 32, animation); // 让地图跟随指定对象产生移动(无论插入有多少张数组地图,此跟随默认对所有地图生效) // 另外请注意,此处能产生跟随的对像是任意LObject,并不局限于游戏角色。 Follow(hero); // 监听跳跃事件 hero.listener = new JumpI(indexMap, enemyAnimation); AddActionKey(Key.LEFT, new GoLeftKey()); AddActionKey(Key.RIGHT, new GoRightKey()); AddActionKey(Key.UP, new GoJumpKey()); if (LSystem.type != LSystem.ApplicationType.JavaSE) { LPad pad = new LPad(10, 180); pad.SetListener(new PadClick(this)); Add(pad); } this.updateListener =new GameUpdateListener(this); }
public void Use(JumpObject hero) { hero.SetSpeed(hero.GetSpeed() * 2); }