Author Topic: Basic Efficient Collision Detection Routine  (Read 1362 times)

0 Members and 1 Guest are viewing this topic.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.364
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 655
Re: Basic Efficient Collision Detection Routine
« Reply #10 on: 12:51, 26 September 17 »
I had a look at the source code for Depth Charge, while I like the descriptive names for the variables, that's going to be holding up BASIC a lot. I also noticed you're using INKEY$ which is slower than INKEY("key number")<>-1, though with INKEY$ you can use Speed Key (use with care though). I tried this last night, though after the changes, the boat moved briefly and then stopping  ??? Initially I thought the CALL &BB03 was the culprit, but it still occured after I commented them out, something to do with TIME I guess? I had DI/EI around the INPUT routine, probably should have around the TIME routine  ::)

For the variable names, I would just write all those names in Notepad and put a single letter variable next to it, I saw some single letter variables being used, so perhaps use 2 character names for those descriptive variables, a number could be used following a letter - A1, A2 so it kind of groups with the related stuff I suppose.

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.106
  • Country: au
    • index.php?action=treasury
  • Liked: 741
Re: Basic Efficient Collision Detection Routine
« Reply #11 on: 14:42, 26 September 17 »
I had a look at the source code for Depth Charge, while I like the descriptive names for the variables, that's going to be holding up BASIC a lot. I also noticed you're using INKEY$ which is slower than INKEY("key number")<>-1, though with INKEY$ you can use Speed Key (use with care though). I tried this last night, though after the changes, the boat moved briefly and then stopping  ??? Initially I thought the CALL &BB03 was the culprit, but it still occured after I commented them out, something to do with TIME I guess? I had DI/EI around the INPUT routine, probably should have around the TIME routine  ::)

For the variable names, I would just write all those names in Notepad and put a single letter variable next to it, I saw some single letter variables being used, so perhaps use 2 character names for those descriptive variables, a number could be used following a letter - A1, A2 so it kind of groups with the related stuff I suppose.

I've been looking into the code too... it's very interesting.
The boat's moving/stopping is to do with all the sub/bomb processing that goes on after the boat has moved a few steps.
My entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.pouet.net/prod.php?which=66566

Offline freemac

  • CPC6128
  • ****
  • Posts: 218
  • Country: 00
  • Liked: 182
Re: Basic Efficient Collision Detection Routine
« Reply #12 on: 14:58, 26 September 17 »
I found that : http://amstrad.eu/modules/lexikon/entry.php?entryID=179  :)

10 CLS
20 PRINT"coin superieur"
30 LOCATE 1,1
40 a$=COPYCHR$(#0)
50 LOCATE 1,20
60 PRINT a$
RUN

Offline tjohnson

  • Supporter
  • 464 Plus
  • *
  • Posts: 360
  • Country: gb
    • index.php?action=treasury
  • Liked: 97
Re: Basic Efficient Collision Detection Routine
« Reply #13 on: 15:45, 26 September 17 »
Thanks for the feedback, all feedback is welcomed and if you can improve and make it better please feel free!   I didn't realise the descriptive names would slow basic down so that's great.
On INKEY$ i did try INKEY but didn't find it worked as well in practice.  I put the calls in to clear the key buffer to stop the key inputs queing up and the ship moving multiple space when you only want it to move once.
I put the counter into the ship movement as a late addition to allow the ship to move faster than the subs, there is probably a better way of doing it.

Sent from my E5823 using Tapatalk


Offline tjohnson

  • Supporter
  • 464 Plus
  • *
  • Posts: 360
  • Country: gb
    • index.php?action=treasury
  • Liked: 97
Re: Basic Efficient Collision Detection Routine
« Reply #14 on: 15:49, 26 September 17 »

I found that : http://amstrad.eu/modules/lexikon/entry.php?entryID=179  :)

10 CLS
20 PRINT"coin superieur"
30 LOCATE 1,1
40 a$=COPYCHR$(#0)
50 LOCATE 1,20
60 PRINT a$
RUN


I didn't use that method of reading the screen in the depth charge game as I don't think it works on the 464 and wanted it compatible, I did however used it in my other bomb drop game though which I wrote before the depth charge game.

Ive been thinking about another way of checking collision but will need to put down some code to see if it works and is any quicker.

Sent from my E5823 using Tapatalk
« Last Edit: 21:10, 26 September 17 by tjohnson »

Offline freemac

  • CPC6128
  • ****
  • Posts: 218
  • Country: 00
  • Liked: 182
Re: Basic Efficient Collision Detection Routine
« Reply #15 on: 01:18, 27 September 17 »
10 x%=int(rnd*20)+1
20 y%=20
25 pen 2
30 locate x%,y%:print "I"
31 locate x%,y%:print "I"
32 locate x%,y%:print "I"
33 locate x%,y%:print "I"
34 locate x%,y%:print "I"
35 locate x%,y%:print "I"
36 locate x%,y%:print "I"
37 locate x%,y%:print "I"
38 locate x%,y%:print "I"
39 locate x%,y%:print "I"
40 locate x%,y%:print " "
45 y%=y%-1
46 locate x%,y%:a$=copychr$(#0)
47 if a$="O" then 50
48 if asc(a$)<>32 then print "O":goto 10
50 if y%=1 then 10
60 goto 30
5 pen 1:cls:cat

 :D

« Last Edit: 01:24, 27 September 17 by freemac »

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.364
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 655
Re: Basic Efficient Collision Detection Routine
« Reply #16 on: 11:53, 27 September 17 »

I didn't use that method of reading the screen in the depth charge game as I don't think it works on the 464 and wanted it compatible, I did however used it in my other bomb drop game though which I wrote before the depth charge game.

Ive been thinking about another way of checking collision but will need to put down some code to see if it works and is any quicker.

Sent from my E5823 using Tapatalk


Indeed, the COPYCHR$(#0) doesn't exist on a 464 with BASIC 1.0, though in the firmware the function exists, so with a little bit of M/C it's possible to write one. However there is a subtle difference which created havoc in the early days (prior to the 664). The main problem with the firmware relates to when graphics were checked, by this I mean something like a graphical line at a certain text coordinate position. I wrote this little program in the BASIC Programming Tips which demostrates the issue, which relates to what the PEN colour is. On the 464 it doesn't care what the colour is, unlike the later computers which do.


You may also want to try a game I reworked from AA84, I've attached a CDT (tape image) of it here, which has a link to the original game. I bring it up because the game on the CDT is now using an Array for the playing field. What I seem to notice with that and the original game which is checking what's at a position with COPYCHR$(#0) is the array version is running a little bit faster. The only thing lagging in the TAPE version (apart from the TAPE!  :D ), is the drawing process for the time it takes to draw the screen. I didn't think this was as critical though.  :)

Offline ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.106
  • Country: au
    • index.php?action=treasury
  • Liked: 741
Re: Basic Efficient Collision Detection Routine
« Reply #17 on: 15:57, 27 September 17 »
A couple of little things that I noticed, not related to the collision checking:
- The entire status line is reprinted every single frame on line 10920. It's better to print the static text once when the game starts, and then just print the numeric values when they change.
- a line of 40 spaces is printed every frame by line 10905. It doesn't seem to be required (at least, not at this stage), and it slows things down quite a lot.
My entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.pouet.net/prod.php?which=66566

Offline tjohnson

  • Supporter
  • 464 Plus
  • *
  • Posts: 360
  • Country: gb
    • index.php?action=treasury
  • Liked: 97
Re: Basic Efficient Collision Detection Routine
« Reply #18 on: 01:46, 19 March 18 »
I dug this out and made a few small changes today.  Next step will be to start trying to code bits of it in assembler to try to get the speed up and move away from the character movement.



Offline tjohnson

  • Supporter
  • 464 Plus
  • *
  • Posts: 360
  • Country: gb
    • index.php?action=treasury
  • Liked: 97
Re: Basic Efficient Collision Detection Routine
« Reply #19 on: 01:18, 25 March 18 »
Hi all,

I've made a few small improvements to my basic game.  Latest disk attached, no assembler.

Press 3 to add credits, press 1 to start
O and P to make the ship move left and right
Q and W to drop a depth charge either side of the ship.

Cheers Trevor