Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Programmer needs some help please =D

Status
Not open for further replies.

mpaone12

Technical User
Oct 15, 2000
13
US
hello everyone, i'm pretty new at programming (only 16 here) and i'm in my 2nd year in QBasic class in high school. my class is verrry boring and i tend to go ahead of my class a little. Anyways, this is a program that i've been messing around with, (it's obviously not done) and i was wondering if you guys could give me some tips or feedback or anything would be appreciated. i'm not familiar with any real graphics techniques, such as storing graphics in separate files or anything like that, but i just thought some of you guys might get a kick out of it, so here it is, try it out, tell me what you think. thanks alot =) -Mike (mpaone@mediaone.net)

DEFINT A-Z
COMMON SHARED z, scol, zshot, yshot, shot, radius, x, y, speed, sc, counter2
COMMON SHARED bc
DECLARE SUB fire ()
RANDOMIZE TIMER
SCREEN 12: CLS

shot = 0: bc = 1: radius = 5: speed = 5: boardshot = 0: sc = 1

DO

y = INT(RND * 400) + 1
r = INT(RND * 3) + 1
LINE (z + 320, 460)-(z + 20 + 320, 463), 12, BF 'board thing

SOUND 5000, 1

FOR x = 0 TO 650 STEP r

LOCATE 1, 10: PRINT "Speed ="; speed
LOCATE 2, 10: PRINT "bc ="; bc
LOCATE 3, 10: PRINT "yshot ="; yshot

mcol = INT(RND * 9) + 6

IF starcount < 100 THEN
xstar = INT(RND * 640)
ystar = INT(RND * 480) 'makes stars
chance = INT(RND * 10)
IF chance = 5 THEN
PSET (xstar, ystar), 1
starcount = starcount + 1
ELSE PSET (xstar, ystar), 0
END IF
END IF

counter = counter + 1
IF counter < 62 THEN
PALETTE 1, sc * 256 ^ 2 + sc * 256 + sc
sc = sc + 1
ELSE
PALETTE 1, sc * 256 ^ 2 + sc * 256 + sc
sc = sc - 1
END IF
IF counter > 123 THEN
counter = 0
sc = 1
END IF

LINE (x, y)-(x, y), 14 'missle thing
CIRCLE (x, y), 3, mcol
CIRCLE (x - r, y), 3, 0

FOR t = 1 TO 20000: NEXT t
FOR t = 1 TO 20000: NEXT t

key$ = INKEY$
IF key$ = CHR$(0) + CHR$(77) THEN
LINE (z + 320, 460)-(z + 20 + 320, 463), 0, BF
z = z + 10
LINE (z + 320, 460)-(z + 20 + 320, 463), 12, BF

ELSEIF key$ = CHR$(0) + CHR$(75) THEN
LINE (z + 320, 460)-(z + 20 + 320, 463), 0, BF
z = z - 10
LINE (z + 320, 460)-(z + 20 + 320, 463), 12, BF

ELSEIF key$ = &quot;x&quot; THEN
IF speed = 10 THEN speed = speed ELSE speed = speed + 1

ELSEIF key$ = &quot;z&quot; THEN
IF speed = 5 THEN speed = speed ELSE speed = speed - 1

ELSEIF shot = 0 THEN
IF key$ = CHR$(32) THEN
snd = INT(RND * 1000) + 400
SOUND snd, .5
shot = 1
boardshot = 1
END IF

END IF

IF shot = 1 THEN CALL fire

IF yshot > 440 THEN GOSUB shotsetback

LINE (0, y)-(x, y), 14 'redraw missle

NEXT x

LINE (0, y)-(x, y), 0 'erase missle

LOOP

shotsetback:
yshot = 0: shot = 0: zshot = 0: boardshot = 0
RETURN

'LOCATE 1, 50: PRINT &quot;x =&quot;; x
'LOCATE 2, 50: PRINT &quot;r =&quot;; r
'LOCATE 3, 50: PRINT &quot;z =&quot;; z
'LOCATE 4, 50: PRINT &quot;shot =&quot;; shot
'LOCATE 5, 50: PRINT &quot;zshot =&quot;; zshot
'LOCATE 6, 50: PRINT &quot;yshot =&quot;; yshot
'LOCATE 7, 50: PRINT &quot;y =&quot;; y
'LOCATE 8, 50: PRINT &quot;480 - y =&quot;; 480 - y

SUB fire

IF zshot = 0 THEN
zshot = z + 10 + 320
END IF

scol = 15

counter2 = counter2 + 1
IF counter2 < 62 THEN
PALETTE 12, 0 * 256 + 0 * 256 ^ 2 + bc
bc = bc + 1
ELSE
PALETTE 12, 0 * 256 + 0 * 256 ^ 2 + bc
bc = bc - 1
END IF
IF counter2 > 123 THEN
counter2 = 0
bc = 1
END IF

LINE (zshot - 5, 430 - yshot)-(zshot, 420 - yshot), 8
LINE (zshot, 420 - yshot)-(zshot + 5, 430 - yshot), 8
LINE (zshot + 5, 430 - yshot)-(zshot - 5, 430 - yshot), 8
PAINT (zshot, 422 - yshot), 15, 8

LINE (zshot - 5, 430 - yshot + speed)-(zshot, 420 - yshot + speed), 0
LINE (zshot, 420 - yshot + speed)-(zshot + 5, 430 - yshot + speed), 0
LINE (zshot + 5, 430 - yshot + speed)-(zshot - 5, 430 - yshot + speed), 0
PAINT (zshot, 422 - yshot + speed), 0, 0

radius = radius + 1
IF radius > 5 THEN radius = 1
yshot = yshot + speed

IF yshot + 40 < (480 - y) AND yshot + 50 > (480 - y) THEN
IF zshot > x - 10 AND zshot < x + 15 THEN
FOR q# = 1 TO 20 STEP .1
CIRCLE (x, y), q#, 12
NEXT q#
END IF
END IF

END SUB
 
Hey, Vietkong, that's pretty cool!
I had a hard time hitting the missle but I finally did.
Question: Why didn't the missle fall or explode after I hit it?

All you pros out there with your dreary APIs and SQLs and DSNs can relax now. You have just met the future... it is us....
VCA.gif

 
Vietkong,

I don't know if it was intentional or not (I only took a quick look-see) but the red bar fades for too long. Just like Alt255 I had a hard time hitting the rocket thing cause I couldn't line up the bar. Recommend that the bar have a seperate palette number--again I only took a quick look and I do know you're using screen 12 and it's limited to 16 colors, but the fading bar really is annoying.

On another note I would recommend you modifiy something:

LOCATE 3, 10: PRINT &quot;yshot =&quot;; yshot

change it to:

LOCATE 3, 10: PRINT &quot;yshot =&quot;; yshot; SPACE$(2)

Otherwise you'll still get &quot;yshot= 0 0&quot;. The previous number's last digit is still showing. But, all in all, it's not bad.

--MiggyD &quot;It's mind over matter. They don't mind so you don't matter to them.&quot;
 
hey everyone, thanks for the responses and tips. oh, yah..and the bar fading was just something i was messing around with. i'll have to add some scoring and theme and other things later on. lol, it's just my little thing i do when i get bored in class, hehe. thanks for the suggestion about the spacing too MiggyD. but there's one problem, i've tried to use another palette for the board, but it goes very slow when i have two palettes fading at the same time. any suggestions? thanks again all! X-)
 
vietkong,

My first suggestion is to make notations (REMs) in the code. I had a difficult time trying to figure out what is doing what, where it came from, etc, etc.

Anyway, here's some modifications to your code (THIS IS A SMALL PATCHED-UP UPDATE). Incase anyone else wants to see what it is. all my changes are in read.


DEFINT A-Z
COMMON SHARED z, scol, zshot, yshot, shot
COMMON SHARED radius, x, y, speed, sc, counter2
COMMON SHARED bc

DECLARE SUB fire ()
[red]DECLARE SUB StarField ()[/red]

RANDOMIZE TIMER
SCREEN 12
CLS

shot = 0: bc = 1: radius = 5: speed = 5: boardshot = 0: sc = 1

[red]'********************
'*** MAIN PROGRAM ***
'********************
[/red]DO
y = INT(RND * 400) + 1
r = INT(RND * 3) + 1

[red]'******* orig is rem'd out -- shooting bar is now green so won't fade
LINE (z + 320, 460)-(z + 20 + 320, 463), 2, BF 'board thing
'LINE (z + 320, 460)-(z + 20 + 320, 463), 12, BF 'board thing
'********************************************************************[/red]

SOUND 5000, 1

FOR x = 0 TO 650 STEP r
LOCATE 1, 10: PRINT &quot;Speed =&quot;; speed
LOCATE 2, 10: PRINT &quot;bc =&quot;; bc
LOCATE 3, 10: PRINT &quot;yshot =&quot;; yshot; [red]SPACE$(2);[/red]
mcol = INT(RND * 9) + 6

[red]'****** this loop is cluttering up readability of code
'****** so I've moved it to a sub named StarField and
'****** made the variables there static to the sub. It
'****** doesn't appear to slow down the display since
'****** you have CHANCE set to PSet on a hit of 5. What
'****** doest this mean?? It means you can delete the
'****** following REM'd lines, including MY REMARK lines.
'****** ---MIGGYD
CALL StarField
'IF starcount < 100 THEN 'makes stars
' xstar = INT(RND * 640)
' ystar = INT(RND * 480)
' chance = INT(RND * 10)
' IF chance = 5 THEN
' PSET (xstar, ystar), 1
' starcount = starcount + 1
' ELSE
' PSET (xstar, ystar), 0
' END IF
'END IF
'***************************************************[/red]

counter = counter + 1

IF counter < 62 THEN
PALETTE 1, sc * 256 ^ 2 + sc * 256 + sc
sc = sc + 1
ELSE
PALETTE 1, sc * 256 ^ 2 + sc * 256 + sc
sc = sc - 1
END IF

IF counter > 123 THEN
counter = 0
sc = 1
END IF

LINE (x, y)-(x, y), 14 [red]'comet trail[/red]
CIRCLE (x, y), 3, mcol [red]'comet body[/red]
CIRCLE (x - r, y), 3, 0

[red]'****** orig is rem'd out -- waisted keystroks
FOR t = 1 TO 40000: NEXT t
'FOR t = 1 TO 20000: NEXT t
'FOR t = 1 TO 20000: NEXT t
'*********************************************[/red]

key$ = INKEY$ [red]'main logic[/red]

IF key$ = CHR$(0) + CHR$(77) THEN
LINE (z + 320, 460)-(z + 20 + 320, 463), 0, BF
z = z + 10
[red]'******* orig is rem'd out -- bar is now green so won't fade
LINE (z + 320, 460)-(z + 20 + 320, 463), 2, BF
'LINE (z + 320, 460)-(z + 20 + 320, 463), 12, BF
'********************************************************************[/red]
ELSEIF key$ = CHR$(0) + CHR$(75) THEN
LINE (z + 320, 460)-(z + 20 + 320, 463), 0, BF
z = z - 10
[red]'******* orig is rem'd out -- shooting bar is now green so won't fade
LINE (z + 320, 460)-(z + 20 + 320, 463), 2, BF
'LINE (z + 320, 460)-(z + 20 + 320, 463), 12, BF
'********************************************************************[/red]
ELSEIF key$ = &quot;x&quot; THEN
IF speed = 10 THEN
speed = speed
ELSE
speed = speed + 1
END IF
ELSEIF key$ = &quot;z&quot; THEN
IF speed = 5 THEN
speed = speed
ELSE
speed = speed - 1
END IF
ELSEIF shot = 0 THEN
IF key$ = CHR$(32) THEN
snd = INT(RND * 1000) + 400
SOUND snd, .5
shot = 1
boardshot = 1
END IF
END IF

IF shot = 1 THEN CALL fire
IF yshot > 440 THEN GOSUB shotsetback
LINE (0, y)-(x, y), 14 [red]'redraw comet's trail[/red]
NEXT x
LINE (0, y)-(x, y), 0 [red]'erase comet's trail[/red]
LOOP

shotsetback:
yshot = 0: shot = 0: zshot = 0: boardshot = 0
RETURN


SUB fire

IF zshot = 0 THEN
zshot = z + 10 + 320
END IF

scol = 15
counter2 = counter2 + 1

IF counter2 < 62 THEN
PALETTE 12, 0 * 256 + 0 * 256 ^ 2 + bc
bc = bc + 1
ELSE
PALETTE 12, 0 * 256 + 0 * 256 ^ 2 + bc
bc = bc - 1
END IF
IF counter2 > 123 THEN
counter2 = 0
bc = 1
END IF

LINE (zshot - 5, 430 - yshot)-(zshot, 420 - yshot), 8
LINE (zshot, 420 - yshot)-(zshot + 5, 430 - yshot), 8
LINE (zshot + 5, 430 - yshot)-(zshot - 5, 430 - yshot), 8
PAINT (zshot, 422 - yshot), 15, 8

LINE (zshot - 5, 430 - yshot + speed)-(zshot, 420 - yshot + speed), 0
LINE (zshot, 420 - yshot + speed)-(zshot + 5, 430 - yshot + speed), 0
LINE (zshot + 5, 430 - yshot + speed)-(zshot - 5, 430 - yshot + speed), 0
PAINT (zshot, 422 - yshot + speed), 0, 0

radius = radius + 1
IF radius > 5 THEN radius = 1
yshot = yshot + speed

IF yshot + 40 < (480 - y) AND yshot + 50 > (480 - y) THEN
IF zshot > x - 10 AND zshot < x + 15 THEN
FOR q# = 1 TO 20 STEP .1
CIRCLE (x, y), q#, 12
[red]'********* ADD &quot;game over&quot; IF THERE'S A HIT
END
'*********************************[/red]
NEXT q#
END IF
END IF

END SUB


[red]DEFINT A-Z
SUB StarField STATIC

IF starcount < 100 THEN
xstar = INT(RND * 640)
ystar = INT(RND * 480) 'makes stars
chance = INT(RND * 10)
IF chance = 5 THEN
PSET (xstar, ystar), 1
starcount = starcount + 1
ELSE
PSET (xstar, ystar), 0
END IF
END IF

END SUB[/red]

&quot;It's mind over matter. They don't mind so you don't matter to them.&quot;
 
Here's the best I can give you using two PALETTEs. I do not particularly like graphics.

Please note, I've followed your example above with respects to code notations. I've only marked a few and left the rest for you to decypher--sometimes you ARE your own teacher. Enjoy! ...


SCREEN 12 'screen mode
CLS
DIM FadingWhite&(127), FadingRed&(127) 'create storage arrays to hold colors
FOR FadeIn = 0 TO 63 'a color thingy
FadingRed&(FadeIn) = FadeIn
FadingWhite&(64 + FadeIn) = 65536 * FadeIn + 256 * FadeIn + FadeIn
NEXT FadeIn
FOR FadeOut = 63 TO 0 STEP -1 'another color thingy
FadingRed&(127 - FadeOut) = FadeOut
FadingWhite&(63 - FadeOut) = 65536 * FadeOut + 256 * FadeOut + FadeOut
NEXT FadeOut

COLOR 7
PRINT &quot;This is the FadingWhite& variable -- text white&quot;: PRINT
COLOR 4
PRINT &quot;this is the FadingRed& Variable -- Text Red&quot;: PRINT
COLOR 2
PRINT &quot;press any key to exit&quot;
DO
FOR Cyc = 1 TO 126
IF INKEY$ <> &quot;&quot; THEN EXIT DO
PALETTE 4, FadingRed&(Cyc)
PALETTE 7, FadingWhite&(Cyc)
FOR SlowDown = 1 TO 3000
IF INKEY$ <> &quot;&quot; THEN EXIT DO
NEXT SlowDown
NEXT Cyc
LOOP WHILE INKEY$ = &quot;&quot;
FOR FadeAll = 63 TO 0 STEP -1
PALETTE 4, FadeAll
PALETTE 2, 256 * FadeAll
PALETTE 7, 65536 * FadeAll + 256 * FadeAll + FadeAll
FOR SlowDown = 1 TO 10000: NEXT SlowDown
NEXT FadeAll

SCREEN 0
END 'exit program


I hope this has helped you

-miggyD &quot;It's mind over matter. They don't mind so you don't matter to them.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top