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

Topics - Realguigui

#1
Development / menu with parameters
November 16, 2017, 10:10:07 AM
Hello.
I have created a menu to manage the display and use of a digicode. It works but I would like to make it customizable to make it usable with several doors. For the moment, the secret code of the digicode and the name of the door that it opens are hardcoded in the code of the menu. This requires me to create a menu for each digicode. Would there be a way to launch my menu digicode by passing some parameters ("secret codes","door", map etc.) like a function ?
If it's not possible, is it a good idea to use some savegame_variables hardcoded in the menu that I initialize just before the lauch of the digicode's menu ?

Thank you
#2
Development / block blocked on custom entity
March 07, 2017, 06:20:53 PM
Hello

In the same layer, if I push a block on a custom entity just created (default settings) and their bounding boxes (16px by 16px) are exactly superimposed, the block can not move anymore. This problem does not occur when the custom entity is above the block.

Is this normal?
#3
Development / enemy movement
February 13, 2017, 10:56:09 AM
Hello.
I'm studying the generic_soldier.lua code of zelda solarus dx. I have created a new model of enemy and I integrate, step by step, some functions of generic_soldier. I notice the use of 2 variables "going_hero" and "being_pushed" and in order to understand their function I don't use them in my code but they seems to be necessary because there is a behavior that I can't explain.
In my code, I have integrated, for the moment, the "target hero", the "change direction of sprite" and the "parrage with the sword" functions. I have also try an "audacious" : "movement:start(self,self:restart())" at line 83.

my code:
Code (lua) Select

-- Lua script of enemy mon_enemie.
-- This script is executed every time an enemy with this model is created.

-- Feel free to modify the code below.
-- You can add more events and remove the ones you don't need.

-- See the Solarus Lua API documentation for the full specification
-- of types, events and methods:
-- http://www.solarus-games.org/doc/latest

local enemy = ...
local game = enemy:get_game()
local map = enemy:get_map()
local hero = map:get_hero()
-- sprite du corps de l'enemie
local body_sprite
-- sprite de l'épée de l'enemie
local sword_sprite
-- mouvement de l'enemie
local movement

-- Event called when the enemy is initialized.
function enemy:on_created()
  -- On crée le sprite du corps de l'enemie en fonction de la race de l'enemie (nommage formalisé)
  body_sprite = enemy:create_sprite("enemies/" .. enemy:get_breed())
  -- On crée le sprite de l'épée de l'enemie en fonction de la race de l'enemie (nommage formalisé)
  sword_sprite = enemy:create_sprite("enemies/" .. enemy:get_breed().."_sword")
  -- On parametre les points de vie à l'enemie
  enemy:set_life(5)
  -- On parametre les dégats en pts de vie qu'inflige l'enemie
  enemy:set_damage(1)
  -- On parametre que l'enemie est repoussé quand il touché
  enemy:set_pushed_back_when_hurt(true)
  -- On parametre que le sprite épée est invincible
  self:set_invincible_sprite(sword_sprite)
  -- On parametre que le sprite épée quand il recoit une attaque de type "sword" déclenche l'evenement enemy:on_custom_attack_received
  self:set_attack_consequence_sprite(sword_sprite, "sword", "custom")
end

-- Event called when the enemy should start or restart its movements.
-- This is called for example after the enemy is created or after
-- it was hurt or immobilized.
function enemy:on_restarted()
  print("restarted")
  -- On crée un mouvement de type "target"
  movement = sol.movement.create("target")
  -- On param que la cible de ce mouvement est le héro
  movement:set_target(hero)
  -- On param la vitesse du mouvement enemie
  movement:set_speed(10)
  -- On affecte le mouvement à l'enemie et on le lance
  movement:start(enemy)
end

-- LORSQUE L'ENEMIE CHANGE DE DIRECTION
function enemy:on_movement_changed(movement)
  print("change direction")
  --if not being_pushed then
    -- On recupere la direction du mouvement
    local direction4 = movement:get_direction4()
    -- On represente la nouvelle direction en changeant la direction du sprite du corps de l'enemie
    body_sprite:set_direction(direction4)
    -- On represente la nouvelle direction en changeant la direction du sprite de l'épée de l'enemie
    sword_sprite:set_direction(direction4)
  --end
end

-- LORSQUE L'ENEMIE RECOIT UNE ATTAQUE QUE L'ON VEUT GERER SOIT MEME
function enemy:on_custom_attack_received(attack, sprite)
  -- Si l'attaque et de type sword et qu'elle touche l'epée enemie
  if attack == "sword" and sprite == sword_sprite then
    -- On joue le son de choc d'épées
    sol.audio.play_sound("sword_tapping")
   
    --being_pushed = true
    local x, y = self:get_position()
    local angle = self:get_angle(self:get_map():get_entity("hero")) + math.pi
    local movement = sol.movement.create("straight")
    movement:set_speed(128)
    movement:set_angle(angle)
    movement:set_max_distance(32)
    movement:set_smooth(true)
    movement:start(self,self:restart())
  end
end

   
The strange behavior : When the hero hit the enemy's sword, as expected, he is pushed away and the sprite change direction but after this, he walks but stay motionless. Yet there is a "restarted" in the console that prove the function "on_restarted" is call after the pushing movement but the "target" movement seems not to work. If I hit him again in his body, he's hurt and he moves again toward the hero.

Thanks
#4
Hello.
Is it possible to code an on_obtaining () event function related to an item created during code execution ?
I know this is possible in item.lua but I want to code specific actions in this event function.

Thank you.
#5
Development / hard to activate a walkable switch
January 28, 2017, 06:34:05 PM
Hello.

I think the activation of walkable switch needs too much accurency. Also, the activation zone seems to be offset toward down.
Is there a simple solution to resolve this ?

Switch NOT ACTIVATED


Switch ACTIVATED
#6
Hello.

I've reuse and modify the code of this thread for making a moving plateform.
Sadly, I have an offset between the custom entity and the associate sprite.
It seems normal in the editor because even I set the origin point of the 32x32 sprite at (16,16), at the opposite it's impossible to set the origin point of the 32x32 custom entity.

Sprite parameters:


Offset in the editor:


On the second picture, the origin point of the sprite (16,16) seems to be at same coordinates of the default origin point (8,13) of the 16x16 upper left square of the 32x32 custom entity. This is probably normal but the result is identical even with this code in the model of custom entity where I modify the origin point of the custom entity:
Code (lua) Select
--****************************************************************************************************
-- EVENEMENT : A LA CREATION DE L'ENTITE PLATEFORME MOBILE AVEC DES VALEURS PAR DEFAUT
--****************************************************************************************************
function entity:on_created()
  -- On créé un sprite a affecter à l'entité
  self:create_sprite("entities/platform")
  -- On parametre la taille de l'entité en px
  self:set_size(32, 32)
  -- On parametre le point d'origine de l'entité par rapport à son coin haut gauche en px
  self:set_origin(16, 16)
...


Game screen


Like you can see, in the game the offset is exactly the same as in the editor.
#7
Hello.

After trying the function map:create_dynamic_tile() with the help of the documentation, it seems that the name of the key in the table "properties" that indicated the name of the pattern is "pattern" and not "tile_pattern_id".

Code with wrong key
Code (lua) Select
local dt_lava = {["name"]="test_lave",["layer"]=1,["x"]=320,["y"]=336,["width"]=32,["height"]=32,["tile_pattern_id"]="lava",["enabled_at_start"]=true}

local dt_test = map:create_dynamic_tile(dt_lava)


Debug Console
Info: Simulation started
Error: In on_started: [string "maps/donjon01_01.lua"]:29: bad argument #1 to create_dynamic_tile (Bad field 'pattern' (string expected, got nil))
Info: Simulation finished


Code with the key "pattern"
Code (lua) Select

local dt_lava = {["name"]="test_lave",["layer"]=1,["x"]=320,["y"]=336,["width"]=32,["height"]=32,["pattern"]="lava",["enabled_at_start"]=true}

local dt_test = map:create_dynamic_tile(dt_lava)


No errors and
#8
Bugs & Feature requests / sprite:set_animation bug ?
January 17, 2017, 05:45:42 PM
Hello. Sorry for my english but I'm french.

At the almost end of the code below, I use the function "sprite:set_animation" in the line : entity:get_sprite():set_animation("entree",traversage()). In the documentation, I'm reading that the second parameter may be a "function that will be called when the animation finishes". Sadly, the animation and the function start at the same millisecond (I put 2 print os.clock() to verify that). My animation have 9 steps with 100 ms of delay for each.
Well, bug or I forgot something ?

Code of the custom entitie:
-- Lua script of custom entity mur_illusion.
-- This script is executed every time a custom entity with this model is created.

local entity = ...
local game = entity:get_game()
local map = entity:get_map()
-- On recupere le hero dans une variable locale
local hero = map:get_hero()

-- variable qui contient l'autre custom entity qui correspond à l'autre coté du mur illusion
-- on ne l'affecte pas car on ne sait pas s'il est déjà créé au moment de la création de cette entité
local autre_mur = nil

local traversage_en_cours = false

--****************************************************************************************************
-- EVENEMENT : A LA CREATION DE L'ENTITE MUR ILLUSION
--****************************************************************************************************
function entity:on_created()
  -- RECUPERATION DE L'AUTRE MUR
  -- On recupere le préfixe de notre entité (partie à gauche du dernier "_")
  -- On cherche la position du "_" suivi d'un chiffre
  local index = string.find(entity:get_name(),"_%d")
  -- On recupere les lettres du nom de notre variable de la 1ere position jusqu'a la valeur de l'index pour obtenir notre prefixe
  local prefixe = string.sub(entity:get_name(),1,index)
  -- Si le mur opposé existe (s'il y a 2 entités sur la carte qui ont le meme préfixe)
  if map:get_entities_count(prefixe) == 2 then
    -- On recupere le mur de sortie opposé grace au nommage formalisé
    -- pour chaque entité trouvé sur la map qui ont le meme préfixe
    for found_entity in map:get_entities(prefixe) do
      -- Si cette entité n'est pas l'entité actuelle alors
      if found_entity ~= entity then
        -- On a trouvé notre autre entité et on l'affecte à notre var
        autre_mur = found_entity
       
        -- On attend un instant pendant que le code continue de s'executer que les entitées et leur fonctions soient initialisées pour ...
        sol.timer.start(100, function()
          -- ... transmettre notre entité à l'autre mur au cas ou il ne nous ai pas récupéré au moment de sa creation car créé en 1er
          autre_mur:set_mur_oppose(entity)
          return false
        end)

      end     
    end
  end


  -- On initialise certains parametres que l'on a pas pu initialisés avec l'editeur
  -- On rend l'entité intraversable
  entity:set_traversable_by(false)

  -- On parametre un test de collision de type "facing" avec lancement de la fonction hero mur interaction
  entity:add_collision_test("facing",hero_mur_interaction)

end

--****************************************************************************************************
-- FONCTION EXTERNE QUI PERMET DE PARAMETRER LE MUR OPPOSE
--****************************************************************************************************
function entity:set_mur_oppose(other_entity)
  autre_mur = other_entity
end


--****************************************************************************************************
-- FONCTION LANCEE LORSQUE LE HERO ENTRE EN CONTACT "DE FACE" AVEC LE MUR ILLUSION (TEST DE COLLISION)
--****************************************************************************************************
function hero_mur_interaction()
  -- Si le hero pousse le mur
  if hero:get_animation()=="pushing" and traversage_en_cours == false then

    -- On signale qu'il y a traversage en cours pour eviter que le processus se relance immédiatement
    traversage_en_cours = true

    -- On freeze le hero
    hero:freeze()

    -- On rend invisible le hero
    hero:set_visible(false)

    print ("avant animation: " .. os.clock())

    -- On lance l'animation d'entrée dans le mur
    entity:get_sprite():set_animation("entree",traversage())

  end
   
end



function traversage()

  print ("fonction traversage: " .. os.clock())
 
  -- On remets l'animation "normal" sur le mur illusion
  entity:get_sprite():set_animation("normal")

  -- On lance l'animation "sortie"
   
  -- On recupere les coordonnées qui font face au mur opposé
  local x,y,layer = autre_mur:get_facing_position()
 
  -- Selon la  direction du mur ont ajoute quelques pixels dans la bonne direction pour ne pas se retrouver coincé dans le mur
  if autre_mur:get_direction() == 0 then
      -- On déplace le hero au dela du mur opposé
      hero:set_position(x+10,y,layer)
  end

  if autre_mur:get_direction() == 1 then
      -- On déplace le hero au dela du mur opposé
      hero:set_position(x,y-10,layer)
  end

  if autre_mur:get_direction() == 2 then
      -- On déplace le hero au dela du mur opposé
      hero:set_position(x-10,y,layer)
  end

  if autre_mur:get_direction() == 3 then
      -- On déplace le hero au dela du mur opposé
      hero:set_position(x,y+30,layer)
  end

  -- On defreeze le hero
    hero:unfreeze()

  -- On rend visible le hero
    hero:set_visible(true)

  -- On signale que le mur est de nouveau traversable
  traversage_en_cours = false

end



Debug Console:(I tried 2 times to go throught the wall)
Info: Solarus 1.5.1
Info: Opening quest 'C:/Users/atic/Google Drive/old school'
Info: Sound volume: 100
Info: Music volume: 100
Info: Joypad support enabled: true
Info: 2D acceleration: no
Info: Turbo mode: no
Warning: Cannot use quest size 320x240: this quest only supports 256x224 to 256x240. Using 256x224 instead.
Info: Video mode: normal
Info: LuaJIT: yes (LuaJIT 2.0.3)
This is a sample quest for Solarus.
Info: Language: fr
Info: Lua console: yes
Info: Simulation started
avant animation: 14.907
fonction traversage: 14.907
avant animation: 19.33
fonction traversage: 19.33
Info: Simulation finished


Thanks for your help.