Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Blitz => Topic started by: lilw4t3rdr0p on October 27, 2006
-
Okay, Here is my very first attemp at Blitz Basic.
Does the code look right? Is there anything missing? Anything I don't need?
I tried to have some shapes, movement, color, text, random, and I tried to work with spacing (getting things visually pleasing).
This is only from my third lesson, so be kind!
Any feedback would be great!
Thanks.
Here you go:
Graphics 640,480,32,3
SetBuffer BackBuffer()
While Not KeyDown(1)
Color 222, 0, 0
Text (242),(228),"My Love!"
Color 0, 200, 15
Text (64), (194), "You Make My Dreams Come True."
Color 75, 75, 230
Text (262), (262), "With Love, Tracy!"
Color 178, 178, 10
Text Rnd (180), (100), "Whoo!"
VWait
Color 178, 178, 10
Text Rnd (460), (362), "Yay!"
VWait
Color 225, 25, 225
Rect 95, 42, 20, 20
Color 225, 25, 255
Oval 237, 420, 20, 20
Flip
Cls
Wend
Edit - [ Code ] tags added.
-
Not bad at all, and welldone. The only thing I'd mention, is that it's not neccassary to have brackets around the positons of the text.
You can also substitute the 32 for a 0 if you wanted to, so the the program automatically finds a colour bit depth. But I generally use 32bit as colours can look naff.
Btw, Use 2 for Windowed mode, rather then 3 as that is for a custom scaled window size that isnt generally recognized. For example
Graphics 128,128,32,3.
Graphics 640,480,32,2
SetBuffer BackBuffer()
While Not KeyDown(1)
Color 222, 0, 0
Text 242,228,"My Love!"
Color 0, 200, 15
Text 64, 194, "You Make My Dreams Come True."
Color 75, 75, 230
Text 262, 262, "With Love, Tracy!"
Color 178, 178, 10
Text Rnd (180), 100, "Whoo!"
VWait
Color 178, 178, 10
Text Rnd (460), 362, "Yay!"
VWait
Color 225, 25, 225
Rect 95, 42, 20, 20
Color 225, 25, 255
Oval 237, 420, 20, 20
Flip
Cls
Wend
-
Thank Clyde.
Is the code tag something I can add and if so... how do I do it?
-
Nice one lilw4t3rdr0p :)
How about add a text scroller ? 8)
-
I haven't learned that yet. I think that may be coming next.
Thank you.
-
As he is doing RND dont he need the brackets ?
Text Rnd (180), (100), "Whoo!"
-
Yep Codeman, you're right.
Blame me for it, I taught her to do it that way :)
Thanks for the mushy message Tracy, it's a great start. Well done!
-
Thanks!
I try!
-
Have to get you doing starfields and scrollers next.
-
Sounds good to me!
-
Code tags are part of the ways you can format your topics / replies; you'll see a list of these by not doing a Quick Reply.
You do need the brackets for using Rand / Rnd, that is correct but as the y position isn't random then there is no need to include them.
;
; As In Original Program. Notice Y is not a random position.
;
Text Rnd (180), (100), "Whoo!"
;
; Altered.
;
Text Rnd (180), 100, "Whoo!"
A Few Tips:
Both the following commands are used for producing a Random number, but with slight differences.
Rnd is for floating point variables # ( numbers with decimal points )
Rand is for integers % ( for example 2, 50, 120 etc - whole numbers )
Also you can have 2 ranges in these commands for example Rand (120,240) which will give a random number between 120 and 240.
-
Thanks Clyde.
I will try that!
-
No worries LDW :) glad to help where I can.
All the best,
Clyde.
-
nice first progy lilw4t3rdr0p,
im sure youll get on full terms with blitz in no time then you can show us how its done ;)
-
Thanks! That is my plan! :D
-
Okay, So here is my next step. (intergers and Varibles next)
But it won't run. It says Font not found. So my question is how do I know what fonts Blitz will and will not run?
-
Blitz will be able to use any fonts you have installed on your computer..
Why not post the offending bit of code and we'll sort the bug out for you.
-
Thanks!
Graphics 640,480,32,2
SetBuffer BackBuffer()
While Not KeyDown(1)
LF = LoadFont ("Veranda", 20, True, False, False)
LF = LoadFont ("Times New Roman", 24, False, False, True)
LF = LoadFont ("Arial", 16, True, False, True)
SETFONT LF1
Color 222, 0, 0
Text 242, 228,"I love You!"
SETFONT LF2
Color 0, 200, 15
Text 64, 194, "You Make My Dreams Come True."
SETFONT LF3
Color 75, 75, 230
Text 262, 262, "Thank You!"
Color 178, 178, 10
Text Rnd (180), 100, "DBF/GVY!"
VWait
Color 178, 178, 10
Text Rnd (460), (362), "WHOO!"
VWait
Color 225, 25, 225
Rect 95, 42, 20, 20
Color 225, 25, 255
Oval 237, 420, 20, 20
Flip
Cls
Wend
-
Graphics 640,480,32,2
SetBuffer BackBuffer()
While Not KeyDown(1)
LF1 = LoadFont ("Verdana", 20, True, False, False)
LF2 = LoadFont ("Times New Roman", 24, False, False, True)
LF3 = LoadFont ("Arial", 16, True, False, True)
SetFont LF1
Color 222, 0, 0
Text 242, 228,"I love You!"
SetFont LF2
Color 0, 200, 15
Text 64, 194, "You Make My Dreams Come True."
SetFont LF3
Color 75, 75, 230
Text 262, 262, "Thank You!"
Color 178, 178, 10
Text Rnd (180), 100, "DBF/GVY!"
VWait
Color 178, 178, 10
Text Rnd (460), (362), "WHOO!"
VWait
Color 225, 25, 225
Rect 95, 42, 20, 20
Color 225, 25, 255
Oval 237, 420, 20, 20
Flip
Cls
Wend
Fixed :)
Your variables were wrong and you'd tried to load a font called Veranda!
-
I see where I was wrong and I am a dork! Thank you!
-
Also I wouldnt have the fonts loaded each time in the main loop.
-
So you mean to put them before the while not keydown?
-
Yes mate. Otherwize they are always being loaded during the loop.
-
Okay, Thanks a lot!
-
Why didn't I see that? Doh!
-
I think you were preoccupied! :)
Thanks for all your help. I will work on it some more today!
-
Here is the code after some changes and the tutorial.
I tried to change the speed on the Shapes and the random words, but could not get it to work.
Maybe I have not covered that yet.
Any suggestions or feedback would be great. Thanks.
; First Attempt
; By Lilw4t3rdr0p
; Open Screen
; X size, Y size, Bit depth, mode
Graphics 640,480,32,2
; Setbuffer
SetBuffer BackBuffer()
; Load fonts ("font", size, bold, italics, underline)
LF1 = LoadFont ("Batang", 20, True, False, False)
LF2 = LoadFont ("Chaucer", 24, False, False, True)
LF3 = LoadFont ("Cotillion", 22, True, False, True)
; Load varible
XPOS = 0
; Load Speed
Speed = 3
; Wait for Keypress
While Not KeyDown(1)
; Set font
SetFont LF1
; Set color
Color 222, 0, 0
; Command
Text XPOS, 242, "I love You!"
; Set varible
XPOS=XPOS+SPEED
; Set reverse
If XPOS> 640 Then SPEED = -2
If XPOS< 0 Then SPEED = 2
; Set font
SetFont LF2
; Set color
Color 0, 200, 15
; Command
Text 64, 194, "You Make My Dreams Come True."
; Set font
SetFont LF3
; Set color
Color 75, 75, 230
; Command
Text 262, 282, "Thank You!"
; Set color
Color 178, 178, 10
; Set command (text) (movement)
Text Rnd (180), 100, "DBF/GVY!"
; Set color
Color 178, 178, 10
; Command (text) (movement)
Text Rnd (460), 362, "WHOO!"
; Set color
Color 200, 200, 200
; Command (shape) (movement)
Rect Rnd (95), 42, 20, 20
; Set color
Color 225, 25, 255
; Command (shape) (movement)
Oval Rnd (237), 420, 20, 20
; Set color
Color 215, 50, 50
; Command (shape) (movement)
Oval Rnd (95), 42, 20, 20
; Set color
Color 25, 255, 255
; Command (shape) (movement)
Rect Rnd (237), 420, 20, 20
If XPOS> 640 Then SPEED = -2
If XPOS< 0 Then SPEED = 2
; Set to flip from logical to physical
Flip
; Set to slow (refresh)
VWait
; Close loop
Cls
; Start loop over (go back to the top)
Wend
-
First thing I spotted is that you are changing PosX twice in the loop.
Are you trying to get the shapes to move differently from the text? If so you will need another variable, perhaps something like PosX2
One other tip, its great you are commenting your code, to further help out you can press Tab to format parts of the program better.
; First Attempt
; By Lilw4t3rdr0p
;
; Open Screen:- Screen Width, Screen Height, Colour Bit depth, mode.
;
Graphics 640,480,32,2
SetBuffer BackBuffer()
;
; Load fonts ("font", size, bold, italics, underline)
;
LF1 = LoadFont ("Batang", 20, True, False, False)
LF2 = LoadFont ("Chaucer", 24, False, False, True)
LF3 = LoadFont ("Cotillion", 22, True, False, True)
;
; Setup variables.
;
XPOS = 0
Speed = 3; Load Speed
; Wait for Keypress
While Not KeyDown(1)
SetFont LF1 ; Set to use LF1 font
Color 222, 0, 0 ; Set color
Text XPOS, 242, "I love You!" ; Print x,y,text
;
; Increment speed.
;
XPOS=XPOS+SPEED
;
; Check Direction.
;
If XPOS> 640 Then SPEED = -2
If XPOS< 0 Then SPEED = 2
SetFont LF2 ; Set font
Color 0, 200, 15 ; Set color
Text 64, 194, "You Make My Dreams Come True." ; Print Text
SetFont LF3 ; Set font
Color 75, 75, 230 ; Set color
Text 262, 282, "Thank You!" ; Print Text
Color 178, 178, 10 ; Set color
Text Rnd (180), 100, "DBF/GVY!"
Color 178, 178, 10 ; Set color
Text Rnd (460), 362, "WHOO!" ; Print Text at Random X Position.
Color 200, 200, 200 ; Set color
Rect Rnd (95), 42, 20, 20 ; Command (shape) (movement)
Color 225, 25, 255 ; Set color
Oval Rnd (237), 420, 20, 20 ; Command (shape) (movement)
Color 215, 50, 50 ; Set color
Oval Rnd (95), 42, 20, 20 ; Command (shape) (movement)
Color 25, 255, 255 ; Set color
Rect Rnd (237), 420, 20, 20 ; Command (shape) (movement)
;If XPOS> 640 Then SPEED = -2
;'If XPOS< 0 Then SPEED = 2
Flip
VWait
Cls
Wend
-
So can I set more then one speed.
Like a different speed for each shape and text?
Set them like this:
Speed1 = 2
Speed2 = 4
Speed3 = 6
etc?
Command:
XPOS=XPOS1 ?
And (I may not be here yet) but how do I make them move vertically?
Thanks for the above comments. Very helpful.
-
Y_pos variables ? :)
remember;
Text X , Y , "TEXT"
:)
-
For different speeds depending on the variable name it'll be something like this mate.
And did you know that the types of variables you are using are often called Local.
XPos1=XPos1+SpeedX1
XPos2=XPos2+SpeedX2
..etc
YPos1=YPos1+SpeedY1
YPos2=YPos2+SpeedY2
Btw, as a general rule that I use, I try not to use all capitals for Variable names, unless they are declared as Const ( constant: variables that stay the same through out )
For example, seeing as the Resolution of the Screen is going to be the same throughout and wont ever change.
You can have something like this.
Const ScreenHeight=640
Const ScreenWidth=480
Graphics ScreenHeight, ScreenWidth,32,2
-
Hmmm. Interesting. Makes sense. Okay. Thanks.
-
Do I use the same idea to change the speed of the shapes?
The new additions to the code and I are not friends. I will try some more and if I can't get it myself, then I will post for suggestions.
:)
-
Definitely a karma moment posting your first program!
-
@LWD: Yes dude if you like you can use the very same mate.