Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Fluid sprite paths

Author
Message
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 28th Nov 2003 12:45
Hi everyone,

I did a post a few down regarding IRQ's, which I've been told aren't possible.

So I've created a routine called from the main loop that detects the position of Mr. BadGuy and simply moves the sprite accordingly in any direction.

The problem is, how can I, say, have various paths for the spite to follow, and even more so, a circular path?

I've tried plotting the path in an array, for exmple if the sprite is at 0,0 and it needs to move 100 pixels to the right, then at each loop, check if the sprite is great than 100, and if so, then go onto the next array. It's all fairly complex, but 'kinda' works.

But of course circular paths, arcs, etc, are causing me a nightmare.

I'm sure that DBP, powerful as it is, will have some 'better' method.

Any ideas would be really appreciated...

TIA

~ J ~
CoTang
22
Years of Service
User Offline
Joined: 18th Nov 2003
Location:
Posted: 28th Nov 2003 15:16
Hehe, I'm working on the same thing right now. So far I can get 1 single sprite to move. BUT I'm trying to fool prrof my subroutine right now so that when ever I need it to move a certain path I can just set a few variable.

So what you need to do is create a SCRIPT. It doesn't matter how you do it as long as your script contains 2 varibles. 1st variable is the direction. ex. 1 = Forward, 2 = back, 3 = right, 4 = left, 5 = turn 45* ...etc...etc...
The Second variable is the cycle count. Meaning how long you want the 1st variable to go for.

So for my script if I want a sprite to move in a box direction it would look something like this...

(1,50),(3,50),(3,50),(3,50)

Once you have your script written, you have to EXTRACT the first variable and cycle and then you just use a big Select Case statment and your good to go...

SELECT DIRECTION
CASE 1: Move Sprite Up : Dec Cycle
CASE 2: Move Sprite Down : Dec Cycle
etc....
If Cycle = 0 Then EXTRACT next set of variable and do again.

Make sure you don't put this in its own loop or else you'll have to wait till it finish before you can do any other command.

There is probebly another way of doing this, but this is so far what I came up with.

Peace.
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 28th Nov 2003 15:25
Hmmm, that actually sounds like a good idea.

Kinda like Logo I imagine.

Right, MANY thanks, off to code that now...!

~ J ~
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 28th Nov 2003 15:26
Going back to the arc and circular method, simply draw a circle on graph paper, and work out the intersections to plot the path.

You're a star!!! Cheers CoTang

~ J ~
CoTang
22
Years of Service
User Offline
Joined: 18th Nov 2003
Location:
Posted: 28th Nov 2003 16:03
Hehe Thanks...I think. But anyways here my code for the box I commented the best I could so copy ans paste it into DBP and run it.
CoTang
22
Years of Service
User Offline
Joined: 18th Nov 2003
Location:
Posted: 28th Nov 2003 16:06
I havn't done a circle path yet, but I think that might be a big one. Oh well let me how that goes.
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 28th Nov 2003 16:12
Brilliant, cheers for that.

I think I MAY have an idea over the multiple sprite, I'll have a play about and let you know.

Thanks again.

~ J ~
krannock
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United Kingdom
Posted: 28th Nov 2003 17:36 Edited at: 28th Nov 2003 17:53
hi guys,
i found this bit of code on the net for plotting a circle.
dont know if it helps but it might give you an idea.
it chops the circle into eight and plots it in eighths.
you could take the first plot off the last set to do the first eighth and the next eighth and so on. I think the first set of plots is to just start them off.
you could mix the plots around and shift the x,y pos to make the sprite change direction but still curve.
i hope it helps.

good luck.

Function PlotCircle(xpos,ypos,radius)
x=0
y=radius
h=1-radius
Plot(xpos+x,ypos+y) ;Draw the starting pixels
Plot(xpos-x,ypos-y)
Plot(xpos+x,ypos-y)
Plot(xpos-x,ypos+y)
Plot(xpos+y,ypos+x)
Plot(xpos-y,ypos-x)
Plot(xpos+y,ypos-x)
Plot(xpos-y,ypos+x)
While y>x ;Loop the arc
If h<0
h=h+(2*(x+1))
x=x+1
Else
h=h+(2*(x-y))+5
x=x+1
y=y-1
EndIf
Plot(xpos+x,ypos+y) ;Draw 1/8 at a time
Plot(xpos+y,ypos+x)
Plot(xpos-x,ypos-y)
Plot(xpos-y,ypos-x)
Plot(xpos-x,ypos+y)
Plot(xpos-y,ypos+x)
Plot(xpos+x,ypos-y)
Plot(xpos+y,ypos-x)
Wend
End Function

Smile it could be worse....I smiled...it got worse!

Login to post a reply

Server time is: 2026-07-27 01:33:01
Your offset time is: 2026-07-27 01:33:01