Post by williac on Feb 12, 2005 20:04:20 GMT -5
This is my first attempt with b4gl. It will eventually have custom sprites and sounds but For now I used resources that came with b4gl.
8XenoTrogdor8 helped me with the moving a sprite using the mouse. the rest I picked up from the example code I saw.
any comments are cool good or bad!!!!
to play move the big orance circle(will be crosshair soon) with the mouse. to shoot the red ball (will be ??? soon) click the left mouse button.
I also plan on cleaning up the code(placing all dim's together ect when Im done!#nosmileys#nosmileys#nosmileys
8XenoTrogdor8 helped me with the moving a sprite using the mouse. the rest I picked up from the example code I saw.
any comments are cool good or bad!!!!
to play move the big orance circle(will be crosshair soon) with the mouse. to shoot the red ball (will be ??? soon) click the left mouse button.
struc Sobject
dim sprite
dim x
dim y
endstruc
Dim file : file = OpenFileRead ("Files/score.txt") ' Open a file and read the highscore
Dim hscore
dim playername$
hscore = Val (ReadLine (File)) ' Read the highscore from the file
playername$ = ReadLine (File) ' Read the name from the file
if playername$=0 then playername$="no name" endif
CloseFile (file)
dim score
dim nameenter
nameenter=false
dim blast
blast=loadsound("Sounds\laser.wav")
dim mbleft
dim timer
timer=2400
mbleft=false
dim screen_width,screen_height
screen_width=spriteareawidth()-24
screen_height=spriteareaheight()-24
dim tex1,tex2
tex1= LoadTexture ("Data\ball.png")
tex2= LoadTexture ("Data\FB01.png")
dim sobject crosshair
crosshair.sprite=newsprite(tex2)
crosshair.x=200
crosshair.y=200
dim sobject target
target.sprite=newsprite(tex1)
dim targetspeed#
targetspeed#=1
SprSetVel (vec2 (targetspeed#,targetspeed#))
sprsetpos(100,100)
' Text buffered will eliminate the flicker, but you will have to call DrawText ().
TextMode (TEXT_BUFFERED)
'/////////////////////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////
while true 'start of main loop
if not timer>0 then gosub writescore endif
timer=timer-1
locate 1, 1: print"highscore: "+ hscore + " "+playername$
locate 1, 2: print"score: "+ score
locate 1,25: print timer/40+ " seconds left"
' X will be a percentage (given by the mouse X position) of screen width.
crosshair.x=mouse_x ()* SpriteAreaWidth ()
' Y will be a percentage (given by the mouseY position) of screen hieght.
crosshair.y=mouse_y ()* SpriteAreaHeight ()
'moves crosshair with mouse
bindsprite(crosshair.sprite)
sprsetPos (crosshair.x,crosshair.y)
'moves target around the screen bouncing off of the edges
bindsprite(target.sprite)
AnimateSprites ()
if SprLeft () < 0 or SprRight () > SpriteAreaWidth () then
SprSetXVel (-SprXVel ())
endif
if SprTop () < 0 or SprBottom () > SpriteAreaHeight () then
SprSetYVel (-SprYVel ())
endif
if mouse_button(0) then
if mbleft=false then
playsound(blast)
gosub checkhit
mbleft=true
endif
else mbleft=false
endif
' Draw sprites and text to the screen.
DrawText ()
waittimer(25)' keeps cycles per second at 40
wend 'end main loop
'//////////////////////////////////////////////////////////////////////////////////
'//////////////////////////////////////////////////////////////////////////////
checkhit:
if crosshair.x > sprleft() and crosshair.x < sprright() and crosshair.y > sprtop() and crosshair.y < sprbottom() then
score= score + 1
sprsetpos(rnd()%screen_width+12,rnd()%screen_height+12)
targetspeed#=targetspeed#+0.1
SprSetVel (vec2 (targetspeed#,targetspeed#))
endif
return
writescore:
if score>hscore then
gosub entername
file = OpenFileWrite ("Files/score.txt")
if FileError () <> "" then print FileError (): end endif
WriteLine (file, score)
WriteLine (file,playername$)
CloseFile (file)
endif
sleep(2000)
run
return
entername:
playername$=""
cls
while nameenter=false
playername$=playername$+Inkey$()
locate 6,5 :print "enter name:"+playername$
DrawText ()
if ScanKeyDown (vk_return) then nameenter=true endif
wend
return
I also plan on cleaning up the code(placing all dim's together ect when Im done!#nosmileys#nosmileys#nosmileys