1000行代码写小游戏(一)

用lua写的小游戏,主要玩法是点击进行采矿并和怪物搏斗等操作,人物属性有体力,血量,恢复,攻击,防御

采矿可以挖到金币和经验,打怪升级最后决战boss赢取胜利,升级可以获得技能点增加属性,还有老虎机系统等外围系统


首先说下小怪和矿的配置格式和需要用到的参数读取函数:

local sz = CCDirector:sharedDirector():getVisibleSize()
local BonusType = CreateEnumTable({"MINE", "ENEMY", "SYSTEM", "BOSS"})
local KeyType = CreateEnumTable({"IRON", "SILVER", "GOLD"})
local SysType = CreateEnumTable({"AACT", "AATK", "ADEF", "AKEY", "ADOT", "ROCK"})
local gameConfig = {
	initBattleData = {
	    active = 50,     -- 体力
	    hp = 100,        -- 生命
	    recover = 10,    -- 恢复
	    atk = 10,        -- 攻击
	    def = 10,        -- 防御
	},
	bonus = {
		{
			types = BonusType.MINE,
			width = 39,
			height = 15,
			pos = ccp(10, 269),
			curlife = 0,
			digged = false,
		},
		{
			types = BonusType.ENEMY,
			width = 30,
			height = 30,
			pos = ccp(10, 235),
			curlife = 0,
			digged = false,
		},
		{
			types = BonusType.SYSTEM,
			width = 48,
			height = 48,
			pos = ccp(10, 104),
			sys = SysType.ADOT,
			color = "lightyellow",
			cost = {200,400,1000,1600,2400,3600,5000,6400,8000,10000},
			curst = 1,
		},
		{
			types = BonusType.SYSTEM,
			width = 59,
			height = 47,
			pos = ccp(174, 252),
			sys = SysType.AATK,
			color = "lightyellow",
			cost = {200,400,1000,1600,2400,3600,5000,6400,8000,10000},
			curst = 1,
		},
		{
			types = BonusType.SYSTEM,
			width = 80,
			height = 81,
			pos = ccp(439, 203),
			sys = SysType.ROCK,
			color = "darkyellow",
			cost = {200},
			result = {0,0,0},
			curst = 0,
		},
	},
}

function getUserMaxExp(level)
	return math.ceil(level/3)*100
end

function getInitBattleData()
	return gameConfig.initBattleData
end

function getLevelUpAddSkillDot(level)
	return math.ceil(level/5)*5
end

function countBarScaleX(scale, hpAndActivePercent)
	if hpAndActivePercent then
		return math.min(1, math.max(0.02, scale)) * math.min(1, math.max(0.5, hpAndActivePercent))
	else
		return math.min(1, math.max(0.01, scale))
	end
end

function getBonusListInfo()
	return gameConfig.bonus
end

function getMineActivendRecover(width, height)
	local area = width*height
	local lenght = width+height
	local cost = math.floor(area/50)
	if cost >= width/3 then cost = math.floor(width/5) end
	local cover = math.ceil(height/5) - 2
	if cost <= 1.5*cover then cover = cost end
	local mineData = {
		life = width,
		recover = cover,
		digMoney = math.floor(area/2),
		digExp = math.floor(area/2),
		clickMoney = math.floor(area/20),
		clickCost = cost,
	}
	return mineData
end

function getEnemyLifeAndRecover(width, height)
	local area = width*height
	local lenght = width+height
	local enemyData = {
		life = width,
		atk = math.ceil(lenght/3),
		def = math.ceil(lenght/10),
		recover = math.ceil(height/5) - 2,
		digMoney = math.floor(area/4),
		digExp = math.floor(area/1),
	}
	return enemyData
end

bonus里面配置的是系统的类型、位置、大小、状态等信息

下面的函数主要是不同等级的经验、技能点等属性的计算,和小怪、矿的属性计算,主要根据方块的长宽进行计算


下一节介绍玩家的等级等信息的更新方法

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值