Author Topic: Fruit Ninja for the CSE  (Read 4602 times)

0 Members and 1 Guest are viewing this topic.

Offline M. I. Wright

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
  • (say it out loud)
    • View Profile
Fruit Ninja for the CSE
« on: March 19, 2015, 11:39:50 pm »
If you want to see how this looked like when it first started, go to this Cemetech thread, but from now onwards I'll be crossposting everything from there to here and vice versa.

Anyway! This is an attempt to clone @Deep Thought 's monochrome Fruit Ninja game for the color calcs using xLIBC (as such, it requires Doors CSE to run). The control scheme is pretty similar so far (swipe across the keypad to draw a line onscreen, the screen is mapped from the MATH row downwards, every key works except for ON) except for those annoying dots that appear... but those'll be fixed easily enough.
A demo:


Download here (If you just want the program without the background pic, that's here). The code alone is here.

edit: some more important info from the Cemetech thread--
Quote
For those wondering how it works:
You may have noticed that the TI-OS's getKey command maps keys by row, then column. Using the ᴇ, iPart() and fPart() commands, the program extracts those row/column values, multiplies them to make them usable on the screen, and uses the multiplied column value/multiplied row value as X/Y coords to draw the line.

The example in the video uses xLIBC to draw the lines , but I have one that just moves an O around on the homescreen using pure TI-BASIC; that can be found here. (code here)
« Last Edit: March 19, 2015, 11:54:48 pm by M. I. Wright »

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Fruit Ninja for the CSE
« Reply #1 on: March 20, 2015, 02:27:29 am »
This is looking pretty sweet so far!
So it's in hybrid basic?

Good luck finishing it off!

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline M. I. Wright

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
  • (say it out loud)
    • View Profile
Re: Fruit Ninja for the CSE
« Reply #2 on: April 11, 2015, 12:15:15 am »
This is looking pretty sweet so far!
So it's in hybrid basic?

Good luck finishing it off!

Yes it is, and thank you!

I got a decently fast "fruit" (size-3 pixel) working; I don't think the speed at which it travels is quite right, but it's good enough for a test.
Download here.
Dunno if it's gonna be this fast with actual fruit sprites. Fingers crossed for now.

Offline M. I. Wright

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
  • (say it out loud)
    • View Profile
Re: Fruit Ninja for the CSE
« Reply #3 on: April 13, 2015, 06:57:53 pm »
Can someone help? I found this formula on math.stackexchange.com to test if a point is on a line:

Code: [Select]
y-y1=((y2-y1)/(x2-x1))*(x-x1)
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:


Code: [Select]
((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: [Select]
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.

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Fruit Ninja for the CSE
« Reply #4 on: April 15, 2015, 11:09:57 am »
For a vertical line, you just need something like "If (y-y1)*(x2-x1) = (y2-y1)*(x-x1)" or "If (y-y1)*(x2-x1) - (y2-y1)*(x-x1) = 0"
That gets rid of the division by zero. But that also only checks one point. Are you really sure the <17 code works as expected? I would try using the second formula (the one that checks for zero), then check the top left corner of your sprite and the bottom right corner. If one of the equations returns zero, there was a hit. If the signs are different (one positive, one negative) then there was a hit. If the signs are the same, then there was no hit.

I don't really remember TI-BASIC very well, but something like this:
Code: [Select]
(y-y1)*(x2-x1) - (y2-y1)*(x-x1) -> A
If A = 0
points+1->points
Else
If Sign(A) =/= Sign((y+15-y1)*(x2-x1) - (y2-y1)*(x+15-x1)
points+1->points
End
I don't think there's really a Sign function, but something along those lines should work ok...

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Fruit Ninja for the CSE
« Reply #5 on: April 15, 2015, 04:33:41 pm »
you can get sign(x) by doing x / abs(x)

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Fruit Ninja for the CSE
« Reply #6 on: April 18, 2015, 12:14:30 am »
Ah, that's a neat trick. But thinking about it later, i'm pretty sure what i posted above won't work either. It might work for infinite lines, but you'd have to check both sets of opposite corners.

Offline M. I. Wright

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
  • (say it out loud)
    • View Profile
Re: Fruit Ninja for the CSE
« Reply #7 on: April 18, 2015, 01:42:28 pm »
Thanks for your help- but I ended up using the formula from this Wikipedia article:

abs((y2-y1)x-(x2-x1)y+x2*y1-y2*x1
sqrt((y2-y1)^2+(x2-x1)^2))

It still returns a divide-by-0 error for a certain distance between lines, but that can be easily rectified by doing this:
Code: [Select]
:If not(sqrt((y2-y1)^2+(x2-x1)^2
:x2+1->x2
:If 16>=abs((y2-y1)x-(x2-x1)y+x2*y1-y2*x1/sqrt((y2-y1)^2+(x2-x1)^2)) //16 because that'll be the sprite width in pixels
:"do stuff

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.

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Fruit Ninja for the CSE
« Reply #8 on: April 18, 2015, 01:50:18 pm »
good to know you got it fixed!

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline M. I. Wright

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
  • (say it out loud)
    • View Profile
Re: Fruit Ninja for the CSE
« Reply #9 on: April 19, 2015, 07:45:02 pm »
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!