Moving a 2x2 pixel 'ball' around the screen
Moving a 2x2 pixel 'ball' around the screen
...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'?
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
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Moving a 2x2 pixel 'ball' around the screen
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.
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.
- 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
Oh, man. It's just 4 pixels, use rom plot
Re: Moving a 2x2 pixel 'ball' around the screen
Ah - that's it. Those two sodding lines. I knew it would be simple...Ast A. Moore wrote: ↑Wed Feb 14, 2018 12:27 pmCode: 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.
Heheh.. Or maybe a zig-zagging DRAW routine...
My Speccy site: thirdharmoniser.com
Re: Moving a 2x2 pixel 'ball' around the screen
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?
Are we witnessing the resurgence of Lasasoft here?
Re: Moving a 2x2 pixel 'ball' around the screen
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
I typed in an SNOW effect, its a 2x2 pixel, that moves OVER the screen
viewtopic.php?f=3&t=207&p=2147#p2147
- Einar Saukas
- Bugaboo
- Posts: 3144
- Joined: Wed Nov 15, 2017 2:48 pm
Re: Moving a 2x2 pixel 'ball' around the screen
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!
Re: Moving a 2x2 pixel 'ball' around the screen
So does this mean work's finally started on Balachor-ball?
Re: Moving a 2x2 pixel 'ball' around the screen
Yes, Balachor's given up his quest for world domination to play ping pong....
Very sensible if you ask me...
Very sensible if you ask me...
My Speccy site: thirdharmoniser.com
Re: Moving a 2x2 pixel 'ball' around the screen
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: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.
Code: Select all
##......
..##....
....##..
......##
Re: Moving a 2x2 pixel 'ball' around the screen
Yes, 2 pixel movement is so much easier, looks just as smooth.
My Speccy site: thirdharmoniser.com
Re: Moving a 2x2 pixel 'ball' around the screen
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.
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.
Re: Moving a 2x2 pixel 'ball' around the screen
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!
Re: Moving a 2x2 pixel 'ball' around the screen
Cheers, 50p and a pack of Rolos in the post.
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.
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