samples/04_physics_and_collisions/05_box_collision_2/app/main.rb
# Sets all the default variables.
# '||' states that initialization occurs only in the first frame.
Sets all the default variables.
'||' states that initialization occurs only in the first frame.
Sets all the default variables . ' || ' states that initialization occurs only in the first frame .
def defaults
    state.tile_size                = 64
    state.gravity                  = -0.2
    state.player_width             = 60
    state.player_height            = 64
    state.collision_tolerance      = 0.0
    state.previous_tile_size     ||= state.tile_size
    state.x                      ||= 0
    state.y                      ||= 800
    state.dy                     ||= 0
    state.dx                     ||= 0
    attempt_load_world_from_file
    state.world_lookup           ||= { }
    state.world_collision_rects  ||= []
    state.mode                   ||= :creating 
    state.select_menu            ||= [0, 720, 1280, 720]
    state.sprite_quantity        ||= 20 
    state.sprite_coords          ||= []
    state.banner_coords          ||= [640, 680 + 720]
    state.sprite_selected        ||= 1
    state.map_saved_at           ||= 0
    if state.sprite_coords == [] 
      count = 1
      temp_x = 165 
      temp_y = 500 + 720
      state.sprite_quantity.times do 
        state.sprite_coords += [[temp_x, temp_y, count]] 
        temp_x += 100 
        count += 1 
        if temp_x > 1280 - (165 + 50) 
          temp_x = 165 
          temp_y -= 75 
        end
      end
    end
  end
def defaults state . tile_size = 64 state . gravity = - 0.2 state . player_width = 60 state . player_height = 64 state . collision_tolerance = 0.0 state . previous_tile_size ||= state . tile_size state . x ||= 0 state . y ||= 800 state . dy ||= 0 state . dx ||= 0 attempt_load_world_from_file state . world_lookup ||= { } state . world_collision_rects ||= [ ] state . mode ||= :creating state . select_menu ||= [ 0 , 720 , 1280 , 720 ] state . sprite_quantity ||= 20 state . sprite_coords ||= [ ] state . banner_coords ||= [ 640 , 680 + 720 ] state . sprite_selected ||= 1 state . map_saved_at ||= 0 if state . sprite_coords == [ ] count = 1 temp_x = 165 temp_y = 500 + 720 state . sprite_quantity . times do state . sprite_coords += [ [ temp_x , temp_y , count ] ] temp_x += 100 count += 1 if temp_x > 1280 - ( 165 + 50 ) temp_x = 165 temp_y -= 75 end end end end
Sets all the default variables.
Sets all the default variables .
# alternates between :creating and :selecting for sprite selection #=======================================IMPORTANT=======================================# # When adding sprites, please label them "image1.png", "image2.png", image3".png", etc. # Once you have done that, adjust "state.sprite_quantity" to how many sprites you have. #=======================================================================================# # IMPORTANT TO ALTER IF SPRITES ADDED IF YOU ADD MORE SPRITES # Sets all the cordinate values for the sprite selection screen into a grid # Displayed when 's' is pressed by player to access sprites # if sprite_coords is an empty array # sets a starting x and y position for display # for the number of sprites you have # add element to sprite_coords array # increment temp_x # increment count # if exceeding specific horizontal width on screen # a new row of sprites starts # new row of sprites starts 75 units lower than the previous row