Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - wrightmat

Pages: 1 ... 14 15 [16] 17
226
Development / Re: Referencing global timers
« on: May 20, 2014, 03:19:33 am »
Works perfectly now - you're amazing! Thanks!

As far as the savegame variables - I fall into the same category as ZSDX on this one. I've been following the engine from the beginning and developing very early on, so I already had a large number of savegame variables established and it was easier to stick with the numbers. I have a system in place now and I actually like them! :-)

227
Development / Re: Referencing global timers
« on: May 19, 2014, 02:06:39 pm »
Hmm... I think I understand what you're saying. My case is a tricky one though. It's basically a race that takes place over two different maps. So regardless of which map you're on, when the timer runs out, you lose the race. This is why I was hoping the timer callback would be persistent. I had even declared that end_race_lost function in each map, and it still didn't appear to be working. For reference, here's the function (those torch entities exist on both maps):

Code: [Select]
sol.audio.play_sound("wrong")
game:set_value("i1028", 4);
torch_1:get_sprite():set_animation("unlit")
torch_2:get_sprite():set_animation("unlit")
torch_3:get_sprite():set_animation("unlit")
game.race_timer = nil


Do you know of any way to make this work?

228
Development / Re: Referencing global timers
« on: May 18, 2014, 11:30:54 pm »
Wow, that was fast! Thanks Christopho!

EDIT: Even with the new code in place, the callback of the timer (in the case above, "end_race_lost") won't run on another map. Erro is "bad argument #3 to '__index' (This map is not running).

229
Development / Referencing global timers
« on: May 18, 2014, 09:07:11 pm »
If I have a timer that I've declared in the "game" context, and my character moves to a different map while the timer is still active, I can't figure out how to reference that timer.

Code: [Select]
race_timer = sol.timer.start(game, 140000, end_race_lost)
race_timer:set_with_sound(true)

Timer declared as above. I know the timer is still active when the map changes because the sound still plays. I also have the time displayed on screen using race_timer:get_remaining_time(). When the hero changes maps, the timer display disappears.

Code: [Select]
  if race_timer ~= nil then
    function map:on_draw(dst_surface)
      local timer_icon = sol.surface.create("hud/timer.png")
      local timer_time = race_timer:get_remaining_time() / 1000
      local timer_text = sol.text_surface.create{
        font = "white_digits",
        horizontal_alignment = "left",
        vertical_alignment = "top",
      }
      timer_icon:draw(dst_surface, 20, 55)
      timer_text:set_text(timer_time)
      timer_text:draw(dst_surface, 40, 60)
    end
  end

The display is disappearing because the timer reference goes to nil, which I'm intentionally checking for. If I comment out the check, I get an error message of "attempt to index global 'race_timer' (a nil value), but the value shouldn't be nil since the timer is in a "game" context, right? Should I be referencing it a different way, or is this a bug in the engine?

230
Development / Re: Tips for cutscenes
« on: April 23, 2014, 11:51:39 pm »
Haha, thanks. I'm glad I'm not the only one who came up with that quick and dirty solution :-)

231
Development / Tips for cutscenes
« on: April 23, 2014, 01:24:51 am »
I'm wondering if anyone has ideas on how to implement cutscenes in Solarus?

Unless I'm missing something in the documentation, it appears that the only option for moving the camera is with map:move_camera which always returns to the hero after the delay is completed - otherwise the engine always centers the camera on the hero.

Is there some trick to center the camera on a different entity, such as an NPC, so RPG-like cutscenes could be created? I even tried making the hero invisible, moving him to the area where the action was taking place and then moving him back and making him visible again after the scene was over, but I couldn't get it to work correctly.

232
Development / Re: Help: Enemy disappearing
« on: March 24, 2014, 03:51:58 am »
Wow, thanks so much Renkineko!

If you were referring to the difficulty of the boss - now that the script works, I've fine-tuned the boss's difficulty level :-)

233
Development / Re: Help: Enemy disappearing
« on: March 20, 2014, 01:38:22 am »
Christopho- no luck on the optimization distance trick, thanks though.

Renkineko- I did double check the sprite, but I always could have missed something!

https://github.com/wrightmat/zbom/blob/master/data/sprites/enemies/gohma.png

234
Development / Re: HUD Script: Small Keys (ALBW Style)
« on: March 20, 2014, 12:11:26 am »
Good call, thanks!

235
Development / HUD Script: Small Keys (ALBW Style)
« on: March 19, 2014, 02:18:49 am »
If anyone's interested, I modified the small keys script provided by christopho in zsdx to display the keys in a manner more consistent with A Link Between Worlds rather than A Link to the Past. By that, I mean that keys are displayed as a number of small icons (consistent with the number of keys obtained) rather than a small key icon and a number.

Code: [Select]
-- Allows small keys to be displayed on maps with small keys enabled.
-- Done in ALBW style, a key icon is shown for each key obtained (no counter or icon)

local small_keys = {}

function small_keys:new(game)
  local object = {}
  setmetatable(object, self)
  self.__index = self

  object:initialize(game)
  return object
end

function small_keys:initialize(game)
  local nb_keys_displayed = 0

  self.game = game
  self.visible = false
  self.surface = sol.surface.create(80, 16)

  self:check()
  self:rebuild_surface()
end

function small_keys:check()
  local need_rebuild = false

  -- Check the number of small keys.
  if self.game:are_small_keys_enabled() then
    local nb_keys = self.game:get_num_small_keys()
    if nb_keys_displayed ~= nb_keys then
      need_rebuild = true
    end
  end

  local visible = self.game:are_small_keys_enabled()
  if visible ~= self.visible then
    self.visible = visible
    need_rebuild = true
  end

  -- Redraw the surface is something has changed.
  if need_rebuild then
    self:rebuild_surface()
  end

  -- Schedule the next check.
  sol.timer.start(self.game, 40, function()
    self:check()
  end)
end

function small_keys:rebuild_surface()
  self.surface:clear()
  if self.game:are_small_keys_enabled() then
    for i=0,self.game:get_num_small_keys()-1 do
      self.icon_img = sol.surface.create("hud/small_key.png")
      self.icon_img:draw(self.surface,i*14)
      if nb_keys_displayed ~= nil then
        nb_keys_displayed = nb_keys_displayed + 1
      else
        nb_keys_displayed = 1
      end
    end
  end
end

function small_keys:set_dst_position(x, y)
  self.dst_x = x
  self.dst_y = y
end

function small_keys:on_draw(dst_surface)
  if self.visible then
    local x, y = self.dst_x, self.dst_y
    local width, height = dst_surface:get_size()
    if x < 0 then
      x = width + x
    end
    if y < 0 then
      y = height + y
    end
    self.surface:draw(dst_surface, x, y)
  end
end

return small_keys

Feel free to use as you wish! I also modified hud/hud.lua to display the small keys at the bottom left above the rupees like they are in ALBW. The script also uses a small key icon of your choice in sprites/hud/small_key.png

236
Development / Help: Enemy disappearing
« on: March 19, 2014, 02:13:40 am »
Hoping for a little help on one of my bosses. For some reason he keeps disappearing when that's not what I'm intending with my script, so I must be missing something. It seems to happen primarily as he's finishing the "opening" phase.

Enemy script:
Code: [Select]
local enemy = ...

-- Gohma: Boss who has to be shot in the eye with an arrow to be hurt

function enemy:on_created()
  self:set_life(9)
  self:set_damage(2)
  self:create_sprite("enemies/gohma")
  self:set_hurt_style("boss")
  self:set_size(64, 32)
  self:set_origin(32, 29)
  self:set_attack_consequence("sword", "protected")
  self:get_sprite():set_animation("walking")
end

function enemy:check_action()
  local action = math.random(10)
  if self:get_life() > 6 then
    -- first phase: if less than three hits then mostly just move around (slowly), and create tektites
    local son_name = self:get_name().."_son"
    self:create_enemy{
      name = son_name,
      breed = "tektite_green",
      treasure_name = "heart"
    }
    if action >= 1 and action <= 7 then self:go(96) else self:blink() end
  elseif self:get_life() > 3 and self:get_life() <= 6 then
    -- second phase: if more than 3 but less than 6 hits then blink a lot more, and create tektites
    if action >= 1 and action <= 7 then self:blink() else self:go(96) end
    local son_name = self:get_name().."_son"
    self:create_enemy{
      name = son_name,
      breed = "tektite_green"
    }
  elseif self:get_life() < 3 and self:get_life() > 0 then
    -- final phase: if more than 6 hits then move a lot faster, and create tektites!
    if action >= 1 and action <= 6 then self:blink() else self:go(128) end
    local son_name = self:get_name().."_son"
    self:create_enemy{
      name = son_name,
      breed = "tektite_green"
    }
  end
  sol.timer.start(self, 100, function() self:open() end)
end

function enemy:go(speed)
  self:get_sprite():set_animation("walking")
  self:set_attack_consequence("arrow", 1)
  local m = sol.movement.create("random")
  m:set_speed(speed)
  m:set_max_distance(24)
  m:start(self)
end

function enemy:blink()
  self:set_attack_consequence("arrow", "protected")
  self:get_sprite():set_animation("blinking")
end

function enemy:open()
  self:set_attack_consequence("arrow", 1)
  self:get_sprite():set_animation("opening")
end

function enemy:on_restarted()
  self:get_sprite():set_animation("walking")
  self:check_action()
end

function enemy:on_obstacle_reached()
  self:check_action()
end

function enemy:on_animation_finished(sprite, animation)
  self:set_attack_consequence("arrow", "protected")
  if animation == "blinking" then
    self:get_sprite():set_animation("closed")
    sol.timer.start(self, random(6)*1000, function() self:open() end)
    self:go(64)
  elseif animation == "opening" then
    self:get_sprite():set_animation("walking")
    sol.timer.start(self, 1000, function() self:check_action() end)
  end
end

Sprite file:
Code: [Select]
animation{
  name = "walking",
  src_image = "enemies/gohma.png",
  frame_delay = 200,
  frame_to_loop_on = 0,
  directions = {
    { x = 0, y = 128, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
    { x = 0, y = 64, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
    { x = 0, y = 96, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
    { x = 0, y = 32, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
  },
}

animation{
  name = "shaking",
  src_image = "enemies/gohma.png",
  frame_delay = 100,
  frame_to_loop_on = 0,
  directions = {
    { x = 64, y = 128, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 2 },
    { x = 64, y = 64, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 2 },
    { x = 64, y = 96, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 2 },
    { x = 64, y = 32, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 2 },
  },
}

animation{
  name = "hurt",
  src_image = "enemies/gohma.png",
  frame_delay = 100,
  frame_to_loop_on = 0,
  directions = {
    { x = 256, y = 32, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
    { x = 256, y = 32, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
    { x = 256, y = 32, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
    { x = 256, y = 32, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
  },
}

animation{
  name = "closed",
  src_image = "enemies/gohma.png",
  frame_delay = 200,
  frame_to_loop_on = 0,
  directions = {
    { x = 256, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
    { x = 256, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
    { x = 256, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
    { x = 256, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 4 },
  },
}

animation{
  name = "blinking",
  src_image = "enemies/gohma.png",
  frame_delay = 150,
  directions = {
    { x = 0, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 3 },
    { x = 0, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 3 },
    { x = 0, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 3 },
    { x = 0, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 3 },
  },
}

animation{
  name = "opening",
  src_image = "enemies/gohma.png",
  frame_delay = 150,
  directions = {
    { x = 128, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 2 },
    { x = 128, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 2 },
    { x = 128, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 2 },
    { x = 128, y = 0, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29, num_frames = 2 },
  },
}

animation{
  name = "immobilized",
  src_image = "enemies/gohma.png",
  directions = {
    { x = 0, y = 128, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29 },
    { x = 0, y = 64, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29 },
    { x = 0, y = 96, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29 },
    { x = 0, y = 32, frame_width = 64, frame_height = 32, origin_x = 32, origin_y = 29 },
  },
}

237
Hmmm... I'll triple check my system config - I just thought I'd check with you too!

238
I went to compile the newest code, and all the sudden I'm getting a cmake error about not being able to find OpenAL which I didn't get yesterday when I compiled older code. I double-checked and my system does have libopenal installed.

Code: [Select]
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE 
-- Found SDL2: /usr/local/lib/libSDL2main.a;/usr/local/lib/libSDL2.so;-lpthread (Required is at least version "2")
-- Found SDL2_image: /usr/include/SDL2 (found suitable version "2.0.0", minimum required is "2")
-- Found SDL2_ttf: /usr/local/include/SDL2 (found suitable version "2.0.12", minimum required is "2.0.12")
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message):
  Could NOT find OpenAL (missing: OPENAL_LIBRARY)
Call Stack (most recent call first):
  /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-2.8/Modules/FindOpenAL.cmake:97 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:18 (find_package)


-- Configuring incomplete, errors occurred!

239
Bugs & Feature requests / Fatal: Non-empty stack after LuaContext::update()
« on: February 16, 2014, 07:45:22 pm »
Not sure if this is a bug in the engine or the fault of my script, but I get the error "Fatal: Non-empty stack after LuaContext::update()" when one of my enemies is on the screen after a few seconds. The enemy script is below:

Code: [Select]
local enemy = ...

-- Octorok: simple enemy who wanders and shoots rocks

local going_hero = false
local awaken = false
local timer

function enemy:on_created()
  self:set_life(1)
  self:set_damage(2)
  self:create_sprite("enemies/octorok_red")
  self:set_hurt_style("monster")
  self:set_pushed_back_when_hurt(true)
  self:set_push_hero_on_sword(false)
  self:set_size(16, 16)
  self:set_origin(8, 13)
end

function enemy:on_movement_changed(movement)
  local direction4 = movement:get_direction4()
  local sprite = self:get_sprite()
  sprite:set_direction(direction4)
end

function enemy:on_obstacle_reached(movement)
  if awaken and not going_hero then
    self:check_hero()
  end
end

function enemy:on_restarted()
  if not awaken then
    self:go_random()
  else
    self:go_hero()
  end
  self:check_hero()
end

function enemy:on_hurt()
  if timer ~= nil then
    timer:stop()
    timer = nil
  end
end

function enemy:check_hero()
  local hero = self:get_map():get_entity("hero")
  local _, _, layer = self:get_position()
  local _, _, hero_layer = hero:get_position()
  local near_hero = layer == hero_layer
    and self:get_distance(hero) < 100

  if awaken then
    if near_hero and not going_hero then
      self:go_hero()
    elseif not near_hero and going_hero then
      self:go_random()
    end
  elseif not awaken and near_hero then
    self:wake_up()
  end
  timer = sol.timer.start(self, 1000, function() self:check_hero() end)
end

function enemy:wake_up()
  self:stop_movement()
  local sprite = self:get_sprite()
  sprite:set_animation("shooting")
  local x, y, l = self:get_position()
  local sx, sy = 0
  if d == 0 then
    sx = x + 8
    sy = y
  end
  if d == 1 then
    sy = y - 8
    sx = x
  end
  if d == 2 then
    sx = x - 8
    sy = y
  end
  if d ==3 then
    sy = y +8
    sx = x
  end
  sol.timer.start(self, 1000, function()
    local rock = self:create_enemy{
      breed = "rock_small",
      x = sx,
      y = sy
    }
    rock:go(d)
    sol.timer.start(self, 2000, function()
      self:check_hero()
    end)
  end)
end

function enemy:go_random()
  local m = sol.movement.create("random")
  m:set_speed(32)
  m:start(self)
  d = m:get_direction4()
  going_hero = false
end

function enemy:go_hero()
  local m = sol.movement.create("target")
  m:set_speed(48)
  m:start(self)
  d = m:get_direction4()
  going_hero = true
end

240
Development / Re: Cryptic error
« on: February 05, 2014, 08:38:56 pm »
Updating SDL worked perfectly! You are a genius, thanks!

Pages: 1 ... 14 15 [16] 17