Added pixel texture element
This commit is contained in:
+11
-3
@@ -20,7 +20,9 @@ rect = ElementRect.new 100, 25, 0xFF0000, position: {x: 50, y: 50}, z: 0, rotati
|
||||
|
||||
image_element = ElementImage.new bg_animation, position: {x: 0, y: 0}, z: -1, click_mode: :block, alpha: 1
|
||||
|
||||
pp text, rect, image_element
|
||||
script_element = ElementScript.new 100, 100, position: {x: 200, y: 200}, z: 2, click_mode: :block, alpha: 1
|
||||
|
||||
pp text, rect, image_element, script_element
|
||||
|
||||
end_scene = Scene.new
|
||||
end_scene << rect
|
||||
@@ -56,9 +58,15 @@ App.update do |delta_time|
|
||||
c_ += delta_time
|
||||
c_c += 1
|
||||
|
||||
# commented out to avoid spamming the console, but you can uncomment to see the delta time being printed every frame
|
||||
# puts "Delta time: #{delta_time}s"
|
||||
|
||||
|
||||
red_pixel = [0xFF, 0, 0, 255] # ARGB
|
||||
green_pixel = [0xFF, 0, 255, 0] # ARGB
|
||||
c_p = c_c % 2 == 0 ? red_pixel : green_pixel
|
||||
raw_bytes = (c_p * (50 * 50)).pack('C*')
|
||||
script_element.update(0, 0, 50, 50, raw_bytes)
|
||||
|
||||
el = App.scene.elements_at(App.mouse_position)
|
||||
|
||||
pp App.text_input if App.text_input != ""
|
||||
@@ -82,7 +90,7 @@ end
|
||||
main_scene << text
|
||||
main_scene << rect
|
||||
main_scene << image_element
|
||||
|
||||
main_scene << script_element
|
||||
App.start main_scene
|
||||
|
||||
time = Time.now - start
|
||||
|
||||
+6
-4
@@ -96,7 +96,7 @@ end
|
||||
# for entities it does similarly
|
||||
# mouse state can be read in systems always
|
||||
|
||||
query = tag(:enemy) & component(:health, true) & anti(name("Trap Preview", true))
|
||||
query = Query.from(tag(:enemy) & component(:health, true) & anti(name("Trap Preview", true)))
|
||||
# in the match name will return just the one entity
|
||||
# tag and componet return list-like tables but they will be parallel and in order
|
||||
# empty columns will be filled with nil (not possible if only & is used)
|
||||
@@ -105,7 +105,7 @@ query = tag(:enemy) & component(:health, true) & anti(name("Trap Preview", true)
|
||||
|
||||
world.system :health_regen, for: query do |match, dt| # no trigger means always
|
||||
# example of a simple health regeneration system that regenerates health for all entities with a health component
|
||||
healths = match[0]
|
||||
healths = query.get[0] # get the first component in the query, in this case health, this will be a list of all health components for entities that match the query
|
||||
healths.add_scalar! :health, 1 * dt
|
||||
healths.clamp! :health, 0, 100
|
||||
end
|
||||
@@ -136,12 +136,14 @@ world.system :trap_placement, trigger: trigger do |dt|
|
||||
end
|
||||
end
|
||||
|
||||
name_query = Query.from(name("Trap Preview", true) & component(:sprite, true))
|
||||
|
||||
# could be done as so or
|
||||
world.system :trap_preview, for: name("Trap Preview", true) do |match, dt| # example from teh game mist trying to be made with this engine
|
||||
world.system :trap_preview do |match, dt| # example from teh game mist trying to be made with this engine
|
||||
# do trap placement logic when a trap is held
|
||||
return unless world.holding_trap?
|
||||
# show a preview of the trap at the mouse position, you can use the mouse position relative to the world for this
|
||||
e = match.first
|
||||
e = name_query.get[0] # get the first entity that matches the name query, in this case the trap preview entity, this will be nil if no entity matches
|
||||
e.position = world.mouse_position_world
|
||||
e.active = true # enable the trap preview entity to show it at the mouse position
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user