Botboy3000 wrote:
I downloaded your program SWIPE and I looked in it and I saw the line:
"FRNBG
I assume this stands for FRuit Ninja BackGround. Is this Appvar available too?

Whoops, yeah. The other downloads had a zip file with the appvar included, but here it is as its own download: https://www.dropbox.com/s/bve2e6fldusg8q1/FRNBG.8xv?dl=0
Can someone help? I found this formula on math.stackexchange.com to test if a point is on a line:

y-y1=((y2-y1)/(x2-x1))*(x-x1)

where x and y are the sprite's coordinates, and x1, x2, y1 & y2 are the line's four coordinates.

It worked, but I had to tweak it a bit to account for the fact that I'll be using 16x16 sprites at some point in the future:


((y2-y1)/(x2-x1))*(x-x1)-(y-y1)<17

It works flawlessly, but only if the line is horizontal or diagonal. If the line is vertical, x2-x1=0 and it throws a divide-by-0 error; I could test to see if x2-x1=0 before running it, but then the user won't get any points if they draw a vertical line. I have no idea how, so could someone adapt the formula to work if the line is vertical so I could do something like this?

Code:

If not(x2-x1 //if the line isn't vertical
Then
If ((y2-y1)/(x2-x1))*(x-x1)-(y-y1)<17
points+1->points
Else
If [version of formula for vertical line]
points+1->points
End

Thanks.
Maybe check to see if it equals 0 like you said, but draw the input lines then, as a separate command.

Like you have in a loop, and draw a vertical line where the point originated.
Since the formula you have is basically trying to find slope, and you just can't calculate the slope if its infinity, so all you need to do is add a miniscule number to x2-x1. Just make it x2-x1+0.001, then it should work, and with no difference in the effect.

Edit: Nvm, I don't think the formula is right for this problem. It may work for a single dot check, but not for a 16x16 rectangle.
Here's a link for checking if a line crosses a circle, which I think is better than the box anyway: Circle intersects Line

Edit2: Sorry, a better answer. Find the distance between a line and the center of the circle. See if that distance is less than the radius, which is going to be 8 for the 16x16 sprite. If it is, it intersects the circle.

Last edit: WIKIPEDIA RULES ALL
Unicorn wanted to understand the code above that detects for bottom-led to top-right swiping, so here:
(Remember, this goes right after "If K:Then")

Code:

10fPart(.1K

This extracts the column of the key pressed. getKey maps keys by row, then column- for instance, Enter is 105 because it's the 5th key in the 10th row of keys. Say you pressed Enter, this line turns 105 into 10.5, then into 5.

Code:

If Ans>3 and not(Z
Then
iPart(.1K

This detects if the key is on the right side of the keypad. If it is, it takes the row value of the key (it again turns it into 10.5, but this time takes the 10)

Code:

If Ans>8
1->Z
End

If the key is on the bottom of the keypad, it advances to the second step.

Code:

If Ans<3 and Ans and Z:Then
iPart(.1K
If Ans<6 and Ans:Then

If it's on the second step and the key is on the right side of the keypad, it checks the row value. If that's on the top part of the keypad, it advances to displaying "GREAT JOB!"

Code:

"GREAT JOB!
real(6,0,0,15,0,47,1
real(6,0,0,15,0,47,1
End
End

displays a message.

Hopefully this helped explain it a bit, and helped you get started on changing the key values. To see key's getKey value, start at 11A on the Y= key, and go down row by row to the key's row, counting by 10s. After that, add 1 to the number going right until you reach it. The resulting number is the key code. For instance, the 9 key's code is 74.

Note that the code above can be broken by pressing, say, ENTER, waiting, then pressing MATH. See if you can figure out how to fix this using startTmr and checkTmr!
Thanks a ton Wright! Smile

So, if I want to check if it goes from top right to bottom left, do this?


Code:

10fPart(.1K
If Ans<3 and not(Z
Then
iPart(.1K
If Ans>5
1->Z
End
If Ans<3 and Ans and Z:Then
iPart(.1K
If Ans<1 and Ans:Then 
"GREAT JOB!
real(6,0,0,15,0,47,1
real(6,0,0,15,0,47,1
End
End


I have a feeling that this is wrong, but it was the best I could figure out. Neutral
Unicorn wrote:
Thanks a ton Wright! Smile

So, if I want to check if it goes from top right to bottom left, do this?


Code:

10fPart(.1K
If Ans<3 and not(Z
Then
iPart(.1K
If Ans>5
1->Z
End
If Ans<3 and Ans and Z:Then
iPart(.1K
If Ans<1 and Ans:Then 
"GREAT JOB!
real(6,0,0,15,0,47,1
real(6,0,0,15,0,47,1
End
End


I have a feeling that this is wrong, but it was the best I could figure out. Neutral


Close! That code detects for swiping from the bottom left to the top row of keys (the small gray ones). To help you out, here's a list of what key outputs you'd get and how it'd check for them when pressing various keys.

If CLEAR is pressed:

Code:

;K=45
10fPart(.1K
;Ans=5
;Ans<3 and not(Z) = False
;DO NOTHING

If NEGATIVE (-) is pressed:

Code:

; K=104
10fPart(.1K
; Ans=4
; Ans<3 and not(Z) = False
; DO NOTHING

If NOTHING is pressed:

Code:

; K=0
10fPart(.1K
; Ans=0
; Ans<3 and not(Z) = True
If Ans<3 and not(Z
Then
iPart(.1K
; Ans=0
; Ans>5 = False
; DO NOTHING

If STO is pressed:

Code:

; K=91
10fPart(.1K
; Ans=1
; Ans<3 and not(Z) = True
If Ans<3 and not(Z
Then
iPart(.1K
; Ans=9
; Ans>5 = True
If Ans>5
1->Z
End
; proceed to next step

Now that we've gotten past the first step, let's move on to detection of the second bit.
If CLEAR is pressed:

Code:

; K=45
10fPart(.1K
; Ans=5
Ans<5 and Ans and Z = False
; DO NOTHING

If 2ND is pressed:

Code:

; K=21
10fPart(.1K
; Ans=1
; Ans<5 and Ans and Z = True
If Ans<5 and Ans and Z:Then
iPart(.1K
; Ans=2
Ans<1 and Ans = False
; DO NOTHING

If Y= is pressed:

Code:

; K=11
10fPart(.1K
; Ans=1
; Ans<5 and Ans and Z = True
If Ans<5 and Ans and Z:Then
iPart(.1K
; Ans<1 and Ans = True
If Ans<1 and Ans:Then 
"GREAT JOB!
real(6,0,0,15,0,47,1
real(6,0,0,15,0,47,1
End
End
; success
I tried to do some key to screen mapping on the 83+ (monochrome) in pure BASIC, however it currently doesn't draw lines, and it also can't use the very top and the very bottom row of keys. Currently, it only draws pixels:

Code:

0->Xmin:1->DeltaX
~62->Ymin:1->DeltaY
DelVar A DelVar BClrDraw
DispGraph
While 1
A+B->A
If A=20:DelVar ADelVar BClrDraw
getKey->K
If Ans:Then
Pt-On(~9+iPart(188fPart(Ans/10)),3-(~2+8(iPart(Ans/10)-1
1->B
End:End

The only trouble is how to make the lines. I did try using a While K loop inside the While 1 loop, but that didn't work at all, as the screen was completely blank (probably because of how slow getkey registers). thoughts? Smile
Would it be possible to use line() commands to do it? Or would that be too slow?
--
Any idea how I would handle drawing and erasing sprites quickly? For now I'm just drawing a size-3 inverted pixel with real(7,4,X,Y,3 and then re-inverting it later to erase it, but that's obviously not going to cut it for an actual Fruit Ninja remake.
M. I. Wright wrote:
Would it be possible to use line() commands to do it? Or would that be too slow?

That's the problem... In order to draw a line, you need 2 points. In order to get 2 points, you need 2 getkey values stored in different variables, and draw the line from there, and then keep doing that until the user stops pressing buttons. I tried doing a while getkey loop but the way i had it didn't quite work...
Michael2_3B wrote:
M. I. Wright wrote:
Would it be possible to use line() commands to do it? Or would that be too slow?

That's the problem... In order to draw a line, you need 2 points. In order to get 2 points, you need 2 getkey values stored in different variables, and draw the line from there, and then keep doing that until the user stops pressing buttons. I tried doing a while getkey loop but the way i had it didn't quite work...


Ohh. Try storing them in a list-- take a look at what I did in the fruit ninja game (download is on page 1). [as for drawing, basically all you need to know is that real(7,6,X1,Y1,X2,Y2,other,arguments) draws a line. Refer to this page for more info on that.]
--
Right now it's looking like the best way to erase the sprite would be to redraw the entire background, which would be incredibly slow. Drawing a brown rectangle to cover the sprite wouldn't be a good idea (random rectangles everywhere!) unless I were to use a solid color instead of an image for a background, which I'd rather avoid. Maybe I could draw the background as a tilemap and use ReplaceTile()... thoughts?
Perfect, I just found out about Celtic's BufSprite()! The wiki says that it "copies the contents of the graph buffer under the sprite back into Str9, so that you can "erase" the sprite back to the original background." Quoted from SAX:

Quote:

12:47:48 (C) M. I. Wright: or something like that
12:47:40 (C) M. I. Wright: assuming I have a maximum of 5 sprites onscreen at any given time, that'll leave Str9 free for drawsprite, str0 free for storing sprite data, str8 free for storing graph buffer data, and str7 free for holding a string like "Str1Str2...Str5" that I could expr(sub()) the names of the strings out of to iterate through
12:43:28 (C) M. I. Wright: I could store str9 to other strings for every sprite drawn, then iterate through all the strings to erase/redraw sprites
https://www.dropbox.com/s/0m83jmldo0gwkot/FRTNINJA%20%281%29.8xp?dl=0

Good news, I'm releasing a beta version of this! I finally figured out how to display fruit sprites, and so far I've added apples, cherries and tomatoes. I've also added bombs, so watch out for those!

A gameplay screenie:


And you know what? It's even more fun if you set your calculator to degrees instead of radians!
What are the = signs for?
Unicorn wrote:
What are the = signs for?


They're the blade that you slice fruit with, obviously.
What happened to the xlib lines? Shock
You do know that screenshot is messed up? It still has some of the home screen text on it... and also, why is it suddenly homescreen? Like unicorn said, what happened to the xlib lines and the background and stuff??? Shock
Nice work, M. I. Wright! Smile Looking pretty good; looks like this is just in testing mode for now, which is a good idea for making sure everything is working right. I'd be interested to see how you are doing the physics for the fruit and things; it looks like it is parabolic in nature? Anywho, keep up the good work! Smile
You guys it's a joke :|
M. I. Wright wrote:
You guys it's a joke Neutral

You're a bit late for April Fools... Razz Razz
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 3
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement