您的位置:首页 > 编程语言 > Lua

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

2012-04-25 12:11 239 查看
--[[南阳草庐软件科技有限公司
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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息