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

导读:


还记得前几天说过的用Bitmap来管理纸牌游戏的帖子嘛,作者又发出了他最近的代码,介绍如下



  At the moment the prototype has all messages and a game over screen with the score recap.
  Now I want to include Kongregate's highscores APIand then I'll releae the complete tutorial.


到现在为止,纸牌游戏的内容便告一段落了。下面我们将发布完整的教程,下面是代码
  Meanwhile, here it is the code:
  ACTIONSCRIPT:
  importflash.display.BitmapData
  importflash.geom.Rectangle
  importflash.geom.Point
  importflash.filters.DropShadowFilter
  importflash.filters.GlowFilter
  varcard_shadow:DropShadowFilter = newDropShadowFilter(4, 45, 0x000000, .5, 4, 4, 1, 3, false, false, false)
  vartext_glow:GlowFilter = newGlowFilter(0x000000, .6, 4, 4, 2, 3, false, false)
  big_picture = BitmapData.loadBitmap("cardz")
  _root.attachMovie("table", "table", _root.getNextHighestDepth())
  _root.createEmptyMovieClip("game", _root.getNextHighestDepth())
  game.attachMovie("higher", "higher", game.getNextHighestDepth())
  game.attachMovie("lower", "lower", game.getNextHighestDepth())
  game.createEmptyMovieClip("big_pic_obj", game.getNextHighestDepth())
  big_pic_obj.attachBitmap(big_picture, game.getNextHighestDepth())
  big_pic_obj._visible= false
  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 = game.createEmptyMovieClip("small_pic_obj_"+x, game.getNextHighestDepth())
  sequence[x]= x;
  small_picture = newBitmapData(79, 123)
  card.attachBitmap(small_picture, game.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(card_shadow)
  card.onEnterFrame= function(){
  switch(this.action){
  case"come":
  this._x+= 40
  if(this._x>210){
  this._x= 210
  this.action= "stay"
  if(cards_drawn>1){
  game.ok_ko._visible= true
  }
  }
  break
  case"move":
  this._x+= 20
  if(this._x>310){
  this._x= 310
  this.action= "dissolve"
  }
  break
  case"dissolve":
  this._alpha-= 4
  game.lap_score._alpha-= 4
  if(this._alpha<0){
  can_draw = true
  game.ok_ko._visible= false
  if(cards_drawn == 52){
  endgame()
  }
  this.removeMovieClip()
  }
  break
  }
  }
  }
  game.attachMovie("ok_ko", "ok_ko", game.getNextHighestDepth(), {_x:250, _y:230, _visible:false})
  game.attachMovie("score", "score", game.getNextHighestDepth(), {_x:0, _y:140})
  game.attachMovie("lap_score", "lap_score", game.getNextHighestDepth(), {_x:-50, _y:0, _alpha:0})
  game.score.filters= newArray(text_glow)
  game.lap_score.filters= newArray(text_glow)
  sequence.shuffle()
  cards_drawn = 0
  points = 0
  can_draw = true
  draw_card()
  game.higher.onRelease= function(){
  if(can_draw){
  can_draw = false
  higher = true
  draw_card()
  }
  }
  game.lower.onRelease= function(){
  if(can_draw){
  can_draw = false
  higher = false
  draw_card()
  }
  }
  functiondraw_card(){
  game.ok_ko.gotoAndStop(2)
  lap = 0
  if(((sequence[cards_drawn]%13)<=(sequence[cards_drawn-1]%13)and(!higher))or ((sequence[cards_drawn]%13)>=(sequence[cards_drawn-1]%13)and(higher))){
  game.ok_ko.gotoAndStop(1)
  game.lap_score.lap_text.textColor= 0x40ff40;
  if(cards_drawn>0){
  if(!higher){
  lap = 13-(sequence[cards_drawn-1]%13)
  }else{
  lap = sequence[cards_drawn-1]%13+1
  }
  }
  }else{
  lap = -5
  game.lap_score.lap_text.textColor= 0x900000;
  }
  game.lap_score.lap_text.text= lap;
  if(cards_drawn>0){
  game.lap_score._alpha= 100
  }
  points += lap;
  game["small_pic_obj_"+sequence[cards_drawn]]._x= 0
  game["small_pic_obj_"+sequence[cards_drawn]]._y= 10
  game["small_pic_obj_"+sequence[cards_drawn]]._visible= true
  game["small_pic_obj_"+sequence[cards_drawn]].action= "come"
  game["small_pic_obj_"+sequence[cards_drawn-1]].action= "move"
  cards_drawn++;
  game.score.textscore.text= "Cards left: "+(52-cards_drawn)+" - Score: "+points;
  }
  functionendgame(){
  game.removeMovieClip()
  _root.attachMovie("game_over","game_over",_root.getNextHighestDepth())
  game_over.gameovertext.filters= newArray(text_glow)
  _root.game_over.gameovertext.text= "Your score:/n"+points;
  }
  and this is the result
  When it's game over, at the moment you must reload the page to play again. How much did you score?
  Download the source code, and wait for the full tut...
  >>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.


【译者注:这里本来是有一个FLASH的,但是对剪影如何转载FLASH 内容不慎名了,好的是顺着链接也很容易找到了,怎么样,虽然游戏不怎么样,但是这么华丽的UI是不是也为其增添了几分趣味呢?】
  7 Comment(s)
  Marukomu| Dec 28, 2007| Reply
  Good stuff! This is great for work. I think I’m going rebuild one for my wife.
  i scored 74 :P
  I’m the recordman:
  90!
  Awesome!!! 69 btw *_^
  haha 104 winner :D
  54! hurray!!
  limpeh| Dec 29, 2007| Reply
  This game is not bad, but after some time, it’s quite boring since all you need to do is just ‘guessing’. (btw, I got 91)

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值