I'm working on Battleship CSE, but I can't seem to figure out how to detect ship overlapping in the editor which is a problem because I need the same system for hit detection in the actual game as well.
DL Link: https://www.dropbox.com/s/eukyg96066i19xc/BATSHIP.8xp?dl=0
The problem is the way the data is stored and I wanted it this way because it's easier and If the ship is gone it's easy to find out where to draw the line. Anyway, this is how it's stored:

L1(1) P1's 6x1's X coord, L1(6) P1's 6x1 Y coord, L1(11) P1's 6x1's rotation indicator (0=Horizontal 1=Vertical). Player 2's same system starts from (16). I hope you can infer the X of the 5x1 is L1(2)

If anyone can supply me with the formula for detection, I'd really appreciate it.

PT_ gave me this but it doesn't exactly work so feel free to use it as a guider.

Code:
For(A,L1(1),L1(1)+5not(L1(9   // Loop through all the X coordinates of the 5x1 ship
   For(B,L1(5),L(5)+5L1(9   // Loop through all the Y coordinates of the 5x1 ship
      If A>=L1(2) and A<=L1(2)+4not(L1(10)) and B>=L1(6) and B<=L1(6)+4L1(10   // Oh no, there's already a part of the ship at this point
         Goto NO
      End
   End
End


Hope I'm not sounding lazy. I genuinely can't figure out how to do this.

People got confused with the storage system so:
https://docs.google.com/spreadsheets/d/1tyAPybIKeHuXX6wJpPAtBPbwQnsRhCwZXP0MOfjBC3I/edit?usp=sharing
mets11rap wrote:
I'm working on Battleship CSE, but I can't seem to figure out how to detect ship overlapping in the editor which is a problem because I need the same system for hit detection in the actual game as well.
DL Link: https://www.dropbox.com/s/eukyg96066i19xc/BATSHIP.8xp?dl=0
The problem is the way the data is stored and I wanted it this way because it's easier and If the ship is gone it's easy to find out where to draw the line. Anyway, this is how it's stored:

L1(1) P1's 6x1's X coord, L1(6) P1's 6x1 Y coord, L1(11) P1's 6x1's rotation indicator (0=Horizontal 1=Vertical). Player 2's same system starts from (16).

If anyone can supply me with the formula for detection, I'd really appreciate it.

PT_ gave me this but it doesn't exactly work so feel free to use it as a guider.

Code:
For(A,L1(1),L1(1)+5not(L1(9   // Loop through all the X coordinates of the 5x1 ship
   For(B,L1(5),L(5)+5L1(9   // Loop through all the Y coordinates of the 5x1 ship
      If A>=L1(2) and A<=L1(2)+4not(L1(10)) and B>=L1(6) and B<=L1(6)+4L1(10   // Oh no, there's already a part of the ship at this point
         Goto NO
      End
   End
End


Hope I'm not sounding lazy. I genuinely can't figure out how to do this.

This is kind of taking the easy way out, but you can use real(7,0,x,y),which returns the color of that pixel. If you are careful, you can check a pixel in each square that would be occupied if the user were to place his/her ship in the position that they are trying to, and if any of those are blue (because when you place a ship, the squares turn blue), then you know that it would be overlapping with another ship. It is what I used for Block Party, to detect if you are trying to place a piece in a position where there is already some piece bits.
It'll also be smaller and probably faster than doing a bunch operations and comparisons in your list.
Oo! Interesting! But how would I do that in the game itself?
Ok well I will try to pseudocode this...



Code:
A=size of one square on screen
find out what are the coordinates of the piece that the user is trying to place on the screen
if it is horiz:
      for int i=x;i<(x+A*(ship.length));i+=A
      if background_color==real(7,0,x,y)):Then:don't draw
      elseif it is vert:
            for int i=y;i<(y+A*(ship.length));i+=A
            if background_color==real(7,0,x,y)):Then:don't draw
else:Draw the ship
Anyone know why it's not uninverting after a place? https://www.dropbox.com/s/hosgs9igilw75k0/BATSHIP.8xp?dl=0
mets11rap wrote:
Anyone know why it's not uninverting after a place? https://www.dropbox.com/s/hosgs9igilw75k0/BATSHIP.8xp?dl=0
This is not a great way to ask a question: you're making someone download your program, pass it through SourceCoder, read it and try to narrow down where the problem is happening, etc. Please include just the few lines of TI-BASIC in your post, in a [code] box, that cause the problem. Then be patient. Smile
The problem is fixed. Also, sorry Kerm.
  
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 1 of 1
» 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