Skip to content

Commit

Permalink
Fixed some logging lines
Browse files Browse the repository at this point in the history
  • Loading branch information
tanis2000 committed May 3, 2024
1 parent ed4ff48 commit 88c3bc1
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 68 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Binocle Player

[![Windows](https://github.com/tanis2000/binocle-player/actions/workflows/windows.yml/badge.svg)](https://github.com/tanis2000/binocle-player/actions/workflows/windows.yml)
[![macOS](https://github.com/tanis2000/binocle-player/actions/workflows/macos.yml/badge.svg)](https://github.com/tanis2000/binocle-player/actions/workflows/macos.yml)
[![Wasm](https://github.com/tanis2000/binocle-player/actions/workflows/wasm.yml/badge.svg)](https://github.com/tanis2000/binocle-player/actions/workflows/wasm.yml)

Binocle Player aims at providing a pre-compiled version of Binocle that can be used to quickly write 2D games in Lua.

The core philosophy is somewhat similar to Love2D. Binocle Player comes as a pre-compiled binary for macOS and Windows and can run games from the command line.
Expand Down
6 changes: 4 additions & 2 deletions assets/boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ local traceback = debug.traceback
local delta_time = 0

local function on_error(msg)
print("msg: " .. msg .. "\n" .. traceback())
input.set_quit_requested(input_mgr, true)
log.error("Error: " .. msg .. "\n" .. traceback())
if input.set_quit_requested ~= nil then
input.set_quit_requested(input_mgr, true)
end
end

local function call(fn, ...)
Expand Down
4 changes: 2 additions & 2 deletions assets/cooldown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ end

function Cooldown:set(name, seconds, func, ...)
local cd = CooldownInstance(name, seconds, func, ...)
-- print(tostring(cd))
-- log.info(tostring(cd))
self.cooldowns[name] = cd
end

function Cooldown:update(dt)
local count = 0
--io.write("cooldowns:" .. tostring(self) .. "\n")
--log.info("cooldowns:" .. tostring(self))
for idx in pairs(self.cooldowns) do
--log.info("this cd: "..tostring(self.cooldowns[idx]))
self.cooldowns[idx].remaining = self.cooldowns[idx].remaining - dt
Expand Down
1 change: 0 additions & 1 deletion assets/debuggui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ function DebugGui:entity(en)
local res = false
res, cx = imgui.DragFloat("cx", cx, 1, 0, 0, "%.2f", 1)
if res then
print(cx)
en:set_pos_grid(cx, en.cy)
end
local cy = en.cy
Expand Down
4 changes: 2 additions & 2 deletions assets/en/bullet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function Bullet:update(dt)
and self:get_center_x() <= en:get_center_x()+en.radius
and self:get_bottom() >= en:get_bottom() and self:get_bottom() <= en:get_bottom() + en.hei then
-- hit the mob
print("hit")
log.info("hit")
-- remove this from the scene
self:kill()
lume.remove(G.bullets, self)
Expand All @@ -51,7 +51,7 @@ function Bullet:update(dt)

if not G.game.level:is_valid(self.cx, self.cy) or G.game.level:has_collision(self.cx, self.cy) then
-- remove this from the scene
print("wall")
log.info("wall")
self:kill()
lume.remove(G.bullets, self)
end
Expand Down
2 changes: 1 addition & 1 deletion assets/en/cat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function Cat:update(dt)
and self:get_bottom() <= en:get_bottom() + en.hei
and self.cd:has("projectile") then
-- hit the mob
print("hit")
log.info("hit")
en:hurt(1, self.dir)
end
end
Expand Down
4 changes: 2 additions & 2 deletions assets/en/hero.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function Hero.is_shooting(self)
end

function Hero.say(self, s)
print("saying "..s)
log.info("saying "..s)
self:clear_saying()
SayText(self, s)
end
Expand All @@ -181,7 +181,7 @@ function Hero.see_cats(self)
if self:dist_case(c) < 3 and not self.cd:has("cat_seen") then
self.cats_seen = self.cats_seen + 1
if self.cats_seen < #self.cats_sentences+1 then
print("cats")
log.info("cats")
self:say(self.cats_sentences[self.cats_seen])
self.cd:set("cat_seen", 10)
return
Expand Down
2 changes: 1 addition & 1 deletion assets/en/mob.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function Mob:update(dt)
self.target = G.game.h
self.dir = self:dir_to(self.target)
self:bump(0, 0.1)
print("target qcquired")
log.info("target qcquired")
end

local spd = 1
Expand Down
2 changes: 1 addition & 1 deletion assets/en/saymark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function SayMark:update(dt)
SayMark.super.update(self, dt)

if G.game.h:is_alive() and self:dist_case(G.game.h) < self.trigger_distance then
print("trigger say")
log.info("trigger say")
G.game.h:say(self.text)
self:kill()
end
Expand Down
4 changes: 2 additions & 2 deletions assets/en/saytext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function SayText:new(owner, s)
SayText.super.new(self)
self.depth = layers.TEXT
self.owner = owner
print(owner)
log.info(tostring(owner))
self.s = s
self.cd:set("keep_saying", 2.5 + 0.10 * string.len(s))
end
Expand All @@ -15,7 +15,7 @@ function SayText:update(dt)
SayText.super.update(self, dt)

if not self.cd:has("keep_saying") then
print("removing saying")
log.info("removing saying")
self:kill()
end
end
Expand Down
2 changes: 1 addition & 1 deletion assets/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function Entity:load_image(filename, width, height, shader)
local original_image_width, original_image_height = image.get_info(self.image)
for y = 0, original_image_height / height - 1 do
for x = 0, original_image_width / width - 1 do
print(self.name .. " image x "..tostring(x) .. " y " .. tostring(y) .. " w " .. tostring(width) .. " h " .. tostring(height))
log.info(self.name .. " image x "..tostring(x) .. " y " .. tostring(y) .. " w " .. tostring(width) .. " h " .. tostring(height))
local frame = subtexture.subtexture_with_texture(self.texture, x * width, y * height, width, height)
sprite.set_subtexture(self.sprite, frame)
table.insert(self.frames, frame)
Expand Down
4 changes: 2 additions & 2 deletions assets/level.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function Level:has_wall_collision(cx, cy)
end

function Level:set_mark(x, y, v)
print("setting mark " .. tostring(v) .. " at " .. tostring(x) .. "," .. tostring(y))
log.info("setting mark " .. tostring(v) .. " at " .. tostring(x) .. "," .. tostring(y))
if self:is_valid(x, y) then
if v then
self.marks_map[self:coord_id(x, y)] = v
Expand Down Expand Up @@ -218,7 +218,7 @@ function Level:render()
if layer.name == "fg" then
depth = layers.FG
end
-- io.write("v: " .. tostring(value) .. "cx: " .. cx .. "cy: " .. cy .. "\n")
-- log.info("v: " .. tostring(value) .. "cx: " .. cx .. "cy: " .. cy)
--sprite.draw(self.tiles[value].sprite, gd_instance, cx * const.GRID, (layer.height-1) * const.GRID - cy * const.GRID, viewport, 0, self.scale.x, self.scale.y, cam, depth)
sprite.draw_batch(sb, self.tiles[value].sprite, gd_instance, cx * const.GRID, (layer.height-1) * const.GRID - cy * const.GRID, viewport, 0, self.scale.x, self.scale.y, cam, depth)
end
Expand Down
49 changes: 25 additions & 24 deletions assets/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local entity = require("entity")
local Intro = require("scenes/intro")
local cache = require("cache")

-- Initialize the LuaPanda debugger (we use a custom version)
require("LuaPanda").start("127.0.0.1", 8818);

main = {}
Expand Down Expand Up @@ -76,33 +77,33 @@ local intro
function on_init()
---@type Window
win = window.new(const.DESIGN_WIDTH * const.SCALE, const.DESIGN_HEIGHT * const.SCALE, G.title)
io.write("win: " .. tostring(win) .."\n")
log.info("win: " .. tostring(win))
local bg_color = color.black
io.write("bg_color: " .. tostring(bg_color) .."\n")
log.info("bg_color: " .. tostring(bg_color))
window.set_background_color(win, bg_color)
window.set_minimum_size(win, const.DESIGN_WIDTH, const.DESIGN_HEIGHT)

input_mgr = input.new()
io.write("input_mgr: " .. tostring(input_mgr) .."\n")
log.info("input_mgr: " .. tostring(input_mgr))

adapter = viewport_adapter.new(win, "scaling", "pixel_perfect",
const.DESIGN_WIDTH, const.DESIGN_HEIGHT, const.DESIGN_WIDTH, const.DESIGN_HEIGHT);
io.write("adapter: " .. tostring(adapter) .."\n")
log.info("adapter: " .. tostring(adapter))

cam = camera.new(adapter)
io.write("cam: " .. tostring(cam) .."\n")
log.info("cam: " .. tostring(cam))

--default_shader = shader.load_from_file(assets_dir .. "shaders/default_vert.glsl",
-- assets_dir .. "shaders/default_frag.glsl")
--io.write("default shader: " .. tostring(default_shader) .. "\n")
--log.info("default shader: " .. tostring(default_shader))
--
--screen_shader = shader.load_from_file(assets_dir .. "shaders/screen_vert.glsl",
-- assets_dir .. "shaders/screen_frag.glsl")
--io.write("screen shader: " .. tostring(screen_shader) .. "\n")
--log.info("screen shader: " .. tostring(screen_shader))

gd_instance = gd.new()
gd.init(gd_instance, win)
io.write("gd_instance: " .. tostring(gd_instance) .. "\n")
log.info("gd_instance: " .. tostring(gd_instance))

-- BEGIN experimental code to setup a shader, pipeline and renderer
local vs = fs.load_text_file("/assets/shaders/" .. app.shader_prefix() .. "/default_vert.glsl");
Expand All @@ -128,7 +129,7 @@ function on_init()

sb = sprite_batch.new()
sprite_batch.set_gd(sb, gd_instance)
io.write("sb: " .. tostring(sb) .. "\n")
log.info("sb: " .. tostring(sb))

-- Create a viewport that corresponds to the size of our render target
local center = lkazmath.kmVec2New();
Expand All @@ -139,7 +140,7 @@ function on_init()

audio_instance = audio.new()
audio.init(audio_instance)
io.write("audio_instance: " .. tostring(audio_instance) .. "\n")
log.info("audio_instance: " .. tostring(audio_instance))

local music = audio.load_music(audio_instance, assets_dir .. "data/music/theme.mp3")
G.musics["main"] = music
Expand All @@ -155,7 +156,7 @@ function on_init()
end

function main.on_update(dt)
--io.write("dt: " .. tostring(dt) .. "\n")
--log.info("dt: " .. tostring(dt))
if not scene then
G.default_shader = shader.defaultShader()
end
Expand All @@ -175,18 +176,18 @@ function main.on_update(dt)
scene = intro
--return
end
--io.write("scene: " .. tostring(scene.name) .. "\n")
--log.info("scene: " .. tostring(scene.name))

scene:pre_update(dt)

if input.is_key_down(input_mgr, key.KEY_1) then
G.debug = not G.debug
print(G.debug)
log.info(tostring(G.debug))
end

if input.is_key_down(input_mgr, key.KEY_ESCAPE) then
quit_requests = quit_requests + 1
print(quit_requests)
log.info(tostring(quit_requests))
if quit_requests > 1 then
input.set_quit_requested(input_mgr, true)
end
Expand Down Expand Up @@ -240,47 +241,47 @@ function load_sfx(name, filename)
end

function get_window()
io.write("get_window win: " .. tostring(win) .."\n")
log.info("get_window win: " .. tostring(win))
return win
end

function get_adapter()
io.write("get_adapter adapter: " .. tostring(adapter) .."\n")
log.info("get_adapter adapter: " .. tostring(adapter))
return adapter
end

function get_camera()
io.write("get_camera cam: " .. tostring(cam) .."\n")
log.info("get_camera cam: " .. tostring(cam))
return cam
end

function get_input_mgr()
io.write("get_input_mgr input_mgr: " .. tostring(input_mgr) .."\n")
log.info("get_input_mgr input_mgr: " .. tostring(input_mgr))
return input_mgr
end

function get_gd_instance()
io.write("get_gd_instance gd: " .. tostring(gd_instance) .."\n")
log.info("get_gd_instance gd: " .. tostring(gd_instance))
return gd_instance
end

function get_sprite_batch_instance()
io.write("get_sprite_batch_instance sb: " .. tostring(sb) .."\n")
log.info("get_sprite_batch_instance sb: " .. tostring(sb))
return sb
end

function get_audio_instance()
io.write("get_audio_instance audio_instance: " .. tostring(audio_instance) .."\n")
log.info("get_audio_instance audio_instance: " .. tostring(audio_instance))
return audio_instance
end

function get_design_width()
io.write("get_design_width: " .. tostring(const.DESIGN_WIDTH) .."\n")
log.info("get_design_width: " .. tostring(const.DESIGN_WIDTH))
return const.DESIGN_WIDTH
end

function get_design_height()
io.write("get_design_height: " .. tostring(const.DESIGN_HEIGHT) .."\n")
log.info("get_design_height: " .. tostring(const.DESIGN_HEIGHT))
return const.DESIGN_HEIGHT
end

Expand All @@ -297,5 +298,5 @@ function dump(o)
end
end

io.write("End of main.lua\n")
log.info("End of main.lua")

4 changes: 2 additions & 2 deletions assets/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ end

function Process:add_child(child)
assert(child:is(Process))
print("adding children " .. child:__tostring() .. " to " .. self:__tostring())
print(child.id)
log.info("adding children " .. child:__tostring() .. " to " .. self:__tostring())
log.info(tostring(child.id))
if child.parent ~= nil then
child.parent:remove_child(child)
end
Expand Down
6 changes: 3 additions & 3 deletions assets/scenes/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function Game:new(shd)
self:spawn_cats(3)

self.gui = Gui()
print(self.gui)
log.info(tostring(self.gui))
self:add_child(self.gui)

self.day_cycle = DayCycle()
Expand Down Expand Up @@ -92,7 +92,7 @@ function Game:update(dt)

if input.is_key_pressed(input_mgr, key.KEY_L) then
camera.set_position(cam, camera.x(cam) + 100 * dt, camera.y(cam))
io.write(camera.x(cam).."\n")
log.info(camera.x(cam))
elseif input.is_key_pressed(input_mgr, key.KEY_J) then
camera.set_position(cam, camera.x(cam) - 100 * dt, camera.y(cam))
end
Expand Down Expand Up @@ -177,7 +177,7 @@ function Game:garbage_collect()
for idx in lume.ripairs(G.entities) do
en = G.entities[idx]
if en.destroyed then
print("dispose")
log.info("dispose")
en:on_dispose()
end
end
Expand Down
10 changes: 5 additions & 5 deletions assets/scenes/intro.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ function Intro:init(shd)
self.tex = texture.from_image(self.img)
self.mat = material.new()

io.write("intro.mat: " .. tostring(self.mat) .."\n")
io.write("material: " .. tostring(material) .."\n")
io.write("shd: " .. tostring(shd) .."\n")
log.info("intro.mat: " .. tostring(self.mat))
log.info("material: " .. tostring(material))
log.info("shd: " .. tostring(shd))
material.set_texture(self.mat, self.tex)
material.set_shader(self.mat, shd)
self.logo = sprite.from_material(self.mat)
Expand Down Expand Up @@ -62,7 +62,7 @@ function Intro:update(dt)
local x = (const.DESIGN_WIDTH - (self.TEX_WIDTH * scale_x)) / 2.0
local y = (const.DESIGN_HEIGHT - (self.TEX_HEIGHT * scale_y)) / 2.0

--io.write("x: " .. tostring(x) .. " y: " .. tostring(y) .. "\n")
--log.info("x: " .. tostring(x) .. " y: " .. tostring(y))
sprite.draw(self.logo, gd_instance, x, y, viewport, 0, scale_x, scale_y, cam, 0)

scale_x = const.DESIGN_WIDTH / self.TANIS_TEX_WIDTH * 0.25
Expand Down Expand Up @@ -93,7 +93,7 @@ function Intro:update(dt)
end

function Intro:on_destroy()
print("intro:on_destroy()")
log.info("intro:on_destroy()")
if self.default_font ~= nil then
ttfont.destroy(self.default_font)
self.default_font = nil
Expand Down
Loading

0 comments on commit 88c3bc1

Please sign in to comment.