News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Fabrizio Radica

Simple Engine Game in Basic

Started by Fabrizio Radica, 15:48, 29 July 16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rk last

Quote from: Fabrizio Radica on 01:26, 26 August 16

yeah! I really love the new mode!!!
tnx :)

And its all done in basic too.  I dare say that you could easily code a Donkey Kong clone easily with that display and its increase in power.
maRK

Fabrizio Radica

Quote from: rk last on 01:30, 26 August 16
And its all done in basic too.  I dare say that you could easily code a Donkey Kong clone easily with that display and its increase in power.


goooood idea!!!

Donkey Kong, Mr. Do, Space Invaders and Frogger :D

With hardware scrolling and tilemaps with fast pooling routines, we can make a Super Mario Clone also...

AMSDOS

Quote from: rk last on 01:26, 26 August 16
You may need this too when drawing lines.

MOVE x,y [[,i1][,i2]]  Moves the graphic cursor to position x,y. The parameter i1 may be used to change the pen (drawing) colour. The parameter i2 specifies the logical colour, as in DRAW.  4 drawing styles: 
i2 = 0 normal colour i2 = 1 XOR colour i2 = 2 AND colour i2 = 3 OR colour 




Not very 464 friendly though.
* 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

Fabrizio Radica

Quote from: AMSDOS on 10:32, 26 August 16

Not very 464 friendly though.


Exactly :(
I'm back to XOR sprite with background.
It has flicker, but works fine for now... (waiting for new ideas)



AMSDOS


Quote from: Fabrizio Radica on 13:55, 26 August 16


Exactly
I'm back to XOR sprite with background.
It has flicker, but works fine for now... (waiting for new ideas)


It's possible to draw a box (in background colour), which reduces flicker to the edge of the character, but then you've got the background blocks that are at risk of being deleted as your character passes over it.
To make it work your character has to move up or down by a factor of 2 (not 4), to prevent the top or bottom of your character messing up the screen like earlier. Though for Left/Right Motion 4 is used in MODE 0 as each Pixel is 4 co-ordinates along: e.g. PLOT 0,398,1 PLOT 4,398,2 (for Top-Left of Screen).


Anyway, I'll post what I wrote, but I think the XOR version is better (it doesn't destroy the scenery), when it comes to BASIC though, reducing/eliminating the flicker will either involve Compiling the code in a BASIC compiler or setting up a Second Screen to draw the scenery on that screen and alternate, which involves using OUT commands.



10 MODE 0:CLS:BORDER 0:INK 0,0
200 SYMBOL 240,&X111100,&X1111110,&X11101011,&X11111111,&X11111111,&X11000011,&X1100110,&X111100
210 SYMBOL 245,&X1111111,&X1111111,&X1111111,&X1111111,&X1111111,&X111111,&X0,&X0 'wall
220 SYMBOL 246,&X111111,&X1,&X1,&X1,&X1,&X1,&X0,&X0 'background
250 maxx%=20:maxy%=11:lev%=0:DIM map%(maxy%,maxx%)
260 'Read Map
280 FOR y%=1 TO maxy%:FOR x%=1 TO maxx%:READ a%:map%(y%,x%)=a%:LOCATE x%,y%:ON map%(y%,x%) GOSUB 4100,4000:NEXT x%:NEXT y%
290 x%=32*4:y%=400-16*4:v%=2:v2%=4 'Start Sprite position
295 GOSUB 5100
300 CALL &BD19 'Main loop
310 'Collisions
320 yct%=INT(400-y%+16+4-v%)/16:ycd%=INT(400-y%+8+v%)/16
330 xcl%=INT(x%+32+16-v%)/32:xcr%=INT(x%+16+v%)/32
400 LOCATE 1,14: PRINT xc%,yc%,map%(yc%,xc%) 'debug
600 IF NOT(INKEY(8)) AND NOT(map%(ycd%,xcl%-1)=1) THEN GOSUB 5000:x%=x%-v2%:GOSUB 5100
700 IF NOT(INKEY(1)) AND NOT(map%(ycd%,xcr%+1)=1) THEN GOSUB 5000:x%=x%+v2%:GOSUB 5100
800 IF NOT(INKEY(0)) AND NOT(map%(yct%-1,xcr%)=1) THEN GOSUB 5000:y%=y%+v%:GOSUB 5100
900 IF NOT(INKEY(2)) AND NOT(map%(ycd%+1,xcr%)=1) THEN GOSUB 5000:y%=y%-v%:GOSUB 5100
1200 GOTO 300
1990 'Map Data
2000 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
2100 DATA 1,0,0,0,2,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1
2200 DATA 1,0,0,0,2,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1
2300 DATA 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
2400 DATA 1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1
2500 DATA 1,0,0,2,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1
2600 DATA 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
2700 DATA 1,0,0,0,0,2,1,1,1,1,1,1,1,0,0,0,0,0,0,1
2800 DATA 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1
2900 DATA 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1
3000 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
3990 'Tiles
4000 PRINT CHR$(15);CHR$(8);CHR$(246);:RETURN
4100 PRINT CHR$(15);CHR$(9);CHR$(245);:RETURN
4990 'Sprite
5000 MOVE x%,y%:DRAW x%+28,y%,0:DRAW x%+28,y%-14:DRAW x%,y%-14:DRAW x%,y%:RETURN
5100 PLOT -2,-2,1:TAG:MOVE x%,y%:PRINT CHR$(240);:TAGOFF: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

rk last

Even a sprite routine would display a small amount of flicker - and even more if a mask was incorporated too (in Basic).

So the only solution I can see is to store the screen in memory (very expensive in terms of bytes) and then re-display it at the start of the game loop.  Using this approach would dismiss the need for XOR or lines that erase the previous x%/Y% location.  (Im pretty sure that there was a 464 type in that allowed you to store the display off screen.  )

Anyhows, the program flow would be something like...

Draw the map

grab screen and store in memory

GAME LOOP

display chr$(240)

check controls -update x or y position, call the stored image to back to the screen

LOOP





maRK

Fabrizio Radica

Quote from: rk last on 12:16, 27 August 16
Even a sprite routine would display a small amount of flicker - and even more if a mask was incorporated too (in Basic).

So the only solution I can see is to store the screen in memory (very expensive in terms of bytes) and then re-display it at the start of the game loop.  Using this approach would dismiss the need for XOR or lines that erase the previous x%/Y% location.  (Im pretty sure that there was a 464 type in that allowed you to store the display off screen.  )

Anyhows, the program flow would be something like...

Draw the map

grab screen and store in memory

GAME LOOP

display chr$(240)

check controls -update x or y position, call the stored image to back to the screen

LOOP


yes, this is the best solution.
when i was writing games for amiga in asm, i used the same method (double buffer). where i can find all the CPC memory addresses?


- grab memory stored in &c000 (16kb) in &8000?
game loop
- display and move the sprites, ok
- restore from &8000 to &c000?
loop

tnx :)

arnoldemu

Quote from: Fabrizio Radica on 14:59, 27 August 16
...
- grab memory stored in &c000 (16kb) in &8000?
game loop
- display and move the sprites, ok
- restore from &8000 to &c000?
...
If you have firmware active (e.g. from basic or you are using firmware functions), then ~&a600-&bfff is used by firmware.

&0000-&0040 is used by firmware. Basic starts at &170.
HIMEM (highest for basic) is around &a600 (depending on roms), and ~&b000-&bfff is firmware and stack. &c000-&ffff is normal screen location.

So you are restricted where you want to have this other buffer.

If you are using hardware direct you can turn off firmware and use any address you want (e.g. &8000-&bfff), but you don't have this control with BASIC. BASIC needs firmware.

This leaves &4000-&7fff but now your BASIC free space is much less because BASIC memory is continuous.

You could use "bank manager" (bankman). It is on the CPM system discs. It allows you to copy screens and if you are writing for 128KB machine you can store basic data in the extra ram.

The information is in the 6128 manual.

You can make double buffer this way but it will not be fast. To be faster you need to use assembler or c or other language that gives you easier access to firmware then you can use the hardware direct or firmware functions to set the screen location and do hardware double buffer.

Maybe you could try asm or c on the cpc?
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

arnoldemu

Quote from: Fabrizio Radica on 13:55, 26 August 16

Exactly :(
I'm back to XOR sprite with background.
It has flicker, but works fine for now... (waiting for new ideas)
Normally CPC sprites are drawn:
- AND pixels (removing the screen pixels we don't want to show through)
- OR pixels (to add our sprite pixels).

Both draw modes can be used in BASIC. You may end up having less symbols to use and it may flicker, but the colours will be correct and you will need to redraw the background if the sprite moves.

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

arnoldemu

#109
This describes control characters and their parameters and they are executed. You can change colours, draw mode and more.

http://cpctech.cpc-live.com/docs/manual/s158ap07.pdf

So the crazy idea:
- setup a long string in basic with lots of spaces.
a$="                                    "
or perhaps
a$=SPACE$(30)

Now you can find the memory address of the string "descriptor" with @. String descriptor is 1 byte length, 2 bytes address.

e.g. desc=@a$:straddr=peek(desc+1)+(peek(desc+2)*256)

Now you can poke the values into the string.

poke straddr+0,23:poke straddr+1,24:poke straddr+2,'A'
and poke the length in desc+0.

The print a$ to do the whole lot.

Maybe you can "chain" operations and this will reduce flicker?

It would take BASIC time to do the pokes and it would take BASIC time to maintain the string, so maybe you don't win, but it may be possible to use.


EDIT: You can put control characters direct into strings. Using CTRL+letter/number. It produces a symbol which is the drawable version of the control-code.

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

rk last

#110
Heres a screen grab routine that Ive borrowed from an Amstrad Action art program.  Hope it helps.

1 restore 5
2 memory 24549
3 for n=24550 to 24574:read a:poke n,a:next
4 view=24550:store=24559
5 data &f3,33,00,96,17,00,192,&18,8,&f3,33,00,192,17,00,96,0,0,1,00,64,&ed,&b0,&fb,201
6 rem Use Call store to capture screen
7 rem and Call view to display it
maRK

rk last

Quote from: Fabrizio Radica on 14:59, 27 August 16

yes, this is the best solution.
when i was writing games for amiga in asm, i used the same method (double buffer).

tnx :)

Or even use the amigas dual playfield to draw your tiles in the background and sprites/bobs in front :)  Happy memories
maRK

rk last

Quote from: rk last on 16:56, 27 August 16
Heres a screen grab routine that Ive borrowed from an Amstrad Action art program.  Hope it helps.

1 restore 5
2 memory 24549
3 for n=24550 to 24574:read a:poke n,a:next
4 view=24550:store=24559
5 data &f3,33,00,96,17,00,192,&18,8,&f3,33,00,192,17,00,96,0,0,1,00,64,&ed,&b0,&fb,201
6 rem Use Call store to capture screen
7 rem and Call view to display it

Ok, Ive tried this method and although its works your left with even worse flickering.

So the only solution I can see worth using is ESD Advanced.  Create your 8x8 player sprite and another sprite 8x1 and also 1x8.  The latter two will be used for deleting(dont forget to use the OUTPUT option to obtain each sprites memory address).  Save the sprites and then load up the ESD 2 driver.  Now remove the demo at the end of the code and add something like this. 

A far more visually rewarding method

340 Memory &44FF:Load "filename.ADD",&9D4F;load "filename.BNK",&4500
350 x%=100:y%=200

400 rem * Movement Routine *
410 if not(inkey(8)) then x%=x%-1:call 40000,(1x8 Sprites memory address),x%+8,y%: rem draw the 1x8 sprite to the right of the player to kill its trail

450 call 40000,(players sprite address),x%,y%:rem Stamp the player sprite on screen
460 goto 410

ESD 2 offers XOR sprites but you end up with a similar result to chr$. It also includes two other display methods but I`ll let you toy with them :)


maRK

AMSDOS

Quote from: rk last on 12:16, 27 August 16
Even a sprite routine would display a small amount of flicker - and even more if a mask was incorporated too (in Basic).


We've had a few examples of where a second screen has been used to draw the next sequence, I wrote a game a couple of years ago in BASIC which had sprite driver as well as a small assembly routine to partially save the screen which seemed to work, even though the program wasn't really meant for complicated games. @HAL 6128 posted a bouncing ball program in the Hisoft Pascal 4T thread which also made use of a second screen, depending on what version of BASIC you were using, the code needed altering to work in BASIC 1.0.

One program (that I mentioned elsewhere) which I think is worthwhile studying is Quack a Jack, which is a mixture of BASIC 14Kb & M/C 12Kb. I say study because some of the BASIC is dealing with the Internals of the game, the name of the Levels and I even found a BASIC array being defined to match the size of the Playing area (20x11), the graphics are handled by the Binary, though some of those are being called from the BASIC. So I find it impressive that game shows no sign of flicker, it was coded in 1984 on a 464, your main Duck character removes the tiles, though the nasties just move all over it without issue. I thought what Paul Shirley might of done was work out the phase of the tile in relation to his sprite, but when I was watching the demo in the game, when the nasty moves over the duck, a blank square is revealed, which means the nasty hasn't put one in that spot.
* 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

Quote from: rk last on 23:39, 27 August 16
Ok, Ive tried this method and although its works your left with even worse flickering.


Unfortunately that screen grab routine is using LDIR on both accounts to Store and View a screen. It's perfectly fine for within an Art program, though begins to show for a game.

This thread I made last year explores using Sprite Graphics and handling Backdrops and also talks about flickering. The link I provided there was the last version I did which looks at using ESD2 along with my routine to Restore the backdrop. In that situation I was able to reduce the amount of flicker by using LDI to fill in an area around the graphic.
* 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

arnoldemu

Sprites and keyboard control for the duck are drawn using the asm code.

KL TIME PLEASE and KL TIME SET are used. Seems to be some kind of delay loop. These count the 300hz raster interrupts.

Sprites drawn using AND and then XOR. Seems basic is mostly used for "glue" logic.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Fabrizio Radica

#116

ok, are the last BASIC tests... i'll be back to ASM :(
When i was 15, my dream was to program a game for CPC in Basic.
So, After 26 years i wanted to try :)


But first, i would make a complete game... in Basic.
Thanks for your precious help :)


(and i'm sorry for my very bad english :( )

Fabrizio Radica

#117
Hi  :D
I'm back with my new CPC6128, the other is broken, unfortunatly...
Now i would like to implement new functionality and make a Bomberman clone.. always in Locomotive Basic :)


AMSDOS

#118
Quote from: Fabrizio Radica on 22:30, 28 December 16
Hi  :D
I'm back with my new CPC6128, the other is broken, unfortunatly...
Now i would like to implement new functionality and make a Bomberman clone.. always in Locomotive Basic :)


It might help study a Bomberman clone thats been written in BASIC. I found this one which is written in QBASIC, but it's up to 4 players, I'm not sure if there's an 1 player option. The site I found it on mentioned it lacking Sound FXs & Music which is good I guess, as they are more system specific things to add later. Only problem with QBASIC is the layout of it, which makes it look a little bit more like Pascal. GWBASIC tends to look at bit more like Locomotive BASIC.
* 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

Fabrizio Radica

Quote from: AMSDOS on 05:37, 29 December 16

It might help study a Bomberman clone thats been written in BASIC. I found this one which is written in QBASIC, but it's up to 4 players, I'm not sure if there's an 1 player option. The site I found it on mentioned it lacking Sound FXs & Music which is good I guess, as they are more system specific things to add later. Only problem with QBASIC is the layout of it, which makes it look a little bit more like Pascal. GWBASIC tends to look at bit more like Locomotive BASIC.




404 - File or directory not found.The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

:(
[/font][/color][/size]

AMSDOS

Quote from: Fabrizio Radica on 09:52, 29 December 16



404 - File or directory not found.The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

:(



Sorry, but it looks like the site I provided was a dodgy one!  :( This one look legit, I downloaded the SBM which looks legit, the comment inside the BAS file look a bit dodgy though, it looks like a 2 player Bomberman though, as does the one on this site.


This site also has a few Bomberman clones on it, I downloaded the first one boombss2, but the source code was all weird.  ::)  It may need QuickBASIC 4.5 to view it properly.
* 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

Fabrizio Radica


uhm... ok, i'm tired and old :D
but.. what i wrong in this code? O_o
i've problems with the wall collisions and bonus

Lines 320 and 330

i forgot something?
tnx :)




10 clear:MODE 0:CLS:BORDER 0:INK 0,0
20 OUT &BC00,0:OUT &BD00,127
30 OUT &BC00,4:OUT &BD00,18
40 OUT &BC00,5:OUT &BD00,15
50 OUT &BC00,6:OUT &BD00,15
60 OUT &BC00,7:OUT &BD00,17
70 WINDOW #0,1,20,1,15
80 ORIGIN -1,-1
200 SYMBOL 240,&X111100,&X1111110,&X11101011,&X11111111,&X11111111,&X11000011,&X1100110,&X111100 'player right
205 SYMBOL 251,&X111100,&X1111110,&X11010111,&X11111111,&X11111111,&X11000011,&X1100110,&X111100 'player left
210 SYMBOL 245,&X11111110,&X11111110,&X11111110,&X11111110,&X11111110,&X11111100,&X0,&X0 'wall
220 SYMBOL 246,&X1111110,&X1,&X1,&X1,&X1,&X1,&X0,&X0 'background
222 SYMBOL 247,&X111100,&X1111110,&X11111011,&X11111111,&X11111111,&X11111111,&X1111110,&X111100 'bonus
230 SYMBOL 250,&X10000001,&X11111111,&X10000001,&X11111111,&X10000001,&X11111111,&X10000001,&X11111111 'ladder
250 maxx%=20:maxy%=11:lev%=0:DIM map%(maxy%,maxx%):XOROn$=CHR$(23)+CHR$(1):XOROff$=CHR$(23)+CHR$(0)
260 'Read Map
280 FOR y%=1 TO maxy%:FOR x%=1 TO maxx%:READ a%:map%(y%,x%)=a%:LOCATE x%,y%:ON map%(y%,x%) GOSUB 4100,4200,4300:NEXT x%:NEXT y%
290 x%=32*4:y%=400-16*4:vx%=8:vy%=4:walk=0:frcount=1:pframe$(frcount)=CHR$(240):pframe$(frcount+1)=CHR$(251) 'Start Sprite position
295 PRINT XOROn$;:GOSUB 5000
300 'Main loop
310 'Collisions
320 yct%=INT(400-y%+20)/16:ycd%=INT(400-y%+8)/16
330 xcl%=INT(x%+32)/32:xcr%=int(x%+16)/32
400 'LOCATE 1,14: PRINT walk 'debug
600 IF NOT(INKEY(8)) AND NOT(map%(ycd%,xcl%-1)=1) THEN GOSUB 5000:frcount=2:x%=x%-vx%:GOSUB 5000
700 IF NOT(INKEY(1)) AND NOT(map%(ycd%,xcr%+1)=1) THEN GOSUB 5000:frcount=1:x%=x%+vx%:GOSUB 5000
800 IF NOT(INKEY(0)) AND NOT(map%(yct%-1,xcl%)=1) and walk=1 THEN GOSUB 5000:y%=y%+vy%:GOSUB 5000
900 IF NOT(INKEY(2)) AND NOT(map%(ycd%+1,xcl%)=1) THEN GOSUB 5000:y%=y%-vy%:GOSUB 5000
950 IF map%(ycd%+1,xcl%)=0 THEN walk=0:GOSUB 5000:y%=y%-vy%:GOSUB 5000 else walk=1
1000 IF map%(ycd%,xcl%)=3 THEN map%(ycd%,xcl%)=0:locate xcl%,ycd%:locate 1,12:sc%=sc%+1:print sc%
1200 GOTO 300
1990 'Map Data
2000 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
2100 DATA 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1
2200 DATA 1,0,0,0,0,0,0,1,0,0,2,0,0,0,0,0,0,0,0,1
2300 DATA 1,0,0,0,0,0,0,1,0,0,2,1,1,0,0,0,0,0,0,1
2400 DATA 1,0,0,0,0,1,1,1,0,0,2,1,0,0,0,3,0,2,0,1
2500 DATA 1,0,0,0,1,1,1,0,0,0,2,0,0,1,1,1,1,2,0,1
2600 DATA 1,0,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,2,0,1
2700 DATA 1,0,0,0,0,2,1,1,1,1,1,1,1,0,0,0,0,2,0,1
2800 DATA 1,0,0,0,0,2,0,0,0,0,0,0,1,0,0,0,0,2,0,1
2900 DATA 1,0,0,0,0,2,0,0,3,0,0,0,1,0,0,3,0,2,0,1
3000 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
3990 'Tiles
4100 PRINT CHR$(15);CHR$(9);CHR$(245);
4110 POKE &BFAC+x%*4+y%*80,&60:RETURN
4200 PRINT CHR$(15);CHR$(4);CHR$(250);:RETURN
4300 PRINT CHR$(15);CHR$(7);CHR$(247);:RETURN
4990 'Sprite
5000 CALL &BD19:PRINT XOROn$;:TAG:MOVE x%,y%:PRINT pframe$(frcount);:TAGOFF:PRINT XOROff$;:RETURN


AMSDOS

Quote from: Fabrizio Radica on 00:19, 31 December 16
uhm... ok, i'm tired and old :D
but.. what i wrong in this code? O_o
i've problems with the wall collisions and bonus

Lines 320 and 330

i forgot something?
tnx :)



The main problem I had was when your character was moving through the Bonuses. A LOCATE command to position for removing the Bonus was present, but nothing to delete. I've inserted a space to delete the character, but then part of my character gets deleted, so I'm deleting my character and then redrawing which is Line 1000.


The Collision Checks to check and see if you're colliding with the Walls are not adequate enough because the main character is now graphically moving around the screen. If your main character was moving based on the Text position, then yes, checks with the Array would be sufficient. For graphics "test(x-coordinate,y-coordinate)" is your best option. I've altered lines 600-900 and have tried placing the test checks in the best spots, it's not totally foolproof, but at least your character isn't travelling through Walls now.


Also I didn't know what the deal was with the OUT commands and have removed them (it was doing some weird Interlaced Effect), as I was testing everything so much I added a "key 128,"call &bc02:ink 1,26:mode 2"+chr$(13); to reset the inks/mode. When I exit out of your program I can use 0 on the numeric keypad to reset everything. Initially your character was slightly offset of the text-cursor position, I changed line 290 which simply adds 4 to the rest of x%




10 CLEAR:CALL &BC02:MODE 0:CLS:BORDER 0:INK 0,0
70 WINDOW #0,1,20,1,15
80 ORIGIN -1,-1
200 SYMBOL 240,&X111100,&X1111110,&X11101011,&X11111111,&X11111111,&X11000011,&X1100110,&X111100 'player right
205 SYMBOL 251,&X111100,&X1111110,&X11010111,&X11111111,&X11111111,&X11000011,&X1100110,&X111100 'player left
210 SYMBOL 245,&X11111110,&X11111110,&X11111110,&X11111110,&X11111110,&X11111100,&X0,&X0 'wall
220 SYMBOL 246,&X1111110,&X1,&X1,&X1,&X1,&X1,&X0,&X0 'background
222 SYMBOL 247,&X111100,&X1111110,&X11111011,&X11111111,&X11111111,&X11111111,&X1111110,&X111100 'bonus
230 SYMBOL 250,&X10000001,&X11111111,&X10000001,&X11111111,&X10000001,&X11111111,&X10000001,&X11111111 'ladder
250 maxx%=20:maxy%=11:lev%=0:DIM map%(maxy%,maxx%):XOROn$=CHR$(23)+CHR$(1):XOROff$=CHR$(23)+CHR$(0)
260 'Read Map
280 FOR y%=1 TO maxy%:FOR x%=1 TO maxx%:READ a%:map%(y%,x%)=a%:LOCATE x%,y%:ON map%(y%,x%) GOSUB 4100,4200,4300:NEXT x%:NEXT y%
290 x%=4+(32*4):y%=400-16*4:vx%=8:vy%=4:walk=0:frcount=1:pframe$(frcount)=CHR$(240):pframe$(frcount+1)=CHR$(251) 'Start Sprite position
295 PRINT XOROn$;:GOSUB 5000
300 'Main loop
310 'Collisions
320 yct%=INT(400-y%+20)/16:ycd%=INT(400-y%+8)/16
330 xcl%=INT(x%+32)/32:xcr%=INT(x%+16)/32
400 'LOCATE 1,14: PRINT walk 'debug
600 IF NOT(INKEY(8)) AND ((TEST(x%-8,y%-6)<>9) AND (TEST(x%-8,y%-14)<>9)) THEN GOSUB 5000:frcount=2:x%=x%-vx%:GOSUB 5000
700 IF NOT(INKEY(1)) AND ((TEST(x%+32,y%-6)<>9) AND (TEST(x%+32,y%-14)<>9)) THEN GOSUB 5000:frcount=1:x%=x%+vx%:GOSUB 5000
800 IF NOT(INKEY(0)) AND ((TEST(x%,y%+2)<>9) AND (TEST(x%+28,y%+2)<>9)) AND walk=1 THEN GOSUB 5000:y%=y%+vy%:GOSUB 5000
900 IF NOT(INKEY(2)) AND ((TEST(x%,y%-18)<>9) AND (TEST(x%+20,y%-18)<>9)) THEN GOSUB 5000:y%=y%-vy%:GOSUB 5000
950 IF map%(ycd%+1,xcl%)=0 THEN walk=0:GOSUB 5000:y%=y%-vy%:GOSUB 5000 ELSE walk=1
1000 IF map%(ycd%,xcl%)=3 THEN map%(ycd%,xcl%)=0:LOCATE xcl%,ycd%:PRINT" ";:MOVE x%,y%:TAG:PRINT" ";:TAGOFF:GOSUB 5000:LOCATE 1,12:sc%=sc%+1:PRINT sc%
1200 GOTO 300
1990 'Map Data
2000 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
2100 DATA 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1
2200 DATA 1,0,0,0,0,0,0,1,0,0,2,0,0,0,0,0,0,0,0,1
2300 DATA 1,0,0,0,0,0,0,1,0,0,2,1,1,0,0,0,0,0,0,1
2400 DATA 1,0,0,0,0,1,1,1,0,0,2,1,0,0,0,3,0,2,0,1
2500 DATA 1,0,0,0,1,1,1,0,0,0,2,0,0,1,1,1,1,2,0,1
2600 DATA 1,0,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,2,0,1
2700 DATA 1,0,0,0,0,2,1,1,1,1,1,1,1,0,0,0,0,2,0,1
2800 DATA 1,0,0,0,0,2,0,0,0,0,0,0,1,0,0,0,0,2,0,1
2900 DATA 1,0,0,0,0,2,0,0,3,0,0,0,1,0,0,3,0,2,0,1
3000 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
3990 'Tiles
4100 PRINT CHR$(15);CHR$(9);CHR$(245);
4110 POKE &BFAC+x%*4+y%*80,&60:RETURN
4200 PRINT CHR$(15);CHR$(4);CHR$(250);:RETURN
4300 PRINT CHR$(15);CHR$(7);CHR$(247);:RETURN
4990 'Sprite
5000 CALL &BD19:PRINT XOROn$;:TAG:MOVE x%,y%:PRINT pframe$(frcount);:TAGOFF:PRINT XOROff$;: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

Fabrizio Radica

Quote from: AMSDOS on 07:02, 31 December 16

The main problem I had was when your character was moving through the Bonuses. A LOCATE command to position for removing the Bonus was present, but nothing to delete. I've inserted a space to delete the character, but then part of my character gets deleted, so I'm deleting my character and then redrawing which is Line 1000.


The Collision Checks to check and see if you're colliding with the Walls are not adequate enough because the main character is now graphically moving around the screen. If your main character was moving based on the Text position, then yes, checks with the Array would be sufficient. For graphics "test(x-coordinate,y-coordinate)" is your best option. I've altered lines 600-900 and have tried placing the test checks in the best spots, it's not totally foolproof, but at least your character isn't travelling through Walls now.


Also I didn't know what the deal was with the OUT commands and have removed them (it was doing some weird Interlaced Effect), as I was testing everything so much I added a "key 128,"call &bc02:ink 1,26:mode 2"+chr$(13); to reset the inks/mode. When I exit out of your program I can use 0 on the numeric keypad to reset everything. Initially your character was slightly offset of the text-cursor position, I changed line 290 which simply adds 4 to the rest of x%




10 CLEAR:CALL &BC02:MODE 0:CLS:BORDER 0:INK 0,0
70 WINDOW #0,1,20,1,15
80 ORIGIN -1,-1
200 SYMBOL 240,&X111100,&X1111110,&X11101011,&X11111111,&X11111111,&X11000011,&X1100110,&X111100 'player right
205 SYMBOL 251,&X111100,&X1111110,&X11010111,&X11111111,&X11111111,&X11000011,&X1100110,&X111100 'player left
210 SYMBOL 245,&X11111110,&X11111110,&X11111110,&X11111110,&X11111110,&X11111100,&X0,&X0 'wall
220 SYMBOL 246,&X1111110,&X1,&X1,&X1,&X1,&X1,&X0,&X0 'background
222 SYMBOL 247,&X111100,&X1111110,&X11111011,&X11111111,&X11111111,&X11111111,&X1111110,&X111100 'bonus
230 SYMBOL 250,&X10000001,&X11111111,&X10000001,&X11111111,&X10000001,&X11111111,&X10000001,&X11111111 'ladder
250 maxx%=20:maxy%=11:lev%=0:DIM map%(maxy%,maxx%):XOROn$=CHR$(23)+CHR$(1):XOROff$=CHR$(23)+CHR$(0)
260 'Read Map
280 FOR y%=1 TO maxy%:FOR x%=1 TO maxx%:READ a%:map%(y%,x%)=a%:LOCATE x%,y%:ON map%(y%,x%) GOSUB 4100,4200,4300:NEXT x%:NEXT y%
290 x%=4+(32*4):y%=400-16*4:vx%=8:vy%=4:walk=0:frcount=1:pframe$(frcount)=CHR$(240):pframe$(frcount+1)=CHR$(251) 'Start Sprite position
295 PRINT XOROn$;:GOSUB 5000
300 'Main loop
310 'Collisions
320 yct%=INT(400-y%+20)/16:ycd%=INT(400-y%+8)/16
330 xcl%=INT(x%+32)/32:xcr%=INT(x%+16)/32
400 'LOCATE 1,14: PRINT walk 'debug
600 IF NOT(INKEY() AND ((TEST(x%-8,y%-6)<>9) AND (TEST(x%-8,y%-14)<>9)) THEN GOSUB 5000:frcount=2:x%=x%-vx%:GOSUB 5000
700 IF NOT(INKEY(1)) AND ((TEST(x%+32,y%-6)<>9) AND (TEST(x%+32,y%-14)<>9)) THEN GOSUB 5000:frcount=1:x%=x%+vx%:GOSUB 5000
800 IF NOT(INKEY(0)) AND ((TEST(x%,y%+2)<>9) AND (TEST(x%+28,y%+2)<>9)) AND walk=1 THEN GOSUB 5000:y%=y%+vy%:GOSUB 5000
900 IF NOT(INKEY(2)) AND ((TEST(x%,y%-18)<>9) AND (TEST(x%+20,y%-18)<>9)) THEN GOSUB 5000:y%=y%-vy%:GOSUB 5000
950 IF map%(ycd%+1,xcl%)=0 THEN walk=0:GOSUB 5000:y%=y%-vy%:GOSUB 5000 ELSE walk=1
1000 IF map%(ycd%,xcl%)=3 THEN map%(ycd%,xcl%)=0:LOCATE xcl%,ycd%:PRINT" ";:MOVE x%,y%:TAG:PRINT" ";:TAGOFF:GOSUB 5000:LOCATE 1,12:sc%=sc%+1:PRINT sc%
1200 GOTO 300
1990 'Map Data
2000 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
2100 DATA 1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1
2200 DATA 1,0,0,0,0,0,0,1,0,0,2,0,0,0,0,0,0,0,0,1
2300 DATA 1,0,0,0,0,0,0,1,0,0,2,1,1,0,0,0,0,0,0,1
2400 DATA 1,0,0,0,0,1,1,1,0,0,2,1,0,0,0,3,0,2,0,1
2500 DATA 1,0,0,0,1,1,1,0,0,0,2,0,0,1,1,1,1,2,0,1
2600 DATA 1,0,0,0,0,2,0,0,0,0,2,0,0,0,0,0,0,2,0,1
2700 DATA 1,0,0,0,0,2,1,1,1,1,1,1,1,0,0,0,0,2,0,1
2800 DATA 1,0,0,0,0,2,0,0,0,0,0,0,1,0,0,0,0,2,0,1
2900 DATA 1,0,0,0,0,2,0,0,3,0,0,0,1,0,0,3,0,2,0,1
3000 DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
3990 'Tiles
4100 PRINT CHR$(15);CHR$(9);CHR$(245);
4110 POKE &BFAC+x%*4+y%*80,&60:RETURN
4200 PRINT CHR$(15);CHR$(4);CHR$(250);:RETURN
4300 PRINT CHR$(15);CHR$(7);CHR$(247);:RETURN
4990 'Sprite
5000 CALL &BD19:PRINT XOROn$;:TAG:MOVE x%,y%:PRINT pframe$(frcount);:TAGOFF:PRINT XOROff$;:RETURN





Thanks you!
Yes, this "new" engine, move the sprite in different mode from the previous routine because i would like to try best ways.
I did don't know the TEST command. How does it work?

Tnx and Happy New Year :)

AMSDOS

#124
Quote from: Fabrizio Radica on 14:04, 31 December 16

Thanks you!
Yes, this "new" engine, move the sprite in different mode from the previous routine because i would like to try best ways.
I did don't know the TEST command. How does it work?

Tnx and Happy New Year :)


Okay, so all the BASIC Commands/Operators/Functions are documented here on the CPCWiki. TEST is a function that returns an INK value found at the specified graphical co-ordinates. In this case when a key is pressed to move your character, 2-points are tested which are just outside your character relevant to the side your character is most likely to trigger a Collision event, if one is found, which in this case is pen 9 for the wall, your character stops short. Probably where I've gone wrong in my 2-point Collision Test, is I'm using the operator "AND", which is telling BASIC to find a PEN 9 here & there, but if it's a PEN 0 or the edge of the Wall which is using another colour, that condition is not being met, causing the character to fall ever so slightly into the Wall until it finds PEN 9. The whole point of the 2-point test is to check another position in case your character is over a gap or a different colour, essentially in the opposite end of your character, so in this case it might be better using "OR" in-between the TEST checks so for example:


600 IF NOT(INKEY() AND ((TEST(x%-8,y%-6)<>9) AND (TEST(x%-8,y%-14)<>9)) THEN GOSUB 5000:frcount=2:x%=x%-vx%:GOSUB 5000


becomes:


600 IF NOT(INKEY() AND ((TEST(x%-8,y%-6)<>9) OR (TEST(x%-8,y%-14)<>9)) THEN GOSUB 5000:frcount=2:x%=x%-vx%:GOSUB 5000


EDIT:Sorry no, I'm getting my logic all mixed up and "AND" is the one you need to use with the 2 point TEST.



* 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

Powered by SMFPacks Menu Editor Mod