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.

2D All the way! / Point To Point sprite movement...

Author
Message
Dexter
19
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Ohio
Posted: 4th Jan 2006 05:29
ok... heres my question....
when my game starts I want this sprite to move from top of screen to bottom left of screen like in a diagonal... I want it to do that auto maticly with a press of a key...

can I make a start and end point for it to move...
and set speed/time it takes to get there?

Dexter

Who Dey Bengals
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 4th Jan 2006 12:05
You just change the x and y location of the sprite with a timer in a do/loop.

This is rather primitive:



Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 4th Jan 2006 12:40
What language are you using ? DB, DBpro or PB

One way, is calc the distance between the start point an end point (the hypot)

then calc the time (number of steps it'll take) by dividing the Distance by the movement speed..

and finally, then calc the change in X & Y by dividing the the DX=(EndX-StartX) and DY=(EndY-StartY) by time. This will give the change along the X and Y axis


Here's an example of how to do that in PLayBasic. Note: You should be able to easyly alter the code to work with DB or DBpro also.




Dexter
19
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Ohio
Posted: 5th Jan 2006 04:03
Hey Grog Grueslayer your code worked fantastic you have been a great help since I have started using Dark Basic....

I was wondering if I use your code and have two sprites moving at different times... I used the wait command, but it made the Fps wait 3 sec. per frame.... do you know how to delay a sprite for "x" amout of time?
thanx again
Dex

Who Dey Bengals
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 5th Jan 2006 09:00
Np.

Yeah that's what the timer is for... just increase the 10 in "if timer()>tim+10" if you want a longer delay per sprite step.


Dexter
19
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Ohio
Posted: 6th Jan 2006 00:26 Edited at: 6th Jan 2006 01:40
Ok "huston We have a problem"



There is my source code... now I moved the sprides up with the "IF" command because it wouldnt work without that...
it runs this wit only "green beat" will activate then it just stops...

what I want here is to tell the beats when to hit a certin point....
Just like DDR.. that explains alot but instead of 4 steps theres 5... "green" "red" "yellow" "blue" "orange"...

the "inc y", "inc x", and "dec x" are repeated so i get my sprite moving at a right angle to match the bitmap behind it...


i hope this makes sence and also i dont want all theese beats to go of at the same time you know just like DDR they alternate in the song and go to the BPM "beats per min."...

My money is on grog, but any help is accepted thank you...

Dexter

P.S.- I also edited the X and Y cordinates to set the beats in different x cordinates so there not all on top of each other...
sooo... gx = green X
gy = green y

Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 6th Jan 2006 02:15
Well you need tim1,tim2,tim3,tim4,tim5 for it to work. This can be done as a DIM.

Dim Tim(5)

Blob=1
tim(Blob)=timer()
Inc Blob
You are also doing the If wrong.....


if timer()>tim+10 then sprite 5,ox,oy,5

inc oy ...........and why 5 of these? ....inc oy,5
inc oy
inc oy
inc oy
inc oy
inc ox
inc ox
tim=timer()..........This should not be set back to timer() every loop


should be.......

inc Blob
if timer()>tim(Blob)+10

sprite 5,ox,oy,5

inc oy,5
inc ox,2

tim(Blob)=timer()

Endif

So now you have If/Endif which stops the timer() from being set to zero all of the time. You have a DIM. You have 5 different timers. See if you can put my ideas together in the right order, because I have not given you an exact code, I have just given you a grasp of how the code works.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 6th Jan 2006 02:53
Quote: "My money is on grog, but any help is accepted thank you."


Thanks for the vote of confidence. Pincho Paxton pretty much said all I would of said if I got here first.

I would use "keystate()" instead of "scancode()". "Keystate()" detects more than one key being pressed at the same time.

I would also put the sprite data in an array too. If you put everything in arrays you can reduce the sprite stuff to one for/next loop.


Dexter
19
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Ohio
Posted: 6th Jan 2006 04:26 Edited at: 6th Jan 2006 04:33


Ok I think were almost there but it give me a array out of bounds error...

maybe i didnt put it in how you had it in mind... I hope this works and will be acurate movement..

thank you pincho that helped some and i didnt mean anything by the money on grog thing... lol and that "inc y,5" Tip shortens things down... I need to learn some shorten versions of stuff...

Grog, do you think you and show me an example of sprites in a array... I have never messed around with them so im tryin to understand them by looking at the actual thing...
Thank you

Dexter

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 6th Jan 2006 09:19
Quote: "Grog, do you think you and show me an example of sprites in a array... I have never messed around with them so im tryin to understand them by looking at the actual thing...
Thank you"


Np. Arrays are real easy once you get used to them.

The basic arrays are one dimensional (like "dim Text$(5)" which is 6 strings... 0 to 5) but you can add numbers to hold more data (like "dim Text$(9,5)" which is 10 sets of 6 strings for each set). Arrays can be used in many, many ways.

This code snip creates 20 sprites and moves them down the screen at different speeds ( because each sprite has it's own timer() and delay ):



Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 6th Jan 2006 09:27
Dim goes at the beginning of your code........




Dim tim(5)
gx=290:gy=300
rx=330:ry=300
yx=370:yy=300
bx=410:by=300
ox=450:oy=300

Blob=1
tim(Blob)=timer()
Inc Blob
**************************************************************


And you only need 1 DIM....

Just............. Dim tim(5)

Not....

Dim tim(1)
Dim tim(2)
Dim tim(3)
Dim tim(4)
Dim tim(5)

Blob = 1......has to be inside your loop otherwise blob will = 6 onwards, and that is why you will get ARRAY OUT OF BOUNDS.

Dexter
19
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Ohio
Posted: 9th Jan 2006 15:22
OK. sorry guys weekends are killer on me with work... I tried it and fixed it up it works but ill ask just a few questions about the way its acting...

on the part
whe i change the +10 to say +30 theres no difference... but when i change it to +100 it makes a difference... soo every ancerment of 100 makes a difference...

also as the sprite drops the higher thedelay on the sprite the more jumpy it it... I think thats because its also waiting that amount of time every time.... So is there a way to make it a smooth countinous motin all the way down?

tonite I will paste a screen shots or a .exe if you want one tto see what im tryin to get...

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 9th Jan 2006 19:35
Quote: "tonite I will paste a screen shots or a .exe if you want one tto see what im tryin to get..."


That would be good to do. +10 and +30 probably don't make a difference because its real close in time. 1000 = 1 second.


Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 9th Jan 2006 19:39
Quote: "whe i change the +10 to say +30 theres no difference... but when i change it to +100 it makes a difference... soo every ancerment of 100 makes a difference..."


1000 = 1 second, so everything makes some difference, but small numbers are vary hard to notice.

I combine the tim() idea with fractions.......

Listen very carefully I shall say this only once....(French accent)

1/ A sprite can move 1 pixel at a time.
2/ But it can be told to move half a pixel or even less (An imaginary pixel.)
3/ You do this by using #

This effect gives you smooth movement, but I can't show you my example because it is integrated into a project, and I can't rip it out easily. You still keep the tim() thing, as this controls the speed of the game on all computers, but # makes really smooth movement.

Or maybe you are just putting large delays into your game when they could be smaller.

Dexter
19
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Ohio
Posted: 10th Jan 2006 04:52
Ok... Heres some screen shots...

*NOTE* this is a remake of the game guitar hero so you can also goto www.GuitarHero.com and see what its really supose to be...


K First shot is the beats apper and start falling... If this was like an actual son it would not have every beat on there it would be simpler...


Ok... now this is the notes fallin down som... the notes follow thoose slots on the fret board and when the notes "beats" get in the circle you strum your guitar as your holding down that color button and then your rock meter and you points go up... just like DDR...


Big project ahead of me and I think making the cheap guitar was the funnest part so far... lol... but hey I will get to workin on some more of this and try some stuff out.. if you see any ways you think might help me or know anybody who wants in on a pretty neat project send them on in... thanx "Grog and Pincho"...

Dexter

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 11th Jan 2006 06:16
Cool screenshots.


Login to post a reply

Server time is: 2025-05-16 11:14:21
Your offset time is: 2025-05-16 11:14:21