Author Topic: Mouse  (Read 11975 times)

0 Members and 1 Guest are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Mouse
« on: December 04, 2010, 07:23:56 pm »
In a thingie I'm making, I need a mouse feature.

I'm using Qwerty55's code (thanks!):

Code: [Select]
:.This is the sprite
:[80C0A09088D0A818]→Pic1
:While 1
:.Store the screen to the back buffer
:StorePic
:.Display Sprite
:Pt-On(X,Y,Pic1
:DispGraph
:.Erase Sprite
:Pt-Change(X,Y,Pic1
:.Replace the part of the image erased by the Sprite
:RecallPic
:.I used conditionals because the boundary conditions are important
:.Replace with X+getKey(3)-getKey(2)→X if they aren't important.
:If getKey(3) and (X<92)
:X+1→X
:End
:If getKey(55) and (X<72)
:Pt-On(X,Y,Pic1+8
:End
:If getKey(2) and (X>2)
:X-1→X
:End
:If getKey(1) and (Y<60)
:Y+1→Y
:End
:If getKey(4) and (Y>2)
:Y-1→Y
:End
:End

Code: [Select]
.MOUSE
[101010FE10101000]->Pic1
While 1
.Store the screen to the back buffer
StorePic
.Display Sprite
Pt-On(X,Y,Pic1
DispGraph
.Erase Sprite
Pt-Change(X,Y,Pic1
.Replace the part of the image erased by the Sprite
RecallPic
.I used conditionals because the boundary conditions are important
.Replace with X+getKey(3)-getKey(2)->X if they aren't important.
Repeat getKey->Z
End
If Z=15
Goto 9
Else
If getKey(3) and (X<92)
X+1->X
End
If getKey(55) and (X<72)
Pt-On(X,Y,Pic1+8
End
If getKey(2) and (X>2)
X-1->X
End
If getKey(1) and (Y<60)
Y+1->Y
End
If getKey(4) and (Y>2)
Y-1->Y
End
End
End
Lbl 9

The one which is below was edited by me and is really really really slow. The above one is perfect and works really fine!

Any idea why? I know why (Else and GetKey) but how to fix? THX!

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Mouse
« Reply #1 on: December 04, 2010, 07:43:41 pm »
It's the getkey->Z. Storing to a number and comparing the number takes forever. Try replacing every conditional with getkey(keycode).
« Last Edit: December 04, 2010, 07:44:08 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Mouse
« Reply #2 on: December 04, 2010, 07:43:53 pm »
You said it yourself, the problem is the Repeat getKey→Z. Having that in the code will not let program execution advance until that getKey returns a value. When holding down the arrow keys, this will only return a value a few times per second, resulting in the mouse moving code only being reached a few times per second.

I see that you added it so you could press clear to jump out of it, so why not just use direct key input (e.g. getKey(15)) for the clear button as well as the arrow keys?
« Last Edit: December 04, 2010, 07:45:11 pm by Runer112 »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Mouse
« Reply #3 on: December 04, 2010, 07:46:54 pm »
Repeat Getkey is only for turn-based stuff where you want key detection to be done immediately. I think it's pretty much useless in Axe because it runs so fast. In BASIC it can be useful in games like Reuben Quest where otherwise key detection would be horrible, but not in Axe.

I would also use direct input (Getkey with a value in parenthesis afterward), like Runer112 said. Much faster and responsive. Regular getkey is more for menu selections.

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Mouse
« Reply #4 on: December 04, 2010, 08:11:31 pm »
I see some potential relatively major optimizations. which code will you be using?
« Last Edit: December 04, 2010, 08:17:25 pm by happybobjr »
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Mouse
« Reply #5 on: December 05, 2010, 10:31:29 am »
Code: [Select]
.MOUSE
[101010FE10101000]->Pic1
While 1
.Store the screen to the back buffer
StorePic
.Display Sprite
Pt-On(X,Y,Pic1
DispGraph
.Erase Sprite
Pt-Change(X,Y,Pic1
.Replace the part of the image erased by the Sprite
RecallPic
.I used conditionals because the boundary conditions are important
.Replace with X+getKey(3)-getKey(2)→X if they aren't important.
If getKey(3) and (X<92)
X+1→X
End
If getKey(55) and (X<72)
Pt-On(X,Y,Pic1+8
End
If getKey(2) and (X>2)
X-1→X
End
If getKey(1) and (Y<60)
Y+1→Y
End
If getKey(4) and (Y>2)
Y-1→Y
End
getKey(15)
End

I have tried many things, many getKey(15) if different places of the code, with no success :S

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Mouse
« Reply #6 on: December 05, 2010, 10:39:38 am »
getKey(15) will equal 1 if the clear key is being held down and 0 if it isn't. That's all it does: return a value. If you want it to actually do something useful based on whether or not it (or any other key) is held down, you have to put it as the condition in an if statement and then put what you want it to do as the contents of the if statement, just like the other 5 if statements already in the code.
« Last Edit: December 05, 2010, 10:40:52 am by Runer112 »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Mouse
« Reply #7 on: December 05, 2010, 10:40:35 am »
getKey(15) will equal 1 if the clear key is being held down and 0 if it isn't. That's all it does. If you want it to actually do something useful, you have to put it as the condition in an if statement and then put what you want it to do as the contents of the if statement.

I also tried:

Code: [Select]
If getKey(15)
Goto 9
End
.The next line is the last one
Lbl 9

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Mouse
« Reply #8 on: December 05, 2010, 10:42:04 am »
That should work, as long as you insert it into a suitable place in the code. Where did you try putting it?

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Mouse
« Reply #9 on: December 05, 2010, 10:46:07 am »
Code: [Select]
If getKey(3) and (X<92)
X+1→X
End
If getKey(2) and (X>2)
X-1→X
End
If getKey(1) and (Y<60)
Y+1→Y
End
If getKey(4) and (Y>2)
Y-1→Y
End

could be

Code: [Select]
X<92 * getKey(3) -  (X>2 * getKey(2)) + X -> X

Y<60 * getKey(1) -  (Y>2 * getKey(4)) + Y -> Y

I think this gives a speed increase and lowers the byte size.
It should also make the game speed slightly more stable, although this is so small that that wouldn't be noticed here.




Edit: are you tring to have clear end the game?

then you should have

:If Getkey(15)
:Fix 4
:Return
:End
« Last Edit: December 05, 2010, 10:47:38 am by happybobjr »
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Mouse
« Reply #10 on: December 05, 2010, 10:59:55 am »
Code: [Select]
If getKey(3) and (X<92)
X+1→X
End
If getKey(2) and (X>2)
X-1→X
End
If getKey(1) and (Y<60)
Y+1→Y
End
If getKey(4) and (Y>2)
Y-1→Y
End

could be

Code: [Select]
X<92 * getKey(3) -  (X>2 * getKey(2)) + X -> X

Y<60 * getKey(1) -  (Y>2 * getKey(4)) + Y -> Y

I think this gives a speed increase and lowers the byte size.
It should also make the game speed slightly more stable, although this is so small that that wouldn't be noticed here.
I don't think so. Multiplication by a non-constant is definitely one of the slowest things you can do.

Edit:
You could replace the multiplications with and in this case, because you are operating on two values that are 0 or 1.
« Last Edit: December 05, 2010, 11:01:15 am by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Mouse
« Reply #11 on: December 05, 2010, 11:07:15 am »
hum, that means i will be editing my code. thanks.
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Mouse
« Reply #12 on: December 05, 2010, 12:49:16 pm »
Code: [Select]
.MOUSE
[101010FE10101000]->Pic1
While 1
.Store the screen to the back buffer
StorePic
.Display Sprite
Pt-On(X,Y,Pic1
DispGraph
.Erase Sprite
Pt-Change(X,Y,Pic1
.Replace the part of the image erased by the Sprite
RecallPic
.I used conditionals because the boundary conditions are important
.Replace with X+getKey(3)-getKey(2)→X if they aren't important.
If getKey(3) and (X<92)
X+1→X
End
If getKey(55) and (X<72)
Pt-On(X,Y,Pic1+8
End
If getKey(2) and (X>2)
X-1→X
End
If getKey(1) and (Y<60)
Y+1→Y
End
If getKey(4) and (Y>2)
Y-1→Y
End
If getKey(15)
Fix 4
Return
End
End

This works, why?

I have an idea of how to make mouse events now :)

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Mouse
« Reply #13 on: December 05, 2010, 01:23:17 pm »
return, while not part of a subroutine quits the program.

I always have fix 4 because i always use fix 5.
« Last Edit: December 05, 2010, 01:23:42 pm by happybobjr »
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Mouse
« Reply #14 on: December 05, 2010, 01:24:09 pm »
return, while not part of a subroutine quits the program.

I always have fix 4 because i always use fix 5.

I know what Fix 5 does (concetane images and text), but not Fix 4