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 / quicker sprite movement

Author
Message
Shady Simpson
23
Years of Service
User Offline
Joined: 15th Mar 2003
Location: United Kingdom
Posted: 4th May 2003 11:16
hi,

I'm making a 2D sprite game(Space Invaders). The only problem is the speed that the bullet travels at.

My code is something like this:

do

sync

if fire#=1
y=y+12
if y
Vandetta
23
Years of Service
User Offline
Joined: 17th Dec 2002
Location:
Posted: 4th May 2003 12:31
hmm it doesnt look like you finished typing your code

Shady Simpson
23
Years of Service
User Offline
Joined: 15th Mar 2003
Location: United Kingdom
Posted: 4th May 2003 12:37
eh, it's cut off half of my code
here it is again anyway

y=520
way#=1

do

sync

box 0,0,800,600,rgb(100,0,100),rgb(255,0,255),rgb(200,0,200),rgb(0,0,0)



if fire#=0
y=520
endif

if fire#=1
y=y-12
if y < 0
fire#=0
else
x=x
endif

endif

sprite sp#,x,520,sp#

if way#=1
w#=w#+6
endif

if way#=2
w#=w#-6
endif

sprite 30,x+30,y+20,30
sprite 3,w#,100,3
sprite 4,w#-50,100,3
sprite 5,w#+50,100,3
sprite 6,w#+100,100,3

sprite 7,w#,200,3
sprite 8,w#-50,200,3
sprite 9,w#-100,200,3
sprite 10,w#+50,200,3
sprite 11,w#+100,200,3
sprite 12,w#+150,200,3



if w#+190 > 800 then way#=2

if way#=2
if w#-120 < 0 then way#=1
endif

if rightkey() then x=x+12
if leftkey() then x=x-12
if spacekey()
fire#=1
endif

sync

loop

The bullet travels really slow up the screen, I've tried increasing the y value but then it sometimes misses the monsters.

I want a fast but smooth motion of the bullet going up the screen.

Any suggestions?

Thanx.

Vandetta
23
Years of Service
User Offline
Joined: 17th Dec 2002
Location:
Posted: 4th May 2003 13:12
without really thinking too hard as its 2:00 am here, I would say stick a set sync rate 0 right after sync on and instead of using sync try using fastsync.

Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 4th May 2003 13:47 Edited at: 4th May 2003 13:49
thinking a bit more you have two syncs in your loop, so you have halved the game speed, take one out, also your game will have defaulted to (I think...long time since I used it) 30 frames per second since you didn`t set a speed for fps, so your game is actualy running at 15fps cos you make the game wait for a sync twice per loop, use "sync rate 0" and "sync on" to make the game run as fast as possible and remove the unwanted sync at the top of the loop, that way the game will just update the screen without waiting when it hits the sync, one thing though, it may run so fast you have trouble seeing the bullets, if thats the case then alter sync rate to something like 60, hope thats some help.

Mentor.

Flashing Blade
23
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 4th May 2003 13:50 Edited at: 4th May 2003 13:51
instead of doing

y=y-12
...collision check
sync

do:

for count=1 to 3
y=y-10
...collision check
next count
sync

This way the bullet moves up 30 every loop but checks for collisions at three intervals of 10
Flashing Blade
23
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 4th May 2003 13:53
yes do what mentor said first..if still not fast enough try what i said and what mentor said
Shady Simpson
23
Years of Service
User Offline
Joined: 15th Mar 2003
Location: United Kingdom
Posted: 4th May 2003 17:43
Thanx everyone, I'll try each of them.

One more thing, For some reason when I insert a "Sync On" nothing works.

Tell me if this happens on anyone elses

Thanx.

APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 4th May 2003 17:45
Sync On goes at the top of your program but you still use the Sync command inside your loop, thats probably whats happening.

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
Shady Simpson
23
Years of Service
User Offline
Joined: 15th Mar 2003
Location: United Kingdom
Posted: 4th May 2003 18:12
Right, Everyone that reads this post is gunna laugh their heads off at me here but anyway...

how do you set the frames per sec?

I've never used it before because I've just migrated from DB Classic.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th May 2003 18:24
SYNC RATE 60

Sets 60 FPS
Shady Simpson
23
Years of Service
User Offline
Joined: 15th Mar 2003
Location: United Kingdom
Posted: 4th May 2003 18:44
ar yeah, I remember now
thanx for helpin'

Shady Simpson
23
Years of Service
User Offline
Joined: 15th Mar 2003
Location: United Kingdom
Posted: 4th May 2003 20:25 Edited at: 4th May 2003 20:27
Another problem guys,

how can you tell which sprites have just collided?

Like:

do

if sprite collision(1,0)
print "You have hit another sprite"
endif

loop

how can you tell which sprite has just hit sprite 1?

Thanx.

APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 4th May 2003 20:28
I thought that Sprite Collision(1,0) actually returns the sprite number it collided with. Although I haven't used the sprite functions fully yet so someone could correct me on that.

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
Shady Simpson
23
Years of Service
User Offline
Joined: 15th Mar 2003
Location: United Kingdom
Posted: 4th May 2003 20:33
I didn't know it did, but still how would you get it or call it or whatever?

APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 4th May 2003 20:38


You would use the nSpriteHit variable to determine which one was hit and then either delete it or play an explosion animation or something.

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
Shady Simpson
23
Years of Service
User Offline
Joined: 15th Mar 2003
Location: United Kingdom
Posted: 4th May 2003 20:58
eh?, how could I delete the sprte I wanted?

All that does is tell me that the sprite is more than 0.

Could you post a little bit of sample code of what goes between if and endif to express what you mean?

Thanx.

APEXnow
Retired Moderator
23
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 4th May 2003 21:12
Ok, nSpriteHit is an integer variable that is used to store the number of the sprite that collided with sprite number 1.

nSpriteHit As Integer

The SPRITE COLLISION command when called, returns a sprite number greater than zero if a hit occurred between sprite 1 and any other sprites on the screen. If sprite 1 did not hit anything, SPRITE COLLISION will return zero.

So, given this information, you could write something like.


Do you see what I mean?

"Man who looses key to woman's appartment...... He get no nookie" - A wise chinese man.
CloseToPerfect
23
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 5th May 2003 01:51
heres just a bit out of one of my games.
maybe it helps maybe not.



CTP

Shady Simpson
23
Years of Service
User Offline
Joined: 15th Mar 2003
Location: United Kingdom
Posted: 5th May 2003 12:01
Thanx CloseToPerfect, both of them work just Perfects was more effective.

Thanx for helpin' everyone.

Login to post a reply

Server time is: 2026-07-11 12:02:06
Your offset time is: 2026-07-11 12:02:06