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.

Topics - Bagu

Pages: [1]
Your scripts / Classic Tektite Random Jumping AI
« on: June 09, 2018, 08:21:21 pm »
I always liked the random jumping of tektites in Zelda 1 and ALTTP, and was a little disappointed by the tektites in Return of the Hylian which simply walked at the player. Thus once I figured out how to set up random jumping for some other enemies I figured I'd share this extremely basic and simple example of Nintendo tektite behavior.

This also would work for replicating Bits/Bots from Zelda 2 or Zols and Gels from Zelda 1.

example video:

Code: Lua
  1. local enemy = ...
  3. local choices = {"pause","jump","jump","jump"}
  4. -- these are functions the enemy will choose from randomly. I added extra copies of the jump function so he would move 75% of the time instead of 50/50. However, you could create more functions and place each one in the list only once.
  6. function enemy:on_created()
  7.   enemy:set_life(3)
  8.   enemy:set_damage(2)
  9.   enemy:create_sprite("enemies/" .. enemy:get_breed())
  10. end
  12. function enemy:on_restarted()
  13.     enemy[ choices[math.random( 1, #choices )] ](enemy) --this line calls a random function from the "choices" table at the top
  14. end
  16. function enemy:pause()
  17.   local sprite = enemy:get_sprite()
  18.   --sprite:set_animation("idle")
  19. -- uncomment the line above if you want to use a custom pause animation, otherwise it'll use "walking"
  20.   enemy:stop_movement()
  21.   sol.timer.start(enemy, math.random(1, 2000), function() --the timer lasts randomly between 1 and 2000 ms. You can change the minimum and maximum to taste.
  22.     enemy[ choices[math.random( 1, #choices )] ](enemy) --again picks a random function from the choices table, you could also just call enemy:restart
  23.   end)
  24. end
  26. function enemy:jump()
  27.   local sprite = enemy:get_sprite()
  28.   enemy:stop_movement()
  29.   --sprite:set_animation("jumping")
  30. -- uncomment the line above if you want to use a custom jump animation, otherwise it'll keep using "walking"
  31.   local movement = sol.movement.create("jump")
  32.   movement:set_direction8(math.random(0, 7)) -- picks a random direction to jump in
  33.   movement:set_distance(math.random(24, 64)) -- sets a distance between 24 and 64px
  34.   movement:start(enemy)
  35.   sol.timer.start(enemy, 800, function()  -- 800ms is the typical time for the enemy to land from a 64px jump.
  36.     enemy[ choices[math.random( 1, #choices )] ](enemy)
  37.   end)

I probably should have used movement:on_finished() instead of a timer to close the jump function, because if you use distances greater than 64 the jump begins to get cut-off early and it looked bad.

Art-wise, if you use something like Return of the Hylian's tektite sprite, it'll look a little weird because there's a shadow drawn into the animations. Thus the shadow floats through the air with the character as he jumps, instead of staying on the ground. The easiest solution is to simply erase any shadows from your animation frames, though this will make it visually ambiguous whether the character is jumping through the air or sliding across the ground. For the best results, you'd want to use a custom entity or something to place a separate shadow sprite under the character.

Special thanks to llamazing for helping me sort out the random function selection call!

Development / function vs. function:enemy
« on: June 09, 2018, 05:29:35 am »
This is super basic but I've looked around and not found an answer and it's really bugging me.

So I find the following to be much cleaner, neater, and easier to deal with than the alternative:

Code: Lua
  1. function pause()
  2.   local sprite = enemy:get_sprite()
  3.   sprite:set_animation("idle")
  4.   enemy:stop_movement()
  5.   sol.timer.start(enemy, math.random(1, 2000), jump)
  6. end
  8. function jump()
  9.   local sprite = enemy:get_sprite()
  10.   enemy:stop_movement()
  11.   sprite:set_animation("jumping")
  12.   local movement = sol.movement.create("jump")
  13.   movement:set_direction8(math.random(0, 7))
  14.   movement:set_distance(math.random(12, 64))
  15.   movement:start(enemy)
  16.   sol.timer.start(enemy, 800, pause)
  17. end

Whereas if I use "function enemy:blahblahblah" I appear to accomplish the same thing, yet the syntax on things like timers is longer and more restrictive:

Code: Lua
  1. function enemy:pause()
  2.   local sprite = enemy:get_sprite()
  3.   sprite:set_animation("idle")
  4.   enemy:stop_movement()
  5.   sol.timer.start(enemy, math.random(1, 2000), function()
  6.     enemy:jump()
  7.   end)
  8. end
  10. function enemy:jump()
  11.   local sprite = enemy:get_sprite()
  12.   enemy:stop_movement()
  13.   sprite:set_animation("jumping")
  14.   local movement = sol.movement.create("jump")
  15.   movement:set_direction8(math.random(0, 7))
  16.   movement:set_distance(math.random(12, 64))
  17.   movement:start(enemy)
  18.   sol.timer.start(enemy, 800, function()
  19.     enemy:pause()
  20.   end)
  21. end

Then if I start mixing both in the same script, it gets much worse because I'll tend to forget and mismatch the syntaxes to the wrong functions and I spend extra time correcting stupid mistakes to clean up all the error messages.

I see the latter method used in a lot of scripts in enemies by the Solaris team, so there must be some advantage to it, or some reason why it's bad to avoid it. What am I missing? Is there a reason not to use the first approach for all my enemy scripts?

Sorry to ask about such basic stuff all the time!

Development / Choosing a Function Randomly
« on: June 09, 2018, 03:03:23 am »
I've looked at a few different methods of making a random selection from a table, as a means to make an enemy AI choose a function as its next action. For example:

Code: Lua
  1. choices = {"enemy:go_hero()","enemy:random_pause()","enemy:jump_pause()","enemy:go_random()"}
  3.   sol.timer.start(enemy, math.random(1, 3000), function()
  4.     choices[math.random( 1, #choices )]
  5. end)

Code: Lua
  1. function enemy:pickaction()
  2. math.randomseed(os.time())
  3. local a = {"go_hero","random_pause","jump_pause","go_random"}
  4. a[math.random(1,#a)]
  5. end
  7.   sol.timer.start(enemy, math.random(1, 3000), function()
  8.     enemy:pickaction()
  9.   end)

I've tried about 20 different variations of this approach and always wind up with an error message like "= expected near end" or "function arguments expected near [".

I can get it to print the desired results to the console but the engine doesn't seem to want to accept them as anything remotely resembling a function. What am I doing wrong?

Development / Shield Animations Reverse Direction for Sword Attacks
« on: May 13, 2018, 07:11:18 pm »
I'm in the process of creating a custom "tall" link sprite, and I'm running into a strange issue with shield animations. The shield's walking animations work fine, but durring sword attacks, the directions get reversed.

In other words, the shield plays the "down" animation during an upwards sword strike, and the "up" animation during a downwards sword strike. I believe Solarus is reversing the shield's left and right sword animations as well, though it's hard to tell since they appear to be clipping behind Link's body.

What could be causing this? You can see from the video that the animation frames and directions are set up just like any other situation.

(Please excuse the WIP art, the frames are very rough and I still have a lot of polishing to do.)

Development / Left Direction of Hero Sprite Goes Blank
« on: May 04, 2018, 06:41:50 pm »
I'm experimenting with a larger format "tall" hero sprite (placeholder ripped from Beyond Oasis) and the left direction for my sword animation is going "invisible" despite everything looking fine in quest editor.

Is there some obvious common newbie mistake that causes this?

Development / Setting Up A Basic Equipment Menu?
« on: April 23, 2018, 04:21:56 am »
Hi I'm new and I've been following along with Christopho's youtube tutorials and reading through the documentation, but I don't see this too comprehensively answered anywhere.

Basically I just want to be able to equip items to different slots to test them out. I've been able to pull things like enemies and items from the Mystery of Solarus DX/Return of the Hylian/Oni Link Begins source github and have them drop into the map easily, and I was able to replicate the "save on pause" process from Chistopho's video tutorial. Hoever I haven't been able to spot exactly which lua scripts to copy an equipment menu and where to reference it to actually get it to show up.

Can anyone point me in the right direction?

Sorry in advance if this seems like a lazy or stupid question.

Pages: [1]