Hello everyone,
This is the first time i'm asking for help on the forum. I haven't had the need to because I usually find an answer to my question in here already. Here's my question.
I'm creating a clone of tetris. I have the blocks coming down the playing area. Here's my problem. I'm not sure how to write the code that won't let the blocks go to far left, or to far right past the game area. I wanted to use the SPRITE X() command in conjunction with SPRITE COLLISION(), at least that's what I think I need to do. I've looked for examples, tutorials and forums but haven't found a solution yet. I would appreciate any help from anyone. Thank you.
cyatic
rem ********************Tetris Clone Version 0.1a*************************
rem ********************By Alejandro Martinez*****************************
rem ********************Feb. 21, 2003*************************************
rem Game setup
gosub setup
rem Loading images
gosub images
rem Randomizing the blocks apperaring
rx = rnd(6) + 1
rnext = rnd(6) + 1
block1y = 0
block1x = 0
rem This is the Main Game Loop
do
rem Loading of the interface sprite
sprite 20, 0, 0, 8
rem This is the gravity code
block1y = block1y + 1
rem Pasting of sprite game block
sprite (rx), 294 + block1x, 22 + block1y, (rx)
rem Collision detection
rem if sprite collision(rx, 20) > 0
rem Processing input
gosub process
rem Routine for the next block coming up
gosub nextblock
sync
loop
rem *************************SUBROUTINES********************************
rem Randomizing I always do before I write a program
setup:
cls
randomize timer()
rem Hiding the mouse
hide mouse
rem Putting in the sync rate and setting the frame rate to 30 frames per second
sync on
sync rate 30
return
rem Loading of images used in the game
images:
load image "box.bmp", 1
load image "letterl.bmp", 2
load image "tritip.bmp", 3
load image "backl.bmp", 4
load image "bright.bmp", 5
load image "long.bmp", 6
load image "bleft.bmp", 7
load image "inter.bmp", 8
return
rem These are the movement of the blocks done by pressing the movement keys
process:
if downkey()=1 then block1y = block1y + 5
if leftkey()=1 then block1x = block1x - 25
if rightkey()=1 then block1x = block1x + 25
rem This is to exit the game (ONLY FOR DEVELOPEMENTAL PURPOSES!)
if escapekey()=1 then end
return
rem Next block coming up
nextblock:
if rnext = 1 then sprite 8, 522, 329, 1
if rnext = 2 then sprite 9, 522, 315, 2
if rnext = 3 then sprite 10, 509, 323, 3
if rnext = 4 then sprite 11, 522, 315, 4
if rnext = 5 then sprite 12, 507, 323, 5
if rnext = 6 then sprite 13, 535, 303, 6
if rnext = 7 then sprite 14, 507, 323, 7
return