Skip to main content
gamedev.net
🔒 Locked

Whats wrong with this code?

Started by nuketec 1 reply 200+ views
Original Post
nuketec
nuketec
Im trying to make a tetris clone(im only 13) and the first block lands perfectly at the bottom. The second lands on top, the third just stays at the top. GL ************************************************************ Dim BlockNumber As Variant Dim NextBlock, BlockType, Block1, Block2, Block3, Block4, Block5, StartBlock, Go As Integer Private Sub cmdExit_Click() End End Sub Private Sub cmdNew_Click() Call Start End Sub Public Function Start() Go = 0 Block1 = 0 Block2 = 0 Block3 = 0 Block4 = 0 Block5 = 0 ''Make next picture box visible picNext.Visible = True ''Choose the block which is going to be used BlockType = NextBlock ''Choose next block Randomize ''NextBlock = Int((4 * Rnd) + 1) NextBlock = 1 ''Show next block in picture box Select Case NextBlock Case 1: picNext.Picture = LoadPicture(App.Path + "\graphics\1.bmp") Case 2: picNext.Picture = LoadPicture(App.Path + "\graphics\2.bmp") Case 3: picNext.Picture = LoadPicture(App.Path + "\graphics\3.bmp") Case 4: picNext.Picture = LoadPicture(App.Path + "\graphics\4.bmp") End Select Select Case BlockType Case 1: Call Start1 ''Start the revelent function for the block which has been chosen ''Case 2: Call start2 ''Case 3: Call start3 ''Case 4: Call start4 End Select End Function Public Function Start1() ''For line shaped block StartBlock = 232 ''Show the block in starting posistion block(StartBlock).Picture = LoadPicture(App.Path + "\graphics\green.bmp") block(StartBlock + 1).Picture = LoadPicture(App.Path + "\graphics\red.bmp") block(StartBlock + 2).Picture = LoadPicture(App.Path + "\graphics\pink.bmp") block(StartBlock + 3).Picture = LoadPicture(App.Path + "\graphics\yellow.bmp") Timer1.Enabled = True End Function Private Sub Form_Load() Randomize ''NextBlock = Int((4 * Rnd) + 1) NextBlock = 1 End Sub Private Sub Timer1_Timer() On Error GoTo Error341 Go = Go + 1 Call CheckCollide Go = Go - 1 block(StartBlock - (Go * 12)).Picture = LoadPicture("") block(StartBlock - (Go * 12) + 1).Picture = LoadPicture("") block(StartBlock - (Go * 12) + 2).Picture = LoadPicture("") block(StartBlock - (Go * 12) + 3).Picture = LoadPicture("") Go = Go + 1 block(StartBlock - (Go * 12)).Picture = LoadPicture(App.Path + "\graphics\green.bmp") block(StartBlock - (Go * 12) + 1).Picture = LoadPicture(App.Path + "\graphics\red.bmp") block(StartBlock - (Go * 12) + 2).Picture = LoadPicture(App.Path + "\graphics\pink.bmp") block(StartBlock - (Go * 12) + 3).Picture = LoadPicture(App.Path + "\graphics\yellow.bmp") Error341: If Err.Number = 341 Then Go = Go - 1 block(StartBlock - (Go * 12)).Picture = LoadPicture(App.Path + "\graphics\green.bmp") block(StartBlock - (Go * 12) + 1).Picture = LoadPicture(App.Path + "\graphics\red.bmp") block(StartBlock - (Go * 12) + 2).Picture = LoadPicture(App.Path + "\graphics\pink.bmp") block(StartBlock - (Go * 12) + 3).Picture = LoadPicture(App.Path + "\graphics\yellow.bmp") Timer1.Enabled = False Call Start End If End Sub Public Function CheckCollide() If Not (block(StartBlock - (Go * 12)).Picture = LoadPicture("")) Or Not (block(StartBlock - (Go * 12) + 1).Picture = LoadPicture("")) Or Not (block(StartBlock - (Go * 12) + 2).Picture = LoadPicture("")) Or Not (block(StartBlock - (Go * 12) + 3).Picture = LoadPicture("")) Then Timer1.Enabled = False Call Start End If End Function
Kylotan
Kylotan
Sorry, but I can''t work out what the actual problem in your code is. I''m not too good at reading VB code these days. I can tell you, however, that you shouldn''t use Randomize every time you call Rnd. Instead, you should just use Randomize once, preferably at the start of the program. You have it in Form_Load, and that is enough.

One other hint to clean up the program:

Don''t use these 3 lines:
Go = Go + 1
Call CheckCollide
Go = Go - 1

This confuse the meaning of the function, and make it seem like you really want to move things up and down. I assume you actually just need Go incremented for the purposes of the CheckCollide function... so why not just use Go+1 in the CheckCollide function, and remove both the lines above that change Go?

I can''t really give much more advice... I think the program flow needs some work as it isn''t very structured... in other words, just like my BASIC was when I was 13 I know it''s tedious, but try working out the program flow on paper, as sometimes it''s easier to see the errors there. Good luck.
Jumpster
Jumpster
I can think of one thing. Instead of loading those 8 files several times per frame, just load them once into a global value. Has to be faster than calling LoadPicture() What, at least 4 times per loop?

Regards,
Jumpster
Regards,JumpsterSemper Fi

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.