Weekly Qbasic and Qb64 Lesson Topics
July 18, 2018, 07:48:17 am
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

Catch the rabbit


Pages: [1]
  Print  
Author Topic: Catch the rabbit  (Read 469 times)
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« on: December 28, 2010, 08:29:39 am »

This is a game recently started,useing the code, someone gave me.
--------------- code below---------------
Code:
REM
DEFLNG A-Z
CONST True = -1, False = NOT (True)
SCREEN 12
WorkPage& = _LOADIMAGE("Hawk_sprite.bmp") 'create the sprite sheet page
_COPYPALETTE WorkPage&, 0
FrameNum& = 0: x1 = 100: y1 = 100: direction = 1: flap = 0: Active=0:ShowBox= True: Captured = False
DO
    _DISPLAY
    _LIMIT 20
    GOSUB Getkey
    CLS 'need to clear the page ready for new image
    GOSUB Showframe
    IF Captured = False THEN
        GOSUB Showbunny
        GOSUB Collision
    ELSE
        bx = x1 + 50: by = y1 + 54
        CIRCLE (bx, by), 5, 14
    END IF
    LOCATE 29, 1: PRINT bx, hx1, hy1, rx1, rx2 ' "Press Scroll Lock to show boundary box"
LOOP UNTIL INP(&H60) = 1
SLEEP
SYSTEM
Getkey:
IF _KEYDOWN(20480) THEN y1 = y1 + 4
IF _KEYDOWN(18432) THEN y1 = y1 - 4
IF _KEYDOWN(19200) THEN
    x1 = x1 - 4: direction = 2
END IF
IF _KEYDOWN(19712) THEN
    x1 = x1 + 4: direction = 1
END IF
IF _KEYDOWN(100302) THEN
    ShowBox = NOT ShowBox 'Scroll Lock key
    _DELAY .05
END IF
RETURN
Showframe:
SELECT CASE FrameNum&
    CASE 0
        IF direction = 1 THEN
            _PUTIMAGE (x1, y1)-(x1 + 89, y1 + 67), WorkPage&, 0, (1, 1)-(89, 67)
        ELSE
            _PUTIMAGE (x1, y1)-(x1 + 89, y1 + 67), WorkPage&, 0, (89, 1)-(1, 67)
        END IF
    CASE 1
        IF direction = 1 THEN
            _PUTIMAGE (x1, y1)-(x1 + 89, y1 + 67), WorkPage&, 0, (91, 0)-(187, 67)
        ELSE
            _PUTIMAGE (x1, y1)-(x1 + 89, y1 + 67), WorkPage&, 0, (187, 0)-(91, 67)
        END IF
END SELECT
flap = flap + 1
IF flap = 3 THEN
    flap = 0
    FrameNum& = FrameNum& + 1
END IF
IF FrameNum& = 2 THEN FrameNum& = 0
RETURN
Makchance:
chance = INT(RND * 10) + 1
RETURN
Movbunny:
dir = INT(RND * 2) + 1
IF dir = 1 THEN
    dir = 4: x = -10
ELSE
    dir = -4: x = 650
END IF
RETURN
Showbunny:
IF Active = 1 THEN
    bx = bx + dir
    CIRCLE (bx, 400), 5, 14
    IF bx <= 0 OR bx >= 640 THEN
        Active = 0: CLS
    END IF
ELSE
    GOSUB Makchance
    IF chance = 9 THEN
        Active = 1
        GOSUB Movbunny
    END IF
END IF
RETURN
Collision:
hx1 = x1 + 42: hx2 = x1 + 58 'horizontal co-ord of hawk feet
hy1 = y1 + 46: hy2 = hy1 + 10 'vertical  co-ord of hawk feet
rx1 = bx - 4: rx2 = rx1 + 12 'rabbit right + left side co-ords
IF ShowBox = True THEN
    LINE (hx1, hy1)-(hx2, hy2 + 10), 5, B
END IF
IF hy1 >= 394 AND hy2 <= 404 THEN
    IF hx1 >= rx1 AND hx1 <= rx2 THEN
        IF Captured = False THEN
            Captured = True
            SOUND 2500, 1
        END IF
    END IF
END IF
RETURN 
You can get the Hawk_sprite.bmp and a "package" with the .bas, also a executable demo, at my drop box: http://dl.dropbox.com/u/15387474/Hawk_Sprite.zip
The discussion, will be on the various stages, and commands used to get this far,....
 Shortly I will post a more completed version, that has a back ground.
from Garry
« Last Edit: September 06, 2011, 10:05:37 pm by GarrisonRicketson » Report Spam   Logged

Social Buttons

GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #1 on: January 10, 2011, 08:17:40 pm »

ok I went ahead and uploaded this, the GarryHawk10.bas,
with the new background, I did, with the nest,, any one can make up theyre own,..
Also any corrections, etc....if needed.....

-------------code below----------------
Code:
'GARRYHAWK10.BAS
REM
DEFLNG A-Z

CONST True = -1, False = NOT (True)

SCREEN 12
Background& = _LOADIMAGE("abackground.bmp") 'create the background page
WorkPage& = _LOADIMAGE("Hawk_sprite.bmp") 'create the sprite sheet page
_COPYPALETTE WorkPage&, 0
FrameNum& = 0: x1 = 100: y1 = 100: direction = 1: flap = 0: Active = 0: ShowBox = True: Captured = False



DO

    _DISPLAY
    _LIMIT 20
    GOSUB Getkey
    _PUTIMAGE , Background&, 0
    GOSUB Showframe
    IF Captured = False THEN
        GOSUB Showbunny
        GOSUB Collision
    ELSE
        bx = x1 + 50: by = y1 + 54
        CIRCLE (bx, by), 5, 14
    END IF
    LOCATE 29, 1: PRINT bx, hx1, hy1, rx1, rx2
LOOP UNTIL INP(&H60) = 1
SLEEP
SYSTEM

Getkey:
IF _KEYDOWN(20480) THEN y1 = y1 + 4
IF _KEYDOWN(18432) THEN y1 = y1 - 4
IF _KEYDOWN(19200) THEN
    x1 = x1 - 4: direction = 2
END IF
IF _KEYDOWN(19712) THEN
    x1 = x1 + 4: direction = 1
END IF
RETURN

Showframe:
SELECT CASE FrameNum&
    _CLEARCOLOR 0, WorkPage&
    CASE 0
        IF direction = 1 THEN
            _PUTIMAGE (x1, y1)-(x1 + 89, y1 + 67), WorkPage&, 0, (1, 1)-(89, 67)
        ELSE
            _PUTIMAGE (x1, y1)-(x1 + 89, y1 + 67), WorkPage&, 0, (89, 1)-(1, 67)
        END IF
    CASE 1
        IF direction = 1 THEN
            _PUTIMAGE (x1, y1)-(x1 + 89, y1 + 67), WorkPage&, 0, (91, 0)-(187, 67)
        ELSE
            _PUTIMAGE (x1, y1)-(x1 + 89, y1 + 67), WorkPage&, 0, (187, 0)-(91, 67)
        END IF
END SELECT
flap = flap + 1
IF flap = 3 THEN
    flap = 0
    FrameNum& = FrameNum& + 1
END IF
IF FrameNum& = 2 THEN FrameNum& = 0
RETURN

Makchance:
chance = INT(RND * 10) + 1
RETURN

Movbunny:
dir = INT(RND * 2) + 1
IF dir = 1 THEN
    dir = 4: x = -10
ELSE
    dir = -4: x = 650
END IF
RETURN

Showbunny:
IF Active = 1 THEN
    bx = bx + dir
    CIRCLE (bx, 400), 5, 14
    IF bx <= 0 OR bx >= 640 THEN
        Active = 0
    END IF
ELSE
    GOSUB Makchance
    IF chance = 9 THEN
        Active = 1
        GOSUB Movbunny
    END IF
END IF
RETURN

Collision:
hx1 = x1 + 42: hx2 = x1 + 58 'horizontal co-ord of hawk feet
hy1 = y1 + 46: hy2 = hy1 + 10 'vertical  co-ord of hawk feet
rx1 = bx - 4: rx2 = rx1 + 12 'rabbit right + left side co-ords

IF ShowBox = True THEN
    LINE (hx1, hy1)-(hx2, hy2 + 10), 5, B
END IF

IF hy1 >= 394 AND hy2 <= 404 THEN
    IF hx1 >= rx1 AND hx1 <= rx2 THEN
        IF Captured = False THEN
            Captured = True
            SOUND 2500, 1
        END IF
    END IF
END IF
RETURN 
--------------------end code-------------------------------
http://dl.dropbox.com/u/15387474/Abackground.bmp
Ok guess thats about it, I am anxious to see how to make the Hawk, release and drop the "circle" into his nest, and get 10 points,...the circle later will be changed into a rabbit,...
Edit: Here is the rabbit.bmp, :
http://dl.dropbox.com/u/15387474/Rabbit4.bmp
   How to add the _keydown , so if the Z is pressed it gets released ? So just guessing, a new case needs to be made, and instead of the circle, _putimage and _loadimage, I guess this would be a good place, or first explain how to add the code to release the circle, then later, on how to load and put the 4 frame rabbit, so he is jumping around, eracticly, (randomly), I think just back and forth is too easy,..
guess thats about it for now from Garry

from Garry
« Last Edit: September 06, 2011, 10:10:00 pm by GarrisonRicketson » Report Spam   Logged

Dustie Bear
Full Member
***
Posts: 115


« Reply #2 on: March 10, 2011, 10:30:36 pm »


Hi

I downloaded the Hawk sprite and the background

For some reason im getting invalid handle on line 6.

havnet checked thing out yet, Im sure i put them in qb64 folder but
will check that out soon.

Dustie
Report Spam   Logged
Dustie Bear
Full Member
***
Posts: 115


« Reply #3 on: March 10, 2011, 10:33:15 pm »

Never mind LOL

I didnt pay atention to the fact that its in a zip file.  Grin

Just put it in there epecting it to work Cool


Dustie
Report Spam   Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Buy traffic for your forum/website
traffic-masters
Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy