Page 1 of 1

Trouble Using GET/PUT for simple shooter

Posted: Fri Dec 26, 2008 1:19 pm
by Kris
Hello, my name is Kris. I'm currently taking a QBasic high school course. It doesn't teach any graphics or gaming however, so I'm teaching myself that. For my first game, I'm trying to put crosshairs and a target on a black background and move the crosshairs to shoot the target. I can't get the crosshairs to move properly, though. After reading through the code over and over again, I have found a fixed several errors, and this has made it run better, but still not properly. The target is supposed to be missing at this point, as all I'm doing right now is testing the function of moving the crosshair and getting that to work. Would you mind taking a look and giving some advice? Thanks. I suspect the problem has to do with the GET/PUT combo.

[code]
SCREEN 13
WAIT &H3DA, 8
DIM crosshair(500)
DIM target(1000)
'Draw the starting position of the crosshair
x1 = 120
x2 = 130
x3 = 125
x4 = 125
y1 = 100
y2 = 100
y3 = 95
y4 = 105
LINE (x1, y1)-(x2, y2), 4 'Color it red Horizontal Line
LINE (x3, y3)-(x4, y4), 4 'Color it red Vertical Line
DO
WAIT &H3DA, 8
GET (x2, y4)-(x1, y3), crosshair 'I suspect the problem is with the GET and PUT statements
press$ = INKEY$
IF press$ = "q" THEN END
IF press$ = "a" THEN x1 = x1 - 10
IF press$ = "a" THEN x2 = x2 - 10
IF press$ = "a" THEN x3 = x3 - 10
IF press$ = "a" THEN x4 = x4 - 10
IF press$ = "s" THEN y1 = y1 + 10
IF press$ = "s" THEN y2 = y2 + 10
IF press$ = "s" THEN y3 = y3 + 10
IF press$ = "s" THEN y4 = y4 + 10
IF press$ = "d" THEN x1 = x1 + 10
IF press$ = "d" THEN x2 = x2 + 10
IF press$ = "d" THEN x3 = x3 + 10
IF press$ = "d" THEN x4 = x4 + 10
IF press$ = "w" THEN y1 = y1 - 10
IF press$ = "w" THEN y2 = y2 - 10
IF press$ = "w" THEN y3 = y3 - 10
IF press$ = "w" THEN y4 = y4 - 10
IF press$ = "w" THEN PUT (x4, y1), crosshair
IF press$ = "s" THEN PUT (x4, y1), crosshair
IF press$ = "d" THEN PUT (x4, y1), crosshair
IF press$ = "a" THEN PUT (x4, y1), crosshair
LOOP[/code]

Posted: Fri Dec 26, 2008 2:58 pm
by burger2227
1) You only have to GET the crosshair once as it does not change. If you re-get it, you are getting stuff you don't want. Like black background before it is PUT anyway.

2) You should save the old top left corner position to erase the previous PUT and then move to the new PUT position. When PUT has no options it is in XOR mode. So you can PUT the crosshairs back over the old position on a black background and erase the old position. Then PUT the new position. There also is a PSET option that can place images on any background.

3)You cannot go off the screen ONE pixel with GET or PUT. So you can only move right until any part of the GET area is off the screen. So you should limit the area to 300 - widthofimage - 1. Same thing for depth 200 in Screen 13. You will get an "Illegal Function" error.

Also you may want to use capital letters in case Caps Lock is on. To do that:

Code: Select all

press$ = UCASE$(INKEY$)
Then just make your IF statements all cap letters. You might wanna try Select Case too.

Ted

Thanks

Posted: Fri Dec 26, 2008 3:25 pm
by Kris
Thanks alot. The crosshair is working perfectly, now I need to get the target on there and moving. How do I put my game on the site, or should I make my own website for it(I plan on expanding the game alot once this basic part is working)?

Slow down a bit

Posted: Fri Dec 26, 2008 3:50 pm
by burger2227
You have a lot of work ahead. The target will be the next problem! When you PUT either over the other, you will erase or distort the colors of the other one. If you use the PSET option, one will be erased some.

Goto: www.QbasicStation.com

Look in member's files for 2 Demo's called QBG1 and QBG2. The QBG.EXE tutorial can show you how to make a mask for the images. This allows you to go over top of another image in the background.

Graphic Games can be difficult to make, so take your time! You can Upload your game there. If you want feedback put it in the "Needs Help" category after you sign up as a member. Don't make EXE files as nobody can see the code. Save your program as Text Readable when Saving it. Have fun!

Ted

mouse in Qb

Posted: Sat Jan 10, 2009 1:31 am
by iamdenteddisk
I would suggest downloading a example mouse program from petes called "inturuptx" it is the only working mouse I found to work with qb4.5 on windowsxp machines using intell processors... spend a day commenting the code it is worthwhile, you will be good from there add a fsecond and third inturupt to the program to read the buttons a slick sprite and you created a 2d shooter and even God games and if you want to eventualy create 3D games use the inturuptx code for the mouse driver and implement a good particle system there are plenty of resources online for all of this . most likely your only problem is the get/put routine you have is from a library which dont fully use your bios you just got to find one that will or use the get/put from inturuptx too which is pure qb no library required.....just an idea!