CPCWiki forum

General Category => Programming => Topic started by: Fabrizio Radica on 18:16, 16 October 18

Title: Sprites on Basic
Post by: Fabrizio Radica on 18:16, 16 October 18
Hi,
I've a question.
i've made this - unoptimized code -, for make a "big" sprite maked with AMSprite, but doesn't works.
Is displayed incorrectly.
Why? Can you help me?
Tnx :)

10 cls: mode 0
20 posx=posx+1:posy=1:restore 5000
100 for y=1 to 8
120 for x=1 to 4
200 read a:poke &c000+(x+posx)+(y+posy)*80,a
220 next x
300 next y

500 goto 500

5000 REM sprite
5010 DATA 0,68,136,0
5020 DATA 0,68,136,0
5030 DATA 145,48,48,98
5040 DATA 0,153,102,0
5050 DATA 0,153,102,0
5060 DATA 16,0,0,32
5070 DATA 136,0,0,68
5080 DATA 128,0,0,64



Title: Re: Sprites on Basic
Post by: PuzCPC on 18:31, 16 October 18



Hi,


Try this


200 read a:poke &c000+(x+posx)+(y+posy)*&800,a
Title: Re: Sprites on Basic
Post by: Fabrizio Radica on 19:41, 16 October 18
Hi!,
works fine!
please, can you explain me why? :)
tnx :)

Quote from: PuzCPC on 18:31, 16 October 18

Hi,


Try this


200 read a:poke &c000+(x+posx)+(y+posy)*&800,a
Title: Re: Sprites on Basic
Post by: HAL6128 on 21:18, 16 October 18
This is the way how the screen memory is organized. The next line on screen doesn't start after 80 (&50) instead after &800:e.g. first line &C000, second line &C800 (not &C050 which is the 9th line). Pretty weird, isn't it? :)
By the way: you can create a faster sprite in Basic with symbol definition and transparency too.
Title: Re: Sprites on Basic
Post by: mr_lou on 04:44, 17 October 18
Quote from: HAL 6128 on 21:18, 16 October 18
By the way: you can create a faster sprite in Basic with symbol definition and transparency too.

Yea, poking to screen memory from BASIC really isn't the way to go. It is extremely slow.


You should either get some RSX sprite routines, or else use SYMBOL to define sprites and simply PRINT to display them.
Title: Re: Sprites on Basic
Post by: Fabrizio Radica on 08:00, 17 October 18
I've used symbol definition (and transparency) on this but i wanted to try new solutions for big sprites or big tiles.
Anyway, next time i whould like to use ASM (but I do not know the z80 opcode at the moment) :)

So, for big sprites (or tiles) recommend me to use two or more - symbol definition  -attached?tnx :)
https://www.youtube.com/watch?v=qhCgyKwt6JQ

Quote from: HAL 6128 on 21:18, 16 October 18This is the way how the screen memory is organized. The next line on screen doesn't start after 80 (&50) instead after &800:e.g. first line &C000, second line &C800 (not &C050 which is the 9th line). Pretty weird, isn't it? :)
By the way: you can create a faster sprite in Basic with symbol definition and transparency too.
Title: Re: Sprites on Basic
Post by: mr_lou on 08:42, 17 October 18
For big sprites using SYMBOL, yes we would just use multiple characters. One good recent example of this is the BASIC game Coolbox. http://www.cpc-power.com/index.php?page=detail&num=13102 (http://www.cpc-power.com/index.php?page=detail&num=13102)
You might be interested in looking at the source of that game. :-)

There are a few options. If we take a 4-character example, the most basic ones would look like this:

sprite1$ = "ABCD" ' Long 4x1 character sprite
sprite2$ = "AB̉←←↓CD" ' Square 2x2 character sprite
sprite3$ = "A←↓B←↓C←↓D" ' Long 1x4 character sprite

Those are single coloured ones.
The arrows are control codes. There exists control codes that can change pen color and paper color and tell the CPC to print the character on top of another. These control codes are listed in the back of the CPC instruction manual. (Chapter 9 in the CPC464 instruction manual). I bet you can also find them here on the CPCwiki.
Title: Re: Sprites on Basic
Post by: HAL6128 on 19:23, 17 October 18
Yeah, it's like mr_lou said... you can combine 8x8 characters to a bigger and colored sprite and it's even fast enough to have some joy. Keep on going with BASIC, it's fun! :)

I did two games attempt which were programmed completley in BASIC:
A Frogger conversion. The biggest sprite was a lorry with 3 characters together.
https://youtu.be/V3oEWzbJ8G8 (https://youtu.be/V3oEWzbJ8G8)
And a Candy Crush conversion (not finished). The biggest sprite contains 4 colored characters.
https://youtu.be/CLWD8bjoM3w (https://youtu.be/CLWD8bjoM3w)

Cheers
Title: Re: Sprites on Basic
Post by: ervin on 23:25, 17 October 18
HAL, those are *very* impressive!
Title: Re: Sprites on Basic
Post by: Fabrizio Radica on 07:21, 18 October 18
...as we say in Italy: MINCHIA!!!  :P



Quote from: HAL 6128 on 19:23, 17 October 18Yeah, it's like mr_lou said... you can combine 8x8 characters to a bigger and colored sprite and it's even fast enough to have some joy. Keep on going with BASIC, it's fun! :)

I did two games attempt which were programmed completley in BASIC:
A Frogger conversion. The biggest sprite was a lorry with 3 characters together.
https://youtu.be/V3oEWzbJ8G8 (https://youtu.be/V3oEWzbJ8G8)
And a Candy Crush conversion (not finished). The biggest sprite contains 4 colored characters.
https://youtu.be/CLWD8bjoM3w (https://youtu.be/CLWD8bjoM3w)

Cheers
Title: Re: Sprites on Basic
Post by: tjohnson on 09:29, 18 October 18
Quote from: Fabrizio Radica on 07:21, 18 October 18
...as we say in Italy: MINCHIA!!!  :P
are you able to share any code?  I tried to get transparency working but couldn't
Title: Re: Sprites on Basic
Post by: AMSDOS on 11:35, 18 October 18
Don't know if I could interest anyone in a Huge Chunky Maze with Hazard within?
Title: Re: Sprites on Basic
Post by: AMSDOS on 10:14, 23 October 18
Quote from: tjohnson on 09:29, 18 October 18
are you able to share any code?  I tried to get transparency working but couldn't


I have a number of examples on the Programming Tread I've built over the years, but this link (http://www.cpcwiki.eu/forum/programming/silly-programming-ideas-turning-text-into-graphics/msg149093/#msg149093) shows a simple example of using Transparency. The other examples I've included around that try to condense the graphical data so it could be used for something like a 10-Liner.
Title: Re: Sprites on Basic
Post by: Dabz on 07:20, 01 November 18
Dont forget Sean McManus's excellent sprite tools:-


https://www.sean.co.uk/books/amstrad/cpcdownload.shtm


Dabz
Title: Re: Sprites on Basic
Post by: AMSDOS on 08:46, 01 November 18
Quote from: Dabz on 07:20, 01 November 18
Dont forget Sean McManus's excellent sprite tools:-


https://www.sean.co.uk/books/amstrad/cpcdownload.shtm (https://www.sean.co.uk/books/amstrad/cpcdownload.shtm)


Dabz


I seems to be the best approach for handing Sprites of various lengths of sizes and works on all systems. It can really transform a game as I was able to demonstrate earlier with early versions of my game (http://www.cpcwiki.eu/forum/programming/'get-the-cash'-in-locomotive-basic-cpc-basic-3-and-a-pinch-of-asm/?action=dlattach;attach=18943) and the final result after Easi-Sprite Driver was implemented (http://www.cpcwiki.eu/imgs/0/0e/Get_The_Cash.zip). The horror with that was both versions were still being compiled.
Powered by SMFPacks Menu Editor Mod