adding menu with sliders
							parent
							
								
									e7b6352e7a
								
							
						
					
					
						commit
						81556a1a19
					
				
							
								
								
									
										53
									
								
								app/main.rb
								
								
								
								
							
							
						
						
									
										53
									
								
								app/main.rb
								
								
								
								
							| 
						 | 
				
			
			@ -1,7 +1,14 @@
 | 
			
		|||
require "app/bounce.rb"
 | 
			
		||||
 | 
			
		||||
BOUNCE_ACCL = 1.02
 | 
			
		||||
GRAVITY = 0.9
 | 
			
		||||
GRAVITY = 0.5
 | 
			
		||||
 | 
			
		||||
MIN_GRAVITY = 0.1
 | 
			
		||||
MAX_GRAVITY = 2.0
 | 
			
		||||
 | 
			
		||||
MIN_BOUNCE = 1.0
 | 
			
		||||
MAX_BOUNCE = 1.1
 | 
			
		||||
 | 
			
		||||
CX = 636
 | 
			
		||||
CY = 399
 | 
			
		||||
CR = 205
 | 
			
		||||
| 
						 | 
				
			
			@ -13,8 +20,8 @@ def tick args
 | 
			
		|||
  cy = CY
 | 
			
		||||
  cr = CR
 | 
			
		||||
  # pause
 | 
			
		||||
  args.state.paused = false if args.state.paused.nil?
 | 
			
		||||
  if args.state.ball.nil?
 | 
			
		||||
  if args.state.paused.nil?
 | 
			
		||||
    args.state.paused = true
 | 
			
		||||
    args.state.ball = {
 | 
			
		||||
      x: 500,
 | 
			
		||||
      y: 500,
 | 
			
		||||
| 
						 | 
				
			
			@ -23,11 +30,24 @@ def tick args
 | 
			
		|||
      x: 0,
 | 
			
		||||
      y: 0
 | 
			
		||||
    }
 | 
			
		||||
    args.state.bounce = BOUNCE_ACCL
 | 
			
		||||
    args.state.gravity = GRAVITY
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # INPUT
 | 
			
		||||
  if args.inputs.keyboard.key_up.space
 | 
			
		||||
    args.state.paused = !args.state.paused
 | 
			
		||||
    if !args.state.paused
 | 
			
		||||
      #REINIT with inputs
 | 
			
		||||
      args.state.ball = {
 | 
			
		||||
        x: 500+Math.rand(150),
 | 
			
		||||
        y: 400+Math.rand(50),
 | 
			
		||||
      }
 | 
			
		||||
      args.state.ball_vector = {
 | 
			
		||||
        x: 0,
 | 
			
		||||
        y: 0
 | 
			
		||||
      }
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # LOOP
 | 
			
		||||
| 
						 | 
				
			
			@ -49,6 +69,9 @@ def tick args
 | 
			
		|||
      new_move_x, new_move_y = reflection_vector(x,y,cx,cy,move_x,move_y)
 | 
			
		||||
      args.state.ball_vector[:x] = new_move_x * BOUNCE_ACCL
 | 
			
		||||
      args.state.ball_vector[:y] = new_move_y * BOUNCE_ACCL
 | 
			
		||||
      # play sound
 | 
			
		||||
      sound = Math.rand(3)+1
 | 
			
		||||
      args.outputs.sounds << "sounds/bounce#{sound}.wav"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # move the ball
 | 
			
		||||
| 
						 | 
				
			
			@ -78,22 +101,42 @@ def tick args
 | 
			
		|||
  # RENDER
 | 
			
		||||
  #
 | 
			
		||||
  # BG
 | 
			
		||||
  bg = args.state.paused ? 'sprites/BG1_menu.png' : 'sprites/BG1.png'
 | 
			
		||||
  args.outputs.sprites << {
 | 
			
		||||
    x: 0,
 | 
			
		||||
    y: 0,
 | 
			
		||||
    w: 1280,
 | 
			
		||||
    h: 720,
 | 
			
		||||
    path: 'sprites/BG1.png' }
 | 
			
		||||
    path: bg }
 | 
			
		||||
 | 
			
		||||
  if  args.state.paused
 | 
			
		||||
    # Render menu
 | 
			
		||||
    args.outputs.labels  << [640, 40, "Game is paused. Press <space> to continue", 4, 1]
 | 
			
		||||
    # min_x = 440
 | 
			
		||||
    # mid = 615
 | 
			
		||||
    # max_x = 780
 | 
			
		||||
    args.outputs.sprites << {
 | 
			
		||||
      x: 615,
 | 
			
		||||
      y: 445,
 | 
			
		||||
      w: 32,
 | 
			
		||||
      h: 32,
 | 
			
		||||
      path: 'sprites/slider.png'
 | 
			
		||||
    }
 | 
			
		||||
    args.outputs.sprites << {
 | 
			
		||||
      x: 615,
 | 
			
		||||
      y: 325,
 | 
			
		||||
      w: 32,
 | 
			
		||||
      h: 32,
 | 
			
		||||
      path: 'sprites/slider.png'
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # BALL
 | 
			
		||||
 | 
			
		||||
  args.outputs.sprites << {
 | 
			
		||||
    x: args.state.ball[:x]-16,
 | 
			
		||||
    y: args.state.ball[:y]-16,
 | 
			
		||||
    w: 32,
 | 
			
		||||
    h: 32,
 | 
			
		||||
    path: 'sprites/ball.png' }
 | 
			
		||||
    path: 'sprites/ball.png' } if !args.state.paused
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 1.3 MiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 3.9 KiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 155 KiB  | 
		Loading…
	
		Reference in New Issue