Game Programming and Development Tools

How to track down Mouse movements? (Blitz3D) – DeathFox

DeathFox
Member

Posts: 57
From:
Registered: 04-25-2006
I'm making a game for my software engineering class, and its a boxing game. Anyways, I plan to use mouse gestures for the moves. So can anyone help me to track down the mouse movements. Like a left jab for example, the left mouse button should be pressed and the mouse should be moved for a left to right direction. HELP
buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
ooh interesting I would like to know this also.

sorry I can't help you. I will look on the blitz site to see anything about mouse position.

------------------
that post was really cool ^
|
[|=D) <---|| me

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
ok found some stuff. If you want to check what mouse button they are hitting, you can either use GetMouse() or MouseDown() or MouseHit(). I think the most effective would be MouseDown.

here's some (sort-of) psuedo-code implementing MouseDown():
(if it has a ;; at the end of the line it's real code that would work...)


If MouseDown(1) Then ;;
Jab(left)
TryBlock(opponent)
EndIf;;

see that would check if the left button was pushed on the mouse and then jab with the left hand then use a function that would sometimes block and sometimes not block the punch.

also mouse movements? just use the MouseX and MouseY.

just have your game loop store the MouseX and MouseY return variables in OldMouseX (that's a Global you create) and OldMouseY (ditto) and then have an if statement checking to see if they increase at a certain value. or decrease. like this:

While Not KeyHit(1)
Global OldMouseX = MouseX()
Global OldMouseY = MouseY()

(other game loop stuff)

Global NewMouseX = MouseX()
Global NewMouseY = MouseY()

If NewMouseX - OldMouseX >= 5 Then
Jab(left)
TryBlock(opponent)
Endif

(Same for the y direction if you wanted it)

Wend

See, you just have to find the right stuff. It's all there. hope that I helped you, and now you just have to implement this in a real way. *NOTE* Some of this code isn't real, obviously. all the MouseX and MouseY and MouseDown stuff is real. you have to create the Jab and Block and stuff functions. of course you don't have to do it that way, im just showing you how to make the movements and mouse buttons control it.

------------------
that post was really cool ^
|
[|=D) <---|| me

Lava
Member

Posts: 1905
From:
Registered: 01-26-2005
Well I think you would want to use the MouseX() and MouseY() commands for this. And so basically you want to make a initial mouse value which the mouse will start in, but not be restrained to and then have the current mouse position (mouseX() and Mousey() in blitz's case) and substract that from the original starting mouse position, then take the varible that is attributed from that difference of the the 2 values, so when the mouse starts and you move it you can track the value it has when moved from that starting point.

Here is a quick program I just wrote to demonstrate the ideas, it's not exact to what your game will be like, but it's to show the princibles of it all. In it you will be able to rotate a cube. Just copy and paste this into Blitz 3D.


;Setting the graphics
Graphics3D 800,600

;Camera
camera=CreateCamera(pl)
PositionEntity camera,0,1,-10

;Cube we will rotate
cube=CreateCube()

;Original position of mouse
Mouse_px=400
Mouse_py=300

;Center the mouse to start with, but not looping it so we have freedom
MoveMouse Mouse_px,Mouse_py

;Loop
While Not KeyHit(1)

;Substract current mouse position from Original mouse position
Mouse_x=MouseX()-Mouse_px
Mouse_y=MouseY()-Mouse_py

;rotate block according to Mouse_x and Mouse_y, which counts the mouse position if moved from original position
RotateEntity cube,Mouse_Y,Mouse_X,0

;Render everything
RenderWorld

;This shows you what the varible's numbers are
Text 0,20,MouseX()
Text 0,40,MouseY()
Text 0,60,Mouse_x
Text 0,80,Mouse_y

;Flip Buffer
Flip

;End While Not Loop
Wend

;End of Program
End

------------------

[This message has been edited by LAVA (edited November 10, 2006).]

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
heh we said sort of the same thing.

only you gave a more elaborate, correct non-psuedo-code example.

------------------
that post was really cool ^
|
[|=D) <---|| me

DeathFox
Member

Posts: 57
From:
Registered: 04-25-2006
Thanks guys
Mene-Mene

Member

Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
You could also use a function called MouseXSpeed()

Ex.

repeat
;Main loop
;;;;;;
;;;;;;
if movement > 100

If mousehit(1)

Jab(1)

endif

elseif movement < -100

If mousehit(1)

Jab(-1)
endif

endif


------------------
MM out-
Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice.

[This message has been edited by Mene-Mene (edited November 16, 2006).]