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! / help with simple shooter

Author
Message
patchwilde
11
Years of Service
User Offline
Joined: 29th Mar 2012
Location:
Posted: 29th Mar 2012 19:37
Hello I was hoping somebody could help me with this code for a shooting program. Admittedly it's from an updated version of Hands on DBPro Vol I pages 556-557 (e-book). It is supposed to load a graphic for a plane/ship that moves horizontally along the bottom of the screen and be able to fire a single shot straight up. The code won't compile at all and I want to know how to fix it. Please help!
PS I have no clue on how to post a code snippet here

Rem Project: sprites215
Rem Created: Wednesday, March 28, 2012

Rem ***** Main Source File *****
` Define required data type
#CONSTANT plane 1
#CONSTANT missile 2
` Define required data types
TYPE VelocityType
speed AS INTEGER
angle AS INTEGER
ENDTYPE

TYPE PositionType
x AS INTEGER
y AS INTEGER
ENDTYPE

` Set up main variables
GLOBAL missilevelocity AS VelocityType
GLOBAL planeposition AS PositionType

` Main program logic
InitialiseGame()
DO
HandlePlane()
IF SPRITE EXIST(missile)
HandleMissile()
ENDIF
LOOP
END

FUNCTION InitialiseGame()
`Set up missile velocity
missilevelocity.speed = 5
missilevelocity.angle = 0
` Set screen resolution
SET DISPLAY MODE 1280, 1024, 32
SET WINDOW POSITION 400, 0
` Set backdrop colour
COLOR BACKDROP RGB(64, 64, 255)
BACKDROP ON
` Set up plane sprite
LOAD IMAGE "media\starship.bmp", 1
SPRITE plane, 640, 900, 1
` Load image to be used for missile
LOAD IMAGE "media\missile.bmp", 2
ENDFUNCTION

FUNCTION HandleMissile()
MOVE SPRITE missile, missilevelocity.speed
IF SPRITE Y(missile) < 0
DELETE SPRITE missile
ENDIF
ENDFUNCTION

FUNCTION HandlePlane()
` Find plane's position
planeposition.x = SPRITE X(plane)
planeposition.y = SPRITE Y(plane)
` Check for keyboard hit
keycode = SCANCODE()
` React to key pressed
SELECT keycode
CASE 52 `V (left)
IF planeposition.x > 8
DEC planeposition.x, 5
ENDIF
ENDCASE
CASE 53 ` Z (right)
IF planeposition.x < 1272
INC planeposition.x, 5
ENDIF
ENDCASE
CASE 57 `space (fire missile)
IF NOT SPRITE EXIST(missile)
`Create missile sprite at top of plane
SPRITE missile, planeposition.x + SPRITE WIDTH(plane) / 2, planeposition.y, 2
ENDIF
ENDCASE
ENDSELECT
` Move the plane sprite to its new position
SPRITE plane, planeposition.x, planeposition.y, 1
ENDFUNCTION
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 5th Apr 2012 04:55
You would be better posting on the Db forum rather than the 2d forum. I can't see anything obvious from the code above. An error message would help identify what is going wrong. To add a code snippet. Click the code button that is visible on the post window, and paste the code underneath the tag. Then, click code again to complete the process.

zeroSlave
14
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 5th Apr 2012 05:24 Edited at: 5th Apr 2012 05:24
Hello there, As DVader said, this should go in the DB forum. I looked through your code, and the first thing I would suggest is:


Get your code tabbed and organized. It will help a lot.
Secondly, I edited the code above to make it work. the word 'plane' is a reserved word in DBP (make object plane)
Can't use it as a variable. I switched it to "plane12" and it ran just fine.

patchwilde
11
Years of Service
User Offline
Joined: 29th Mar 2012
Location:
Posted: 6th Apr 2012 18:57
Thank you guys. ZeroSlave the suggestion worked. Thanks for the help!

Login to post a reply

Server time is: 2024-03-29 06:02:34
Your offset time is: 2024-03-29 06:02:34