News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_AMSDOS

Collision Detection required for this program.

Started by AMSDOS, 09:26, 25 August 10

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AMSDOS

I was working on this game before I went into hiding some years ago and sadly it's missing Collision Detection and just needs some sort of objective (might just have it drop some acid when you shoot it and you have to avoid it!) and Sound of Course (I'm terrible at Sound Effects  :( ). Realise this is horribly slow, at the minute I've left it like this to get some idea how such a program would appear. Any thoughts about how I should do a Collision Detection for it?

10 MODE 1:DEFINT A-Z:INK 0,2:INK 1,26:INK 2,6:BORDER 26
20 X=1: Y=14: XDIR=1: YDIR=1: XMAN=100
30 SYMBOL 254,0,31,35,39,47,63,31,0
40 SYMBOL 255,0,252,254,254,254,254,252,0
50 GOSUB 1000 ' print and move pill
60 GOSUB 2000 ' print cannon
70 GOSUB 2040 ' move cannon
80 GOSUB 2100 ' Fire Pressed
100 GOTO 50
1000 TAG: MOVE X,Y
1010 GRAPHICS PEN 1:PRINT CHR$(254)+CHR$(255);:TAGOFF
1020 IF X=599 THEN XDIR=-1
1030 IF Y=399 THEN YDIR=-1
1040 IF X=1 THEN XDIR=1
1050 IF Y=14 THEN YDIR=1
1060 X=X+XDIR:Y=Y+YDIR:RETURN
1999 ' PRINT CANNON
2000 TAG:MOVE XMAN,14
2010 GRAPHICS PEN 1:PRINT CHR$(32)+CHR$(244)+CHR$(32);:TAGOFF
2020 RETURN
2030 ' CHECK FOR KEY
2040 a$=INKEY$
2050 IF (a$="O" OR a$="o") AND (xman<>1) THEN xman=xman-1
2060 IF (a$="P" OR a$="p") AND (xman<>599) THEN xman=xman+1
2070 IF (a$=" ") THEN fire=1
2080 RETURN
2100 IF fire=0 THEN RETURN
2110 IF fire=1 THEN MOVE xman+22,12:DRAW xman+22,Y-2,1:FOR delay=1 TO 10:NEXT delay:MOVE xman+22,12:DRAW xman+22,399,0:fire=0:RETURN
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Devilmarkus

#1
Small patch:
2110 IF fire=1 THEN GOSUB 3000:MOVE xman+22,12:DRAW xman+22,Y-2,1:FOR delay=1 TO 10:NEXT delay:MOVE xman+22,12:DRAW xman+22,399,0:fire=0:RETURN
3000 TAGOFF:LOCATE 1,1:PRINT"     ":FOR t=16 TO 400 STEP 6:IF TEST(xman+22,t) = 1 THEN TAGOFF:LOCATE 1,1:PRINT"hit!":TAG:RETURN
3010 NEXT:TAG:RETURN


BTW.: To make it a bit faster: You are using 1 pixel steps. But the game is in MODE 1 so you can use 2 pixel steps. You will not see a difference only that your game is a bit faster.
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Devilmarkus

I optimized your game a bit for speed:
10 MODE 1:DEFINT A-Z:INK 0,2:INK 1,26:INK 2,6:BORDER 26
20 X=1: Y=14: XDIR=1: YDIR=1: XMAN=100
30 SYMBOL 254,0,31,35,39,47,63,31,0
40 SYMBOL 255,0,252,254,254,254,254,252,0
50 GOSUB 1000 ' print and move pill
60 GOSUB 2000 ' print cannon
70 GOSUB 2040 ' move cannon
80 'GOSUB 2100 ' Fire Pressed
100 GOTO 50
1000 TAG: MOVE X,Y
1010 GRAPHICS PEN 1:PRINT CHR$(254)+CHR$(255);:TAGOFF
1020 IF X=599 THEN XDIR=-2
1030 IF Y=398 THEN YDIR=-2
1040 IF X=1 THEN XDIR=2
1050 IF Y=14 THEN YDIR=2
1060 X=X+XDIR:Y=Y+YDIR:RETURN
1999 ' PRINT CANNON
2000 TAG:MOVE XMAN,14
2010 GRAPHICS PEN 1:PRINT CHR$(32)+CHR$(244)+CHR$(32);:TAGOFF
2020 RETURN
2030 ' CHECK FOR KEY
2040 a$=INKEY$:IF a$="" THEN RETURN
2050 IF (a$="O" OR a$="o") AND xman>1 THEN xman=xman-4
2060 IF (a$="P" OR a$="p") AND xman<599 THEN xman=xman+4
2070 IF (a$=" ") THEN GOSUB 2110
2080 RETURN
2110 GOSUB 3000:MOVE xman+22,12:DRAW xman+22,Y-2,1:FOR delay=1 TO 10:NEXT delay:MOVE xman+22,12:DRAW xman+22,399,0:fire=0:RETURN
3000 TAGOFF:LOCATE 1,1:PRINT"     ":FOR t=16 TO 400 STEP 6:IF TEST(xman+22,t) = 1 THEN TAGOFF:LOCATE 1,1:PRINT"hit!":TAG:RETURN
3010 NEXT:TAG:RETURN
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

AMSDOS

Ah yes I forgot about the TEST function of course! Yes I noticed that I could speed things up a bit if I increment things by 2 (since I'm in Mode 1)  ;D  I put a CALL &BD19 just to smooth things out a bit - the Bouncy pill was looking a bit out of character!

Just looking at your modifications it appears you have the program blowing up the pill before shooting the Laser.  ;)

Of course I had some ideas after posting this and did a Collision Detection a totally different way - with the same result though!  ;)

10 MODE 1:DEFINT A-Z:INK 0,2:INK 1,26:INK 2,6:BORDER 26
20 X=INT(RND*300): Y=INT(RND*300): XDIR=1: YDIR=1: XMAN=100: DIM P(2)
30 SYMBOL 254,0,31,35,39,47,63,31,0
40 SYMBOL 255,0,252,254,254,254,254,252,0
50 GOSUB 1000
60 GOSUB 2000
70 GOSUB 2040
80 GOSUB 2100
100 GOTO 50
1000 TAG: CALL &BD19:MOVE X,Y
1010 GRAPHICS PEN 1:PRINT CHR$(254)+CHR$(255);:TAGOFF
1020 IF X=599 THEN XDIR=-1
1030 IF Y=399 THEN YDIR=-1
1040 IF X=1 THEN XDIR=1
1050 IF Y=14 THEN YDIR=1
1060 X=X+XDIR:Y=Y+YDIR:p(1)=x+5:p(2)=x+25:RETURN
1999 ' PRINT CANNON
2000 TAG:MOVE XMAN,14
2010 GRAPHICS PEN 1:PRINT CHR$(32)+CHR$(244)+CHR$(32);:TAGOFF
2020 RETURN
2030 ' CHECK FOR KEY
2040 a$=INKEY$
2050 IF (a$="O" OR a$="o") AND (xman<>1) THEN xman=xman-2
2060 IF (a$="P" OR a$="p") AND (xman<>599) THEN xman=xman+2
2070 IF (a$=" ") THEN fire=1
2080 RETURN
2100 IF fire=0 THEN RETURN
2110 IF fire=1 THEN MOVE xman+22,12:DRAW xman+22,Y-2,1:FOR delay=1 TO 10:NEXT delay:MOVE xman+22,12:DRAW xman+22,399,0:fire=0: GOSUB 3000:RETURN
3000 IF xman+22>p(1) AND xman+22<p(2) THEN END ELSE RETURN


Naturally since I love Arrays, I decided to setup an array - 2 points, the first points to the left side of the object and second points to the right side of the object (I did some plotting prior to this to work out the edge of the guts of this object), works quite effectively too! Though Test is pretty good with what it does, just wondered if there's a Firmware address for Test? The other thing I did with my program was Set a Random location for my Pill to appear onscreen. Just makes it a bit harder. Of course I made it so when you hit the Pill, the program stops!  ;D

Interesting concept I started here, could be interesting to see how many ways a Collision Detection could be written into this demo!  ;D
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Devilmarkus

#4
You can also use this: (I know I added some more but it shows a simple collision detection)
10 MODE 1:DEFINT A-Z:INK 0,2:INK 1,26:INK 2,6:BORDER 26
20 X=1: Y=14: XDIR=1: YDIR=1: XMAN=100
30 SYMBOL 254,0,31,35,39,47,63,31,0
40 SYMBOL 255,0,252,254,254,254,254,252,0
50 GOSUB 1000 ' print and move pill
60 GOSUB 2000 ' print cannon
70 GOSUB 2040 ' move cannon
100 GOTO 50
1000 TAG: MOVE X,Y
1010 GRAPHICS PEN 1:PRINT CHR$(254)+CHR$(255);:TAGOFF
1020 IF X>599 THEN XDIR=-2
1030 IF Y>378 THEN YDIR=-2
1040 IF X<2 THEN XDIR=2
1050 IF Y<16 THEN YDIR=2
1060 X=X+XDIR:Y=Y+YDIR:RETURN
1999 ' PRINT CANNON
2000 TAG:MOVE XMAN,14
2010 GRAPHICS PEN 1:PRINT CHR$(32)+CHR$(244)+CHR$(32);:TAGOFF
2020 RETURN
2030 ' CHECK FOR KEY
2040 a$=INKEY$:IF a$="" THEN RETURN
2050 IF (a$="O" OR a$="o") AND xman>1 THEN xman=xman-4
2060 IF (a$="P" OR a$="p") AND xman<599 THEN xman=xman+4
2070 IF (a$=" ") THEN GOSUB 2110
2080 RETURN
2110 IF xman+22 >x AND xman+22 < x+30 THEN GOSUB 3000:TAGOFF:LOCATE 1,1:sc=sc+100:PRINT"SCORE:";sc:TAG:MOVE xman+22,12:DRAW xman+22,Y-2,1:FOR delay=1 TO 10:NEXT delay:MOVE xman+22,12:DRAW xman+22,378,0:x=RND*500+20:y=RND*350+30:RETURN
2120 TAG:MOVE xman+22,12:DRAW xman+22,378,1:FOR delay=1 TO 10:NEXT delay:MOVE xman+22,12:DRAW xman+22,378,0:RETURN
3000 TAG: MOVE X,Y
3010 GRAPHICS PEN 0:PRINT CHR$(254)+CHR$(255);:TAGOFF:RETURN


BTW.: Your code would not work on a CPC 464!
For BASIC 1.0 you need to remove all GRAPHICS PEN x and replace by a PLOT -2,-2,x
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

AMSDOS

Devilmarkus wrote:

You can also use this: (I know I added some more but it shows a simple collision detection)

BTW.: Your code would not work on a CPC 464!
For BASIC 1.0 you need to remove all GRAPHICS PEN x and replace by a PLOT -2,-2,x


That's great, you've got to a bit of trouble there and I was actually starting to enjoy playing it!  ;D . Originally I was trying to do it like that with the maths in the IF statement, though just threw it all into an array cause it seemed easier to write it like that!

I know I'm neglecting my BASIC 1.0 roots!  ???  I was under the impression that GRAPHICS PEN can be substituted with just PEN in BASIC 1.0. Otherwise I can just go to GRA SET PEN which works on all the systems. "PLOT -2,-2,x" seems confusing I guess the idea there is to PLOT off screen in "x" which sets the graphics pen ink that way!
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

I was just having some thoughts about what this program could be and wondered how a simple Pang would work, I'll confess I've never played Pang, though I haven't played Zap 't' Balls either and the only thing I can think of which remotely comes close to those would be Asteroids. The idea I had would involve one object to shoot at the start and as it's being shot up it would get smaller in size and more smaller versions of that Bubble/Rock would appear. And I guess that would present how those additional objects would interact if they Collided with each other. At the moment routines like the movement of the alien object would have to be modified to accomodate a series of additional objects - that are to be moved around screen, the tricky bit I'm guessing is how to have small and larger objects, each would have their own details.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

steve

#7
You could have a simple ball shape that can bounce off walls unaffected by gravity, when you shoot it it divides into two smaller balls 5 or six shots and the balls are small enough that they disappear, however if two balls collide they merge into a ball larger than the combined sizes of the two or more colliding balls so if you cannot shoot them fast enough you have more targets then you started with, the longer you take the harder the game becomes.

AMSDOS

steve wrote:

You could have a simple ball shape that can bounce off walls unaffected by gravity, when you shoot it it divides into two smaller balls 5 or six shots and the balls are small enough that they disappear, however if two balls collide they merge into a ball larger than the combined sizes of the two or more colliding balls so if you cannot shoot them fast enough you have more targets then you started with, the longer you take the harder the game becomes.

Ah, the possibilities are endless!  ;D
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Xifos

Hi,

You could try changing the key check.
Using if inkey(codekey)<>-1 then...
Rather than inkey$
:)

For exemple : if inkey(47)<>-1 tests if <space> is pressed

Powered by SMFPacks Menu Editor Mod