Moving a 2x2 pixel 'ball' around the screen

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
Morkin
Bugaboo
Posts: 3266
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Moving a 2x2 pixel 'ball' around the screen

Post by Morkin »

...OK so this has got to be really simple, but I'm a bit rusty.

A 2 pixel by 2 pixel (square) ball. Moving 1 pixel at a time. Can be going horizontally, vertically or diagonally.

The vertical movement is OK - position = screen row and screen row + 1 pixel line.

What's the simplest way of doing the lateral movement? i.e. calculate the screen position, and draw the 'ball'?
My Speccy site: thirdharmoniser.com
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: Moving a 2x2 pixel 'ball' around the screen

Post by Ast A. Moore »

The standard method of converting the horizontal coordinate into a screen address + number of shifts applies:

Code: Select all

;B holds the x coordinate
;HL holds the screen address of line start

	ld a,b			;x coord: five highest bits=column (0-31),
	rra			;we need to shift them into the lowest five bits
	rra
	rra
	and %00011111		;clear the three highest bits
	add a,l			;add A (column pos) to L (low byte of address, which is col 0)
	ld l,a			;back into L. HL now holds the address

	ld a,b			;x coord: three lowest bits=pixel position (0-7) within cell
	and %00000111		;isolate them. A now holds the number of shifts.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
DenisGrachev
Dizzy
Posts: 88
Joined: Fri Feb 09, 2018 2:32 am
Location: Novosibirsk, RU
Contact:

Re: Moving a 2x2 pixel 'ball' around the screen

Post by DenisGrachev »

Oh, man. It's just 4 pixels, use rom plot ;)
User avatar
Morkin
Bugaboo
Posts: 3266
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: Moving a 2x2 pixel 'ball' around the screen

Post by Morkin »

Ast A. Moore wrote: Wed Feb 14, 2018 12:27 pm

Code: Select all



	ld a,b			;x coord: three lowest bits=pixel position (0-7) within cell
	and %00000111		;isolate them. A now holds the number of shifts.
Ah - that's it. Those two sodding lines. I knew it would be simple...
DenisGrachev wrote: Wed Feb 14, 2018 12:39 pm Oh, man. It's just 4 pixels, use rom plot ;)
Heheh.. Or maybe a zig-zagging DRAW routine... :)
My Speccy site: thirdharmoniser.com
User avatar
R-Tape
Site Admin
Posts: 6400
Joined: Thu Nov 09, 2017 11:46 am

Re: Moving a 2x2 pixel 'ball' around the screen

Post by R-Tape »

2x2 pix is a bit of a pain, it can spread over two bytes so it's like a sprite, but it would feel a bit daft to have a preshifted 2x2box.

Are we witnessing the resurgence of Lasasoft here?
C.Born
Manic Miner
Posts: 210
Joined: Sat Dec 09, 2017 4:09 pm

Re: Moving a 2x2 pixel 'ball' around the screen

Post by C.Born »

Hi
I typed in an SNOW effect, its a 2x2 pixel, that moves OVER the screen
viewtopic.php?f=3&t=207&p=2147#p2147
User avatar
Einar Saukas
Bugaboo
Posts: 3094
Joined: Wed Nov 15, 2017 2:48 pm

Re: Moving a 2x2 pixel 'ball' around the screen

Post by Einar Saukas »

R-Tape wrote: Thu Feb 15, 2018 12:56 pm2x2 pix is a bit of a pain, it can spread over two bytes so it's like a sprite, but it would feel a bit daft to have a preshifted 2x2box.
Preshifting a 2x2 ball would only take 7 frames of 1 byte each, and a special case for the 8th frame when it spreads over two bytes.

I think it would feel a bit daft NOT using preshifted graphics here!
User avatar
Rorthron
Dynamite Dan
Posts: 1644
Joined: Sun Nov 12, 2017 10:35 pm

Re: Moving a 2x2 pixel 'ball' around the screen

Post by Rorthron »

So does this mean work's finally started on Balachor-ball?

;)
User avatar
Morkin
Bugaboo
Posts: 3266
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: Moving a 2x2 pixel 'ball' around the screen

Post by Morkin »

Yes, Balachor's given up his quest for world domination to play ping pong....

Very sensible if you ask me...
My Speccy site: thirdharmoniser.com
Ralf
Rick Dangerous
Posts: 2283
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Moving a 2x2 pixel 'ball' around the screen

Post by Ralf »

Preshifting a 2x2 ball would only take 7 frames of 1 byte each, and a special case for the 8th frame when it spreads over two bytes.
If you want it easy, make this ball move by 2 pixels, not by one. In such case you always draw only one byte and need 4 preshifted frames:

Code: Select all

##......
..##....
....##..
......##
User avatar
Morkin
Bugaboo
Posts: 3266
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: Moving a 2x2 pixel 'ball' around the screen

Post by Morkin »

Yes, 2 pixel movement is so much easier, looks just as smooth.
My Speccy site: thirdharmoniser.com
Ralf
Rick Dangerous
Posts: 2283
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Moving a 2x2 pixel 'ball' around the screen

Post by Ralf »

I would add that in real games 1 pixel movement may be often too slow.

Actual games rarely run at 50 fps. They have smaller framerates. So let's count.

To move from left side of screen to right you need to cover 256 pixels distance. If you have 25 fps you make 25 pixels per second so moving across the screen takes 10 seconds.

If you have 12 fps which is quite often you would need 20 seconds.

So I would say (without much research, just supposing) that in most Spectrum games sprites actually move by 2 pixels.
User avatar
R-Tape
Site Admin
Posts: 6400
Joined: Thu Nov 09, 2017 11:46 am

Re: Moving a 2x2 pixel 'ball' around the screen

Post by R-Tape »

Ralf wrote: Thu Feb 22, 2018 10:02 am I would add that in real games 1 pixel movement may be often too slow.
Agreed. If sprites are going to move in 1 pixel steps it should ideally be at 50 fps, anything less is a bit slow for action games IMO.

Most games are 25fps so two pixels every two frames is the same, and looks smooth enough. It is ever so slightly jagged in diagonal movements, but good enough.

I think Vallation is 2pixels at 50fps, which plays well and is not too fast for a shooter.

I don’t know why but Manic Miner is okay with its 2 pixels at 12.5 fps, and Catacombs of Balachor plays great with (I think) 8 pixel jumps, I love the way you whizz around in that game.

It’s reassuring what you can get away with!
User avatar
Morkin
Bugaboo
Posts: 3266
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: Moving a 2x2 pixel 'ball' around the screen

Post by Morkin »

Cheers, 50p and a pack of Rolos in the post. :lol:

The Balachor games' sprite movement is 4 pixels at a time, except the missiles you shoot which are 8, but they're supposed to go fast.

We tried varieties of 1 and 2 pixel movement with Balachor's Revenge but as already mentioned, it was either:
- too sluggish for the sprite to cross the screen in a reasonable time
- too fast to see the animations, if the sprite moved more quickly
- too 'skatey', if you keep the speed but slow the animation change down

Without overdoing the mutual dev love-in, I thought EFMB had a nice balanced mix of sprite animation and movement speed.
My Speccy site: thirdharmoniser.com
Post Reply