Skip to content

Commit

Permalink
添加动画库,基本的攻击范围显示,和伤害文字动画
Browse files Browse the repository at this point in the history
  • Loading branch information
ttwings committed Oct 10, 2017
1 parent 6909291 commit 263ec93
Show file tree
Hide file tree
Showing 17 changed files with 305 additions and 183 deletions.
68 changes: 34 additions & 34 deletions Actor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Class=require "lib/middleclass"
anim8=require "lib/anim8"
require "assets/data/actors"
require "assets/data/mapWuGuan"
require("bullets")
require("lib.messages")
---- test bullet
bullet={}
message={}
Actor=Class("actor")
Actor["actorMsg"]={}
-- fly Msg
Expand Down Expand Up @@ -101,35 +106,47 @@ function Actor:drawBag()
end

--------------------------- 键盘控制 ------------------------
cd=10
cd=0
function Actor:key(dt)
speed = 600
cd=cd-dt
--cd=cd-dt
if love.keyboard.isDown("f") then
self.x = self.x + dt*speed
self.animNow=self.anim.moveRight
self.r = 0
elseif love.keyboard.isDown("s") then
self.x = self.x - dt*speed
self.animNow=self.anim.moveLeft
self.r = 3.1415
end

if love.keyboard.isDown("d") then
self.y = self.y + dt*speed
self.animNow=self.anim.moveDown
self.r = 3.1415/2
elseif love.keyboard.isDown("e") then
self.y = self.y - dt*speed
self.animNow=self.anim.moveUp
self.r = 3.1415*1.5
end

-- if love.keyboard.isDown("j") then


-- end
if love.keyboard.isDown("k") then
local bullet = {x=self.x/2,y=self.y/2,x0=self.x/2,y0=self.y/2,w=4,h=4,r=self.r or 0,color={255,0,0,100},range=100,speed=1000,cd=0.5}
local message = {text="暴击",x=self.x/2,y=self.y/2,x0=self.x/2,y0=self.y/2,w=4,h=4,r=self.r or 0,color={255,255,0,255},range=100,speed=100,cd=0.5}
cd = cd + dt
local text = string.format("%s%s%s%s%s",bullet.x/2,bullet.y/2,bullet.x0/2,bullet.y0/2,#bullets)
if love.keyboard.isDown("k") and cd > message.cd then
-- table.insert(self.actorMsg,self["名称"] .. "测试信息")
-- fly msg test
local msg={x=self.x,y=self.y,text="测试信息111",cd=3}
table.insert(flyMsgs,msg)
--local msg={x=self.x,y=self.y,text="测试信息111",cd=3}
--table.insert(flyMsgs,msg)
bullets.add(bullet)
messages.add(message)
--print(text)
cd = 0
end
end

Expand All @@ -147,22 +164,23 @@ function Actor:keypressed(key)
end
end
end

-------------- 总体功能 -------------------------
function Actor:draw()
-- for i,v in pairs(actorMsg) do
-- love.graphics.print(v,400,400+20*i)
-- end
Actor:drawMsg()
Actor:drawBag()
Actor:drawFly()
--Actor:drawMsg()
--Actor:drawBag()
--Actor:drawFly()
bullets.draw()
messages.draw()
end

function Actor:update(dt)
-- self:key(dt)
self:atRoom()
self["animNow"]:update(dt)
bullets.update(dt)
messages.update(dt)
end
-- -- 更新角色的位置
------------------ 更新角色的位置 --------------
function Actor:atRoom()
local rx,ry
rx = math.modf(self.x/256)+1 or 1
Expand All @@ -171,21 +189,8 @@ function Actor:atRoom()
self.room=mapWuGuan[ry][rx]
end
end
-- 绘制飞行文字
function Actor:addFlyMsg(msg)
-- body
flyMsg.x= msg.x
flyMsg.y = msg.y
flyMsg.text = msg.text
flyMsg.cd = msg.cd
end

function Actor:drawFly()
for i,v in ipairs(flyMsgs) do
love.graphics.print(v.text, v.x, v.y)
end
end
-- 行走图文件
------------------ 行走图文件 --------------------
function Actor:image(name)
local path = "assets/graphics/Characters/"
self.image=love.graphics.newImage(path .. name)
Expand All @@ -195,12 +200,7 @@ end

function Actor:anims()
local image = self.image
-- skillImg = love.graphics.newImage("assets/graphics/Animations/Attack2.png")
-- local skillG = anim8.newGrid(192,192,skillImg:getWidth(),skillImg:getHeight())
local g = anim8.newGrid(32,48,image:getWidth(),image:getHeight())
-- animation = anim8.newAnimation(g('1-4',2),0.2)
-- skillAnim = anim8.newAnimation(skillG('1-5',1),0.2)

self["anim"]["moveDown"] = anim8.newAnimation(g('1-4',1),0.3)
self["anim"]["moveLeft"] = anim8.newAnimation(g('1-4',2),0.3)
self["anim"]["moveRight"] = anim8.newAnimation(g('1-4',3),0.3)
Expand All @@ -210,11 +210,11 @@ end
function Actor:drawAnim()
self["animNow"]:draw(self.image,self.x/2,self.y/2)
end
-- 获得物品
--------------------------- 获得物品 ---------------------------
local cd
function getObj()
if self.target~=nil then
table.insert( self.misc,self.target)
print( #self.misc .. ":"..self.misc[#self.misc] )
end
end
end
23 changes: 13 additions & 10 deletions Date.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ hours = {"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥
months = {"","","","","","","","","","","",""}
numbers = {"","","","","","","","","",""}
season = {"","","",""}
weather = { "","多云","","阵雨","雷阵雨","雷阵雨伴有冰雹",
"雨夹雪","小雨","中雨","大雨","暴雨","大暴雨","特大暴雨",
"阵雪","小雪","中雪","大雪","暴雪","","冻雨","沙尘暴",
"小到中雨","中到大雨","大到暴雨","暴雨到大暴雨",
"大暴雨到特大暴雨","小到中雪","中到大雪","大到暴雪",
"浮尘","扬沙","沙尘暴","强沙尘暴","特强沙尘暴轻雾",
"浓雾强浓雾","轻微霾","轻度霾","中度霾","重度霾","特强霾","","飑线"}
--weather = { "晴","多云","阴","阵雨","雷阵雨","雷阵雨伴有冰雹",
-- "雨夹雪","小雨","中雨","大雨","暴雨","大暴雨","特大暴雨",
-- "阵雪","小雪","中雪","大雪","暴雪","雾","冻雨","沙尘暴",
-- "小到中雨","中到大雨","大到暴雨","暴雨到大暴雨",
-- "大暴雨到特大暴雨","小到中雪","中到大雪","大到暴雪",
-- "浮尘","扬沙","沙尘暴","强沙尘暴","特强沙尘暴轻雾",
-- "浓雾强浓雾","轻微霾","轻度霾","中度霾","重度霾","特强霾","霰","飑线"}

font = love.graphics.newFont("assets/font/simsun.ttf", 18)
font = love.graphics.newFont("assets/font/myfont.ttf", 20)
love.graphics.setFont(font)

function date:update(dt)
Expand All @@ -25,7 +25,6 @@ function date:update(dt)
end

function date:draw()
-- colorText(colorstr)
local d = date
local yearStr = hours[d.year]..animals[d.year]
local monthStr = months[d.month]
Expand All @@ -37,6 +36,7 @@ function date:draw()
end

--- 将数字转为文字
---@return string
function replaseNumber(number)
-- local numbers = number ..""
numbers = string.gsub(number,"1", "")
Expand All @@ -52,6 +52,9 @@ function replaseNumber(number)
return numbers
end

---new
---@param second number 回合数
---@return table date 日期
function date.new(second)
date.second = second
date.minute = math.modf(date.second/60)
Expand All @@ -60,7 +63,7 @@ function date.new(second)
date.week = math.modf(date.day/7)
date.month = math.modf(date.week/3)
date.year = math.modf(date.month/12)
--
---- 日期转化
date.minute = math.modf(date.minute%60)+1
date.hour = math.modf(date.hour%12)+1
date.day = math.modf(date.day%7)+1
Expand Down
37 changes: 6 additions & 31 deletions GameScreen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ local Screen = require( "lib/Screen" )
local sti = require "sti"
local actorsdata=require "assets/data/actors"
local anim8 = require 'lib/anim8'
-- local Class = require "lib/middleclass"
require "Date"
-- 主要对象类,角色类,房间类,区域类
require "Actor"
require "Npc"
require "assets/data/actors"
require "assets/data/rooms"
require "lib/guiDraw"
require "lib/colorT"
require "lib/drawTool"

local GameScreen = {}
local map
local world
Expand Down Expand Up @@ -50,20 +48,10 @@ function canvasGUIload()
end

function loadData( )
-- actor class
-- actor class
actor=Actor:new(actors["段誉"])
-- actor:readData(actors["段誉"])
-- npc1 = Actor:new(actors["言达平"])
-- npc2 = Actor:new(actors["鲁坤"])
npcs:add(actors,5)
-- npc1.x = 500
-- npc1.y = 600
-- npc2.x = 800
-- npc2.y = 1000
-- npc1:readData(actors["言达平"])
-- actor.misc = {}
--
font = love.graphics.newFont("assets/font/msyh.ttf", 18)
local font = love.graphics.newFont("assets/font/myfont.ttf", 20)
love.graphics.setFont(font)
map = sti("assets/tileMaps/wuguan.lua",{"box2d"})
-- Prepare translations
Expand All @@ -88,8 +76,6 @@ function loadData( )
local bx,by = objs[i].x,objs[i].y
local ax,ay = actor.x/2,actor.y/2
local distance=math.abs(bx-ax) + math.abs(by-ay)
-- print(distance)
-- print( distance )
if (distance<100) then
actor.target = objName .. ":"..bx .. ":".. by
break
Expand All @@ -101,21 +87,14 @@ function loadData( )
--
function spriteLayer:draw()
for _, sprite in pairs(self.sprites) do
local x = math.floor(actor.x/2)
local y = math.floor(actor.y/2)
actor:drawAnim()
npcs:drawAnim()
-- npc1:drawAnim()
-- npc2:drawAnim()
-- actor:drawFly()
actor:draw()
--npcs:drawAnim()
end
end


canvasLoad()
end


function GameScreen.new( )
local self=Screen.new()
loadData()
Expand All @@ -125,8 +104,6 @@ function GameScreen.new( )
love.graphics.setShader()
-- GUI
guiDraw()
-- actor:draw()
-- actor:drawBag()
love.graphics.print("FPS:" .. love.timer.getFPS(),1220,0)
date.draw()
end
Expand All @@ -136,8 +113,7 @@ function GameScreen.new( )
map:update(dt)
actor:key(dt)
actor:update(dt)
-- npc1:update(dt)
npcs:update(dt)
--npcs:update(dt)
-- 地图的位移
tx = math.floor((actor.x - 1280)/ 2)
ty = math.floor((actor.y - 800)/ 2)
Expand All @@ -149,5 +125,4 @@ function GameScreen.new( )
return self
end


return GameScreen
4 changes: 2 additions & 2 deletions MainScreen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ local ScreenManager = require("lib/ScreenManager")
local snow = require( "Snow" )
local MainScreen = {}
local bg = love.graphics.newImage("bg.jpeg")
local font = love.graphics.newFont("assets/font/msyh.ttf", 24)
local titlefont = love.graphics.newFont("assets/font/msyh.ttf", 48)
local font = love.graphics.newFont("assets/font/myfont.ttf", 32)
local titlefont = love.graphics.newFont("assets/font/myfont.ttf", 56)
local menu = {}
local index = 1
function MainScreen.new( )
Expand Down
2 changes: 1 addition & 1 deletion Snow.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
----------------- 下雪动画 ----------------
local snow={}
local circles={}
function snow.init(n)
Expand All @@ -15,7 +16,6 @@ end

function snow.draw()
for i,v in ipairs(circles) do
-- v=circles[i]
love.graphics.setColor(v.color)
love.graphics.circle("fill",v.x,v.y,v.r-1)
love.graphics.circle("fill",v.x,v.y,v.r-2)
Expand Down
27 changes: 27 additions & 0 deletions ani.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "lib/animation"
-- ani 动画测试
ani = {}

ani.init = function (img,w,h,dur)
local w,h,sw,sh,dur,offx,offy
w = w or 192
h = h or 192
dur = dur or 0.05
local path = "assets/graphics/Animations/"..img..".png"
local img = love.graphics.newImage(path)
sw,sh = img:getDimensions()
ani.animation = love.graphics.newAnimation(img,1,1,w,h,0,0,sw,sh,dur)
-- ani.animation.mode = 1
end


ani.update = function (dt)
ani.animation:update(dt)
end

ani.draw = function (x,y,r,sx,sy,offx,offy)
local x,y
x = ani.animation.x or 400
y = ani.animation.y or 300
ani.animation:draw(x,y,r,sx,sy,offx,offy)
end
Binary file modified assets/font/myfont.ttf
Binary file not shown.
Loading

0 comments on commit 263ec93

Please sign in to comment.