gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
I have a question I thought I was having an error with my game but I am now thinking it is freezing cause it has to take the the time to load is there anyway I can stop this? |
Lazarus
Member
Posts: 1668
From: USA
Registered: 06-06-2006
|
You could try not running the game at all. Okay, I'm kidding. There's really no way you can stop it from taking a few seconds to load(if that is what is happening) - that's just how long it takes to load the program resources, I guess. |
Mene-Mene
Member
Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
|
Depends upon how big the game is, and the power of your computer. If its enormous, and your computer slow, not much you can do about this. Thats what some people mean when they talk about language speed sometimes. Ex. In some games, if there's minor tasks done everytime, to speed up the runtime they'll run it in say Assembly, while the other pieces in C++ because Assembly is faster. ------------------ MM out- Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice. "Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto |
samw3
Member
Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
|
You've need to explain a little more. A shot-in-the-dark answer to your general question would be for you to preload on start up. But, please explain more. ------------------ Sam Washburn |
gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
well what I am doing is I am working on my first real game it is space invaders and I am using b3d I am using text instead of pictures and when I shoot the bullet sometimes when the bullet gets to the end of the screen it freezes temporarily |
Mene-Mene
Member
Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
|
I'm pretty sure thats a bug. ------------------ MM out- Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice. "Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto |
samw3
Member
Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
|
Text doesn't really take any time to load. Its probably a loop problem. Can you post some code? ------------------ Sam Washburn |
gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
here is the code ;sets the screen size Graphics 800,600 ;sets the constants Const tank$ = "<*!*>" Const enemy$ = "<O> " Const bullet$ = "!" Const enemybullet$ = "o" ;the tank ;all the variables for the tank Type tank Field x,y Field tankstring$ End Type ;the bullet ;all the variables for the bullet Type bullet Field x,y Field bulletstring$ Field bullet Field move End Type Type enemy Field x,y Field hitcounter Field dx End Type Global ship.enemy = New enemy ship\x = 100 ship\y = 0 ship\dx = 1 Global player.tank = New tank Global playerbullet.bullet = New bullet ;starting position for tank player\x = 400 player\y = 550 player\tankstring$ = tank$ ;starting position for bullet playerbullet\bulletstring$ = bullet$ playerbullet\x = player\x + 16 playerbullet\y = player\y ;keeps the bullet in the right spot and stops it from shooting to many times playerbullet\bullet = 0 playerbullet\move = 0 ;the entire game is stored in this loop Dim alien$(1, 14) While Not KeyDown(1) Cls testinput() enemies() Text player\x, player\y, player\tankstring$ Repeat Cls enemies() testinput() ship\x = ship\x + ship\dx If ship\dx = -1 And ship\x <= 100 Then ship\dx = 1 EndIf Text player\x, player\y, player\tankstring$ Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$ Flip Until ship\x >= 200 Flip If ship\x >= 100 Then ship\y = ship\y + 12 ship\dx = 1 Flip EndIf If ship\x >= 200 Then ship\y = ship\y + 12 ship\dx = -1 Flip EndIf Flip Repeat Cls enemies() testinput() ship\x = ship\x + ship\dx Text player\x, player\y, player\tankstring$ Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$ Flip Until ship\x <= 100 If ship\x <= 100 Then ship\y = ship\y + 12 ship\dx = 1 Flip EndIf If ship\x <= 200 Then ship\y = ship\y + 12 ship\dx = -1 Flip EndIf Flip Wend Function testinput() If KeyHit(57) playerbullet\bullet = 1 playerbullet\move = 1 updatebullet() Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$ EndIf If KeyDown(203) ;moves the tank left player\x = player\x - 3 If player\x <= 0;stops the tank from going off screen player\x = 10 EndIf If playerbullet\move = 0 Then playerbullet\x = playerbullet\x - 3;moves the bullet left with the tank EndIf EndIf ;If player presses right, move him right. If KeyDown(205) ;moves the tank right;;;;;; player\x = player\x + 3;;;; If player\x >= 800;stops the tank from going off screen player\x = 790 EndIf If playerbullet\move = 0 Then playerbullet\x = playerbullet\x + 3; moves the bullet right with the tank EndIf EndIf End Function Function updatebullet() ;move the bullet While playerbullet\bullet = 1 Cls Repeat Text player\x, player\y, player\tankstring$ Cls If KeyHit(1) End EndIf testinput() enemies() If playerbullet\bullet = 1 Then If playerbullet\move = 1 Then Text player\x, player\y, player\tankstring$;prints the tank on the screen Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$;prints the bullet playerbullet\y = playerbullet\y - 3 If playerbullet\y <= 0 Then;determines whether the bullet goes off the screen ;sets the bullet back to the starting position playerbullet\y = player\y;;;;;;;;;;;;;;;;;;;;; playerbullet\x = player\x + 16;;;;;;;;;;;;;;;; playerbullet\bullet = 0;determines whether the bullet has been shot playerbullet\move = 0;determines whether to move the bullet with the tank EndIf EndIf EndIf If playerbullet\move = 0 Then playerbullet\y = player\y;;;;;;;;;;;;;;;;;;;;; playerbullet\x = player\x + 16;;;;;;;;;;;;;;;; Flip EndIf Flip ship\x = ship\x + ship\dx If ship\dx = -1 And ship\x <= 100 Then ship\dx = 1 EndIf Text player\x, player\y, player\tankstring$ Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$ Flip Until ship\x >= 200 Flip ;checks whether it has hit the side If ship\x >= 100 Then ship\y = ship\y + 12 ship\dx = 1 Flip EndIf ;checks whether it has hit the side If ship\x >= 200 Then ship\y = ship\y + 12 ship\dx = -1 Flip EndIf playerbullet\y = playerbullet\y + 3 Text player\x, player\y, player\tankstring$ Repeat Text player\x, player\y, player\tankstring$ Cls If KeyHit(1) End EndIf testinput() enemies() If playerbullet\bullet = 1 Then If playerbullet\move = 1 Then Text player\x, player\y, player\tankstring$;prints the tank on the screen Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$;prints the bullet playerbullet\y = playerbullet\y - 3 If playerbullet\y <= 0 Then;determines whether the bullet goes off the screen ;sets the bullet back to the starting position playerbullet\y = player\y;;;;;;;;;;;;;;;;;;;;; playerbullet\x = player\x + 16;;;;;;;;;;;;;;;; playerbullet\bullet = 0;determines whether the bullet has been shot playerbullet\move = 0;determines whether to move the bullet with the tank EndIf EndIf EndIf If playerbullet\move = 0 Then playerbullet\y= player\y;;;;;;;;;;;;;;;;;;;;; playerbullet\x = player\x + 16;;;;;;;;;;;;;;;; Flip EndIf Flip ship\x = ship\x + ship\dx Text player\x, player\y, player\tankstring$ Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$ Until ship\x <= 100 ;checks whether it has hit the side If ship\x <= 100 Then ship\y = ship\y + 12 ship\dx = 1 Flip EndIf ;checks whether it has hit the side If ship\x <= 200 Then ship\y = ship\y + 12 ship\dx = -1 Flip EndIf playerbullet\y = playerbullet\y + 3 Text player\x, player\y, player\tankstring$ If playerbullet\y <= 0 And playerbullet\y < 1 Then playerbullet\bullet = 0 EndIf Flip Text player\x, player\y, player\tankstring$ Wend End Function Function FindChar$(i) Locate ship\x,ship\y If i = 0 Locate ship\x,ship\y Return enemy$ EndIf End Function ;makes the enemies appear on screen Function enemies() Locate ship\x,ship\y For rows = 0 To 0 Locate ship\x,ship\y For columns = 0 To 14 Locate ship\x,ship\y alien$(rows,columns) = FindChar$(rows) Locate ship\x,ship\y Next Locate ship\x,ship\y Next Locate ship\x,ship\y For rows = 0 To 0 Locate ship\x,ship\y For columns = 0 To 14 Write alien$(rows,columns) Next Print "" Next Locate ship\x,ship\y + 12 For rows = 0 To 0 Locate ship\x,ship\y For columns = 0 To 14 Locate ship\x,ship\y alien$(rows,columns) = FindChar$(rows) Locate ship\x,ship\y Next Locate ship\x,ship\y Next Locate ship\x,ship\y For rows = 0 To 0 Locate ship\x,ship\y + 12 For columns = 0 To 14 Write alien$(rows,columns) Next Print "" Next For rows = 0 To 0 Locate ship\x,ship\y For columns = 0 To 14 Locate ship\x,ship\y alien$(rows,columns) = FindChar$(rows) Locate ship\x,ship\y Next Locate ship\x,ship\y Next Locate ship\x,ship\y For rows = 0 To 0 Locate ship\x,ship\y + 24 For columns = 0 To 14 Write alien$(rows,columns) Next Print "" NextEnd Function |
it won't copy and paste properly is there a place I can upload it? |
gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
or maybe it did |
samw3
Member
Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
|
Woah. that's a bunch of code to wade through. Did you write that all yourself, or are you running through a tutorial? Can you edit it down to just the portion that shoots the bullet and especially the part where the bullet hits the edge of the screen? ------------------ Sam Washburn |
gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
Function updatebullet() ;move the bullet While playerbullet\bullet = 1 Cls Repeat Text player\x, player\y, player\tankstring$ Cls If KeyHit(1) End EndIf testinput() enemies() If playerbullet\bullet = 1 Then If playerbullet\move = 1 Then Text player\x, player\y, player\tankstring$;prints the tank on the screen Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$;prints the bullet playerbullet\y = playerbullet\y - 3 If playerbullet\y <= 0 Then;determines whether the bullet goes off the screen ;sets the bullet back to the starting position playerbullet\y = player\y;;;;;;;;;;;;;;;;;;;;; playerbullet\x = player\x + 16;;;;;;;;;;;;;;;; playerbullet\bullet = 0;determines whether the bullet has been shot playerbullet\move = 0;determines whether to move the bullet with the tank EndIf EndIf EndIf If playerbullet\move = 0 Then playerbullet\y = player\y;;;;;;;;;;;;;;;;;;;;; playerbullet\x = player\x + 16;;;;;;;;;;;;;;;; Flip EndIf Flip ship\x = ship\x + ship\dx If ship\dx = -1 And ship\x <= 100 Then ship\dx = 1 EndIf Text player\x, player\y, player\tankstring$ Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$ Flip Until ship\x >= 200 Flip ;checks whether it has hit the side If ship\x >= 100 Then ship\y = ship\y + 12 ship\dx = 1 Flip EndIf ;checks whether it has hit the side If ship\x >= 200 Then ship\y = ship\y + 12 ship\dx = -1 Flip EndIf playerbullet\y = playerbullet\y + 3 Text player\x, player\y, player\tankstring$ Repeat Text player\x, player\y, player\tankstring$ Cls If KeyHit(1) End EndIf testinput() enemies() If playerbullet\bullet = 1 Then If playerbullet\move = 1 Then Text player\x, player\y, player\tankstring$;prints the tank on the screen Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$;prints the bullet playerbullet\y = playerbullet\y - 3 If playerbullet\y <= 0 Then;determines whether the bullet goes off the screen ;sets the bullet back to the starting position playerbullet\y = player\y;;;;;;;;;;;;;;;;;;;;; playerbullet\x = player\x + 16;;;;;;;;;;;;;;;; playerbullet\bullet = 0;determines whether the bullet has been shot playerbullet\move = 0;determines whether to move the bullet with the tank EndIf EndIf EndIf If playerbullet\move = 0 Then playerbullet\y= player\y;;;;;;;;;;;;;;;;;;;;; playerbullet\x = player\x + 16;;;;;;;;;;;;;;;; Flip EndIf Flip ship\x = ship\x + ship\dx Text player\x, player\y, player\tankstring$ Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$ Until ship\x <= 100 ;checks whether it has hit the side If ship\x <= 100 Then ship\y = ship\y + 12 ship\dx = 1 Flip EndIf ;checks whether it has hit the side If ship\x <= 200 Then ship\y = ship\y + 12 ship\dx = -1 Flip EndIf playerbullet\y = playerbullet\y + 3 Text player\x, player\y, player\tankstring$ If playerbullet\y <= 0 And playerbullet\y < 1 Then playerbullet\bullet = 0 EndIf Flip Text player\x, player\y, player\tankstring$ Wend End Function |
that is the updatebullet function and that function is called when the space bar is pressed I think I commented it if it needs to be commented more just tell me |
Lava
Member
Posts: 1905
From:
Registered: 01-26-2005
|
In Blitz it depends on what you're making the program do. If you make it do a whole bunch of things all at once it will freeze for a second. Like I was working on a 3D game and whenever a bullet would hit an object it would freeze before the meteor would destruct. Well I fixed it by shortening my code like samw3 said, because I had a collision mesh and various other things taking place all at once, now you're working in 2D, but I am sure it's the same princible ------------------
[This message has been edited by LAVA (edited January 25, 2007).] |
samw3
Member
Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
|
Ok, according to your code: If playerbullet\y <= 0 Then;determines whether the bullet goes off the screen ;sets the bullet back to the starting position but your loop says Repeat ... Until ship\x >= 200 Why are you waiting for the ships x coordinate to be greater than 200? Am I missing something? I guess the comments are a little sparse and general in this area. ------------------ Sam Washburn |
gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
the reason the loop says that is because it is for the aliens moving it go's left until it hits a certain spot I had to add it into the update bullet section it was the only way I could think of so that the enemies would keep moving while the bullet fired |
gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
maybe you can figure out a better way to do it |
Mene-Mene
Member
Posts: 1398
From: Fort Wayne, IN, USA
Registered: 10-23-2006
|
I noticed there is tons of "flip" commands. You should only need one. I started to rewrite it, but gave up. ------------------ MM out- Thought travels much faster than sound, it is better to think something twice, and say it once, than to think something once, and have to say it twice. "Frogs and Fauns! The tournament!" - Professor Winneynoodle/HanClinto |
gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
so maybe taking some flip commands out would help? |
samw3
Member
Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
|
I see.. its a creative solution, not to overly critique your code, but it also violates a programming principal called loose coupling. Another way to do it would be keep the loop outside of updatebullet() and have the updatedbullet() function only update one step of the bullet along its path. You see, the problem with the tight coupling you use here is that its very hard to follow which parts do what functionality, thus making it difficult to track down bugs like these. You have done a good job using functions like testinput(), but then you also use key hit outside of this function as well. I can't find your bug, maybe refactor this a bit an try a structure like this:
gameOver = false While Not gameOver testInput() ; each of these functions updates the player, enemies or bullets one step in game time updatePlayer() updateEnemies() updateBullets() Flip ; EDIT: this should be the one flip per mene-mene's advice Wend
|
This is just a structure of course, you will have to fill in the gaps with your refactored code. ------------------ Sam Washburn [This message has been edited by samw3 (edited January 25, 2007).] [This message has been edited by samw3 (edited January 25, 2007).] |
gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
I am taking some out but I still need more than one other wise the enemies zoom across the screen |
gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
why does it black out at times? |