forums

TNT Basic Forums > Programming Q&A
Making a tetris style game
< Last Thread     Next Thread >
Author
Thread        Post A Reply

11-14-2003 22:32

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

Hello everyone! i've come up with a great idea for a new tetris-style game!.. i would like to heva some help with the coding.. i'm trying to make the "coloumns" fall down from the top of the screen and down.. and when something hits it, i want it to disappear and a new coloumn will start falling from the top. PLEASE help me.. this is my first game!

11-14-2003 23:17

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

Problem with sprite col

i've tried to use sprite col to see if a ball hits the brick...

this code

if (sprite col(3,2)) = 1
sprite off 3
end if

and this code


int hitbrick=sprite col (2,3)

if hitbrick=1
sprite off 3

end if

but none of them works... the second code is straight from the pong-game and should work fine... ase int does in pong!

helphelp!

11-15-2003 00:30

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

(sprite col(3,2)) = 1

is not correct. sprite col returns the ID of the sprite that collided. Try:

(sprite col(3,2)) = 2

11-15-2003 01:17

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

thanks!

now to the second problem.. Sprite off wont work!.. it works for split-second if i add draw frame before end if.. but i want it out of there for good. or at least make it start falling from the top again

11-15-2003 13:32

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

That used to happen to me alot.
Make sure that when the sprite off command is called you don't call the sprite command again.

What I usaually do is this:

global int s[2]
.
.
s[1] = true
.
.
.
if s[1] = true
sprite 1,1x,1y,pic
end if
.
.
.
sprite off 1
s[1] = false

Good luck with this,
MapMaker

11-16-2003 02:24

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

thank you!! i'll try this tomorrow.. to late to start coding now...

i got another quiestion though..
can i make a function for all the falling bricks so it wont be nessecery to make a completely new funcion for each individual brick that falls down?
like..

function(brick)
brick falls
brick stop at bottom or if it hits another brick
if brick is hit by a specific sprite it is set to off
end function(brick)

and then apply it to the brick sprite...
like
brick = function(brick)
or something...
i dont know if you get it, but i dont know how to explain it =)

11-16-2003 13:41

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

In my game, I have to test the values of over 800 sprites.
Of course, I'm not going to make a separate function for each one :)
Sorry if I misunderstood what you want, but what I do is this:


procedure test()
int cnum
for cnum = 0 to (number_of_blocks) step 1
if s[cnum] = true 'coming from my previous post

if (not (sprite col(cnum, ((min_number_of_bloaks) to (number_of_blocks)))) or if sy[cnum] = (bottom)
sy[cnum] = sy[cnum] + 1 'I always store my sprites' x and y locats in arrays like so
end if

if (sprite col(num, (specific_sprite))
s[cnum] = false
end if

end if
next cnum
end proc

procedure drawblocks()
int num
for num = 0 to (number_of_blocks) step 1
if s[num] = true
sprite num,sx[num],sy[num],spritepic
draw frame
end if
next num
end proc



This should take care of everything you need, Good luck with this,
MapMaker

11-16-2003 18:02

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

Have you seen my example game Beans? It's a Puyo Puyo clone, which is similar to tetris. Fully commented TNT Basic source code is available here. It might be helpful to you.

Mark

11-16-2003 18:32

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

Thank you map maker.. but i thik i'll have to learn in smaller steps.. i didn't really understand what you just wrote!... please tell me where to put the code for sprite off... (on sprite 3)


...
' main loop
repeat

' draw sprites
sprite 1,player,469,0
sprite 2,bally,ballx,1
sprite 3,bricky,brickxvel,2

draw frame

'move brick
brickxvel=brickxvel+1

'check for hits
'bounce the ball of the brick, smash brick and make a new one.
int hitbrick=sprite col (2,3)
if hitbrick=3
ballx=ballx-ballxvel
ballxvel=-ballxvel
end if
...

11-16-2003 18:33

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

THANKS MARK! i'll check it out!

11-16-2003 18:34

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

.... i get a "file not found" on this adress...

http://www.tntbasic.com/downloads/examples/BeansSource.sit

11-16-2003 23:06

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

Ya, I forgot, that beans source could really help you. If you cant get to it I can e-mail you my copy.

You'd put the 'sprite off' right before s[cnum] = false, int procedure test(), so you'd get:


procedure test()
int cnum
for cnum = 0 to (number_of_blocks) step 1
if s[cnum] = true 'coming from my previous post

if (not (sprite col(cnum, ((min_number_of_bloaks) to (number_of_blocks)))) or if sy[cnum] = (bottom)
sy[cnum] = sy[cnum] + 1 'I always store my sprites' x and y locats in arrays like so
end if

if (sprite col(num, (specific_sprite))
sprite off cnum
s[cnum] = false
end if

end if
next cnum
end proc

procedure drawblocks()
int num
for num = 0 to (number_of_blocks) step 1
if s[num] = true
sprite num,sx[num],sy[num],spritepic
draw frame
end if



next num
end proc


Hope this helps again, tell me if you can't get the beans code.
MapMaker

11-16-2003 23:13

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

Wait, your using a ball, how does that fit into Tetris?
Do you mean your making that kind of game with a ball and paddle on the bottom and bricks up above?
Or is it just a new kind of Tetris?

Using your code, I'd put the sprite off code in the bottom part of your script, where the ball hits the brick and reverses direction, if I understand your game correctly; making it look like:


...
' main loop
repeat

' draw sprites
sprite 1,player,469,0
sprite 2,bally,ballx,1
sprite 3,bricky,brickxvel,2

draw frame

'move brick
brickxvel=brickxvel+1

'check for hits
'bounce the ball of the brick, smash brick and make a new one.
int hitbrick=sprite col (2,3)
if hitbrick=3
sprite off 3 '<----------------------------------------
ballx=ballx-ballxvel
ballxvel=-ballxvel
end if
...


Hope this helps & Good luck,
MapMaker

11-17-2003 02:50

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

thank you! all of you!

the game i'm making is a mixture of tetris and "bricks"..

you are the pad. you bounces the ball to hit the bricks that are falling down from above.

almost like in "Pop pop" =D

11-17-2003 15:52

Posted by:
soccergirl#9

Find more posts by soccergirl#9

Yeah thats great what are you guys talking about?

I'm new here and I want to try tomake friends please don't think I'm just being rude.

11-17-2003 18:55

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

Hi

Welcome to the TNT forums, we were just talking about how to get bricks to fall down and dissapear when they are hit with a ball in a tetris - style game that fjerkon is making.

Do you mind if I ask if you are new to programming or just TNT?

Good luck with your game fjerkon,
MapMaker

11-17-2003 23:22

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

'check for hits
'bounce the ball of the brick, smash brick and make a new one.
int hitbrick=sprite col (2,3)
if hitbrick=3
sprite off 3 '<----------------------------------------
ballx=ballx-ballxvel
ballxvel=-ballxvel
end if


That's where i put the "sprite off" from the start and it didn't work! =(
tried it one more time just to be sure.. but nope.. maybe this is a bug?

11-18-2003 00:06

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

check for hits
'bounce the ball of the brick, smash brick and make a new one.
int hitbrick=sprite col (2,3)
if hitbrick=3
sprite off 3 '<----------------------------------------
ballx=ballx-ballxvel
ballxvel=-ballxvel
end if


Hmm, maybe your not checking for sprite col too often.
Try putting in print "This Works!", so it would look like this:


int hitbrick=sprite col (2,3)
if hitbrick=3
sprite off 3
print "This Works!"
ballx=ballx-ballxvel
ballxvel=-ballxvel
end if

If this dosn't work, your probably not checking for sprite col at the right time.

Hopw this helps,
MapMaker

11-18-2003 01:42

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

YEEES!

it works... finally.

i made a
global int brick=1
then
if brick=1
sprite 3,bricky,brickxvel,2
end if
then
int hitbrick=sprite col (2,3)
if hitbrick=3
sprite off 3
global int brick=0
ballx=ballx-ballxvel
ballxvel=-ballxvel
end if

does it look like a good way to do it?

11-18-2003 18:43

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

Ya, thats a good way.

I try and stay away from "then"s, they can get tricky sometimes, I just use it all in a big "if", but your way is just as valid.

Good luck with your game,
MapMaker

11-18-2003 18:45

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

:)

Ok, I see the "Then" was just part of your post.
That looks good, is it all in 1 group or is it split up into procedures?

Again good luck,
MapMaker

11-18-2003 20:33

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

no its splited up.. but would like to have this as a function that i can applie to all bricks.. now.. if i want to make a new brick that starts falling down when i hit this brick using the same code.. how do i do that?

11-24-2003 22:52

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

Sorry, I've fixed the Beans link now. It should have bean, err been:

http://www.tntbasic.com/download/examples/files/BeansSource.sit

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.