finished menu
parent
81556a1a19
commit
4834ffe34d
28
app/main.rb
28
app/main.rb
|
@ -5,9 +5,11 @@ GRAVITY = 0.5
|
|||
|
||||
MIN_GRAVITY = 0.1
|
||||
MAX_GRAVITY = 2.0
|
||||
STEP_GRAVITY = 0.02
|
||||
|
||||
MIN_BOUNCE = 1.0
|
||||
MAX_BOUNCE = 1.1
|
||||
STEP_BOUNCE = 0.0011
|
||||
|
||||
CX = 636
|
||||
CY = 399
|
||||
|
@ -49,14 +51,25 @@ def tick args
|
|||
}
|
||||
end
|
||||
end
|
||||
# MENU CONTROLS
|
||||
if args.inputs.right && args.state.paused
|
||||
args.state.gravity += STEP_GRAVITY if args.state.gravity < MAX_GRAVITY
|
||||
elsif args.inputs.left && args.state.paused
|
||||
args.state.gravity -= STEP_GRAVITY if args.state.gravity > MIN_GRAVITY
|
||||
end
|
||||
|
||||
if args.inputs.up && args.state.paused
|
||||
args.state.bounce += STEP_BOUNCE if args.state.bounce < MAX_BOUNCE
|
||||
elsif args.inputs.down && args.state.paused
|
||||
args.state.bounce -= STEP_BOUNCE if args.state.bounce > MIN_BOUNCE
|
||||
end
|
||||
# LOOP
|
||||
if !args.state.paused
|
||||
#ball vector
|
||||
move_x = args.state.ball_vector[:x]
|
||||
move_y = args.state.ball_vector[:y]
|
||||
# apply gravity
|
||||
move_y = move_y - GRAVITY
|
||||
move_y = move_y - args.state.gravity
|
||||
args.state.ball_vector[:x] = move_x
|
||||
args.state.ball_vector[:y] = move_y
|
||||
|
||||
|
@ -67,8 +80,8 @@ def tick args
|
|||
new_y = y + move_y
|
||||
if bouncing?(new_x,new_y,cx,cy,cr)
|
||||
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
|
||||
args.state.ball_vector[:x] = new_move_x * args.state.bounce
|
||||
args.state.ball_vector[:y] = new_move_y * args.state.bounce
|
||||
# play sound
|
||||
sound = Math.rand(3)+1
|
||||
args.outputs.sounds << "sounds/bounce#{sound}.wav"
|
||||
|
@ -111,19 +124,22 @@ def tick args
|
|||
|
||||
if args.state.paused
|
||||
# Render menu
|
||||
args.outputs.labels << [640, 40, "Game is paused. Press <space> to continue", 4, 1]
|
||||
args.outputs.labels << [640, 40, "Press <space> to start the game", 6, 1]
|
||||
# min_x = 440
|
||||
# mid = 615
|
||||
# max_x = 780
|
||||
# l = 340
|
||||
gravity_x = 440 + args.state.gravity * 179
|
||||
args.outputs.sprites << {
|
||||
x: 615,
|
||||
x: gravity_x,
|
||||
y: 445,
|
||||
w: 32,
|
||||
h: 32,
|
||||
path: 'sprites/slider.png'
|
||||
}
|
||||
bounce_x = 440 + (args.state.bounce - 1)*3400
|
||||
args.outputs.sprites << {
|
||||
x: 615,
|
||||
x: bounce_x,
|
||||
y: 325,
|
||||
w: 32,
|
||||
h: 32,
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
Loading…
Reference in New Issue