• Print

Author Topic: So, i've started writing a game...  (Read 655 times)

vrensul

  • Sr. Member
  • ****
  • Posts: 319
  • 44th Degree Digital Wizard of the HighBytes Order
So, i've started writing a game...
« on: August 07, 2011, 03:19:40 PM »
And i'm not very good with graphics in general.  After messing with some stuff last night, and figuring how to tie in some type of timer so far i've done this.

Code: [Select]
CLS
COLOR 7, 0
PRINT "Entering program..."

TYPE StarType 'star type
     x AS INTEGER
     y AS INTEGER
     color AS LONG
     BigStar AS INTEGER
END TYPE

TYPE Planet 'planet type
     x AS INTEGER
     y AS INTEGER
     Color AS LONG
     radi AS INTEGER
     R AS INTEGER
     G AS INTEGER
     B AS INTEGER
END TYPE

PRINT "Smacking some bits around..."
DIM stars1(50) AS StarType
DIM stars2(25) AS StarType

PRINT "Got some hedge hogs here!"
DIM ScrFORE AS LONG
DIM Plan AS Planet
DIM TotalNumberOfBigStars AS INTEGER
TotalNumberOfBigStars = 6
BigStarCount = 0
DIM Stars1MIN 'Stars min color range (0-255)
DIM Stars1MAX ' ... And the max.
DIM Stars2MIN ' Same as above but for stars 2...
DIM Stars2MAX ' ""
Stars1MIN = 210
Stars1MAX = 255
Stars2MIN = 40
Stars2MAX = 90
ScrFORE& = _NEWIMAGE(800, 600, 32)

Start:
PRINT "Searching for Voyager"
RANDOMIZE TIMER

'rand the planet
Plan.x = INT(RND * (750 - 50 + 1)) + 50
Plan.y = INT(RND * (550 - 50 + 1)) + 50
Plan.radi = INT(RND * (40 - 10 + 1)) + 10
Plan.R = INT(RND * (200 - 20 + 1)) + 20
Plan.G = INT(RND * (200 - 20 + 1)) + 20
Plan.B = INT(RND * (200 - 20 + 1)) + 20
Plan.Color& = _RGB32(Plan.R, Plan.G, Plan.B)


' Rand the initial stars...
FOR Counter = 1 TO 50
     stars1(Counter).x = INT(RND * (800 - 1 + 1)) + 1
     stars1(Counter).y = INT(RND * (600 - 1 + 1)) + 1
     stars1(Counter).color& = _RGB32(INT(RND * (Stars1MAX - Stars1MIN + 1)) + Stars1MIN, INT(RND * (Stars1MAX - Stars1MIN + 1)) + Stars1MIN, INT(RND * (Stars1MAX - Stars1MIN + 1)) + Stars1MIN)
     'stars1(Counter).color& = _RGB32(INT(RND * (Stars1MAX - Stars1MIN + 1)) + Stars1MIN, INT(RND * (Stars1MAX - Stars1MIN + 1)) + Stars1MIN, INT(RND * (Stars1MAX - Stars1MIN + 1)) + Stars1MIN)
     IF stars1(Counter).BigStar = 0 AND BigStarCount < TotalNumberOfBigStars THEN
          Dice = CINT(RND)
          IF Dice = 1 THEN
               BigStarCount = BigStarCount + 1
               stars1(Counter).BigStar = Dice
          END IF
     END IF
NEXT Counter
FOR Counter = 1 TO 25
     stars2(Counter).x = INT(RND * (800 - 1 + 1)) + 1
     stars2(Counter).y = INT(RND * (600 - 1 + 1)) + 1
     stars2(Counter).color& = _RGB32(INT(RND * (Stars2MAX - Stars2MIN + 1)) + Stars2MIN, INT(RND * (Stars2MAX - Stars2MIN + 1)) + Stars2MIN, INT(RND * (Stars2MAX - Stars2MIN + 1)) + Stars2MIN)
NEXT Counter


SetupScreens:
SCREEN ScrFORE&
_FULLSCREEN



NewLoop:
switchTIMEmax = 20 ' THIS is the time mechanism for the stars AND the "planet"
switchTIMEcur = 0 ' This is what it stars at.
WHILE INKEY$ = ""
     _DISPLAY
     CLS
     _LIMIT 250 'Loops per second...

     FOR cnt = 1 TO 50

          ' Stars # 2
          IF switchTIMEcur = CINT(switchTIMEmax / 4) OR switchTIMEcur = switchTIMEmax THEN ' If we should move a star2s...
               IF cnt < 26 THEN 'If valid subscript...
                    stars2(cnt).y = stars2(cnt).y + 1
                    IF stars2(cnt).y > 1 AND stars2(cnt).y < 601 THEN
                         PSET (stars2(cnt).x, stars2(cnt).y), stars2(cnt).color& 'Draw if within screen range.
                    ELSE 'Else, it's out of range, make a new star!  You can name it too....
                         '                          max  min       min
                         stars2(cnt).x = INT(RND * (800 - 1 + 1)) + 1
                         stars2(cnt).y = INT(RND * (2 - 1 + 1)) + 1
                         stars2(cnt).color& = _RGB32(INT(RND * (Stars2MAX - Stars2MIN + 1)) + Stars2MIN, INT(RND * (Stars2MAX - Stars2MIN + 1)) + Stars2MIN, INT(RND * (Stars2MAX - Stars2MIN + 1)) + Stars2MIN)
                    END IF 'End field checking IF
               END IF 'End subscript check
          ELSE ' If it isn't time to move the star2s....
               IF cnt < 26 THEN 'Still need to check subscript...
                    PSET (stars2(cnt).x, stars2(cnt).y), stars2(cnt).color& 'And you still need to draw it every refresh.
               END IF
          END IF


          'Stars # 1
          ' Draw these every refresh of the loop.
          stars1(cnt).y = stars1(cnt).y + 1 'move them, ask no questions.
          IF stars1(cnt).y > 1 AND stars1(cnt).y < 601 THEN ' IF in range of view
               PSET (stars1(cnt).x, stars1(cnt).y), stars1(cnt).color& 'Draw the star.
               IF stars1(cnt).BigStar = 1 THEN ' If it's a big star, make it big.
                    PSET (stars1(cnt).x + 1, stars1(cnt).y), stars1(cnt).color&
                    PSET (stars1(cnt).x - 1, stars1(cnt).y), stars1(cnt).color&
                    PSET (stars1(cnt).x, stars1(cnt).y + 1), stars1(cnt).color&
                    PSET (stars1(cnt).x, stars1(cnt).y - 1), stars1(cnt).color&
               END IF
          ELSE ' If out of view, make a new one.
               '                          max  min       min
               stars1(cnt).x = INT(RND * (800 - 1 + 1)) + 1
               stars1(cnt).y = INT(RND * (2 - 1 + 1)) + 1
               stars1(cnt).color& = _RGB32(INT(RND * (Stars1MAX - Stars1MIN + 1)) + Stars1MIN, INT(RND * (Stars1MAX - Stars1MIN + 1)) + Stars1MIN, INT(RND * (Stars1MAX - Stars1MIN + 1)) + Stars1MIN)
               IF stars1(cnt).BigStar = 1 THEN 'big star dies out.
                    BigStarCount = BigStarCount - 1
               END IF
               stars1(cnt).BigStar = 0 'Regardless, lets flag it as new (big star).
               IF stars1(cnt).BigStar = 0 AND BigStarCount < TotalNumberOfBigStars THEN 'we need a new BIGstar.
                    Dice = CINT(RND)
                    IF Dice = 1 THEN 'Roll the dice, see if we can grow!
                         BigStarCount = BigStarCount + 1
                         stars1(cnt).BigStar = Dice
                    END IF
               END IF
          END IF

     NEXT cnt

     'Planet...
     IF switchTIMEcur = switchTIMEmax THEN ' If it's time to draw
          IF Plan.y + Plan.radi > 600 - Plan.radi THEN 'Out of range?
               Plan.x = INT(RND * (750 - 50 + 1)) + 50
               Plan.y = 1
               Plan.radi = INT(RND * (40 - 10 + 1)) + 10
               Plan.R = INT(RND * (200 - 20 + 1)) + 20
               Plan.G = INT(RND * (200 - 20 + 1)) + 20
               Plan.B = INT(RND * (200 - 20 + 1)) + 20
               Plan.Color& = _RGB32(Plan.R, Plan.G, Plan.B)
          ELSE ' IN RANGE!!!!
               Plan.y = Plan.y + 1
               CIRCLE (Plan.x, Plan.y), Plan.radi, _RGB32(Plan.R - 25, Plan.G - 25, Plan.B - 25)
               'CIRCLE (Plan.x, Plan.y), Plan.radi, Plan.Color&
               'PAINT (Plan.x, Plan.y), Plan.Color&
               PAINT (Plan.x, Plan.y), _RGB32(Plan.R - 25, Plan.G - 25, Plan.B - 25)

               'EXPERIMENTAL!
               ' this makes shading on my cheesey planet.  It's a work in progress :(
               FOR n = 2 TO Plan.radi
                    IF n <= Plan.radi - 3 THEN
                         CIRCLE (Plan.x, Plan.y), n, _RGB32(Plan.R - (n - 15), Plan.G - (n - 15), Plan.B - (n - 15))
                    ELSE
                         CIRCLE (Plan.x, Plan.y), n, _RGB32(Plan.R - n + 2, Plan.G - n + 2, Plan.B - n + 2)
                    END IF
               NEXT n
          END IF
          switchTIMEcur = 0
          'we drew.  Reset time to draw again.
     ELSE 'You have to draw the planet anyway, just this doesn't +1 it.
          switchTIMEcur = switchTIMEcur + 1
          CIRCLE (Plan.x, Plan.y), Plan.radi, _RGB32(Plan.R - 25, Plan.G - 25, Plan.B - 25)
          'CIRCLE (Plan.x, Plan.y), Plan.radi, Plan.Color&
          'PAINT (Plan.x, Plan.y), Plan.Color&
          PAINT (Plan.x, Plan.y), _RGB32(Plan.R - 25, Plan.G - 25, Plan.B - 25)

          'EXPERIMENTAL!
          ' this makes shading on my cheesey planet.  It's a work in progress :(
          FOR n = 2 TO Plan.radi
               IF n <= Plan.radi - 3 THEN
                    CIRCLE (Plan.x, Plan.y), n, _RGB32(Plan.R - (n - 15), Plan.G - (n - 15), Plan.B - (n - 15))
               ELSE
                    CIRCLE (Plan.x, Plan.y), n, _RGB32(Plan.R - n + 2, Plan.G - n + 2, Plan.B - n + 2)
               END IF
          NEXT n
     END IF
WEND
END

Ya i know it's not a game yet.  Just kind of a warning, i may need some graphical help later; like my ugly planet.   :(  It's not nearly as bad as it was.  But my question is, would it be easier to attempt to draw the items on the screen in game and copy to memory, or externally and then import from file?  This would be done at the beginning so i'm not too worried about speed at creation/load point...  But i'm sure everyone here has more game making experience than me at this point.

Edited to fix a sentence.
' With programming, you  can do anything!
DEF SEG = &HBANKACNT 'weekend starts here...
     poke checking, 1000000
DEF SEG ' quit job here.

Theophage

  • Full Member
  • ***
  • Posts: 137
    • Email
Re: So, i've started writing a game...
« Reply #1 on: August 07, 2011, 03:31:42 PM »
The parallax star motion is pretty sweet, but yeah, I'd go for an already drawn sprite/tile for the planet.
...
END OF LINE

TerryRitchie

  • Hero Member
  • *****
  • Posts: 1308
  • G=C800:5
    • Email
Re: So, i've started writing a game...
« Reply #2 on: August 08, 2011, 07:22:13 AM »
Drawing graphics using good old QuickBasic commands is tedious at best, but very doable. The advantage: no graphics files cluttering the game's directory.  I've only attempted a few times, and those time were simply emulating 8 bit graphics found in old coin-op games.  Now that I have a language that supports loading many different graphic file types I see no need to try and create complex scenery through code.  Use your favorite graphics editor and its tools to create graphics and then load them in through code.

Sketcz

  • Newbie
  • *
  • Posts: 16
Re: So, i've started writing a game...
« Reply #3 on: August 08, 2011, 12:11:31 PM »
Not to hijack the thread, but it's a related question and I didn't think it needs a new topic.

For my current game I've been doing all the graphics using the DRAW command, which does slow things down (luckily this will be played on current beefy PCs).

What is the alternative to this, without loading external files.

How does copying to memory work? Does it draw things once, copies it, and then repastes it again and again?

I've gotten to the point where the DRAW files are actually used for animation.

TerryRitchie

  • Hero Member
  • *****
  • Posts: 1308
  • G=C800:5
    • Email
Re: So, i've started writing a game...
« Reply #4 on: August 08, 2011, 12:37:17 PM »
Draw for animation. Holy smokes, I don't think draw was ever envisioned to do that.  Sprites are where it's at.  Basically the way I handled this problem in the past was to either use QuickBasic commands to draw my characters, use GET to put them in an array (save them in memory) and the use PUT to place the images where I wanted, or load external files, GET portions of the files (Sprites) and then again use PUT to place the images.

Since QB64 I have abandoned drawing manually and only use loading of files now. No need to use GET and PUT any longer, these have been replaced with far superior commands available in QB64 (_LOADIMAGE, _PUTIMAGE, _COPYIMAGE, etc..)  I use these commands to treat images as individual sprites, especially since they can natively use transparent .PNG files.  And to take the sprite handling to the next level I created a library to handle the sprites for me.

Sketcz

  • Newbie
  • *
  • Posts: 16
Re: So, i've started writing a game...
« Reply #5 on: August 08, 2011, 02:15:54 PM »
I use a mixture of DRAW, LINE and CIRCLE for all my imagery needs. I spent yesterday afternoon, hours in fact, using DRAW to create 6 new characters. I thought I was going to go made manually retyping them in reverse for the mirrors version (L to R, E to H, and vice versa), when I realised I could copy and paste the lot into Word and do a search and replace on each letter (I'd switch L to Q, then R to L, then Q to R).

Holy smokes I'm like a kid given his dad's welding set.  ::)

The fact that DRAW leaves an imprint of itself on the screen when moved can be useful at times. I made the impression of a trampoline material stretching when moving two lines, since as they moved they didn't erase themselves and now it looks like a material bulge as someone lands on it.

Having said that, I'm getting about 50 runs of the Main Loop before going to Secondary Loop, and the speed is good at that number. But if I have to start dropping the number of Main Loop runs it'll introduce flicker (since old graphics are blacked out in the secondary loop) and things will slow, so I might have to turn to better alternatives.

Then again, I can already feel the motivation waning. I need to stick to one day projects I reckon.

cr0sh

  • Full Member
  • ***
  • Posts: 140
  • QB64 rox the box!
    • phoenixgarage.org || crazy ideas, irrational projects
    • Email
Re: So, i've started writing a game...
« Reply #6 on: August 08, 2011, 02:31:28 PM »
Draw for animation. Holy smokes, I don't think draw was ever envisioned to do that.  Sprites are where it's at.

While I agree with you that "sprites are where it's at", using DRAW for animation is actually a quite old use of the command. The DRAW command itself (from Microsoft) is almost 30 years old; I remember several different Microsoft "Extended Color Basic" programs for the TRS-80 Color Computer 2 (back when I was a kid - 1984ish) that used DRAW for simple "sprite" animation-type effects (because it could be faster and less memory intensive - remember, BASIC on this 1 MHz machine could only access about 24K without doing complex tricks with machine code - and even then, you might only be on a machine with 32K anyhow).

:)

TerryRitchie

  • Hero Member
  • *****
  • Posts: 1308
  • G=C800:5
    • Email
Re: So, i've started writing a game...
« Reply #7 on: August 08, 2011, 03:02:08 PM »
Yeah, I had a COCO I, II, and III in my time as well and remember the 24K limit no matter how much actual RAM was installed. I do remember draw being used for easy rotation, but I can't recall seeing it used for animation, although I don't doubt it could have been.  I used to keep a copy of my sprites on a separate graphics page, copy the ones I needed to graphics page 1 and then flip to page 0 while page 1 was shown, copy graphics to 0 then, flip again, and so on.  For a .89Mhz processor, the 6809e was a pretty fast versatile chip. (or POKE 65495,0 to speed that puppy up!)

vrensul

  • Sr. Member
  • ****
  • Posts: 319
  • 44th Degree Digital Wizard of the HighBytes Order
Re: So, i've started writing a game...
« Reply #8 on: August 08, 2011, 04:18:38 PM »
I have a COCO 1.  Still works and all. (don't write to disk when you use that poke trick!)  What piece of computer right?  I mean, how many people didn't have one?  I was wee small when I got mine.  Dad bought a CoCo 3 later and I fell in love with Karonos Rift and super pitfall 3.  Hmmm  wonder if karonos rift has ever been re-made.  I could just see the bug-eyed robot staring at me now. 


Back on topic,
Anyhow I'm taking the suggestions and using MS paint for drawing stuff (i'm a terrible artist).  Now just have to figure out how to get the black of the png file to actually be transparent.  Currently it over-writes everything.  I have a pretty good idea of the rest of the game if I can get past that point.  TBH, it'll be pretty quick going after that.
' With programming, you  can do anything!
DEF SEG = &HBANKACNT 'weekend starts here...
     poke checking, 1000000
DEF SEG ' quit job here.

TerryRitchie

  • Hero Member
  • *****
  • Posts: 1308
  • G=C800:5
    • Email
Re: So, i've started writing a game...
« Reply #9 on: August 08, 2011, 05:59:34 PM »
The program that you use to create the .PNG file needs to support the creation of transparent of a .PNG layer in the file.  Most, if not all graphics paint type programs that support creation of .PNG should support this.

Not to knock your choice as I realize why you chose it, but MSPaint is a terrible app to do any kind of really serious graphics work in.  Don't get me wrong, I've seen some amazing video of people doing amazing things with it, but I think they locked themselves in a room with it for over a year to do that.

I'm not even sure if MSPaint supports .PNG?  If you are simply naming the images you create with the .PNG extension then they are still .BMP files, just in disguise.

But, to make matters worse I don't know what other program to suggest.  I use PhotoImpact X3 and I have friends who swear by Photoshop and GIMP (GIMP is free).

unseenmachine

  • Hero Member
  • *****
  • Posts: 3215
  • A fish, a fish, a fishy o!
Re: So, i've started writing a game...
« Reply #10 on: August 08, 2011, 07:13:07 PM »
IMAGE& = _LOADIMAGE("QBLogo.PNG", 32)
_CLEARCOLOR _RGB32(0,0,0),IMAGE&

http://qb64.net/wiki/index.php?title=CLEARCOLOR
UnseenGDK Download : http://dl.dropbox.com/u/8822351/UnseenGDK.bm
GDK Tutorial : http://dl.dropbox.com/u/8822351/UnseenGDK_Tutorial.doc
VQB02 : http://dl.dropbox.com/u/8822351/VQB02.zip

vrensul

  • Sr. Member
  • ****
  • Posts: 319
  • 44th Degree Digital Wizard of the HighBytes Order
Re: So, i've started writing a game...
« Reply #11 on: August 08, 2011, 07:57:19 PM »
Quote
_CLEARCOLOR _RGB32(0,0,0),IMAGE&
Thanks unseen.  I spent about an hour or so on clearcolor, and a few others last night and it just didn't work for me.  Somehow i ended up trying to extract pixel 1,1 information and setting that as the color, but then i got tangled up in rgba32 or something.  Anyhow that works.  Thanks.

Quote
MSPaint is a terrible app to do any kind of really serious graphics work in.
You're right on that one.  You haven't seen my "art work" though.  :-[  I'm in need of assistance with the circle tool.  Seriously, i'm that bad.  Anyhow thanks for the suggestions.  I'm gonna look up gimp and if that doesn't work, i'll check out sourceforge (or start a new project).  BTW, paint will load and save png files but I think that's it's limit.  I haven't looked at the header or anything so not sure if it's just a naming convention, but there's no info about an ALPHA channel when you load a png.
' With programming, you  can do anything!
DEF SEG = &HBANKACNT 'weekend starts here...
     poke checking, 1000000
DEF SEG ' quit job here.


vrensul

  • Sr. Member
  • ****
  • Posts: 319
  • 44th Degree Digital Wizard of the HighBytes Order
Re: So, i've started writing a game...
« Reply #13 on: August 15, 2011, 08:57:14 PM »
Ok.  So here's what i've done so far, every chance i've gotten to work on it.  It's my FIRST attempt at writing a game beyond that one memory game.  I'm not too far from finished.  I know i'm not a good artist, so dont be too rough on the art  :-[  Anyhow keep the images in the dir with the EXE after you compile.  Next venture will be into how to animate some of the colors using something called "color cycling", and finally coding the rest of the "features" of the game and setting up opening and closings.

Download here : http://dl.dropbox.com/u/3050338/Stardom.zip

BTW, use the mouse to move, and LMB to shoot.  Them dudes are set to be really easy.
' With programming, you  can do anything!
DEF SEG = &HBANKACNT 'weekend starts here...
     poke checking, 1000000
DEF SEG ' quit job here.

Galleon

  • Administrator
  • Hero Member
  • *******
  • Posts: 3787
  • QB Forever
    • Email
Re: So, i've started writing a game...
« Reply #14 on: August 16, 2011, 02:02:26 AM »
I sat around for a minute or so after shooting down the first 2 enemies waiting for something to happen... well... at least I didn't get Rickrolled!

  • Print