Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mouse input/movement by numpad PROBLEMS
#11
well in qb4.5, well the version that i hav anyway the codes for the numpad are as follows:
1 - 4F
2 - 50
3 - 51
4 - 4B
5 - 4C
6 - 4D
7 - 47
8 - 48
9 - 49

so ya, if i input them like that, they dont work, if i input them as qb4.0 codes which are like 70-82 around there, in qb4.5, they become some of the letters

heres the code anyway
Code:
' A simple ball moving qbasic program
' ©2005 Jimmy Jones

DEFINT A-Z

SCREEN 13
CLS
'Draw a filled circle for our sprite
CIRCLE (4, 3), 4, 4
PAINT (4, 3), 12, 4

'Set aside enough space to hold the sprite
DIM ball%(37)

'Get the sprite into the ball% array .. before clearing the screen, doofus!
GET (0, 0)-(8, 7), ball%

' Clear the screen
CLS

' Set default ballx% and bally% coordinates 'coordinates ....
ballx% = 160
bally% = 100

' Set the ball to it's default location
PUT (ballx%, bally%), ball%
PRINT ballx%; bally%

DO
GOSUB getInput
IF nothingHappened% = 0 THEN GOSUB drawCircle
IF exitloop1% = 1 THEN EXIT DO
LOOP

SLEEP
SYSTEM

getInput:
I$ = UCASE$(INKEY$) 'your characters are all uppercase.
IF I$ = "" THEN nothingHappened% = 1: RETURN   ' No button being pressed? DO NOTHING!
IF I$ = CHR$(47) THEN ballx% = ballx% - 1:    bally% = bally% + 1
IF I$ = CHR$(48) THEN bally% = bally% + 1
IF I$ = CHR$(49) THEN ballx% = ballx% + 1:    bally% = bally% + 1
IF I$ = CHR$(4B) THEN ballx% = ballx% - 1
IF I$ = CHR$(4C) THEN ballx% = 160:    bally% = 100
IF I$ = CHR$(4D) THEN ballx% = ballx% + 1
IF I$ = CHR$(4F) THEN ballx% = ballx% - 1:    bally% = bally% - 1
IF I$ = CHR$(50) THEN bally% = bally% - 1
IF I$ = CHR$(51) THEN ballx% = ballx% + 1:    bally% = bally% - 1
nothingHappened% = 0
'Allow quitting
IF I$ = CHR$(27) THEN exitloop1% = 1: SYSTEM
RETURN


drawCircle:

CLS
PUT (ballx%, bally%), ball%
PRINT ballx%; bally%
'What you want to do here clear the screen and redraw the ball at new location,
'Also printing the ball's x and y coordinates for unknown reason...
RETURN
so ya, thats the code, and it dont seem to work, gives an error msg "Expected: )", and won't run, plus i need a way of creating borders, because if the ball's coordinates are off the screen, it sais illegal call function and highklights the PUT command in the subroutine drawCircle, so some sort of borders would be nice
Reply
#12
You cannot input HEXADECIMAL CODES in a CHR$() statement. Simply looking up CHR$() with the help function would have worked.

And, I wouldn't put

Code:
' ©2005 Jimmy Jones

in there, if I were you.. first because most of that code was written by me, character by character, and second because you would not have a legal right to copyright short snippets of code that do general things..
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#13
ok, well srry for joking around, its out, its not like id keep it there, when i released, id delete all comments anyway to save space, and thank you for telling me wher to get the ASCII codes, now it works fine, but i still need a system of borders, because if the ballx% or bally% values are off the screen, it goes bak to the editor and highlights PUT (ballx%, bally%), ball% and sais "Expected: )", so is ther a way to create a working border
Reply
#14
Comments don't take up space in the final executable. The compiler completely ignores those.
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Reply
#15
I don't know if it errors out if it's just a little off the screen or not, but to create limits you can do a few things..


Reset ex.:
IF x = 360 THEN x = 359

Prevention ex:
IF X < 360 THEN x = x + 1


You can use either, but people tend to use a reset when there's more than one way to add to the x or when their program has a bug and they want to limit the values for testing.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#16
well i tried this:

IF ballx% < 0 THEN ballx% = 0
IF ballx% > 319 THEN ballx% = 319
IF bally% < 0 THEN bally% = 0
IF ballx% > 199 THEN ballx% = 199

i think its rite, but im niot sur where it would go...

well heres my most recent code:
Code:
' A simple ball moving qbasic program

DEFINT A-Z

SCREEN 13
CLS
'Draw a filled circle for our sprite
CIRCLE (4, 3), 4, 4
PAINT (4, 3), 12, 4

'Set aside enough space to hold the sprite
DIM ball%(37)

'Get the sprite into the ball% array .. before clearing the screen, doofus!
GET (0, 0)-(8, 7), ball%

' Clear the screen
CLS

' Set default ballx% and bally% coordinates
ballx% = 160
bally% = 100

' Set the ball to it's default location
PUT (ballx%, bally%), ball%
PRINT ballx%; bally%

DO
GOSUB getInput
IF nothingHappened% = 0 THEN GOSUB drawCircle
IF exitloop1% = 1 THEN EXIT DO
LOOP

SLEEP
SYSTEM

getInput:
I$ = UCASE$(INKEY$) 'your characters are all uppercase.
IF I$ = "" THEN nothingHappened% = 1: RETURN   ' No button being pressed? DO NOTHING!
IF I$ = CHR$(49) THEN ballx% = ballx% - 1:     bally% = bally% + 1
IF I$ = CHR$(50) THEN bally% = bally% + 1
IF I$ = CHR$(51) THEN ballx% = ballx% + 1:    bally% = bally% + 1
IF I$ = CHR$(52) THEN ballx% = ballx% - 1
IF I$ = CHR$(53) THEN ballx% = 160:    bally% = 100
IF I$ = CHR$(54) THEN ballx% = ballx% + 1
IF I$ = CHR$(55) THEN ballx% = ballx% - 1:    bally% = bally% - 1
IF I$ = CHR$(56) THEN bally% = bally% - 1
IF I$ = CHR$(57) THEN ballx% = ballx% + 1:    bally% = bally% - 1
nothingHappened% = 0
'Allow quitting
IF I$ = CHR$(27) THEN exitloop1% = 1: SYSTEM
RETURN


drawCircle:

CLS
PUT (ballx%, bally%), ball%
PRINT ballx%; bally%
'What you want to do here clear the screen and redraw the ball at new location,
'Also printing the ball's x and y coordinates for unknown reason...
RETURN
Reply
#17
Careful when copying and pasting. You had ballx% at the last one instead of bally%.

This does everything properly except the screen resetting-to-how-it-was. Currently the color blends with the background; it's not solid. I don't know/remember how to do that in screen 13. Maybe Na_th_an can fill us in?

Code:
' A simple ball moving qbasic program

DEFINT A-Z

screen 13
'Set aside enough space to hold the sprite
DIM ball%(37)

CLS
'Draw a filled circle for our sprite
CIRCLE (4, 3), 4, 4: PAINT (4, 3), 12, 4

'Get the sprite into the ball% array ..
GET (0, 0)-(8, 7), ball%

'Clear the screen
CLS
CIRCLE (160, 100), 50, 1
PAINT (160, 100), 50, 1

' Set default ballx% and bally% coordinates
ballx% = 160
bally% = 100

' Set the ball to it's default location
PUT (ballx%, bally%), ball%
PRINT ballx%; bally%
nothingHappened% = 1

DO
GOSUB getInput
IF nothingHappened% = 0 THEN GOSUB drawCircle
IF exitloop1% = 1 THEN EXIT DO
LOOP

SLEEP
SYSTEM

getInput:
I% = ASC(UCASE$(INKEY$)) 'your characters are all uppercase.
IF I% = 0 THEN nothingHappened% = 1: RETURN   ' No button being pressed? DO NOTHING!
if i% < 49 or i% > 57 then return

oldx% = ballx%: oldy% = bally%

IF I% = 49 THEN ballx% = ballx% - 1: bally% = bally% + 1
IF I% = 50 THEN bally% = bally% + 1
IF I% = 51 THEN ballx% = ballx% + 1: bally% = bally% + 1
IF I% = 52 THEN ballx% = ballx% - 1
IF I% = 53 THEN ballx% = 160: bally% = 100
IF I% = 54 THEN ballx% = ballx% + 1
IF I% = 55 THEN ballx% = ballx% - 1: bally% = bally% - 1
IF I% = 56 THEN bally% = bally% - 1
IF I% = 57 THEN ballx% = ballx% + 1: bally% = bally% - 1

IF ballx% < 0 THEN ballx% = 0
IF ballx% > 319 THEN ballx% = 319
IF bally% < 0 THEN bally% = 0
IF bally% > 199 THEN bally% = 199

nothingHappened% = 0
'Allow quitting
IF I$ = CHR$(27) THEN exitloop1% = 1: SYSTEM
RETURN


drawCircle:
'You can also put this first PUT statement where "oldx%: = ballx%" goes,
'and just use ballx% instead of oldx%. (same for bally%)
PUT (oldx%, oldy%), ball%
Put (ballx%, bally%), ball%

LOCATE 1,1: PRINT ballx%; bally%
RETURN
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#18
thnx, it works to an extent, the rite and bottom borders dont work, im thinking that i need to take a few away since the ball's coordinates are the top left coner of the sprite.
Reply
#19
Quote:thnx, it works to an extent, the rite and bottom borders dont work, im thinking that i need to take a few away since the ball's coordinates are the top left coner of the sprite.
Exactly.

Subtract the ball sprite's width from the right limit, then add one.
Reply
#20
ok, well now im going to change the sprite, [Image: 16x16char5mi.png], that one where the lite blu is transparent, im pretty sur how to make it using pretty much pset, but gettin it into the memory using DIM is hard, wat number would i put in the brackets in DIM char% (?). nkow there are 76 blank pixels so thatn would make 180 used pixels, would i just use 180 as the number???
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)