From f5eaa22a1c9598c9f7a55a41614d1ce4769dee4a Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Tue, 1 Mar 2022 02:48:49 +0530 Subject: * Adds Ambience SFX & Management * Notification - In-Progress * Collision Callbacks * Interactive & Pickable entities - In-Progress --- core/ambience.lua | 15 +++++ core/constants.lua | 11 ++++ core/enitity.lua | 0 core/map.lua | 164 +++++++++++++++++++++++++++++++++++++++++++++++++ core/notifications.lua | 31 ++++++++++ core/screen_shaker.lua | 28 +++++++++ 6 files changed, 249 insertions(+) create mode 100644 core/ambience.lua create mode 100644 core/constants.lua create mode 100644 core/enitity.lua create mode 100644 core/map.lua create mode 100644 core/notifications.lua create mode 100644 core/screen_shaker.lua (limited to 'core') diff --git a/core/ambience.lua b/core/ambience.lua new file mode 100644 index 0000000..13919d9 --- /dev/null +++ b/core/ambience.lua @@ -0,0 +1,15 @@ +Class = require("libs.hump.class") + +Ambience = Class { + init = function(self, ambienceTypes) + if ambienceTypes then + for i,ambience in pairs(ambienceTypes) do + local ambientSound = love.audio.newSource("assets/sfx/"..ambience..".ogg", "static") + ambientSound:setLooping(true) + ambientSound:play() + end + end + end +} + +return Ambience \ No newline at end of file diff --git a/core/constants.lua b/core/constants.lua new file mode 100644 index 0000000..5284e6d --- /dev/null +++ b/core/constants.lua @@ -0,0 +1,11 @@ +constants = {} + +constants.resetBgColor = {0.15, 0.15, 0.15} +constants.resetFgColor = {1, 1, 1} + +function constants:resetColors() + love.graphics.setColor(constants.resetFgColor) + love.graphics.setBackgroundColor(constants.resetBgColor) +end + +return constants \ No newline at end of file diff --git a/core/enitity.lua b/core/enitity.lua new file mode 100644 index 0000000..e69de29 diff --git a/core/map.lua b/core/map.lua new file mode 100644 index 0000000..acbdc4a --- /dev/null +++ b/core/map.lua @@ -0,0 +1,164 @@ +Class = require("libs.hump.class") +Gamestate = require("libs.hump.gamestate") +STI = require("libs.sti") +Moonshine = require("libs.moonshine") +Camera = require("libs.hump.camera") +Windfield = require("libs.windfield") +require("libs.tserial") +print(TSerial) +require("core.notifications") + +local zoomFactor = 2 +local player = { + x=0, + y=0, + sprite=love.graphics.newImage("assets/images/player_demo.png"), + speed=100 +} + +local windowWidth, windowHeight = love.graphics.getDimensions() +local _w = windowWidth/zoomFactor +local _h = windowHeight/zoomFactor + +Map = Class { + __include=Gamestate, + init = function(self, mapName) + _gameWorld = Windfield.newWorld(0,0) + _gameWorld:addCollisionClass('player') + _gameWorld:addCollisionClass('interactive') + effect = Moonshine(windowWidth, windowHeight, Moonshine.effects.crt) + .chain(Moonshine.effects.vignette) + .chain(Moonshine.effects.scanlines) + .chain(Moonshine.effects.chromasep) + effect.scanlines.thickness = .2 + effect.scanlines.opacity = .5 + effect.chromasep.angle = 1 + effect.chromasep.radius = 2 + + notifications = Notifications(zoomFactor) + camera = Camera() + camera:zoom(zoomFactor) + currentMap = STI("assets/maps/"..mapName..".lua") + if currentMap.layers["entities"] then + for i,obj in pairs(currentMap.layers["entities"].objects) do + if obj.name=="player" and obj.type=="player" then + player.x = obj.x + player.y = obj.y + player.collider = _gameWorld:newBSGRectangleCollider(player.x, player.y, 8, 8, 0) + + player.collider:setFixedRotation(true) + player.collider:setCollisionClass('player') + end + + if obj.type=="interactive" then + local collider = _gameWorld:newRectangleCollider(obj.x, obj.y, obj.width, obj.height) + local interactiveData = { + type = obj.type, + interactive_type = obj.properties.interactive_type, + data = obj.properties.data + } + collider:setObject(interactiveData) + collider:setCollisionClass('interactive') + collider:setType("static") + end + end + end + + if currentMap.layers["walls"] then + for i,obj in pairs(currentMap.layers["walls"].objects) do + local wall = _gameWorld:newRectangleCollider(obj.x, obj.y, obj.width, obj.height) + wall:setType("static") + end + end + end, + entities={} +} + +function Map:update(dt) + + local vx = 0 + local vy = 0 + + if love.keyboard.isDown("up") then + vy = player.speed * -1 + end + + if love.keyboard.isDown("down") then + vy = player.speed + end + + if love.keyboard.isDown("left") then + vx = player.speed * -1 + end + + if love.keyboard.isDown("right") then + vx = player.speed + end + + player.collider:setLinearVelocity(vx, vy) + + _gameWorld:update(dt) + player.x = player.collider:getX() - 4 + player.y = player.collider:getY() - 4 + + camera:lookAt(player.x, player.y) + currentMap:update(dt) + + if camera.x < _w/2 then + camera.x = _w/2 + end + + if camera.y < _h/2 then + camera.y = _h/2 + end + + local mapWidth = currentMap.width * currentMap.tilewidth + local mapHeight = currentMap.height * currentMap.tileheight + + if camera.x > (mapWidth - _w/2) then + camera.x = (mapWidth - _w/2) + end + + if camera.y > (mapHeight - _h/2) then + camera.y = (mapHeight - _h/2) + end + + if player.collider:enter('interactive') then + local _interColliderData = player.collider:getEnterCollisionData('interactive') + local interactiveCollider = _interColliderData.collider + local interactiveData = interactiveCollider:getObject() + + if interactiveData.interactive_type=="pickable" then + notifications:send(interactiveData.data) + end + + if interactiveData.interactive_type=="message_notification" then + notifications:send(interactiveData.data) + end + end + notifications:update(dt) +end + +function Map:draw() + effect(function() + camera:attach() + drawMapLayer("ground") + drawMapLayer("decorations") + love.graphics.draw(player.sprite, player.x, player.y) + drawMapLayer("foreground") + _gameWorld:draw() + camera:detach() + notifications:draw() + end) +end + +function Map:keypressed(key, scancode) +end + +function drawMapLayer(layerName) + if currentMap.layers[layerName].visible then + currentMap:drawLayer(currentMap.layers[layerName]) + end +end + +return Map \ No newline at end of file diff --git a/core/notifications.lua b/core/notifications.lua new file mode 100644 index 0000000..05950f2 --- /dev/null +++ b/core/notifications.lua @@ -0,0 +1,31 @@ +Class = require("libs.hump.class") +Timer = require("libs.hump.timer") +Notifications = Class { + init = function(self, zoomFactor) + color = {1, 0, 0, 1} + local windowWidth, windowHeight = love.graphics.getDimensions() + end, + _message={} +} + +function Notifications:update(dt) + Timer.update(dt) +end + +function Notifications:draw() + if self._message then + love.graphics.setColor(color) + love.graphics.print(self._message, 10, wind) + end +end + +function Notifications:send(message) + self._message = message + color = {1, 0, 0, 1} + if Timer then + Timer.clear() + end + Timer.tween(5, color, {0, 0, 0, 0}, 'linear') +end + +return Notifications \ No newline at end of file diff --git a/core/screen_shaker.lua b/core/screen_shaker.lua new file mode 100644 index 0000000..0316559 --- /dev/null +++ b/core/screen_shaker.lua @@ -0,0 +1,28 @@ +Class = require("libs.hump.class") +Shack = require("libs.shack") +local Timer = require("libs.hump.timer") + +ScreenShaker = Class { + init = function(self) + monsterGrowl = love.audio.newSource("assets/sfx/monster_growl.wav", "static") + local width, height = love.graphics.getDimensions() + Shack:setDimensions(width, height) + Timer.every(10, shakeScreen) + end +} + +function ScreenShaker:update(dt) + Timer.update(dt) + Shack:update(dt) +end + +function ScreenShaker:draw() + Shack:apply() +end + +function shakeScreen() + Shack:setShake(20) + monsterGrowl:play() +end + +return ScreenShaker \ No newline at end of file -- cgit v1.2.3