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 / Brick Game, paddle won't slide to right but slights to the left.

Author
Message
GamesForLife
14
Years of Service
User Offline
Joined: 9th Oct 2010
Location:
Posted: 23rd Jan 2011 10:24
REM Project: Brick_game
REM Created: 21/01/2011 11:33:59
REM
REM ***** Main Source File *****
REM Dwain Maxwell

REM Define global variables

GLOBAL BallX as integer = 0
GLOBAL BallY as integer = 0

GLOBAL SpeedX as integer = 1
GLOBAL SpeedY as integer = -1

GLOBAL PaddleX as word = 5
GLOBAL PaddleY as word = 20

GLOBAL backgroundimage as integer = 1
GLOBAL ballimage as integer = 2
GLOBAL brickimage as integer = 3
GLOBAL paddleimage as integer = 6

GLOBAL ballsprite as integer = 2
GLOBAL bricksprite as integer = 3
GLOBAL paddlesprite as word = 5

GLOBAL Gamestate$ as string = "Initialize"
GLOBAL Playerturns as integer = 3

DIM BricksArray(15,15) as integer

REM Define State of Bricks

DATA 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
DATA 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
DATA 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

REM Main Function

ReadyGameForPlay()
LoadBricksArray()
PlayBricksGame()

END

REM Procedure and Functions

FUNCTION ReadyGameForPlay()

SYNC ON
SYNC RATE 60
HIDE MOUSE
RANDOMIZE TIMER()

SET TEXT FONT "Arial"
SET TEXT SIZE 16
SET TEXT TO BOLD
INK 0,0

REM Set Up Images

LOAD IMAGE "Background.bmp", Backgroundimage
LOAD IMAGE "Paddle.bmp", Paddleimage
LOAD IMAGE "Gameball.bmp", Ballimage
LOAD IMAGE "Brick.bmp", Brickimage

REM Create Sprites

SPRITE Paddlesprite, 999,999, Paddleimage
SPRITE Ballsprite, 999,999, Ballimage
SPRITE Bricksprite, 999,999, Brickimage

REM Determine length and width of paddle

PaddleX = (SCREEN WIDTH()/2) - (SPRITE WIDTH(paddlesprite)/2)
PaddleY = SCREEN HEIGHT() - 25

ENDFUNCTION

FUNCTION LoadBricksArray()

FOR j = 1 TO 5
FOR i = 1 TO 15
READ BricksArray(i,j)
NEXT i
NEXT j
ENDFUNCTION

FUNCTION PlayBricksGame()

DO
PASTE IMAGE BACKGROUNDIMAGE, 0 ,0

SELECT Gamestate$

CASE "Play"
DisplayBricks()
BounceTheBall()
LookForCollisionWithPaddle()
ENDCASE

CASE "Initialize"
ReadyBallAndPaddle()
DisplayBricks()
RESTORE
IF UPKEY() = 1
Gamestate$ = "Play"
ENDIF
ENDCASE

CASE "Over"
CENTER TEXT SCREEN WIDTH()/2 , SCREEN HEIGHT()/2, "GAME OVER"
CENTER TEXT SCREEN WIDTH()/2 , SCREEN HEIGHT()/2 + 30, "Press UP key to play new game"
IF UPKEY() = 1
PlayerTurns = 3
RESTORE
Gamestate$ = "Initialize"
LoadBricksArray()
ENDIF
ENDCASE
ENDSELECT

IF gamestate$ <> "Over"
ProcessPlayerInput()
TEXT 25,25, " Balls Remaining: " + STR$(PlayerTurns)
ENDIF

SYNC

LOOP

ENDFUNCTION

FUNCTION DisplayBricks()
Width = SPRITE WIDTH(BrickSprite) + 2
Height = SPRITE HEIGHT(BrickSprite) + 2

Blockcount = 0
FOR i = 1 to 15
FOR j = 1 to 5

IF BricksArray(i,j) = 1
INC Blockcount
SPRITE Bricksprite, 65 + Width * i, 75 + Height * j, Brickimage

PASTE SPRITE Bricksprite, 65 + Width * i, 75 + Height * j

REM Determine if there is a collision between ball and brick
IF SPRITE COLLISION(Bricksprite,Ballsprite) = 1
BricksArray(i,j) = 0
DeflectBallOffBricks()
ENDIF
ENDIF
NEXT j
NEXT i

REM All blocks cleared

IF Blockcount = 0
GAMEstate$ = "Initialize"
Loadbricksarray()
ENDIF

ENDFUNCTION

FUNCTION BounceTheBall()
BallX = BallX + SpeedX
BallY = BallY + SpeedY

ProcessSideOfScreenCollisions()

ProcessTopOfScreenCollisions()

ProcessMisses()

SPRITE Ballsprite, BallX, BallY, BallImage

ENDFUNCTION

FUNCTION ProcessSideOfScreenCollisions()

IF BallX < 1
BallX = 1
SpeedX = SpeedX * -1
ENDIF

IF BallX > SCREEN WIDTH() -14
BallX = SCREEN WIDTH() -14
SpeedX = SpeedX * -1
ENDIF
ENDFUNCTION

FUNCTION ProcessTopOfScreenCollisions()

IF BallY < 0
BallY = 0
SpeedY = SpeedY * -1
ENDIF

ENDFUNCTION

FUNCTION ProcessMisses()

IF BallY > SCREEN HEIGHT() -6
playerturns = playerturns - 1
IF playerturns < 1
Gamestate$ = "Over"
ELSE
Gamestate$ = "Initialize"
ENDIF
ENDIF
ENDFUNCTION

FUNCTION LookForCollisionWithPaddle()

IF SPRITE COLLISION(paddlesprite, ballsprite) = 1
DeflectballoffPaddle()
ENDIF
ENDFUNCTION

FUNCTION ReadyBallAndPaddle()

BallX = PaddleX + (SPRITE WIDTH(Paddlesprite)/2) - (SPRITE WIDTH(BallSprite)/2)

BallY = PaddleY - 14

SpeedX = rnd(2) + 1
SpeedY = rnd(2) - 6

SPRITE BallSprite, BallX, BallY, BallImage

ENDFUNCTION

FUNCTION ProcessPlayerInput()

IF PaddleX < 6 Then PaddleX = 6

Rightsideofpaddle = PaddleX + SPRITE WIDTH(Paddlesprite)

IF Rightsideofpaddle > SCREEN WIDTH()
PaddleX = SCREEN WIDTH() - SPRITE WIDTH(Paddlesprite)
ENDIF

IF LEFTKEY()
DEC PaddleX, 6
ENDIF

IF RIGHTKEY()
DEC PaddleX, 6
ENDIF

SPRITE Paddlesprite, PaddleX, PaddleY, Paddleimage

ENDFUNCTION

FUNCTION DeflectballoffPaddle()

Centerofball = SPRITE X(Ballsprite) + SPRITE WIDTH(Ballsprite)/2
Leftsideofpaddle = SPRITE X(Paddlesprite)
Rightsideofpaddle = SPRITE X(Paddlesprite) + SPRITE WIDTH (Paddlesprite)

IF Centerofball < leftsideofpaddle + 15
SpeedX = -RND(4) -1
ENDIF

IF Centerofball > rightsideofpaddle - 15
SpeedX = RND(4) -1
ENDIF

SpeedY = -RND(2) -3

ENDFUNCTION

FUNCTION DeflectBalloffbricks()

Centerofball = SPRITE X(Ballsprite) + SPRITE WIDTH(Ballsprite)/2

Leftsideofbrick = SPRITE X(bricksprite)

Rightsideofbrick = SPRITE X(bricksprite) + SPRITE WIDTH(Bricksprite)

IF Centerofball < leftsideofbrick OR Centerofball > rightsideofbrick

SpeedX = SpeedX * -1
ELSE
SpeedY = SpeedY * -1
ENDIF

ENDFUNCTION
kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 23rd Jan 2011 12:49
It's almost impossible to help you, because you just show us the whole code, and in title describe what's wrong with it. You know the code better than us, so you should atleast have an idea what's the problem, and point it so we could help. Maybe someone will read the whole code and then take his time to help, but it would be easier also if you would put the code in brackets

In progress of making Archery Simulator... Or maybe not simulator x]?

@There'll be a sig @
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd Jan 2011 14:20 Edited at: 23rd Jan 2011 14:25
Quote: "
IF LEFTKEY()
DEC PaddleX, 6
ENDIF

IF RIGHTKEY()
DEC PaddleX, 6
ENDIF
"


you're telling PaddleX to DEC when either left/rightkey are pressed... fix that.

and, yes, put the code in a code box next time (select the code and hit the code button so it looks like...

)

good luck!

Virtual Nomad @ California, USA . DBPro V7.5
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
GamesForLife
14
Years of Service
User Offline
Joined: 9th Oct 2010
Location:
Posted: 27th Jan 2011 23:57
Thanks Virtual Nomad, sorry im a beginner to Dark Basic and using forums when it comes to using box's for code snippets. Cant believe it was such a stupid mistake i made. Thanks again for both of your guys help.....

Login to post a reply

Server time is: 2024-11-24 08:00:04
Your offset time is: 2024-11-24 08:00:04