Blitz Plus

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Which is better, Blitz (Not Blitz Plus FOOL!) or Quick Basic?

Blitz
4
67%
Quick Basic
1
17%
Hamm Sammich (For all of you know-nothings!)
1
17%
 
Total votes: 6

User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Post by Falco Girgis »

640 x 640 screen
You do realize that resolution is probably impossible in Blitz, right? I don't think you know what you're talking about....
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

A "Type" is simply a group of variables with the ability to make new groups with one command, hence, more bullets. Such types are declared as follows:

Code: Select all

Type "Name Of Type"
	Field "All Variables That Make Up This Type"
End Type
Replace everything in quotes with your stuff.

An example of a simple bullet type would be like this.

Code: Select all

Type Bullet
	Field Bulletx,Bullety,BulletxVelocity,BulletyVelocity
End Type
Types are useless until you create them. To create a single type, do this:

Code: Select all

Global SpecialBullet.Bullet = New Bullet
Now, you can access the varibles in that created type like so:

Code: Select all

SpecialBullet\Bulletx = 20
SpecialBullet\Bullety = 15
SpecialBullet\BulletxVelocity = 5 ;and so on...
But this way of creating types is not so great when it comes to things like bullets. For this, we require functions, so I will brief them first.

Functions:
Consider a "Function" as a seperate block of code that can be called apon at any time. You can pass variables to them, and return values back to where you called it (They return to the line that called them). Examples will help more:

Code: Select all

Function SayHi()
	Text 0,0,"Hello?"
End Function
Now, anytime you type "SayHi()", the text "Hello?" will be put at coords. 0,0. This function is a bit limited, so lets pass arguments to it.

Code: Select all

Function SayHi(xPosition,yPosition)
	Text xPosition,yPosition,"Hello?"
End Function
This means, we can type...

Code: Select all

SayHi(25,74)
And the text "Hello?" will be placed at those coords.

Now you should have a pretty good understanding of functions, so lets use them for bullets.

I'm going to use a less complicated example to keep code small. Begin with the usuall setup:

Code: Select all

;Bullet Demo by JS Lemming

;Set graphics mode
Graphics 640,480

;Set buffer to backbuffer
SetBuffer BackBuffer()

;Declare our Bullet Type (only has 2 variables)
Type Bullet
	Field Bulletx,Bullety
End Type

;Create a variable to hold the player's y position
Global PlayerY = 200

;While the user doesn't press the ESC key...
While Not KeyDown(1)

	;Clear the screen
	Cls

	;Goto function for key input
	UserInput()

	;This one moves the bullets
	UpdateBullets()
	
	;Now, it is time to draw the bullets
	DrawBullets()

	;Draw the player as a green oval
	Color 0,255,0
	Oval 5,PlayerY,50,50,1

	;Flip screen into view
	Flip

Wend


;This function will create a bullet type when called
Function CreateBullet()

	;Create the type
	Bullet.Bullet = New Bullet
	
	;Set Bulletx to 20
	Bullet\Bulletx = 20
	
	;Set Bullety to equal player's current y position
	Bullet\Bullety = PlayerY + 20
		;I added 25 to PlayerY so the bullet is centered with green boy

End Function


;This function updates the bullets' position
Function UpdateBullets()

	;For this, we must LOOP through every bullet that we
	;  have created so far
	For Current.Bullet = Each Bullet
	
		;Add 8 to each bullet's x
		Current\Bulletx = Current\Bulletx + 8

	Next

End Function


;This function loops through each bullet and draws them in there
;   correct position
Function DrawBullets()

	For Current.Bullet = Each Bullet
	
		;Turn color to red
		Color 255,0,0
	
		;Draw a rectangle to represent the bullet
		Rect Current\Bulletx,Current\Bullety,20,10,1

	Next

End Function


;This function deals with key input from the user
Function UserInput()

	;See if user is pressing up or down keys, and more player accordingly
	If KeyDown(200) Then PlayerY = PlayerY - 3
	If KeyDown(208) Then PlayerY = PlayerY + 3
	
	;See if user pressed the space bar, if so, create a bullet
	If KeyHit(57) Then CreateBullet()
		;Cange this to KeyDown(57) for rapid fire!

End Function
Just read that carefully, it should explain everything so that you can develope it farther into your game.

As for saving, I would use a function like:

Code: Select all

Function SaveGame()
	Print "Auto Saving....." 
	fileout = WriteFile("gameinfo.tcr") 
	WriteString( fileout, name$ ) 
	WriteString( fileout, gender$ ) 
	WriteString( fileout, age ) 
	WriteString( fileout, strength ) 
	WriteString( fileout, speed ) 
	WriteString( fileout, defence )     
	WriteString( fileout, health ) 
	WriteString( fileout, status$ ) 
	CloseFile( fileout ) 

	For i = 0 to 6
		Write "." 
		Delay 500
	Next

	Print "Save Complete." 
	Delay 5000 
End Function
Hope that answers some of your questions. Post if you run into problems.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Guest

Post by Guest »

We can all learn from our mistakes! - First grade teacher
I remembered that before I emptied my trash can with my first graphical program in it. Maybe I can learn from this piece of sh*t.....

Can ANYONE here help me debug this whole thing? It gives me so many errors, I don't even know when to start!
Hope that answers some of your questions. Post if you run into problems.
I doubt you'd think I'd have THIS many problems, but here's my code:

Code: Select all

; Marcel's attempted two player shooter


; enables graphics mode
Graphics 640,480 

; sets charactor's life
Global Playeronelife=3
Global Playertwolife=3

; repeat the below
Repeat

; if your hit by a bullet, take a life
If playeroneBullety=playeroneY Then
playeronelife-1
EndIf
If playertwoBullety=playertwoY Then
playertwolife-1
EndIf


;if you don't have any more lives, you loose, and program ends
If playeronelife=0 Then
Cls
Print 320,240 "Red, YOU SUCK!You LOOSE!"
Delay 5000
Cls
Print 320,240 "GAME OVER"
Print 320,245 "Blue wins!
Delay 10000
End
EndIf

If playertwolife=0 Then
Cls
Print 320,240 "Blue, YOU SUCK!You LOOSE!"
Delay 5000
Cls
Print 320,240 "GAME OVER"
Print 320,245 "RED wins!
Delay 10000
End
EndIf

; repeats the above forever
Forever

; allows you to walk off the top of the screen and appear on the bottom
If playeroneY > 640
	playeroneY = 0
ElseIf playeroneY < 0
	playeroneY = 640
EndIf


If playertwoY > 640
	playertwoY = 0
ElseIf playertwoY < 0
	playertwoY = 640
EndIf

; generates a buffer
SetBuffer BackBuffer() 

; types
Type playeroneBullet
Field playeroneBulletx,playeroneBullety 
End Type 
Type playertwoBullet
Field playertwoBulletx,playertwoBullety 
End Type 
Type playerone
	Field x,y
End Type
Type playertwo
	Field x,y
End Type

; sets your Y coordinations
PlayeroneY = 200 
PlayertwoY = 200 

; while esc isn't being held
While Not KeyDown(1) 

; clear the screen
Cls

; loads all required images
Global playerone = LoadImage("playerone.bmp")
Global playertwo = LoadImage("playertwo.bmp")
Global bulletone = LoadImage("playeronebullet.bmp")
Global bullettwo = LoadImage("playertwobullet.bmp")

; does these functions
UseroneInput() 
UpdateplayeroneBullets() 
DrawplayeroneBullets() 
UsertwoInput() 
UpdateplayertwoBullets() 
DrawplayertwoBullets() 


; draws playerone and two

DrawImage(playerone, playeroneY, 5)
DrawImage(playertwo, playertwoY, 475)


; flip screen into view
Flip 

Wend 
; _________________________Player ONE Functions_________________
Function CreateBulletone() 
playeroneBullet.playeroneBullet = New playeroneBullet
playeroneBullet\playeroneBulletx = 20
playeroneBullet\playeroneBullety = PlayeroneY + 10 
End Function 
 

Function UpdatePlayeroneBullets() 
For Current.Bulletone = Each Bulletone
Current\Bulletonex = Current\Bulletonex + 8 
Next 
End Function 

Function DrawPLayeroneBullets() 
For Current.playeroneBullet = Each playeroneBullet
DrawImage(playeronebullet, playeroneBullet\playeroneBullety,playeroneBullet\playeroneBulletx)
End Function 

Function UseroneInput() 
If KeyDown(200) Then PlayeroneY = PlayeroneY - 3 
If KeyDown(208) Then PlayeroneY = PlayeroneY + 3 
If KeyHit(203) Then CreateplayeroneBullet() 
End Function 
; __________________Player TWO Functions_______________________
Function CreateBulletone() 
playertwoBullet.playertwoBullet = New playertwoBullet
playertwoBullet\playertwoBulletx = 460
playertwoBullet\playertwoBullety = PlayertwoY - 10 
End Function 
 

Function UpdatePlayertwoBullets() 
For Current.playertwoBullet = Each playertwoBullet
Current\playertwoBulletx = Current\playertwoBulletx - 8 
Next 
End Function 

Function DrawPLayertwoBullets() 
For Current.playertwoBullet = Each playertwoBullet
DrawImage(playertwobullet, playertwoBullet\playertwoBullety,playertwoBullet\playertwoBulletx)
End Function 

Function UsertwoInput() 
If KeyDown(30) Then PlayertwoY = PlayertwoY - 3 
If KeyDown(31) Then PlayertwoY = PlayertwoY + 3 
If KeyHit(57) Then CreateplayertwoBullet() 
End Function 
If that code doesn't have the most errors ever, what does? Please, someone, help me fix it!
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Hmm... The first problem i see here is Print. Print is a console only function, Do no use it graphicly. Instead, use Text. So this line...

Code: Select all

Print 320,240 "Red, YOU SUCK!You LOOSE!"
Should be :

Code: Select all

Text 320,240,"Red, YOU SUCK!You LOOSE!"
All arguments must be separated by commas, not spaces.

You can only globalize variables and such at the beginining of a program, not in a function or loop. Also the code:

Code: Select all

; while esc isn't being held 
While Not KeyDown(1) 

; clear the screen 
Cls 

; loads all required images 
Global playerone = LoadImage("playerone.bmp") 
Global playertwo = LoadImage("playertwo.bmp") 
Global bulletone = LoadImage("playeronebullet.bmp") 
Global bullettwo = LoadImage("playertwobullet.bmp") 

; does these functions 
UseroneInput() 
UpdateplayeroneBullets() 
DrawplayeroneBullets() 
UsertwoInput() 
UpdateplayertwoBullets() 
DrawplayertwoBullets() 


; draws playerone and two 

DrawImage(playerone, playeroneY, 5) 
DrawImage(playertwo, playertwoY, 475) 


; flip screen into view 
Flip 

Wend 
NEVER load an image in a loop. This is loading the images into memory 30 times a second. Destroying any signs of memory for your poor computer. :cry: Also, you must end a "for" loop with the next command.

Might I suggest using Tabs to organize your code better. Compare the following code, and see which one is easier to follow:

Code: Select all

If PlayerX > 40 and PlayerX + 15 < 40
PlayerX = PlayerX * 2
If Score < 50
text 0,0,"You Stink"
endif
for i=0 to 75
PlayerY = PlayerY + 6
if PlayerY < i
text 0,0,"You loose!"
endif
next
endif
Compared to:

Code: Select all

If PlayerX > 40 And PlayerX + 15 < 40
	PlayerX = PlayerX * 2
	
	If Score < 50
		Text 0,0,"You Stink"
	EndIf
	
	For i=0 To 75
		PlayerY = PlayerY + 6
		
		If PlayerY < i
			Text 0,0,"You loose!"
		EndIf	
	Next
EndIf
You cannot have 2 functions with the same name: CreateBulletone().
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Guest

Post by Guest »

Thank you JS lemming! I was able to debug the whole thing all because of you! :kissing:
Guest

Post by Guest »

Hey......I have ANOTHER problem.....Everyone time I run the program, it starts loading, then just ends. This was the final code, and I cannot find any other problems....

Code: Select all

; enables graphics mode
Graphics 640,480 
; sets charactor's life
Global Playeronelife=3
Global Playertwolife=3

; repeat the below
Repeat

; if your hit by a bullet, take a life
If playeroneBullety=playeroneY Then
Playeronelife=Playeronelife-1
EndIf
If playertwoBullety=playertwoY Then
Playertwolife=Playertwolife-1
EndIf


;if you don't have any more lives, you loose, and program ends
If playeronelife=0 Then
Cls
Text 320,240, "Red, YOU SUCK!You LOOSE!"
Delay 5000
Cls
Text 320,240, "GAME OVER"
Text 320,245, "Blue wins!
Delay 10000
End
EndIf

If playertwolife=0 Then
Cls
Text 320,240, "Blue, YOU SUCK!You LOOSE!"
Delay 5000
Cls
Text 320,240, "GAME OVER"
Text 320,245, "RED wins!
Delay 10000
End
EndIf

; repeats the above forever
Forever

; allows you to walk off the top of the screen and appear on the bottom
If playeroneY > 640
	playeroneY = 0
ElseIf playeroneY < 0
	playeroneY = 640
EndIf


If playertwoY > 640
	playertwoY = 0
ElseIf playertwoY < 0
	playertwoY = 640
EndIf

; generates a buffer
SetBuffer BackBuffer() 

; types
Type playeroneBullet
Field playeroneBulletx,playeroneBullety 
End Type 
Type playertwoBullet
Field playertwoBulletx,playertwoBullety 
End Type 
Type playerone
	Field x,y
End Type
Type playertwo
	Field x,y
End Type

; sets your Y coordinations
PlayeroneY = 200 
PlayertwoY = 200 

; loads all required images
Global playerone = LoadImage("playerone.bmp")
Global playertwo = LoadImage("playertwo.bmp")
Global bulletone = LoadImage("playeronebullet.bmp")
Global bullettwo = LoadImage("playertwobullet.bmp")

; while esc isn't being held
While Not KeyDown(1) 

; clear the screen
Cls


; does these functions
UseroneInput() 
UpdateplayeroneBullets() 
DrawplayeroneBullets() 
UsertwoInput() 
UpdateplayertwoBullets() 
DrawplayertwoBullets() 


; draws playerone and two

DrawImage(playerone, playeroneY, 5)
DrawImage(playertwo, playertwoY, 475)


; flip screen into view
Flip 

Wend 

; _________________________Player ONE Functions_________________
Function CreateplayeroneBullet() 
playeroneBullet.playeroneBullet = New playeroneBullet
playeroneBullet\playeroneBulletx = 20
playeroneBullet\playeroneBullety = PlayeroneY + 10 
End Function 
 

Function UpdatePlayeroneBullets() 
For Current.playeroneBullet = Each playeroneBullet
Current\playeroneBulletx = Current\playeroneBulletx + 8 
Next 
End Function 

Function DrawPlayeroneBullets() 
For Current.playeroneBullet = Each playeroneBullet
DrawImage(bulletone, playeroneBullety,playeroneBulletx)
Next
End Function 

Function UseroneInput() 
If KeyDown(200) Then PlayeroneY = PlayeroneY - 3 
If KeyDown(208) Then PlayeroneY = PlayeroneY + 3 
If KeyHit(203) Then CreateplayeroneBullet() 
End Function 
; __________________Player TWO Functions_______________________
Function CreateBullettwo() 
playertwoBullet.playertwoBullet = New playertwoBullet
playertwoBullet\playertwoBulletx = 460
playertwoBullet\playertwoBullety = PlayertwoY - 10 
End Function 
 

Function UpdatePlayertwoBullets() 
For Current.playertwoBullet = Each playertwoBullet
Current\playertwoBulletx = Current\playertwoBulletx - 8 
Next 
End Function 

Function DrawPLayertwoBullets() 
For Current.playertwoBullet = Each playertwoBullet
DrawImage(playertwobullet, playertwoBullety,playertwoBulletx)
Next
End Function 

Function UsertwoInput() 
If KeyDown(30) Then PlayertwoY = PlayertwoY - 3 
If KeyDown(31) Then PlayertwoY = PlayertwoY + 3 
If KeyHit(57) Then CreateBullettwo() 
End Function 
I promise I will use tabs to make it easier to read today. It's the least I can do after all the help you've given me.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Well, the thing is, you have alota stuff in the wrong place. Take this code for example:

Code: Select all

; repeat the below 
Repeat 

; if your hit by a bullet, take a life 
If playeroneBullety=playeroneY Then 
Playeronelife=Playeronelife-1 
EndIf 
If playertwoBullety=playertwoY Then 
Playertwolife=Playertwolife-1 
EndIf 


;if you don't have any more lives, you loose, and program ends 
If playeronelife=0 Then 
Cls 
Text 320,240, "Red, YOU SUCK!You LOOSE!" 
Delay 5000 
Cls 
Text 320,240, "GAME OVER" 
Text 320,245, "Blue wins! 
Delay 10000 
End 
EndIf 

If playertwolife=0 Then 
Cls 
Text 320,240, "Blue, YOU SUCK!You LOOSE!" 
Delay 5000 
Cls 
Text 320,240, "GAME OVER" 
Text 320,245, "RED wins! 
Delay 10000 
End 
EndIf 

; repeats the above forever 
Forever 
It seems you are checking if the player is out of life, before the actuall game even starts. I think that should go in the main game loop, along with all those other if statements about playery and such. Also, using CLS only clears the graphics buffer. You wrote...

Text 320,240, "Red, YOU SUCK!You LOOSE!"

...without fliping the screen into view.

I think I will try to recreate what you wanted to make, and note it well. Then you will see where stuff should go.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Hmm... this topic is getting kinda big, so I think i will make a new topic for this particular blitz talk thing.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Post Reply