Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: DinoKilla on August 24, 2007, 01:53:29 AM



Title: Multiple Pixels
Post by: DinoKilla on August 24, 2007, 01:53:29 AM
Hello, I know this is probably simple for most people but I'm having a hard time figuring it out.  What I'm trying to do is to get a pixel shoot accross the screen from a certain point everytime a certain key is pressed...the problem I'm having is I want to be able to press the key in rapid succession, only everything I try has to finish executing the second, third or whichever shot then it goes back to the shot before it and finishes it and the goes to the first shot and finishes it...not at ALL how I want it.  Any advice? I'm pretty much a QB newb but I should be able to get anything you can tell me.  Thanks.


Title: Re: Multiple Pixels
Post by: wildcard on August 24, 2007, 08:59:20 AM
What most programs do when they need to fire multiple objects is to use an array of them, but it does make it slightly more complicated. I'll see if I get a chance to make an example.


Title: Re: Multiple Pixels
Post by: barok on August 24, 2007, 02:29:50 PM
any chance we could see your source code to see what your doing?  i don't know if i quite follow what your trying to do.  seems to me to be some basic particle handling.


Title: Re: Multiple Pixels
Post by: Mac on August 24, 2007, 02:41:02 PM
Here is a demo of a particle moving.

Fire more than once to see two moving at the same time.

Mac

http://www.network54.com/Forum/190883/message/1179497831/


Title: Re: Multiple Pixels
Post by: DinoKilla on August 25, 2007, 11:08:12 PM
Well I don't have any source, but basically it's kinda like that link to that little game there except I would like to shoot just single pixels in screen 13 but I don't want to be limited to X amount I would like to be able to just keep pressing a button and firing bullets(pixels) as much and as fast as I want.  Like I said before though my main problem is that I can only control 1 pixel at a time and it interrupts the flight of the previous pixels.  So lets say if I made a type with an X and Y value and I made an array of MyType could I somehow have a loop that would always update MyType(i).X and MyType(i).Y or something?  It's causing me alot of trouble but I know it's probably really easy.  Thanks for the help, more help would be appreciated too. =)


Title: Basic technique for multiple pixels
Post by: Mac on August 28, 2007, 10:21:19 PM
Code:
TYPE Pixel
colr AS INTEGER ' Color
curh AS INTEGER
curv AS INTEGER
goalh AS INTEGER
goalv AS INTEGER
END TYPE
CONST MaxPixels = 20
DIM p(MaxPixels) AS Pixel
SCREEN 13
DO
  FOR i = 1 TO MaxPixels
    IF p(i).colr = 0 THEN
      p(i).colr = 15 '3 + INT(RND * 3)
      p(i).curh = 150
      p(i).curv = 100
      p(i).goalh = RND * 300
      p(i).goalv = RND * 200
      PSET (p(i).goalh, p(i).goalv), 12
    ELSE
      Match = 0
      PSET (p(i).curh, p(i).curv), 0: ' Erase old pixel
      SELECT CASE p(i).curh
      CASE IS < p(i).goalh: p(i).curh = p(i).curh + 1
      CASE IS > p(i).goalh: p(i).curh = p(i).curh - 1
      CASE IS = p(i).goalh: Match = 1
      END SELECT
      SELECT CASE p(i).curv
      CASE IS < p(i).goalv: p(i).curv = p(i).curv + 1
      CASE IS > p(i).goalv: p(i).curv = p(i).curv - 1
      CASE IS = p(i).goalv: Match = Match + 1
      END SELECT
      IF Match = 2 THEN
        p(i).colr = 0
      ELSE
        PSET (p(i).curh, p(i).curv), p(i).colr
      END IF
    END IF
    IF c = 3 THEN c = 0: WAIT &H3DA, 8: WAIT &H3DA, 8, 8 ELSE c = c + 1
  NEXT i
  FOR i = -1 TO 1: FOR j = -1 TO 1: PSET (150 + i, 100 + j), 8: NEXT j: NEXT i
LOOP WHILE INKEY$ = ""
END


Title: Re: Multiple Pixels
Post by: DinoKilla on August 30, 2007, 03:07:23 AM
Thank you very much, that is EXACTLY what I'm trying to do.  All help is much appreciated...I'm sure I will be back in the future with more questions!  ;D  Thanks again for all the help.