Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An introduction
#1
I'd like to introduce you to my stepson. He goes by Melnx. He's recently gotten interested in programming and has been dabbling in QB. Basically all I did was give him the original manual and he came up with this last week while I was out of town. Anyway, I just ran the program, was pretty impressed with what he came up with, and thought he might appreciate feedback from some of you who do graphical animation kind of stuff. I don't think he is using subs, get/put or read/data yet. Anyway...following is original code that was basically developed in a vacuum. It's a game...move about the maze while avoiding the "red evil". Arrow keys move.

I'm sure he'll be pissed when he learns that I posted his code without his knowledge, but thought he might be a welcome addition to this community.

-mango.

Melnx's code follows
Code:
REDO:
CLS

'[INI VARIABLES]
   maxspeed = .5
   thrust = .05
   friction = .002
   jumps = 1.5
   gravity = .005
   adjust = gravity * 250
   height = 7
   walk = height
   stride = 2
   COLOR 4

   nmespeed = maxspeed / 3'.15
   nmethrust = .001
   mode = 1

COLOR 2
'LOCATE 2, 2: PRINT "mode: 1-normal 2-custom": INPUT mode
'IF mode = 2 THEN
'LOCATE 5, 5: PRINT "maxspeed [.5]": INPUT maxspeed
'LOCATE 6, 5: PRINT " thrust [.05]": INPUT thrust
'LOCATE 7, 5: PRINT "friction [.001]": INPUT friction
'LOCATE 8, 5: PRINT "jump [1.5]": INPUT jumps
'LOCATE 9, 5: PRINT "gravity [.005]": INPUT gravity
'LOCATE 10, 5: PRINT "mode [0-normal 1-enemy]": INPUT mode
'LOCATE 11, 5: PRINT "difficulty [.001-normal]": INPUT nmemax speed
'LOCATE 12, 5: PRINT "height [5-normal]": INPUT height
'END IF

'[POSITION VARIABLES]
   midx = 320: midy = 260
   nme1x = 1000: nme1y = 1000
SCREEN 12


'[WINDOW VARIABLES
tlx = 0: tly = 0: brx = 639: bry = 479
WINDOW SCREEN (tlx, tly)-(brx, bry)

newscreen:
CLS 1
'[LEVEL VARIABLES]
   LINE (-50, -50)-(1500, 0), 6, BF
   LINE (-50, -50)-(0, 1500), 6, BF
   LINE (-50, 1500)-(1550, 1550), 6, BF
   LINE (1500, -50)-(1550, 1550), 6, BF
   LINE (100, 100)-(150, 1100), 6, BF
   LINE (100, 1000)-(1200, 1050), 6, BF
   LINE (100, 1350)-(1400, 1400), 6, BF
   LINE (200, 800)-(1350, 850), 6, BF
   LINE (1250, 600)-(1300, 1250), 6, BF
   LINE (0, 1200)-(300, 1250), 6, BF
   LINE (100, 450)-(700, 500), 6, BF
   LINE (700, 100)-(750, 600), 6, BF
   LINE (100, 100)-(400, 150), 6, BF
   LINE (500, 0)-(550, 300), 6, BF
   LINE (300, 300)-(600, 350), 6, BF
   LINE (700, 550)-(1000, 600), 6, BF
   LINE (1100, 550)-(1350, 600), 6, BF
   LINE (700, 200)-(1300, 250), 6, BF
   LINE (1000, 350)-(1500, 400), 6, BF
   LINE (700, 950)-(750, 1200), 6, BF
   LINE (300, 600)-(350, 900), 6, BF
   LINE (500, 1200)-(550, 1400), 6, BF
   LINE (1100, 1200)-(1350, 1250), 6, BF
   LINE (1300, 1000)-(1350, 1050), 6, BF
   LINE (1450, 675)-(1500, 725), 6, BF
   LINE (1450, 900)-(1500, 950), 6, BF
   LINE (1450, 1100)-(1500, 1150), 6, BF
   LINE (0, 10000)-(1500, 10100), 4, BF

   LINE (tlx, tly)-(brx, tly), 0
   LINE (tlx, tly)-(tlx, bry), 0
  
DO
  
   '[INPUT KEYS]
   ACT$ = INKEY$
   SELECT CASE ACT$
      CASE CHR$(27)
         END
      CASE CHR$(13)
         GOTO REDO
      CASE CHR$(0) + CHR$(75)   'LEFT
         GOSUB mask
         IF jump = 0 THEN xspeed = xspeed - thrust: walk = walk + stride
         IF jump <> 0 OR land = 1 THEN xspeed = xspeed - (thrust / 2)
      CASE CHR$(0) + CHR$(77)   'RIGHT
         GOSUB mask
         IF jump = 0 THEN xspeed = xspeed + thrust: walk = walk - stride
         IF jump <> 0 OR land = 1 THEN xspeed = xspeed + (thrust / 2)
      CASE CHR$(0) + CHR$(72)   'JUMP
         GOSUB mask
         IF jump = 0 THEN jump = jumps
         land = 0
      CASE CHR$(0) + CHR$(80)   'DOWN
         jump = jumps * -1
   END SELECT

  
   '[ENEMY AI]
   IF mode = 1 THEN
      IF nme1x > midx AND nmexspeed > nmespeed * -1 THEN nmexspeed = nmexspeed - nmethrust
      IF nme1x < midx AND nmexspeed < nmespeed THEN nmexspeed = nmexspeed + nmethrust
      IF nme1y > midy AND nmeyspeed > nmespeed * -1 THEN nmeyspeed = nmeyspeed - nmethrust
      IF nme1y < midy AND nmeyspeed < nmespeed THEN nmeyspeed = nmeyspeed + nmethrust
      nme1x = nme1x + nmexspeed: nme1y = nme1y + nmeyspeed
      distance = ((nme1x - midx) ^ 2 + (nme1y - midy) ^ 2) ^ .5
      IF nmethrust <> 0 THEN LOCATE 1, 1: PRINT distance
      IF ABS(distance) < 15 THEN
         LOCATE 1, 1: PRINT "THE EVIL CAPTURED YOU"
         nmexspeed = 0: nmeyspeed = 0: nmethrust = 0
      END IF
   END IF
  
   '[JUMPING PHYSICS]
   IF jump <= 0 THEN land = 1
   IF POINT(lfootx, lfooty + adjust) > 0 AND land = 1 OR POINT(rfootx, rfooty + adjust) > 0 AND land = 1 THEN
      jump = 0
   END IF
   IF jump <> 0 AND POINT(midx, lfooty) = 0 THEN jump = jump - gravity
  
   '[FALLING PHYSICS]
   IF POINT(lfootx, lfooty + adjust) = 0 AND POINT(rfootx, rfooty + adjust) = 0 AND jump = 0 THEN
      GOSUB mask
      midy = midy + 1
   END IF
  
  
   '[HEADBUMPING PHYSICS]
   IF POINT(headx, heady - (5 + adjust)) > 0 THEN
      jump = 0: land = 1
   END IF
  
  
   '[WALL TACKLING PHYSICS]
   IF POINT(larmx - 1, larmy) > 0 OR POINT(lfootx - 1, lfooty) > 0 THEN
      xspeed = 0: GOSUB mask: midx = midx + 5
   END IF
   IF POINT(rarmx + 1, rarmy) > 0 OR POINT(rfootx + 1, rfooty) > 0 THEN
      xspeed = 0: GOSUB mask: midx = midx - 5
   END IF

  
   '[IF VERY LOW SPEED COMPLETELY STOPS]
   IF ABS(xspeed) < .01 THEN xspeed = 0
  
  
   '[WALKING GRAPHICS]
   IF walk <= height * -1 OR walk >= height THEN
      walk = height: stride = stride * -1
   END IF
  
  
   '[ERASING TERMS]
   IF xspeed <> 0 THEN GOSUB mask
   IF jump <> 0 THEN GOSUB mask
  
  
   '[ALL THE VARIABLES DETERMINED BY 1 MAIN COORDINATE]
   midy = midy - jump
   midx = midx + xspeed
   lfootx = midx + walk: lfooty = midy + 2 * height
   rfootx = midx - walk: rfooty = midy + 2 * height
   topx = midx: topy = midy - 2 * height
   larmx = midx - height: larmy = midy
   rarmx = midx + height: rarmy = midy
   headx = midx: heady = topy - height / 2
   GOSUB show
  
  
   '[FRICTION AND SPEED CONTROL]
   IF xspeed > maxspeed THEN xspeed = maxspeed
   IF xspeed < maxspeed * -1 THEN xspeed = maxspeed * -1
   IF xspeed > 0 THEN
      IF jump = 0 THEN xspeed = xspeed - friction
      IF jump = 1 THEN xspeed = xspeed - friction / 4
   END IF
   IF xspeed < 0 THEN
      IF jump = 0 THEN xspeed = xspeed + friction
      IF jump = 1 THEN xspeed = xspeed + friction / 4
   END IF

  
   '[SCREEN SCROLLING TERMS]
   IF midx >= brx - 100 AND xspeed >= 0 THEN
      brx = brx + 250
      tlx = tlx + 250
      WINDOW SCREEN (tlx, tly)-(brx, bry)
      GOTO newscreen
   END IF
   IF midx <= tlx + 100 AND xspeed <= 0 THEN
      brx = brx - 250
      tlx = tlx - 250
      WINDOW SCREEN (tlx, tly)-(brx, bry)
      GOTO newscreen
   END IF
   IF midy >= bry - 100 AND jump <= 0 THEN
      bry = bry + 150
      tly = tly + 150
      WINDOW SCREEN (tlx, tly)-(brx, bry)
      GOTO newscreen
   END IF
   IF midy <= tly + 100 AND jump >= 0 THEN
      bry = bry - 150
      tly = tly - 150
      WINDOW SCREEN (tlx, tly)-(brx, bry)
      GOTO newscreen
   END IF

LOOP
  
'[MASKING THE GUY AND THE ENEMY]
mask:
   'CIRCLE (nme1x, nme1y), 50, 0
   LINE (rfootx, rfooty)-(midx, midy), 0
   LINE (lfootx, rfooty)-(midx, midy), 0
   LINE (topx, topy)-(midx, midy), 0
   LINE (topx, topy)-(larmx, larmy), 0
   LINE (topx, topy)-(rarmx, rarmy), 0
   CIRCLE (headx, heady), height / 2, 0
RETURN


'[DRAWING THE GUY AND THE ENEMY]
show:
   LINE (rfootx, rfooty)-(midx, midy), 3
   LINE (lfootx, rfooty)-(midx, midy), 3
   LINE (topx, topy)-(midx, midy), 3
   LINE (topx, topy)-(larmx, larmy), 3
   LINE (topx, topy)-(rarmx, rarmy), 3
   CIRCLE (headx, heady), height / 2, 3
   CIRCLE (nme1x, nme1y), 50, 4
RETURN
Reply
#2
Hey, that's pretty cool! It's also kinda fun. Tongue
Reply
#3
I totally agree with Dr. D. The only complaint i have is the keyhandling, but changing it to inp(96) fixed everything. It's a great game that has alot of potential! Big Grin
Jumping Jahoolipers!
Reply
#4
Your stepson is a natural!!!
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#5
I'm not even a beginner in the realm of graphics programming, but I ran the code and, it runs fairly well (my experience is that this doesn't happen too often with many of the submittals of this nature).

I looked at the code, and was very impressed with its organization, its documentation, and the mature use of the IFs, FORs and DOs.
His variable initiation and naming is that of a mature programmer. Maybe I'm wrong, but, hasn't he already been programming in some other language or languages? If not, he must be close to being a genius!

I came away very impressed and, as relsoft states, "He's a natural!" I envy him his ease in picking up, remembering, and using the tools he comes across, as well as his handling of the physics involved in this game!

Wow!
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#6
Haha, it's addictive! :lol:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)