【教程】使用BitmapData来管理和进行纸牌游戏

导读:
  I have already published a tutorial about BitmapData in the post Shuffle an image with BitmapData, but this time I want to show you how to manage a deck of cards using BitmapData.
  Managing a deck of cards is very useful because there are tons of card games you can publish once you have a deck of cards in your library.


我在前面的教程中曾讲过如何使用bitmapdata来洗牌,这回我要向大家展示的是,如何使用这个类来管理一堆的卡片


管理一堆的卡片式很有用的事情,因为库里有了这个之后,你就可以制作任何的卡片游戏了




  The first thing you need is an image with all cards like this one:
  The image is scaled down for blogging reasons, but you can view/download it at its original size here.
  Now, with the same method seen in Shuffle an image with BitmapData, I'll cut off all cards starting from the original image.
  I am publishing some raw actionscript because this is just a prototype, but a full tutorial will come shortly.


首先你得有个象下面这样的卡片,当然因为是博客的原因这幅图片被缩放了,当然你可以追随链接下载其原始的尺寸。


现在就像在前面的一篇教程里见到的那样,你可以通过使用Bitmapdata类来,从这个图片中切出所有的卡片。我将发布关于这个问题的一些原始的as脚本,当然将会在后记的章节中给出全面的教程
  The prototype is about the simplest card game ever: you draw a card and have to say if the next card will be higher on lower than the card you have on the table.
  Being a prototype it's not complete yet, but I want to share this code to you.


这个简单的原型,大概是所有的纸牌中最简单的了:你抽出一张牌,然后猜测接下来发的这张牌是比桌上这张大呢?还是小呢?虽然并没有完成,但是我愿意和你分享这段代码
  ACTIONSCRIPT:
  importflash.display.BitmapData
  importflash.geom.Rectangle
  importflash.geom.Point
  importflash.filters.DropShadowFilter
  vardistance:Number= 4
  varangleInDegrees:Number= 45
  varcolor:Number= 0x000000;
  varalpha:Number= .5
  varblurX:Number= 4
  varblurY:Number= 4
  varstrength:Number= 1
  varquality:Number= 3
  varinner:Boolean= false
  varknockout:Boolean= false
  varhideObject:Boolean= false
  varmy_shadow_filter:DropShadowFilter = newDropShadowFilter(distance, angleInDegrees, color, alpha, blurX, blurY, strength, quality, inner, knockout, hideObject)
  big_picture = BitmapData.loadBitmap("cardz")
  _root.attachMovie("table","table",_root.getNextHighestDepth())
  _root.attachMovie("higher","higher",_root.getNextHighestDepth())
  _root.attachMovie("lower","lower",_root.getNextHighestDepth())
  _root.createEmptyMovieClip("big_pic_obj",_root.getNextHighestDepth())
  big_pic_obj.attachBitmap(big_picture,_root.getNextHighestDepth())
  big_pic_obj._visible= false
  pictures = newArray()
  sequence = newArray()
  Array.prototype.shuffle= function(){
  for(x=0x<52x++){
  varfrom = Math.floor(Math.random()*52)
  varto = this[x]
  this[x]= this[from]
  this[from]= to;
  }
  }
  for(x=0x<52x++){
  card = _root.createEmptyMovieClip("small_pic_obj_"+x, _root.getNextHighestDepth())
  sequence[x]= x;
  small_picture = newBitmapData(79, 123)
  card.attachBitmap(small_picture,_root.getNextHighestDepth())
  small_picture.copyPixels(big_picture,newRectangle(0+(x%13)*79, 0+Math.floor(x/13)*123, 79, 123),newPoint(0, 0))
  card._visible= false
  card.filters= newArray(my_shadow_filter)
  card.onEnterFrame= function(){
  switch(this.action){
  case"come":
  this._x+= 40
  if(this._x>210){
  this._x= 210
  this.action= "stay"
  }
  break
  case"move":
  this._x+= 20
  if(this._x>310){
  this._x= 310
  this.action= "dissolve"
  }
  break
  case"dissolve":
  this._alpha-= 4
  if(this._alpha<0){
  can_draw=true
  this.removeMovieClip()
  }
  break
  }
  }
  }
  sequence.shuffle()
  cards_drawn = 0
  can_draw = true
  draw_card()
  higher.onRelease= function(){
  if(can_draw){
  can_draw=false
  draw_card()
  }
  }
  lower.onRelease= function(){
  if(can_draw){
  can_draw=false
  draw_card()
  }
  }
  functiondraw_card(){
  _root["small_pic_obj_"+sequence[cards_drawn]]._x= 0
  _root["small_pic_obj_"+sequence[cards_drawn]]._y= 30
  _root["small_pic_obj_"+sequence[cards_drawn]]._visible= true
  _root["small_pic_obj_"+sequence[cards_drawn]].action= "come"
  _root["small_pic_obj_"+sequence[cards_drawn-1]].action= "move"
  cards_drawn++;
  }
  and the result is...
  I think simple and stupid games like this one can have a good replay value if I provide a high score table like in Christmas Couples, another simple game that entered in the "million games played" club.
  But I will talk about it in the next post about the experiment, meanwhile take the source code.


在接下来的博客中我们还会继续讨论这个问题,不要错过这段代码
  >>Flash Templatesprovided by Template Monster are pre-made web design products developed using Flash technology.
  They can be easily customized to meet the unique requirements of your project.



本文转自
http://www.emanueleferonato.com/2007/12/26/using-bitmapdata-to-manage-a-deck-of-cards/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值