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.

Newcomers DBPro Corner / Help with my first game. How do I prevent spaceship from leaving the screen?

Author
Message
Booger
19
Years of Service
User Offline
Joined: 30th May 2005
Location:
Posted: 31st May 2005 01:11
Hello.. I am very new to Darkbasic so please forgive me for what may look like a messy code. I want to start of learning Darkbasic Classic by starting with a simple 2D space game. So far, I have been able to display a background image from a bitmap, draw a spaceship, and control it with the keyboard. I have also started to add background music and add a phaser sound when the spacebar is presses. No bullets yet. My code for the phaser doesn't look right. It fires, but the problem is if you keep the spacebar down, the sound is repeated so fast it doesn't sound right.. How do I fix this?
Also, my spaceship moves around smoothly, but how do I prevent it from leaving the screen?

Thank you!!!
gpex
19
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 31st May 2005 04:35
well, i cant view your source, but i asume that when the space bar is pressed that you goto a subroutine or a label, so after right after the "play sound" command put a "wait 100" or 200...etc. Depending on how fast you actually want the sound to repeat. Now, myself not being a very experienced programmer at all, this may not be the best solution so try talking to some of the DB guru's out there.
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 31st May 2005 04:46
code is not displaying so i'm guessing

1- put a counter in the sound subroutine:

if spacekey()=1
soundcounter=soundcounter+1
if soundcounter = 1000 then play sound:soundcounter=0
endif

2- limit the x and y axis movements to the screen size (resolution)

for 800x600 it would be like:

if x#<0 then x#=0
if x#>800 then x#=800
if y#<0 then y#=0
if y#>600 then y#=600

hope it helps
NanoBrain
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 31st May 2005 09:36 Edited at: 31st May 2005 09:41
Scorpyo,

May I modify your sample code by placing a SOUND PLAYING(snd#) command within it?

PLEASE HELP ME,

The snippet below uses the command by itself.


However, if your sound has no silence in it at its ending, speaking of the .wav file itself, and you would like there to be some. Either, edit the sound by adding a moment or two of silence, or implement Scropyo's and my ideas togehter. Like this:



+NanoBrain+
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 31st May 2005 13:14
well if you want your spaceship to stay on screen put

you also have to position you object on screen with

remember to change the object number and stuff to fit your object

NARUTO IS THE NINJA.......not really
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 31st May 2005 15:59
Christian Ang,
PLEASE HELP ME said he was building a 2D game. Right?

PLEASE HELP ME,
This is what you have to do:



Where posx,posy are the coords of you spaceship, and xsize and ysize are you spaceships width and height.
master programmer
19
Years of Service
User Offline
Joined: 30th May 2005
Location: 3D Space
Posted: 31st May 2005 16:34
Add this after your spacekey command:


Then, delete the "play sound" that you already have existing.





______________________________________
<<<<I can program using anything>>>>
Booger
19
Years of Service
User Offline
Joined: 30th May 2005
Location:
Posted: 31st May 2005 23:39
Thank you for all of your help!!!! It works now!!!

Thank you!!!
Booger
19
Years of Service
User Offline
Joined: 30th May 2005
Location:
Posted: 1st Jun 2005 04:23
Thank you!!! It worked!!!

Thank you!!!

Login to post a reply

Server time is: 2024-09-23 21:15:09
Your offset time is: 2024-09-23 21:15:09