Log In  

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?

P#15224 2015-10-10 11:02 ( Edited 2016-12-05 12:48)

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?

P#15225 2015-10-10 12:24 ( Edited 2015-10-10 16:24)

Hmm no, but could you explain that a bit further? Don't exactly know what you mean.

P#15226 2015-10-10 12:43 ( Edited 2015-10-10 16:43)

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.

P#15228 2015-10-10 13:10 ( Edited 2015-10-10 17:10)

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".

Cart #15246 | 2015-10-10 | Code ▽ | Embed ▽ | No License

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.

P#15245 2015-10-10 18:40 ( Edited 2015-10-10 22:51)

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.

P#15254 2015-10-11 01:23 ( Edited 2015-10-11 05:23)
1

Crazy Wheel is born!

Cart #15265 | 2015-10-11 | Code ▽ | Embed ▽ | No License
1

typo^^


use up&down to adjust crazyness!

P#15266 2015-10-11 06:43 ( Edited 2015-10-11 10:46)

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.

P#32865 2016-12-01 03:19 ( Edited 2016-12-01 08:20)

Hi, if you like, you could use this function ?
SPRA(A,N,X,Y,[W,H],[FLIP_X],[FLIP_Y])

Does the same as SPR and apply a rotation of the angle A to the sprite. The rotation is applied to the center of the sprite.

Cart #32869 | 2016-12-01 | Code ▽ | Embed ▽ | No License

P#32870 2016-12-01 06:05 ( Edited 2016-12-01 11:05)

@mimick: your version yields pixel gaps

check this (sprite rotation demo) :
https://www.lexaloffle.com/bbs/?tid=2189

P#32876 2016-12-01 08:28 ( Edited 2016-12-01 13:28)

Ah yes, thanks ! I applied this to my function, it's way nicer now.

Cart #33045 | 2016-12-05 | Code ▽ | Embed ▽ | No License

P#33047 2016-12-05 07:48 ( Edited 2016-12-05 12:48)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 18:00:47 | 0.020s | Q:42