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! / Could someone give me a hand?

Author
Message
PaulC
23
Years of Service
User Offline
Joined: 23rd Feb 2003
Location:
Posted: 27th May 2004 20:04
Hi, I'm Paul. This is my first time on these forums, but I don't think it will be my last.

I've been working on a 2d game based on the Space Invaders concept, but I've run upon a small problem. I have done a ship that can travel around an environment shooting, but when I fire, my ship cannot move, since I use the same variables for both their movement. It would be really great if someone would post their E-Mail and let me send them the source code, unless you can work out the problem from the code alone.

Just in case you can, here's the part of my code that applies to the movement of the objects...

rem load playable vehicle
load bitmap "C:\Paul\Game Graphics\Vehicle.bmp", 2
get image 2, 0, 0, 70, 77
set sprite 2, 1, 1
sprite 2, 260, 300, 2

rem begin loop
repeat

rem this is the part of the code that fires a bullet.
fire:
if spacekey()=1
play music 5
sync rate 0
show sprite 8
sprite 8, x+289, y+282, 8
sync
hide sprite 8
sprite 7, x+295, y+240, 7
sync
sprite 7, x+295, y+180, 7
sync
sprite 7, x+295, y+120, 7
sync
sprite 7, x+295, y+60, 7
sync
sprite 7, x+295, y+0, 7
sync
sprite 7, x+295, y-60, 7
sync
sprite 7, x+295, y-120, 7
sync
sprite 7, x+295, y-180, 7
sync off
load music "C:\Program Files\Microsoft Games\Age of Empires II\Sound\scenario\wolfcastle2_disparo1.mp3", 5
endif

rem Record old position
oldx=x
oldy=y

rem Control position with cursors
control:
if upkey()=1 then y=y-15
if downkey()=1 then y=y+15
if leftkey()=1 then x=x-15
if rightkey()=1 then x=x+15

rem Check for second collision and block new position
if sprite collision(2,5)=1
x=oldx+30
y=oldy
sprite 2,x,y,2
endif

rem Check for collision and block new position
if sprite collision(2,4)=1
x=oldx-30
y=oldy
sprite 2,x,y,2
endif

rem Check for collision and block new position
if sprite collision(2,6)=1
x=oldx
y=oldy-30
sprite 2,x,y,2
endif

rem Check for collision and block new position
if sprite collision(2,10)=1
x=oldx
y=oldy+30
sprite 2,x,y,2
endif

rem draw the sprite at the new position
sprite 2,x+260,y+300,2
sync
goto fire


It'd be really great if you could help me out here.
MoonMan
22
Years of Service
User Offline
Joined: 14th May 2004
Location:
Posted: 27th May 2004 21:34
Actually this question has been asked before, So I'll just direct you to the thread. http://darkbasicpro.thegamecreators.com/?m=forum_view&t=28257&b=4 I hope this can help you. Good luck on your game.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 28th May 2004 00:45
You only need 1 Sync, maybe 2 at most.

PaulC
23
Years of Service
User Offline
Joined: 23rd Feb 2003
Location:
Posted: 28th May 2004 10:15
@Moonman: Thanks alot. I'll check it out now.

@Pincho: Oh, O.K. Thanks for your help.
PaulC
23
Years of Service
User Offline
Joined: 23rd Feb 2003
Location:
Posted: 28th May 2004 10:40
O.K... That was a little help, but I'm using the original DarkBASIC, and it doesn't recognise commands like move sprite and so on, so this doesn't really apply to my script. What would be really great is if someone could tell me how to fix my problem by identifying the problem with my script and explaining it to me in a way that you would have understood when you first entered the world of BASIC.

Thanks to you two guys anyway.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 28th May 2004 11:18
Well, for the bullet you need something like...

When firing activate this.......BulletActive = 1

Put the bullet in front of the ship then....

If BulletActive = 1 then BulletPos = BulletPos - 2

If BulletPos < 0 then BulletActive = 0 : Hide Sprite BulletSpriteNo

Sprite BulletSpriteNo, X , BulletPos, ImageNo

BulletSpriteNo is whatever number you are using for the Bullet.

PaulC
23
Years of Service
User Offline
Joined: 23rd Feb 2003
Location:
Posted: 29th May 2004 12:31
Right. O.K. I think I've sorted it out pretty much. You see, the thing is that I don't know how to make the bullet move in a few lines of code, so instead, I have to do this:

rem this is the part of the code that fires a bullet.
fire:
if spacekey()=1
play music 5
sync rate 0
show sprite 8
sprite 8, x+289, y+282, 8
sync
hide sprite 8
sprite 7, x+295, y+240, 7
sync
sprite 7, x+295, y+180, 7
sync
sprite 7, x+295, y+120, 7
sync
sprite 7, x+295, y+60, 7
sync
sprite 7, x+295, y+0, 7
sync
sprite 7, x+295, y-60, 7
sync
sprite 7, x+295, y-120, 7
sync
sprite 7, x+295, y-180, 7
sync off


But this means that the computer has to go through all of these commands before it can get to the commands that allow movement. Therefore, I changed it to this:

rem fire bullet
fire:
if spacekey()=1
play music 5
sync rate 0
show sprite 8
if upkey()=1 then gosub control
sprite 8, x+289, y+282, 8
sync
hide sprite 8
if upkey()=1 then gosub control
if downkey()=1 then gosub control
sprite 7, x+295, y+240, 7
sync
if 0 > sprite y(7) then gosub control
if upkey()=1 then gosub control
if downkey()=1 then gosub control
sprite 7, x+295, y+180, 7
sync
if 0 > sprite y(7) then gosub control
if downkey()=1 then gosub control
sprite 7, x+295, y+120, 7
if upkey()=1 then gosub control
if downkey()=1 then gosub control
sync
if 0 > sprite y(7) then gosub control
if downkey()=1 then gosub control
sprite 7, x+295, y+60, 7
if upkey()=1 then gosub control
sync
if 0 > sprite y(7) then gosub control
sprite 7, x+295, y+0, 7
if upkey()=1 then gosub control
if downkey()=1 then gosub control
sync
if 0 > sprite y(7) then gosub control
sprite 7, x+295, y-60, 7
if upkey()=1 then gosub control
if downkey()=1 then gosub control
sync
if 0 > sprite y(7) then gosub control
sprite 7, x+295, y-120, 7
if upkey()=1 then gosub control
if downkey()=1 then gosub control
sync
if 0 > sprite y(7) then gosub control
sprite 7, x+295, y-180, 7
if upkey()=1 then gosub control
if downkey()=1 then gosub control
sync off
load music "C:\Program Files\Microsoft Games\Age of Empires II\Sound\scenario\wolfcastle2_disparo1.mp3", 5
endif

Which allows movement up and down. Thanks for everyone's help on this.
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 29th May 2004 22:38 Edited at: 29th May 2004 22:41
OW! that has to be the hardest way to do the job (not to mention the most complicated ever) DO NOT EVER do things over and over by hand when you have a computer handy, that must be murder to code and it still won`t work correctly, try creating code like this (not tested)

sync on:sync rate 40
bullet=1
shooter=2
load image bullet,"bullet.bmp"
load image shooter,"shooter.bmp"
shooter_xpos=200
bullet_y=300
fired=0
hide sprite bullet
do
sprite 1,shooter_xpos,300,shooter
if leftkey() then shooter_xpos=shooter_xpos+1
if rightkey() then shooter_xpos=shooter_xpos-1
if spacekey() and fired=0
fired=1
bullet_x=shooter_xpos
show sprite bullet
endif
if fired=1
bullet_y=bullet_y-3
sprite bullet,bullet_x,bullet_y,bullet
endif
if bullet_y<0
bullet_y=300
fired=0
hide sprite bullet
endif
sync
loop

that should work ok (can`t be troubled to make the media so not tried it), you use a flag (a variable thats normaly either one or zero) to tell the code when the bullet is being shot, then if it isn`t in motion the rest of the code is ignored until the fire button (the spacebar in this code) is pressed, then the flag gets set to one, the code will execute that shows the object, and as long as it is below the top of the screen then it will get moved upwards, when it reaches the top then it the flag is set to zero, and the sprite is hidden and has the position reset to the same height as the laser base, next time you press space it gets turned on at the laser base position and moved to the top of the screen again, hope that explains it well enough, try following the code instructions with some pencil and paper and you will soon realise what it is doing, cheers.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
pizzaman
22
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 30th May 2004 00:27
hey just saw this thread and ouch thats a hard way to program

mentor is right use flags for bullet code
here is a working example for bullet code- its very simple but easy to understand and fully commented + only took 5mins to do



BTW would anyone be interested if i did a mini tutorial for this in other words expand the code to include enemies, obstacles, etc ,-
which of course would be fully commented

it shouldn't take too long to do but would have to wait 1 or 2 days

if anyone is interested just send a post

hope i helped
PST
22
Years of Service
User Offline
Joined: 15th Mar 2004
Location:
Posted: 11th Jun 2004 00:09
I can give you a leg if you need it...

Login to post a reply

Server time is: 2026-06-09 15:43:29
Your offset time is: 2026-06-09 15:43:29