will paypal 20$ for help

BlitzMax Forums/BlitzMax Beginners Area/will paypal 20$ for help

Taytot(Posted 2016) [#1]
i want to code a program where the program will read the mouse position on a x - y axis and give the user points for the mouse staying on the object, which is constantly moving across the screen. the mouse will change to a circle or triangle at random intervals.


Cocopino(Posted 2016) [#2]
Hi, something like this might get you on the right track.
Within the Type you can add other shapes and the mathematical code to achieve "MouseHover" for the current shape. Good luck!

Strict

Global SCREEN_WIDTH = 1400
Global SCREEN_HEIGHT = 900
Graphics SCREEN_WIDTH, SCREEN_HEIGHT

Local target:TTarget = New TTarget
Local score:Int = 0

SeedRnd(MilliSecs())

While Not KeyDown(KEY_ESCAPE)

	Cls()

	target.Update()
	If target.MouseHover() score = score + 1

	target.Draw()
	SetColor(255, 255, 255)
	DrawText(score, 10, 10)

	Flip()
	
Wend


Type TTarget

	Field x:Int
	Field y:Int
	Field shape:Int = 0
	Field deadline:Int 'Millisecs when target should move

	Field radius:Float = 30.0

	Field SHAPE_CIRCLE:Int = 0
	Field SHAPE_RECTANGLE:Int = 1
	Field SHAPE_TRIANGLE:Int = 2

	Method New()
		Reposition()
	End Method

	Method Reposition()
		deadline = MilliSecs() + Rand(1000, 5000)
		x = Rand(0 + radius, SCREEN_WIDTH - radius)
		y = Rand(0 + radius, SCREEN_HEIGHT - radius)
	End Method

	Method MouseHover:Int()

		Select shape
			Case SHAPE_CIRCLE
				If DistPoints(MouseX(), MouseY(), x, y) < radius Return 1 Else Return 0
			Case SHAPE_RECTANGLE

			Case SHAPE_TRIANGLE
			
		End Select
		
	EndMethod

	Method DistPoints:Float(x1:Float, y1:Float, x2:Float, y2:Float)

		Local yDist:Float = Abs(y1 - y2)
		Local xDist:Float = Abs(x1 - x2)
		Return Sqr(yDist ^ 2 + xDist ^ 2)
		
	End Method
	
	Method Update()
		If MilliSecs() > deadline Reposition()
	End Method

	Method Draw()
		SetColor(255, 0, 0)
		Select shape
			Case SHAPE_CIRCLE
				DebugLog("CIRCLE")
				DrawOval(x, y, radius, radius)
			Case SHAPE_RECTANGLE
				
			Case SHAPE_TRIANGLE
			
		End Select
		
	End Method

EndType