Liberty BASIC Community Forum
« game controles »

Welcome Guest. Please Login or Register.
Jan 22nd, 2018, 5:45pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: game controles  (Read 185 times)
kevin
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 418
xx game controles
« Thread started on: Aug 14th, 2017, 04:30am »

goodmorning
I found this code in the JB Archives and I am atepting to develop this into a game
but now if you run the code you will see that the ship is controlled by the arrow keys (left and right)

What I'm trying to do is to change the control of the ship to the mouse
EG right left and most importantly up and down
not to forget shooting multiple shots with the mouse button

may be is there somebody out there that could assist
Pretty please
Code:
'move sprite and shoot
'uses spritetravelxy
nomainwin
'ship is 40x40
'shot is 10x10

maxX=550 : maxY=400
WindowWidth=maxX+50 : WindowHeight=maxY+50

loadbmp "ship","bmp\ship.bmp"
loadbmp "shot","bmp\shoot.bmp"

open "Shooting Multiple Missiles" for graphics_nsb_nf as #1
    #1 "trapclose [quit]"

    'create a black background with stars:
    #1 "down; fill black; color white"
    for i = 1 to 200
        x = int(rnd(0)*maxX)
        y = int(rnd(0)*maxY)
        #1 "set ";x;" ";y
    next
    #1 "getbmp bkg 0 0 ";maxX;" ";maxY

    'set the background
    #1 "background bkg"

    'add your sprites
    #1 "addsprite ship ship"

    'add 10 identical missiles
    'all use same loaded bmp
    'concatenate sprite names
    for i = 1 to 10
        #1 "addsprite shot"+str$(i)+" shot"
    next

    'set ship location
    shipX=100 : shipY=maxY-20
    #1 "spritexy ship ";shipX;" ";shipY

    'set location of all missiles off screen
    shotX=-100 : shotY=-100
    for i = 1 to 10
        #1 "spritexy shot"+str$(i)+" ";shotX;" ";shotY
    next
    activeShot=0    'var to hold number of most recently fired missile

    bgX=0:bgY=0

    'show frame onscreen
    #1 "drawsprites"

    'set up to trap keypresses
    #1 "setfocus; when characterInput [check]"

[mainLoop]
    SCAN    'scan for user events
    gosub [moveship]
    'slight pause to slow action:
    calldll #kernel32, "Sleep",10 as long, re as void
    goto [mainLoop]


[check]
    k$=Inkey$   'place value of Inkey$ into k$
    if k$="4" or asc(right$(k$,1))=37 then gosub [goLeft]
    if k$="6" or asc(right$(k$,1))=39 then gosub [goRight]
    if k$="8" or asc(right$(k$,1))=38 then gosub [goShoot]
    goto [mainLoop]

[goLeft]
    #1 "spritexy? ship x y"
    if x <= 0 then wait   'ship is at left side already
    shipX = shipX - 5
    return

[goRight]
    #1 "spritexy? ship x y"
    if x >= maxX then wait   'ship is at right side already
    shipX = shipX + 5
    return

[goShoot]
    activeShot=activeShot+1
    if activeShot>10 then activeShot=1
    #1 "spritexy? ship x y"
    'start shot near center of ship
    shotX=x+15:shotY=maxY
    'set shot to travel to top of screen and
    'fire event when it gets there
    #1 "spritexy shot"+str$(activeShot)+" ";shotX;" ";shotY
    #1 "spritetravelxy shot"+str$(activeShot)+" ";shotX;"  0 5 [checkShoot]"
    playwave "laser.wav", async
    return

[checkShoot]
    for i = 1 to 10
        #1 "spritexy? shot"+str$(i)+" sx sy"
        if sy<=0 then
            'move shot sprite off screen, update display
            #1 "spritexy shot"+str$(i)+" -100 -100"
        end if
    next
    #1 "drawsprites"    'update screen!
    goto [mainLoop]

[moveship]
    'put sprites in new location
    bgY=bgY-2   'scroll background
    #1 "backgroundxy ";bgX;" ";bgY
    #1 "spritexy ship ";shipX;" ";shipY
    #1 "drawsprites"    'update screen!
    RETURN

[quit]
    unloadbmp "bkg"
    unloadbmp "ship"
    unloadbmp "shot"
    close #1:end
 


Kevin

User IP Logged

KEVIN
tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1732
xx Re: game controles
« Reply #1 on: Aug 17th, 2017, 05:39am »

Hm.
I broke keyboard control
(it always follows mouse)

Kinda fixed that.
Code:
'move sprite and shoot
'uses spritetravelxy
nomainwin
'ship is 40x40
'shot is 10x10

maxX=550 : maxY=400
WindowWidth=maxX+50 : WindowHeight=maxY+50

'loadbmp "ship","bmp\ship.bmp"
loadbmp "ship","sprites\crab1.bmp"
'loadbmp "shot","bmp\shoot.bmp"
loadbmp "shot","sprites\pizza.bmp"

open "Shooting Multiple Missiles" for graphics_nsb_nf as #1
    #1 "trapclose [quit]"

    'create a black background with stars:
    #1 "down; fill black; color white"
    for i = 1 to 200
        x = int(rnd(0)*maxX)
        y = int(rnd(0)*maxY)
        #1 "set ";x;" ";y
    next
    #1 "getbmp bkg 0 0 ";maxX;" ";maxY

    'set the background
    #1 "background bkg"

    'add your sprites
    #1 "addsprite ship ship"

    'add 10 identical missiles
    'all use same loaded bmp
    'concatenate sprite names
    for i = 1 to 10
        #1 "addsprite shot"+str$(i)+" shot"
    next

    'set ship location
    shipX=100 : shipY=maxY-20
    #1 "spritexy ship ";shipX;" ";shipY

    'set location of all missiles off screen
    shotX=-100 : shotY=-100
    for i = 1 to 10
        #1 "spritexy shot"+str$(i)+" ";shotX;" ";shotY
    next
    activeShot=0    'var to hold number of most recently fired missile

    bgX=0:bgY=0

    'show frame onscreen
    #1 "drawsprites"

    'set up to trap keypresses
    #1 "setfocus; when characterInput [check]"
    #1 "when leftButtonUp [shoot]"
    #1 "when mouseMove [move]"       

[mainLoop]
    SCAN    'scan for user events
    gosub [moveship]
    'slight pause to slow action:
    calldll #kernel32, "Sleep",10 as long, re as void
    if toMove goto [move]
    goto [mainLoop]

'-------------------
[move]
toMove = 1 
    #1 "spritexy? ship x y"
    if MouseX>shipX + 5 then 
        gosub [goRight]
    else 
        if MouseX<shipX - 5 then 
            gosub [goLeft]
else
toMove = 0 
      end if
    end if
    goto [mainLoop]

[shoot]
    gosub [goShoot]
    goto [mainLoop]


[check]
    k$=Inkey$   'place value of Inkey$ into k$
    if k$="4" or asc(right$(k$,1))=37 then gosub [goLeft]
    if k$="6" or asc(right$(k$,1))=39 then gosub [goRight]
    if k$="8" or asc(right$(k$,1))=38 then gosub [goShoot]
    goto [mainLoop]

[goLeft]
    #1 "spritexy? ship x y"
    if x <= 0 then wait   'ship is at left side already
    shipX = shipX - 5
    return

[goRight]
    #1 "spritexy? ship x y"
    if x >= maxX then wait   'ship is at right side already
    shipX = shipX + 5
    return
                                         
[goShoot]                                
    activeShot=activeShot+1
    if activeShot>10 then activeShot=1
    #1 "spritexy? ship x y"
    'start shot near center of ship
    shotX=x+15:shotY=maxY
    'set shot to travel to top of screen and
    'fire event when it gets there
    #1 "spritexy shot"+str$(activeShot)+" ";shotX;" ";shotY
    #1 "spritetravelxy shot"+str$(activeShot)+" ";shotX;"  0 5 [checkShoot]"
    playwave "laser.wav", async
    return

[checkShoot]
    for i = 1 to 10
        #1 "spritexy? shot"+str$(i)+" sx sy"
        if sy<=0 then
            'move shot sprite off screen, update display
            #1 "spritexy shot"+str$(i)+" -100 -100"
        end if
    next
    #1 "drawsprites"    'update screen!
    goto [mainLoop]

[moveship]
    'put sprites in new location
    bgY=bgY-2   'scroll background
    #1 "backgroundxy ";bgX;" ";bgY
    #1 "spritexy ship ";shipX;" ";shipY
    #1 "drawsprites"    'update screen!
    RETURN

[quit]
    unloadbmp "bkg"
    unloadbmp "ship"
    unloadbmp "shot"
    close #1:end
 
« Last Edit: Aug 17th, 2017, 05:44am by tsh73 » User IP Logged

damned Dog in the Manger
kevin
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 418
xx Re: game controles
« Reply #2 on: Aug 18th, 2017, 07:24am »

Thank you Tsh73

Kevin wink
User IP Logged

KEVIN
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls