Hi there!
I'm totally new here but got an idea for a small game. A guy has to stay on a wheel which would start to spin if he's not right above it's center point. So I would need to somehow implement lever rules and I would need to rotate the wheel but I really don't know how to do this.
I already took a look at this but really don't understand the code. The first one seems a bit buggy, the second works fine but I can't find the point where the sprite is assigned to the car table.
https://www.lexaloffle.com/bbs/?tid=2189
so to start I would've thought of something simple like this
function draw_wheel()
spr(0,x,y,...)
------------- (get the rotated sprite and draw it)
function _update()
rotate_wheel(1) (add's one degree of rotation every frame (does not have to be 1°))
function _draw()
draw_wheel()
So in a sentence I want a sprite that get's rotated with ever frame by a certain amount.
Some tips?
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](https://www.lexaloffle.com/bbs/files/1703/diegzavatar.jpg)
I can think of a naive algorithm but it will likely look like crap at this low resolution. Since you want to rotate a wheel, have you considered drawing the wheel 'procedurally', that is, with lines?
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi2.png)
Hmm no, but could you explain that a bit further? Don't exactly know what you mean.
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](https://www.lexaloffle.com/bbs/files/10166/ennuigi_icon.jpg)
Instead of rotating and blitting a sprite, you could draw the wheel using line drawing functions like LINE() and CIRC().
Like, say, a circle for the rim and a series of lines through the center point as spokes, and some individual pixels at various points for decoration. Calculate the angle of rotation on any given frame, do a little cos() and sin() math to offset the endpoints of your lines and points, et voila.
I do a really simple version of this with just straight lines in this cart to make those sticks and crosses, for example.
Another approach, depending on how much sprite sheet you want to use and how big your wheel is, is to actually pre-render each of your rotational frames as individual sprites, and just display the correct one each frame.
If your wheel has a lot of rotational symmetry, you can pull this off smoothly with relatively few sprites, even; a wheel with, say, 8 spokes that are evenly spaced only needs to rotate through 1/8th of a circle before it looks like you're back where you're started, so you could do frames enough to do 1/8th of a turn in smooth small increments and then just cycle back to the start of that sprite sequence for the 1/8th threshold, 2/8ths, etc.
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi2.png)
So I had some success with the sprit rotation. I found a cartridge which already did what I needed and altered a little bit to fit my needs. However there seems to be a problem with the algorithm since the whole screen is "falling".
I kinda like the rugged look of the rotation algorithm so I would like to fix it and keep that. But it seems I really have to get my hands on the algorithm myself. Googled a lot but haven't found something valuable about per pixel image rotation.
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi16.png)
I think the "falling" is just an effect caused by the print statement each draw advancing the cursor down the screen, forcing a scroll.
If you called CLS() to clear the old screen, CURSOR() to reset the cursor, or printed at specific coordinates it might help.
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi2.png)
Crazy Wheel is born!
typo^^
use up&down to adjust crazyness!
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi23.png)
Thanks for the snippet. I could be too late but, can you use some constants to create a better abstraction and lower the effort to understand? I'll try to do it and post it there anyways.
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi10.png)
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](https://www.lexaloffle.com/bbs/files/13845/blobby_g.png)
@mimick: your version yields pixel gaps
check this (sprite rotation demo) :
https://www.lexaloffle.com/bbs/?tid=2189
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/bimg/pi/pi10.png)
[Please log in to post a comment]