Naval game

Vragen en suggesties over het programmeren van spelletjes, sprites en dergelijke in Liberty BASIC

Moderator: anthonio

Naval game

Berichtdoor Gordon » za jun 28, 2008 12:10 pm

Ik zag ergens deze eenvoudige game liggen.
Hier is mijn versie.
Code: Selecteer alles
'sonar scherm
'G. Rahman 2008
'27 juni 2008

nomainwin
WindowWidth = 650
WindowHeight = 540

grad = .017453 'radialen
x1 = sin(60*grad)*250: y1 = cos(60*grad)*250
x2 = sin(30*grad)*250: y2 = cos(30*grad)*250

'place a Uboat
randAngle = rnd(0)*360
randAngle = randAngle + 90
randDistance = int(rnd(0)*200+50)

missiles = 5

textbox #m.angle, 590,0 ,40 ,25
textbox #m.dist, 590,30 ,40 ,25
button #m.b, "<<FIRE>>", [fire],ul,560,80
open "Naval Sonar battle screen" for graphics_nsb as #m
#m "trapclose [quit]"


[start]
randAngle = randAngle + 5
UboatX = sin(randAngle*grad)*randDistance
UboatY = cos(randAngle*grad)*randDistance

#m "down; fill black"
#m "backcolor 0 48 0 ;color 0 170 0"
#m "size 1"
#m "place 250 250"
#m "down; circlefilled 250; circle 235; circle 80 ;circle 160"

#m "line 0 250 500 250"
#m "line 250 0 250 500"

#m "line ";x1+250;" ";y1+250;" ";250-x1;" ";250-y1
#m "line ";x2+250;" ";y2+250;" ";250-x2;" ";250-y2

#m "line ";x1+250;" ";y1+0;" ";250-x1;" ";250+y1
#m "line ";x2+250;" ";250-y2;" ";250-x2;" ";250+y2

#m "place 240 497" :#m "| 270"
#m "place 240 12"  :#m "| 90"
#m "place 487 250" :#m "| 0"
#m "place 0 248"   :#m "| 180"

#m "color yellow"
#m "place 500 23" :#m "| ANGLE"
#m "place 500 53" :#m "| DISTANCE"

#m "color red; size 4"
' #m "set ";UboatX+250;" ";UboatY+250  'verwijder hier de rem om het spookschip te zien
#m "flush"

wait


[fire]
'get user input
missiles = missiles - 1
if missiles < 1 then notice "Sorry no missiles!!" :goto [quit]
#m.angle "!contents? angle"
#m.dist "!contents? distance"
if distance > 225 then distance = 225 :notice "rocket LOST!!"
if distance < 20 then notice "Surrender?!?"


#m "color white; size 4"
angle = angle + 90
for i = 1 to distance+20 step 20
MissileX = sin(angle*grad)*i: MissileY = cos(angle*grad)*i
#m "set ";MissileX+250;" ";MissileY+250
sleep = 500 :gosub [delay]
next i

#m "place ";MissileX+250;" ";MissileY+250
#m "down; backcolor yellow ;circlefilled 20"
d = sqr((UboatX-MissileX)^2+(UboatY-MissileY)^2)

sleep = 1000 :gosub [delay]

    if d <25 then
    notice "you GOT him on ";d;" miles" :end
    else
    notice "Missed by about ";int(d); "miles"
    confirm "Do you want a plot";yn$
    if yn$ = "yes" then gosub [plot]
    end if

goto [start]
wait

[plot]
missiles = missiles - 1
#m "backcolor 0 88 0" :#m "color 0 88 0"
#m "down ;circlefilled ";d
sleep = 3000 :gosub [delay]
return
wait

[delay]
    timer sleep , [done]
    wait
    [done]
    timer 0
    return

[quit]
close #m
end


Je hebt 5 raketten ter beschikking om het spookschip te grazen
te nemen. De raketten gaan maximaal 225 mijl vooruit.

Gordon.
Avatar gebruiker
Gordon
Site Admin
 
Berichten: 684
Geregistreerd: zo mei 22, 2005 12:50 am

Re: Naval game

Berichtdoor Gordon » za jul 05, 2008 11:43 pm

Okay,

Hier is een volledige versie.
Met geluid en een enkele bug-fixed.

Gordon
Bijlagen
Naval War.zip
Veel plezier
(119.75 KiB) 177 keer gedownload
Avatar gebruiker
Gordon
Site Admin
 
Berichten: 684
Geregistreerd: zo mei 22, 2005 12:50 am


Keer terug naar Games

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron