iphone上用lua做了个doodlejump的菜单界面

8 篇文章 0 订阅
7 篇文章 0 订阅

--[[南阳草庐软件科技有限公司
    hi.baidu.com/xingyan126
]]
waxClass{"AppDelegate", protocols = {"UIApplicationDelegate"}}

-- Well done! You are almost ready to run a lua app on your iPhone!
--
-- Just run the app (⌘↵) in the simulator or on a device! 
-- You will see a dull, bland "hello world" app (it is your job to spice it up.)
--
-- If your prefer using TextMate to edit the Lua code just type 
-- 'rake tm' from the command line to setup a wax TextMate project.
--
-- What's next?
-- 1. Check out some of the example apps to learn how to do
--    more complicated apps.
-- 2. Then you start writing your app!
-- 3. Let us know if you need any help at http://groups.google.com/group/iphonewax

local tbDef = {
		['stair_normal']			= { 0, 0 , 60, 18},
		['stair_moveH']             = { 0, 18, 60, 36},
		['stair_moveV']             = { 0, 36, 60, 54},
		['stair_on1']               = { 0, 54, 60, 72},
		['stair_false1']            = { 0, 72, 60, 90}
}

local btnDef =
{
    ['play']            ={50, 150};
    ['mutabilplayer']   ={100,200};
    ['score']           ={250,300};
    ['operation']       ={200,350};
    ['stair']           ={40,400};
    ['doodle']           ={55,380};
}


function applicationDidFinishLaunching(self, application)
  local frame = UIScreen:mainScreen():bounds()
  window = UIWindow:initWithFrame(frame)
  
  window:setBackgroundColor(UIColor:colorWithRed_green_blue_alpha(0.196, 0.725, 0.702, 1))
  self.background = UIImageView:initWithFrame(frame)
  self.background:setImage(UIImage:imageNamed("bck.png"))
  window:addSubview(self.background)
  local label = UILabel:initWithFrame(CGRect(0, 100, 320, 40))
  label:setFont(UIFont:boldSystemFontOfSize(30))
  label:setColor(UIColor:whiteColor())
  label:setBackgroundColor(UIColor:colorWithRed_green_blue_alpha(0.173, 0.651, 0.627, 1))
  label:setText("Hello Lua!")
  label:setTextAlignment(UITextAlignmentCenter)    
  window:addSubview(label)
  Menu()
  self.window:makeKeyAndVisible()
end

function Menu()
    local imgplay = UIImage:imageNamed("play.png")
    local p = btnDef['play']
    local size = imgplay:size()
    local play = UIButton:initWithFrame(CGRect(p[1], p[2], size.width, size.height))
    play:setBackgroundImage_forState(imgplay, 0)
    window:addSubview(play)
    local imgMultiplayer = UIImage:imageNamed("multiplayer-on.png")
    p = btnDef['mutabilplayer']
    size = imgMultiplayer:size()
    multiPlayer = UIButton:initWithFrame(CGRect(p[1], p[2], size.width, size.height))
    multiPlayer:setBackgroundImage_forState(imgMultiplayer, 0)
    window:addSubview(multiPlayer)
    
    imgStair = UIImage:imageNamed("statr1-0.png")
    size = imgStair:size()
    p   =   btnDef['stair']
    local stair = UIImageView:initWithFrame(CGRect(p[1], p[2], size.width, size.height));
    stair:setImage(imgStair)
    window:addSubview(stair)
    local imgdoodle = UIImage:imageNamed("lik-right.png")
    size = imgdoodle:size()
    doodle = UIImageView:initWithFrame(CGRect(p[1]+10, p[2]-size.height+4, size.width, size.height))
    doodle:setImage(imgdoodle)
    window:addSubview(doodle);
    --开启线程
    ismenu = ture
    g = 10
    v0 = -100;
    timer = NSTimer:scheduledTimerWithTimeInterval_target_selector_userInfo_repeats(0.01, self, "handleTimer:", nil, true)
end

 count = 1

function handleTimer()
   jumpthread()
end

--抛物运动
function jumpthread()
   local rect =   doodle:frame()
   local deta_t = 0.1
   vt =   v0 + g*deta_t
   local  s = (v0*deta_t + g*deta_t*deta_t)/2;
   rect.y = rect.y + s;
   v0 = vt
   if v0>100 or v0==100 then
        v0 = -100
        rect.y = btnDef['stair'][2]-rect.height+4
   end
   doodle:setFrame(rect)
   doodle:setNeedsDisplay()
end


function splitePNG(img, rect)
    print(type('函数调用'))
    local cgimg = wax.CGContext.CGImageCreateWithImageInRect(img:CGImage(), rect)
    image = UIImage:imageWithCGImage(cgimg)
    return image
end



function applicationDidBecomeActive(self, application)
end

function AppDelegate:applicationDidEnterBackground(application)
end
lua代码如上

项目下载地址:doodlejump.zip



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值