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 - oHInsane

#1
Thanks for your answers, it solved my problem.

My final code is:



  rateau:add_collision_test("overlapping", function(rateau, entity)
  if( entity:get_sprite()~=nil) then
   
    local nom_sprite = entity:get_sprite():get_animation()
    if(nom_sprite == "on_ground")then
        local coords_x, coords_y, coords_layer = entity:get_position()
        local brush_explosed = map:create_custom_entity{
          x = coords_x,
          y = coords_y,
          layer = layer,
          width = 8,
          height = 8,
          direction = 0,
        }   
        -- on affiche l'animation de destruction     
        local brush_sprite= brush_explosed:create_sprite("entities/bush_green")
        brush_sprite:set_animation("destroy")
        -- on remove le sprite du brush
        entity:remove()

    end 
  end


I'll check later how i want this item to interact with ennemies and other entites but for the moment, it's usable as it is.
#2
Hi,

My learning is on a good way thanks to your various helps.

I have another question.

I have created a rake, but I need it the ability to cut a brush (a destructible with can_be_cut set to true).
The rake will eventually deal damage to enemy and cut thoses brushes.

I'm also trying to learn more about usable items this way, here is the code of my item "rake"





-- rateau.lua
local item = ...
local game = item:get_game()

function item:on_using()
  -- some code
  local entities_touched = { }
  rateau:set_origin(4, 5)
  rateau:add_collision_test("overlapping", function(rateau, entity)
  local nom_entite = entity:get_name()
  if(nom_entite == "plantation")then
    local sprite = "entities/bush_green"
      entity:create_sprite(sprite)
      entity:set_animation("destroy")
  end 
-- some code

So my idea is basically to detect if a collision is occuring between my "rateau" (rake) and the bush.
If the collided entity goes by the "plantation" name, then i want to start the bush destroyed sprite animation.

So with this code i have this error:
Error: In collision callback: [string "items/rateau.lua"]:39: attempt to call method 'create_sprite' (a nil value)

If I understand correctly it means my entity can't use the create_sprite animation.

I think i miss the methodology of doing this type of stuff. For the moment i'm thinking like this:
1) test colllision
2) get the entity that is collided
3) start the cut animation if it's a brush.

But It raises questions: the callbacck from the collision test is allowing me to access the "targeted entity". But how do I test if it's a destructible brush. I can test the "destructible" part with the get_type() function (instead of get_name() which force me to list and give one unique name for each damned brush on the map).
And why do I have an error on the create_sprite() function when i try to start the destroy animation of the brush.

Thanks


#3
Development / Re: How to assign an item dynamically
January 20, 2017, 01:46:29 AM
Thanks, I understand better now.

I modified my code to :

game:get_item("boomerang"):set_variant(1)
game:set_item_assigned(1,game:get_item("boomerang"))


And it words fine with the default commande X.

Thank you, I've also sent you a PM christopho about the engine as well.

#4
Development / Re: How to assign an item dynamically
January 19, 2017, 04:56:29 PM
Hi thanks for your anwser.

So my code is now!

function game_manager:start_game(file_name)

  local exists = sol.game.exists(file_name)
  local game = sol.game.load(file_name)
  if not exists then
    -- Initialize a new savegame.
    initial_game:initialize_new_savegame(game)
  end
  game:start()
  --local item = game:get_item("boomerang")
  --game:set_item_assigned(1, item)
game:get_item("boomerang"):set_variant(1)

end


The error is gone but when I press X, nothing is happening, do i have to bind a key like with
set_command_keyboard_binding() ?

I'm quite lost with the item management in general  (equipement), is there a game array where all the equipements that i have is stored or do i have to code it? How do i add en item to the equipment (and remove it if needed)?

Thank you


#5
Development / How to assign an item dynamically
January 19, 2017, 02:04:46 AM
Hi,

I'm getting my hands on solarus and i'm currently reading a lot of documentation and tryng out other projets to understand how far can solarus go.

1) So my first question is: i want to give directly the boomerang at the start of my quest.

I have tried this code

  local item = game:get_item("boomerang")
  game:set_item_assigned(1, item)


But i got the error: "Cannot assign item 'boomerang' because the player does not have it".

So my guess is that i need to instantiate the boomerang first but how?



Thank you.