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 / Need help with my easy 2D game

Author
Message
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 5th Oct 2013 18:17
I am a beginner in darkbasic pro, and this is my first game, except easy text guessing games, and other text games. this is an easy 2D game I try to make, but I have problems with to get the sprite to jump, my method have a lot of bugs, and it would be nice if you could help me I have also problem with sprite collision, I have tried, but can not still not make so the sprite stop when it hits something, could anyone help me with that? I am a completely a new beginner in darkbasic pro therefore are the game I trying to make not perfect, but I try as best I can. Other things I need help with are; when the sprite hits the goalflag a new map is coming, highscore, healthbar, spikes that hurts...etc

sorry for bad English

thanks for help


#constant bg 6
#constant platform 2
#constant goal 4
#constant coin 5
autocam off
backdrop on
color backdrop 0
sync
sync rate 60
SET DISPLAY MODE 512, 512, 32
Load image "sprites\Textures\crate2.jpg", bg
Load image "sprites\TRYMS\platform.png", platform
Load image "sprites\TRYMS\goal.png", goal
Load image "sprites\TRYMS\coin.png", coin
create animated sprite 1, "sprites\TRYMS\squareright.png", 1,1,1
sprite 1, 32, 448, 1
show sprite 1
create animated sprite 7, "sprites\TRYMS\danger2.png",1,1,7
sprite 7,32*12, 430,7
show sprite 7
do

Paste image bg,0,0

Paste image platform,0,480,1
Paste image platform,32,480,1
Paste image platform,32*2,480,1
Paste image platform,32*3,480,1
Paste image platform,32*4,480,1
Paste image platform,32*5,480,1
Paste image platform,32*6,480,1
Paste image platform,32*7,480,1
Paste image platform,32*8,480,1
Paste image platform,32*9,480,1
Paste image platform,32*10,480,1
Paste image platform,32*11,480,1
Paste image platform,32*12,480,1
Paste image platform,32*13,480,1
Paste image platform,32*14,480,1
Paste image platform,32*15,480,1

Paste image platform,32*9,448,1
Paste image platform,32*10,448,1
Paste image platform,32*11,448,1
Paste image platform,32*10,416,1
Paste image platform,32*11,416,1
Paste image platform,32*11,384,1

Paste image coin,32*6,448,1
Paste image goal,32*15,448,1


angle = -1

x = sprite x (1)
y = 400

if spacekey() then sprite 1,x,y,1
if spacekey()=0 then sprite 1,x,448,1

if leftkey()=1
angle = 270
ENDIF

if rightkey()=1
angle = 90
ENDIF

if angle > -1 then sprite 1 , newxvalue(sprite x(1) , angle , 1) , newzvalue(sprite y(1) , angle , 1) , 1

loop
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 5th Oct 2013 23:04
Here is a picture from my project
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 5th Oct 2013 23:55
there are many ways to do jump here one of them:



WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 6th Oct 2013 00:03
thanks for the code, I will try it out tomorrow
Do you know how to get the sprite to not fall through the floor, adding collision? And is it possible to make collision with images??
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 6th Oct 2013 04:45
Use sprite collision with another but remember to create a sliding effect.

WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 6th Oct 2013 10:39
The jumping code you gave me works perfect but what do you mean with to create a sliding effect, and how could I set up a sprite collision. Do I have to change my platform image to a sprite to use the sprite collision command, or could I make a collision with my player sprite with the platform image????
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 6th Oct 2013 14:38
Here is a new picture from my project, but I have problems with to draw my score up on the left of the game window, could anyone help me with that? when I hit the coin-sprite the player will earn 1 point.
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 6th Oct 2013 20:17
you have 3 options:

1- if you're using normal printing commands then you will have to print it in every loop.

2- turn your score results into sprite into sprites and create numbers image, then change the sprite image for a score.

3- use the command "set camera view 0,x1,y1,x2,y2" to define where the game must be drawn on the screen then the space left is part of bitmap 0 where you can normally use printing commands.

in my opinion, as you're still beginner, don't use the third option and I advise you to use the second option because it leaves your 2D game design limitless. while the third option is much better when your score board is very big that can take large amount of the screen leaving you with smaller game environment space.

WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 6th Oct 2013 22:15
Thanks you for your help but I have still problems. because when I print the score on the screen the score-number fall immediately directly into the floor. I have added a video, there you can see my problem. Here is my code


#constant bg 6
#constant platform 2
#constant goal 4
#constant danger2 5
#constant _TRUE = 1
#constant _FALSE = 0
#constant _JUMPSPEED 4
#constant _JUMPPOWER 15
x# = 50
y# = 448
speed# = 4

Rem *********DISPLAY*********

autocam off
backdrop on
color backdrop 0
sync
sync rate 60
SET DISPLAY MODE 512, 512, 32


Rem *********SPRITE**********

Load image "sprites\Textures\crate2.jpg", bg
Load image "sprites\TRYMS\platform.png", platform
Load image "sprites\TRYMS\goal.png", goal
Load image "sprites\TRYMS\danger2.png", danger2


Rem *********PLAYER_SPRITE**********
create animated sprite 1, "sprites\TRYMS\squareright.png", 1,1,1
sprite 1, 32, 448, 1
show sprite 1

Rem **********COIN_SPRITE***********
create animated sprite 8, "sprites\TRYMS\coin.png",1,1,8
sprite 8,32*4, 448,8
show sprite 8

create animated sprite 9, "sprites\TRYMS\coin.png",1,1,9
sprite 9,32*5, 448,9
show sprite 9

create animated sprite 10, "sprites\TRYMS\coin.png",1,1,10
sprite 10,32*6, 448,10
show sprite 10

create animated sprite 11, "sprites\TRYMS\coin.png",1,1,11
sprite 11,32*7, 448,11
show sprite 11


Rem ********PASTE_IMAGE*********

do

Paste image bg,0,0

Paste image platform,0,480,1
Paste image platform,32,480,1
Paste image platform,32*2,480,1
Paste image platform,32*3,480,1
Paste image platform,32*4,480,1
Paste image platform,32*5,480,1
Paste image platform,32*6,480,1
Paste image platform,32*7,480,1
Paste image platform,32*8,480,1
Paste image platform,32*9,480,1
Paste image platform,32*10,480,1
Paste image platform,32*11,480,1
Paste image platform,32*12,480,1
Paste image platform,32*13,480,1
Paste image platform,32*14,480,1
Paste image platform,32*15,480,1

Paste image platform,32*9,448,1
Paste image platform,32*10,448,1
Paste image platform,32*11,448,1
Paste image platform,32*10,416,1
Paste image platform,32*11,416,1
Paste image platform,32*11,384,1

Paste image danger2,32*12,430,1
Paste image goal,32*15,448,1



Rem ********SCORE********




box 0,0,100,25, RGB(0,0,0),RGB(0,255,0),RGB(0,0,255),RGB(0,255,255)
text 3,3, "SCORE = 0"
if sprite hit(1,8)=1 then inc score, 1
if sprite collision(1,8)then sprite 8,600,600,8

if sprite hit(1,9)=1 then inc score, 1
if sprite collision(1,9)then sprite 9,600,600,9

if sprite hit(1,10)=1 then inc score, 1
if sprite collision(1,10)then sprite 10,600,600,10

if sprite hit(1,11)=1 then inc score, 1
if sprite collision(1,11)then sprite 11,600,600,11

print score




Rem *********JUMP*********

x# = x# + (rightkey()-leftkey())*speed#

sprite 1,x#,y#,1

if upkey() then _Jump = _TRUE

if _Jump = _TRUE
inc jump#,_JUMPSPEED
y# = y#-_JUMPPOWER*cos(jump#)

if jump# = 180
y# = 448
jump# = 0
_Jump = _FALSE
ENDIF
ENDIF

Rem *********************

LOOP
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 7th Oct 2013 00:10 Edited at: 7th Oct 2013 00:18
of course because you're not clearing the screen. use the command 'cls' to clear the screen before using print.

or use the command "text x,y,str$(score)" or "set cursor x,y : print score" then you don't have to clear the screen.

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 7th Oct 2013 18:30
And remember to put code in code tags.

WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 7th Oct 2013 22:43
Basjak thank you for your help. Since I'm a beginner I have not learned all the commands and syntax in darkbasic pro. Therefore I have thought about buying a book. That could help me to get started with darkbasic pro. Do you have any tips about a good beginner book for darkbasic pro? I have read comments about the book (Hands On DarkBASIC Pro - Volume 1) is this a book you recommend for a beginner???
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 7th Oct 2013 22:50
Mobiius I'll remember that for the next time I post my code
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 8th Oct 2013 19:48
I started learning by reading hands on DBpro1 and then 2. yet DBpro have evolved since these two books printed but they make a solid reference for beginners. they very easy to follow and put you on a solid ground as beginner.

as well I think you're doing well as a beginner.

WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 9th Oct 2013 22:35
Thanks for help, here is a new video from my project. Now with a working score counter but I have still problems to get my player sprite to collide with the green squares (floor). Is it possible to make that my player sprite could collide with the green squares-floor??? the floor is not a sprite, and I have used paste image to paste them into the game. How could I make a collision???

Login to post a reply

Server time is: 2026-07-07 00:08:45
Your offset time is: 2026-07-07 00:08:45