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 this code

Author
Message
master blade
16
Years of Service
User Offline
Joined: 18th Jan 2008
Location:
Posted: 19th Jan 2008 04:01
hi

i've trying to write a game with darkbasic classic, but now i got a problem. in this code that i will show you i can't drawing the bitmap that will represent a player, i don't know what i'm doing wrong? i hope you guys can help me

this is the code

sync on
sync rate 30

set display mode 640,480,32
hide mouse

`cargamos imagen del player
load bitmap "pacsnake.bmp",1
load bitmap "wall1.bmp",2
hide mouse

get image 1,0,0,32,32
get image 2,0,0,32,32

`ya que tenemos la imagen en memoria eliminamos el bitmap
delete bitmap 1
delete bitmap 2

`variables para colocar al player en su posicion inicial
posx=100
posy=100

`direccion del pacsnake 1=derecha, 2=izquierda, 3=arriba, 4=abajo
dirpac=1


`construimos el escenario
`el muro de arriba
sprite 3,5,5,2 : sprite 4,37,5,2 : sprite 5,69,5,2 : sprite 6,101,5,2 : sprite 7,133,5,2
sprite 8,165,5,2 : sprite 9,197,5,2 : sprite 10,229,5,2 : sprite 11,261,5,2 : sprite 12,293,5,2

`el muro de la izquierda
sprite 13,5,37,2 : sprite 14,5,69,2 : sprite 15,5,101,2 : sprite 16,5,133,2 : sprite 17,5,165,2
sprite 18,5,197,2 : sprite 19,5,229,2 : sprite 20,5,261,2 : sprite 21,5,293,2

`el muro de derecha
sprite 22,293,37,2 : sprite 23,293,69,2 : sprite 24,293,101,2 : sprite 25,293,133,2 : sprite 26,293,165,2
sprite 27,293,197,2 : sprite 28,293,229,2 : sprite 29,293,261,2 : sprite 30,293,293,2

`el muro de abajo
sprite 31,37,293,2 : sprite 32,69,293,2 : sprite 33,101,293,2 : sprite 34,133,293,2 : sprite 35,165,293,2
sprite 36,197,293,2 : sprite 37,229,293,2 : sprite 38,261,293,2 : sprite 39,293,293,2

`colocamos al player
sprite 1,posx,posy,1

do

if rightkey()=1 then dirpac=1
if leftkey()=1 then dirpac=2
if upkey()=1 then dirpac=3
if downkey()=1 then dirpac=4

old_posx=posx
old_posy=posy

if dirpac=1 then gosub movderecha
if dirpac=2 then gosub movizquierda
if dirpac=3 then gosub movarriba
if dirpac=4 then gosub movabajo

sprite 1,posx,posy,1

sync on

loop

movderecha:
posx=posx+8
if posx>261 then posx=261
return

movizquierda:
posx=posx-8
if posx<37 then posx=37
return

movarriba:
posy=posy-8
if posy<37 then posy=37
return

movabajo:
posy=posy+8
if posy>261 then posy=261
return

wait key

see ya'

darkbasic classic
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Jan 2008 06:25 Edited at: 19th Jan 2008 06:40
Please use the Code button. You'll find it located in the top right corner just above where you type your message text.

You don't have to make a new post - you can use the Edit button to edit the existing one.

As for your problem (actually there are lots), are the two bmp files full screen size or 31x31 pixels?

If they are already the correct size then you don't use Load Bitmap - use Load Image. Look in the help files to see what Load Bitmap actually does - or read a few tutorials.

As it is, the images are being loaded into screens 1 and 2, then you are grabbing a 31x31 pixel image from screen 0! Hence no images...

Also:

* You only need to hide the mouse once.
* You should use Set Current Bitmap 0 before deleting Bitmaps.
* The command at the end of the main loop is Sync - not Sync On.
* Wait Key where you put it does nothing. It never gets executed.

Finally, you can make your code easier to follow by combining sections. For example you have:



This would be better as:



Assuming that the variable dirpac isn't used for anything other than selecting the correct procedure to gosub...

As I said, you would benefit from reading a few tutorials so you get a good grounding in the basic stuff...

Good luck!

TDK_Man

Login to post a reply

Server time is: 2024-05-17 11:06:47
Your offset time is: 2024-05-17 11:06:47