diff --git a/game/asset/audio/sfx/book_flip.1.ogg b/game/asset/audio/sfx/book_flip.1.ogg new file mode 100644 index 0000000..110051e Binary files /dev/null and b/game/asset/audio/sfx/book_flip.1.ogg differ diff --git a/game/asset/audio/sfx/book_flip.10.ogg b/game/asset/audio/sfx/book_flip.10.ogg new file mode 100644 index 0000000..d7136f7 Binary files /dev/null and b/game/asset/audio/sfx/book_flip.10.ogg differ diff --git a/game/asset/audio/sfx/book_flip.2.ogg b/game/asset/audio/sfx/book_flip.2.ogg new file mode 100644 index 0000000..7a9b833 Binary files /dev/null and b/game/asset/audio/sfx/book_flip.2.ogg differ diff --git a/game/asset/audio/sfx/book_flip.3.ogg b/game/asset/audio/sfx/book_flip.3.ogg new file mode 100644 index 0000000..4b8a9b4 Binary files /dev/null and b/game/asset/audio/sfx/book_flip.3.ogg differ diff --git a/game/asset/audio/sfx/book_flip.4.ogg b/game/asset/audio/sfx/book_flip.4.ogg new file mode 100644 index 0000000..a2adc60 Binary files /dev/null and b/game/asset/audio/sfx/book_flip.4.ogg differ diff --git a/game/asset/audio/sfx/book_flip.5.ogg b/game/asset/audio/sfx/book_flip.5.ogg new file mode 100644 index 0000000..eba65d9 Binary files /dev/null and b/game/asset/audio/sfx/book_flip.5.ogg differ diff --git a/game/asset/audio/sfx/book_flip.6.ogg b/game/asset/audio/sfx/book_flip.6.ogg new file mode 100644 index 0000000..2ab2487 Binary files /dev/null and b/game/asset/audio/sfx/book_flip.6.ogg differ diff --git a/game/asset/audio/sfx/book_flip.7.ogg b/game/asset/audio/sfx/book_flip.7.ogg new file mode 100644 index 0000000..7f30bb9 Binary files /dev/null and b/game/asset/audio/sfx/book_flip.7.ogg differ diff --git a/game/asset/audio/sfx/book_flip.8.ogg b/game/asset/audio/sfx/book_flip.8.ogg new file mode 100644 index 0000000..88ff902 Binary files /dev/null and b/game/asset/audio/sfx/book_flip.8.ogg differ diff --git a/game/asset/audio/sfx/book_flip.9.ogg b/game/asset/audio/sfx/book_flip.9.ogg new file mode 100644 index 0000000..1052594 Binary files /dev/null and b/game/asset/audio/sfx/book_flip.9.ogg differ diff --git a/game/asset/image/book/StoryMode.png b/game/asset/image/book/StoryMode.png new file mode 100644 index 0000000..34c42f4 Binary files /dev/null and b/game/asset/image/book/StoryMode.png differ diff --git a/game/asset/image/book/StoryModeBook.png b/game/asset/image/book/StoryModeBook.png new file mode 100644 index 0000000..ab27944 Binary files /dev/null and b/game/asset/image/book/StoryModeBook.png differ diff --git a/game/asset/image/book/StoryModeBook11.png b/game/asset/image/book/StoryModeBook11.png new file mode 100644 index 0000000..544d671 Binary files /dev/null and b/game/asset/image/book/StoryModeBook11.png differ diff --git a/game/asset/image/book/StoryModeBook16.png b/game/asset/image/book/StoryModeBook16.png new file mode 100644 index 0000000..749c209 Binary files /dev/null and b/game/asset/image/book/StoryModeBook16.png differ diff --git a/game/asset/image/book/StoryModeBook2.png b/game/asset/image/book/StoryModeBook2.png new file mode 100644 index 0000000..bd0dfab Binary files /dev/null and b/game/asset/image/book/StoryModeBook2.png differ diff --git a/game/asset/image/book/StoryModeBook3.png b/game/asset/image/book/StoryModeBook3.png new file mode 100644 index 0000000..d36aaad Binary files /dev/null and b/game/asset/image/book/StoryModeBook3.png differ diff --git a/game/asset/image/book/StoryModeBook4.png b/game/asset/image/book/StoryModeBook4.png new file mode 100644 index 0000000..749c209 Binary files /dev/null and b/game/asset/image/book/StoryModeBook4.png differ diff --git a/game/asset/image/book/StoryModeBook5.png b/game/asset/image/book/StoryModeBook5.png new file mode 100644 index 0000000..c66f873 Binary files /dev/null and b/game/asset/image/book/StoryModeBook5.png differ diff --git a/game/asset/image/book/StoryModeBook6.png b/game/asset/image/book/StoryModeBook6.png new file mode 100644 index 0000000..2a1a397 Binary files /dev/null and b/game/asset/image/book/StoryModeBook6.png differ diff --git a/game/asset/image/book/StoryModeBook7.png b/game/asset/image/book/StoryModeBook7.png new file mode 100644 index 0000000..140c11a Binary files /dev/null and b/game/asset/image/book/StoryModeBook7.png differ diff --git a/game/asset/image/book/StoryModeBook8.png b/game/asset/image/book/StoryModeBook8.png new file mode 100644 index 0000000..d3f5bdb Binary files /dev/null and b/game/asset/image/book/StoryModeBook8.png differ diff --git a/game/asset/image/book/StoryModeBook9.png b/game/asset/image/book/StoryModeBook9.png new file mode 100644 index 0000000..544d671 Binary files /dev/null and b/game/asset/image/book/StoryModeBook9.png differ diff --git a/game/src/world/common/component/animation.lua b/game/src/world/common/component/animation.lua new file mode 100644 index 0000000..f3cc6c8 --- /dev/null +++ b/game/src/world/common/component/animation.lua @@ -0,0 +1,49 @@ +local image = require("wrapper.lappy.new.image").obj + +local components = {} + +components.dict = { + image_frame = "image_frame", + trigger_frame = "trigger_frame", + frame_i = "frame_i", + run_time = "run_time", + anim_direction = "anim_direction", + next_trigger_frame = "next_trigger_frame", + fps = "fps" +} + +function components.image_frame (c, paths) + c.data = { + images = {}, + path = paths or {} + } + for k, v in ipairs(paths) do + table.insert(c.data.images, image:load_to(v, v)) + end +end + +function components.trigger_frame (c, array) + c.data = array or {} +end + +function components.frame_i (c, index) + c.data = index or 1 +end + +function components.run_time (c, float) + c.data = float or 0 +end + +function components.anim_direction (c, one) + c.data = one or 1 +end + +function components.next_trigger_frame (c, index) + c.data = index or 1 +end + +function components.fps (c, frame_per_second) + c.data = frame_per_second or 12 +end + +return components diff --git a/game/src/world/common/component/audio.lua b/game/src/world/common/component/audio.lua new file mode 100644 index 0000000..6f30d83 --- /dev/null +++ b/game/src/world/common/component/audio.lua @@ -0,0 +1,24 @@ +local source = require("wrapper.lappy.new.source").obj + +local components = {} + +components.dict = { + bgm = "bgm", + sfx = "sfx", +} + +function components.bgm (c, path) + c.data = { + source = source:load_to(path, path, "stream"), + path = path + } +end + +function components.sfx (c, path) + c.data = { + source = source:load_to(path, path, "static"), + path = path + } +end + +return components diff --git a/game/src/world/common/system/flip.lua b/game/src/world/common/system/flip.lua new file mode 100644 index 0000000..b493a17 --- /dev/null +++ b/game/src/world/common/system/flip.lua @@ -0,0 +1,97 @@ +local floor = math.floor + +local system_constructor = require("wrapper.Concord.system") +local audio = require("src.world.common.component.audio") +local animation = require("src.world.common.component.animation") + +local system = {} + +system.__index = system + +system.pool = { + pool = { + audio.dict.sfx, + animation.dict.anim_direction, + animation.dict.fps, + animation.dict.frame_i, + animation.dict.image_frame, + animation.dict.next_trigger_frame, + animation.dict.run_time, + animation.dict.trigger_frame, + } +} + +system.components = { + [audio.dict.sfx] = audio.sfx, + [animation.dict.anim_direction] = animation.anim_direction, + [animation.dict.fps] = animation.fps, + [animation.dict.frame_i] = animation.frame_i, + [animation.dict.image_frame] = animation.image_frame, + [animation.dict.next_trigger_frame] = animation.next_trigger_frame, + [animation.dict.run_time] = animation.run_time, + [animation.dict.trigger_frame] = animation.trigger_frame, +} + +function system.new() + local new_system = system_constructor.new("flip", system.pool) + if (new_system) then + for k, v in pairs(system) do + new_system[k] = v + end + return new_system + else + return nil + end +end + +--- system frame +local function update_time(time, delta, indicator) + return time + (delta * indicator) +end + +local function get_loop(index, _max) + local md = index % _max + if (md == 0) then + return _max + else + return index % _max + end +end + +local function update_fps_time(time, fps) + -- floor time to 1. check x fps per second + return floor(time / (1 / fps)) +end + +-- system trigger frame +local function is_trigger(trigger_frames, trigger_id, frame_id) + return (trigger_frames[trigger_id] == frame_id) +end + +function system:update(dt) + for _, e in ipairs(self.pool) do + e[animation.dict.run_time].data = update_time( + e[animation.dict.run_time].data, dt, e[animation.dict.anim_direction].data + ) + local new_index = update_fps_time( + e[animation.dict.run_time].data, e[animation.dict.fps].data + ) + e[animation.dict.frame_i].data = get_loop( + new_index, + #e[animation.dict.image_frame].data.images + ) + + if (is_trigger( + e[animation.dict.trigger_frame].data, + e[animation.dict.next_trigger_frame].data, + e[animation.dict.frame_i].data + )) then + e[animation.dict.next_trigger_frame].data = get_loop( + e[animation.dict.next_trigger_frame].data + 1, #e[animation.dict.trigger_frame].data + ) + e[audio.dict.sfx].data.source:play() + end + end +end + +return system diff --git a/game/src/world/common/template/book.lua b/game/src/world/common/template/book.lua new file mode 100644 index 0000000..b350f67 --- /dev/null +++ b/game/src/world/common/template/book.lua @@ -0,0 +1,39 @@ +local flip = require("src.world.common.system.flip") + +local template = {} + +template.default_data = { + sfx = "asset/audio/sfx/book_flip.1.ogg", + anim_direction = 1, + fps = 12, + frame_i = 1, + image_frame = { + "asset/image/book/StoryMode.png", + "asset/image/book/StoryModeBook.png", + "asset/image/book/StoryModeBook2.png", + "asset/image/book/StoryModeBook3.png", + "asset/image/book/StoryModeBook4.png", + "asset/image/book/StoryModeBook5.png", + "asset/image/book/StoryModeBook6.png", + "asset/image/book/StoryModeBook7.png", + "asset/image/book/StoryModeBook8.png", + "asset/image/book/StoryModeBook9.png", + "asset/image/book/StoryModeBook11.png", + "asset/image/book/StoryModeBook16.png", + }, + next_trigger_frame = 1, + run_time = 0, + trigger_frame = {1}, +} +function template.assemble(e, data) + e:give(flip.pool.pool[1], data.sfx) + e:give(flip.pool.pool[2], data.anim_direction) + e:give(flip.pool.pool[3], data.fps) + e:give(flip.pool.pool[4], data.frame_i) + e:give(flip.pool.pool[5], data.image_frame) + e:give(flip.pool.pool[6], data.next_trigger_frame) + e:give(flip.pool.pool[7], data.run_time) + e:give(flip.pool.pool[8], data.trigger_frame) +end + +return template diff --git a/game/src/world/race/init.lua b/game/src/world/race/init.lua index 2f5a575..53d3460 100644 --- a/game/src/world/race/init.lua +++ b/game/src/world/race/init.lua @@ -1,10 +1,14 @@ local reap = require("lib.reap") local BASE = reap.base_path(...) +local image = require("wrapper.lappy.new.image").obj local world = require("wrapper.Concord.world") local debug_entity = require("src.world.common.template.debug_entity") +local book = require("src.world.common.template.book") + +local animation = require("src.world.common.component.animation") local wrapper = world:extend() @@ -22,8 +26,26 @@ function wrapper:load(_args) position = {0, 0}, label = "race world" } + }, + { + assemblage = book.assemble, + data = book.default_data } }) end +function wrapper:draw() + wrapper.super.draw(self) + + for k, v in pairs(self.entities) do + if v[animation.dict.frame_i] ~= nil then + local frame_i = v[animation.dict.frame_i].data + local img = v[animation.dict.image_frame].data.images + if (img ~= nil) then + love.graphics.draw(img[frame_i]) + end + end + end +end + return wrapper diff --git a/game/wrapper/Concord/world.lua b/game/wrapper/Concord/world.lua index 841e975..15053e1 100644 --- a/game/wrapper/Concord/world.lua +++ b/game/wrapper/Concord/world.lua @@ -22,6 +22,7 @@ function wrapper:new(path, name) wrapper.super.new(self, path, name) self.is_loaded = false self.world = World() + self.entities = {} end local function load_systems(world, system_paths) @@ -46,17 +47,18 @@ local function load_systems(world, system_paths) end end -local function load_entities(world, data) +local function load_entities(self, world, data) for _, d in pairs(data) do local entity = entity_builder.new() entity:assemble(d.assemblage, d.data) world:addEntity(entity) + table.insert(self.entities, entity) end end function wrapper:load(system_paths, entities_data) load_systems(self.world, system_paths) - load_entities(self.world, entities_data) + load_entities(self, self.world, entities_data) self.is_loaded = true self.world:emit("load") end