Mercurial > vanillian
diff main.lua @ 25:8891a036fb23
Add bumping and talking
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sun, 16 Dec 2012 11:08:54 +0100 |
| parents | d16e33662aa0 |
| children | 52488e54b266 |
line wrap: on
line diff
--- a/main.lua Sat Dec 15 20:57:28 2012 +0100 +++ b/main.lua Sun Dec 16 11:08:54 2012 +0100 @@ -14,6 +14,8 @@ local scroll_speed = 250 local scroll_margin = 64 local MUSIC +local TEXT = "" +local SOUNDS = {} function newMob(x, y, cells) @@ -29,12 +31,29 @@ end function makeVillain(villain) + villain.is_villain = true function villain.sprite:walk(dt, dir) local x = self.x + DX[dir] * 24 local y = self.y + DY[dir] * 16 - local tx, ty = math.floor((x+32)/48), math.floor((y+60)/48) - local cell = MAP.layers['control']:get(tx, ty) - if cell and cell.properties and not cell.properties.block then + local mx, my = math.floor((x+32)/48), math.floor((y+60)/48) + local cell = MAP.layers['control']:get(mx, my) + local bump = false + for i, s in pairs(SPRITES) do + if not s.is_villain then + local d = (x - s.x) * (x - s.x) + ((y - s.y) * (y - s.y)) + if d < 100 then + bump = true + if s.properties.text then + TEXT = s.properties.text + SOUNDS.talk:play() + else + SOUNDS.bump:play() + TEXT = "" + end + end + end + end + if not bump and cell and cell.properties and not cell.properties.block then self.x = self.x + DX[dir] * dt * 250 self.y = self.y + DY[dir] * dt * 250 end @@ -46,6 +65,7 @@ if love.keyboard.isDown("right") then self:walk(dt, 2) end if love.keyboard.isDown("down") then self:walk(dt, 3) end if love.keyboard.isDown("left") then self:walk(dt, 4) end + if love.keyboard.isDown(" ") then TEXT = "" end if self.x + tx < scroll_margin then tx = math.min(tx + dt * scroll_speed, 0) else @@ -69,6 +89,8 @@ love.graphics.setFont(love.graphics.newFont('pf_tempesta_seven_extended_bold.ttf')) SHADOW_IMAGE = love.graphics.newImage('shadow.png') MOBS_IMAGE = love.graphics.newImage('mobs.png') + SOUNDS.bump = love.audio.newSource('bump.xm', 'static') + SOUNDS.talk = love.audio.newSource('talk.xm', 'static') load_map('level01.tmx') end @@ -79,21 +101,26 @@ MAP.drawObjects = false MAP.layers['control'].visible = false if MAP.properties.music then + if MUSIC then + MUSIC:stop() + end MUSIC = love.audio.newSource(MAP.properties.music, 'static') MUSIC:setLooping(true) MUSIC:play() end for i, data in pairs(MAP.layers['mobs'].objects) do if data.name == 'villain' then - makeVillain(newMob(data.x, data.y, '1-2,1')) + local mob = makeVillain(newMob(data.x, data.y, '1-2,1')) + mob.sprite.properties = data.properties else - newMob(data.x, data.y, data.properties.cells or '1-2,2') + local mob = newMob(data.x, data.y, data.properties.cells or '1-2,2') + mob.sprite.properties = data.properties end end end -function draw_text() - text = "Lorem ipsum dolor sit ament conectetur adipiscit elit.\nLorem ipsum dolor sit ament conectetur adipiscit elit." +function draw_text(text) + text = text:gsub('[|]', '\n') love.graphics.setColor(0, 0, 0) love.graphics.print(text, 3, 3) love.graphics.print(text, 5, 3) @@ -119,7 +146,7 @@ end end love.graphics.translate(-math.floor(tx), -math.floor(ty)) - draw_text() + draw_text(TEXT) end
