game works now
| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					./art
 | 
				
			||||||
 | 
					.run
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,40 @@
 | 
				
			||||||
 | 
					# A = old position, c = center of ball, v = current moving vector
 | 
				
			||||||
 | 
					def reflection_vector(ax,ay,cx,cy,xv,yv)
 | 
				
			||||||
 | 
					  # Bouncing of resulting point: R
 | 
				
			||||||
 | 
					  rx = ax + xv
 | 
				
			||||||
 | 
					  ry = ay + yv
 | 
				
			||||||
 | 
					  ux = rx - cx
 | 
				
			||||||
 | 
					  uy = ry - cy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  r = (-ux*cx + ux*ax -uy*cy + uy*ay).to_f / ( ux * ux + uy * uy).to_f
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fx = cx + r * ux
 | 
				
			||||||
 | 
					  fy = cy + r * uy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  afx = fx - ax
 | 
				
			||||||
 | 
					  afy = fy - ay
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  gx = ax + 2 * afx
 | 
				
			||||||
 | 
					  gy = ay + 2 * afy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  rgx = gx - rx
 | 
				
			||||||
 | 
					  rgy = gy - ry
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return rgx,rgy
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# x,y further away than r allows?
 | 
				
			||||||
 | 
					def bouncing?(x,y,cx,cy,r)
 | 
				
			||||||
 | 
					  # d(cx,cy,x,y) > r?
 | 
				
			||||||
 | 
					  d = Math.sqrt((x - cx)*(x-cx) + ( y - cy)*( y - cy))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  d > r
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# if the speed vector is higher than the radius, we are done (2x radius would be still okay actually)
 | 
				
			||||||
 | 
					def too_fast?(vx,vy,r)
 | 
				
			||||||
 | 
					  d = Math.sqrt(vx*vx+vy*vy)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  d > r
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,99 @@
 | 
				
			||||||
 | 
					require "app/bounce.rb"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					BOUNCE_ACCL = 1.02
 | 
				
			||||||
 | 
					GRAVITY = 0.9
 | 
				
			||||||
 | 
					CX = 636
 | 
				
			||||||
 | 
					CY = 399
 | 
				
			||||||
 | 
					CR = 205
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def tick args
 | 
				
			||||||
 | 
					  # INIT
 | 
				
			||||||
 | 
					  # circle
 | 
				
			||||||
 | 
					  cx = CX
 | 
				
			||||||
 | 
					  cy = CY
 | 
				
			||||||
 | 
					  cr = CR
 | 
				
			||||||
 | 
					  # pause
 | 
				
			||||||
 | 
					  args.state.paused = false if args.state.paused.nil?
 | 
				
			||||||
 | 
					  if args.state.ball.nil?
 | 
				
			||||||
 | 
					    args.state.ball = {
 | 
				
			||||||
 | 
					      x: 500,
 | 
				
			||||||
 | 
					      y: 500,
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    args.state.ball_vector = {
 | 
				
			||||||
 | 
					      x: 0,
 | 
				
			||||||
 | 
					      y: 0
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # INPUT
 | 
				
			||||||
 | 
					  if args.inputs.keyboard.key_up.space
 | 
				
			||||||
 | 
					    args.state.paused = !args.state.paused
 | 
				
			||||||
 | 
					  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
 | 
				
			||||||
 | 
					    args.state.ball_vector[:x] = move_x
 | 
				
			||||||
 | 
					    args.state.ball_vector[:y] = move_y
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # bounce
 | 
				
			||||||
 | 
					    x = args.state.ball[:x]
 | 
				
			||||||
 | 
					    y = args.state.ball[:y]
 | 
				
			||||||
 | 
					    new_x = x + move_x
 | 
				
			||||||
 | 
					    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
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # move the ball
 | 
				
			||||||
 | 
					    move_x = args.state.ball_vector[:x]
 | 
				
			||||||
 | 
					    move_y = args.state.ball_vector[:y]
 | 
				
			||||||
 | 
					    args.state.ball[:x] = args.state.ball[:x] + move_x
 | 
				
			||||||
 | 
					    args.state.ball[:y] = args.state.ball[:y] + move_y
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # END?
 | 
				
			||||||
 | 
					  if !args.state.paused
 | 
				
			||||||
 | 
					    if too_fast?(move_x, move_y, cr)
 | 
				
			||||||
 | 
					      #RESET state and pause
 | 
				
			||||||
 | 
					      args.state.ball = {
 | 
				
			||||||
 | 
					        x: 500,
 | 
				
			||||||
 | 
					        y: 500,
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      args.state.ball_vector = {
 | 
				
			||||||
 | 
					        x: 0,
 | 
				
			||||||
 | 
					        y: 0
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      args.state.paused = true
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # RENDER
 | 
				
			||||||
 | 
					  #
 | 
				
			||||||
 | 
					  # BG
 | 
				
			||||||
 | 
					  args.outputs.sprites << {
 | 
				
			||||||
 | 
					    x: 0,
 | 
				
			||||||
 | 
					    y: 0,
 | 
				
			||||||
 | 
					    w: 1280,
 | 
				
			||||||
 | 
					    h: 720,
 | 
				
			||||||
 | 
					    path: 'sprites/BG1.png' }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if  args.state.paused
 | 
				
			||||||
 | 
					    args.outputs.labels  << [640, 40, "Game is paused. Press <space> to continue", 4, 1]
 | 
				
			||||||
 | 
					  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' }
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
| 
		 After Width: | Height: | Size: 1.5 MiB  | 
| 
		 After Width: | Height: | Size: 1.3 MiB  | 
| 
		 After Width: | Height: | Size: 1.2 MiB  | 
| 
		 After Width: | Height: | Size: 1.3 MiB  | 
| 
		 After Width: | Height: | Size: 1.1 MiB  | 
| 
		 After Width: | Height: | Size: 1.5 MiB  | 
| 
		 After Width: | Height: | Size: 8.4 KiB  | 
| 
		 After Width: | Height: | Size: 21 KiB  | 
| 
		 After Width: | Height: | Size: 42 KiB  | 
| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					devid=squishibutz
 | 
				
			||||||
 | 
					devtitle=Squishibutz
 | 
				
			||||||
 | 
					gameid=Bouncing
 | 
				
			||||||
 | 
					gametitle=Sguis Bouncing
 | 
				
			||||||
 | 
					version=0.1
 | 
				
			||||||
 | 
					icon=metadata/bounce_@1.png
 | 
				
			||||||
| 
		 After Width: | Height: | Size: 1.4 MiB  | 
| 
		 After Width: | Height: | Size: 1.3 MiB  | 
| 
		 After Width: | Height: | Size: 4.7 KiB  | 
| 
		 After Width: | Height: | Size: 11 KiB  | 
| 
		 After Width: | Height: | Size: 46 KiB  |