Menu

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.

Show posts Menu

Messages - Christopho

#1051
Development / Re: Custom Entity: Companion
January 23, 2015, 09:21:35 AM
Exactly. If you don't need to save it, just use the fact that it is possible to add anything to any object: not only functions but also tables or any datatype. In your case, the game since you want it to persist accross maps.
Something like this:

game.companion_info = {
  x_from_hero = 0,
  y_from_hero = 0,
}


It will also work by using savegame variables (game:get/set_value()), but this is overkill if you don't actually need to save the information.
#1052
Development / Re: Custom Entity: Companion
January 22, 2015, 09:24:31 AM
Your entity script is called when the entity is created, so the map:create_custom_entity() has to be done from outside. I was recommending to do it from game:on_map_changed() so that you have it on all maps. And game:on_map_changed() is a function that you have to define wherever the game is initialize (in game_manager.lua if you follow my tutorials/examples).

As a first step, if you have trouble do it on all maps from game:on_map_changed(), you can start by creating the entity from the map editor on a specific map.
#1053
Development / Re: Custom Entity: Companion
January 21, 2015, 10:04:47 PM
In game:on_map_changed(map), create the custom entity with map:create_custom_entity(........) with the appropriate parameters : in particular, the model will be the name of your custom entity script.

And yes, sol.timer.start would be done in entity:on_created().
Note that you can make a timer repeat itself automatically by returning true in its callback.
#1054
Development / Re: Custom Entity: Companion
January 21, 2015, 08:58:46 AM
Hi,
Direct pixel manipulation is not possible yet from Lua, but this is a planned feature for a next version. In the meantime you can make your image semi-transparent so that it blends when it is drawn. All drawing operations are alpha-blended.

You code should work but there are a few issues:
- The position of an entity is always integer numbers. The engine truncates the coordinates when you call set_position(). Maybe this is simply okay in your case.
- entity:on_update() is called at each frame, and it is good practice to be independent from the frame rate. So you can replace on_update() by a repeated timer called with a delay that you control. (Another solution is to create a movement object instead but I don't think that any built-in movement provides the kind of acceleration that you need. Or maybe a pixel movement whose trajectory is something that you compute initially and a speed that you change over time?)

About your last question (making it global), a custom entity cannot survive accross maps, but this is not a problem. You can easily re-create a new one when entering any map. For example in game:on_map_changed(). It is even possible to keep the state but I don't think you need that (but if you do, I can explain :))
#1055
Development / Re: Quicksand custom entity
January 20, 2015, 09:06:22 AM
Quote from: wrightmat on January 20, 2015, 12:46:21 AM
One question - if I wanted to slow the hero's walking speed when he overlaps the quicksand (making it harder to get out), how would I go about returning his speed when he's no longer in the quicksand?
A way to do this is to create a second timer that checks the collision again (with if quicksand:overlaps(hero)) and if not, restore the speed. Warning: if the quicksand can die, the timer should belong to the hero and not to the quicksand, in order to be sure that it will be called.
Quote from: wrightmat on January 20, 2015, 12:46:21 AM
Also, any advice on how to make the hero sink/fall when he gets to the center?
Call hero:freeze() to remove control from the player and then do what you want with the sprites of the hero. Like starting the animation "falling" (usually used with holes) or a custom one.
#1056
Development / Re: Quicksand custom entity
January 19, 2015, 05:33:29 PM
- The variables ex, ey and el should be local to the file, otherwise they are global and all quicksand instances share them.
- The collision test should only react to the hero, not to other entities. Your current code tries to move the hero every time any entity overlaps the quicksand.
- Your code is creating a new collision test at each frame (on_update). You should create the collision test only once. Creating a new movement at each frame is also wrong.
- Starting a movement on the hero is probably a bad idea because an entity cannot have several movements at the same time. If you start a movement, then the player's movement from the keyboard/joypad is lost. And as soon as the player changes the state (like by using the sword), your movement is lost and the keyboard/joypad movement is back. A better approach should be to directly change the hero coordinates towards the quicksand.


local entity = ...
local map = entity:get_map()
local hero = map:get_entity("hero")

local ex, ey, el
local timer

-- Quicksand: entity which slows the hero until
-- he finally falls in
function entity:on_created()
  self:create_sprite("entities/quicksand")
  self:set_size(32, 32)
  self:set_origin(16, 16)
  ex, ey, el = self:get_position()
  self:get_sprite():set_animation("quicksand")

  self:add_collision_test("overlapping", function(quicksand, other)

    -- This callback will be repeatedly called while other is overlapping the quicksand

    if other:get_type() ~= "hero"
      return
    end
    local hero = other

    -- Only do this in some specific states (in particular, don't do it while jumping, flying with the hookshot, etc.)
    if hero:get_state() ~= "free" and hero:get_state() ~= "sword loading" ........(and maybe others)......... then
      return
    end

    -- Move the hero towards the quicksand's center every 200 ms while he is overlapping it.
    if timer == nil then
      timer = sol.timer.start(self, 200, function()
        hero:set_xy(........)   -- Some coordinates one pixel towards the center of the quicksand
        timer = nil  -- This variable "timer" ensures that only one timer is running.
      end)
    end

  end)
end


I did not test it, but this is an idea. I hope it can help!
(By the way, I still need to play your game! Sorry for the long time!)
#1057
Development / Re: Sprite animation names
January 16, 2015, 10:09:27 AM
It should work, maybe there is a bug. Can you send me your project?
#1058
The Mac OS X version usually comes after the Windows version. We are working on it, we should be able to release it very soon. Sorry for the inconvenience!
#1059
Hi,
The ALTTP resource pack is only compatible with version 1.3 of the engine.
#1060
Development / Re: Sprite animation names
January 13, 2015, 09:12:06 AM
Quote from: Mimiga on January 13, 2015, 03:35:08 AM
function sol.main:on_draw(screen)
end

However, that still brings me to my other question: every time I want to draw a file to the screen, do I have to encase it in this function? Furthermore, I see that trying to use .JPGs causes the game to crash, so I assume the engine can't handle the image data of a jpeg. Is there documentation on what files that it accepts on the create function? In the documentation it does not specify what files are able to be loaded through sol.surface.create.
Yes, in this one or in another on_draw() function. game:on_draw() is called at each frame but only during a game, and sol.main:on_draw() is called at each frame even before starting a game (like in the title screen). There is also menu:on_draw() if you choose to use a menu. In this case, add the menu to the game and you don't have to redefine game:on_draw().
JPG images should work. What is the crash exactly? Is there an error message or an error.txt file?

Also, don't forget that on_draw() is called at each frame, so you should load the file once before and them only draw it at each frame.

Quote from: Mimiga on January 13, 2015, 03:35:08 AM
Question 2: Is it possible to have z-indices for pictures? Like make a picture show behind the dialogue box, or to switch a picture's z-index to have one on top of another? Or is it because the surface IS the entire screen that it goes over everything and is therefore impossible?
The order is simply defined by when you call the draw() functions. For example, if you draw two objects, the second one will be drawn after the first one and therefore above it.
#1061
Bugs & Feature requests / Re: Quick Find
January 11, 2015, 01:38:04 PM
I missed your message, this happens sometimes.
I created an issue for your suggestion: https://github.com/christopho/solarus/issues/640
#1062
Bugs & Feature requests / Re: Sword animation speed bug
January 07, 2015, 09:34:55 PM
Exactly, the tunic sprite is the master one. Its state determines the end of the sword sequence. Actually, the sword and shield one are even synchronized to the tunic one.

If you want to change the animation speed at runtime, a way to do that is to change the animation with hero:set_animation(), setting another animation that has the same frames but a different speed.

The sprite API would give more control, but you don't have direct access to the sprites objects of the hero like you can with enemies or custom entities (well... except with very dirty metatable tricks). But you can do a few things through the hero functions like hero:set_animation(). The reason why the sprites of the hero are not directly exposed to Lua is because they belong to the engine only. Maybe this will change one day :)
#1063
Bugs & Feature requests / Re: Sword animation speed bug
January 07, 2015, 11:08:08 AM
There are several sprites involved when the hero is swinging his sword: the sword sprite, but also the tunic sprite and the shield sprite. If you change the animation speed of one of them, or if you remove some frames, then you should also do the same change in the other two sprites.
#1064
Hi,
Did the editor say that the upgrade was successful? It seems that your switch "secret_chest_1" still has the old syntax. The old syntax uses subtype = "1" and the new syntax uses subtype = "walkable".

Can you send me your project before and after the upgrade ? I would like to fix your data files, check if the upgrade fails and why, and also why there is a crash (a syntax error in a map file should never crash the editor, but show an error instead).
#1065
You should try something like

function game:on_command_pressed(command)
  if command == "action" and
      not game:is_suspended() and
      game:get_hero():get_state() == "free" and
      game:get_command_effect("action") == nil then
    .......... (your code to jump)
  end
end

Put this code where your game object is created. In my tutorials, this would go to game_manager.lua.
I have not tested but this should be the idea.