:D
This one is slightly more complicated, and I actually wrote this one
before the avalanche game. Its named test 5 so your boss doesn't
think you are slacking off...
; a sweet game written in IDL by Bill Freeman!
; e-mail bugs to billfreeman44 [[at]] yahoo.com
pro test6,totaluserpoints,dead=dead ; program if the user DIES or the
game ends....
; MAKE SAVE FILE IF IT DOES NOT EXIST ALREADY
temp = file_search('highscores.sav',count=count)
if count eq 0 then begin
hsscore=(indgen(10)+10)*15
hsname=replicate('billfreeman44@yahoo.com',10)
save,hsname,hsscore,filename='highscores.sav'
print, 'High Score list has been made.'
endif
if keyword_set(dead) then begin
oplot,indgen(100),indgen(100),linestyle=difficulty
print, "HIT!"
print, "ALL LIVES GONE!"
PRINT, "YOU FAIL..."
PRINT, "GAME OVER!!"
PRINT, "TOTAL POINTS= "+strcompress(string(totaluserpoints))
endif else begin
totaluserpoints=totaluserpoints+1000
print, "You win!"
PRINT, "TOTAL POINTS= "+strcompress(string(totaluserpoints))
endelse
restore,'highscores.sav'
if totaluserpoints gt min(hsscore) then begin
name='string'
print, "AND YOU GOT A HIGH SCORE!"
PRINT, "A+ AND A GOLD STAR FOR YOU!"
PRINT, "ENTER YOUR NAME BELOW!!! (or type exit to quit)"
read,name
if name eq 'exit' then goto, theend
hsscore[n_elements(hsscore)-1]=totaluserpoints
hsname[n_elements(hsscore)-1]=name
endif
hsname=hsname[reverse(sort(hsscore))]
hsscore=hsscore[reverse(sort(hsscore))]
plot,[0,100],[0,100],/
nodata,background=backgroundcolor,color=enemycolor
for i=0,n_elements(hsscore)-1,1 do print,i+1,' '+hsname[i],hsscore[i]
save,hsname,hsscore,filename='highscores.sav'
theend:
end
pro test5
;COLORS
;red+256.*green+65536.*blue
red=150
blue=65536.*150
yellow=150+256.*150
orange=150+256.*97
green=256.*150
white=200+256.*200+65536.*200
black=1
;VARIABLES
levelnum=1 ; starting level (don't set to 0)
maxnumlevels=21 ; last level
userlinestyle=0 ; user linestyle!
enemycolor=white
usersizex=1 ; inital starting value for the size!
usersizey=1 ; inital starting value for the size!
backgroundcolor=black ; background color
maxenemies=500 ; maximum number of enemies!
maxpoints=50 ; max number of points on the screen
enemypsym=2 ; psym of the enemies... this makes the game look totally
different if changed
enemythick=1 ; thickness of the enemies
A = FINDGEN(17) * (!PI*2/16.)
USERSYM, COS(A)*2.0, SIN(A)*2.0, /FILL ; generates a circle for the
user defined psym
pointpsym=8 ; psym value of the point
pointthick=1 ; thickness of the points that you collect.... doesn't
make them easier to get
numlives=3 ; number of lives that you start with
invinciblestyle=1 ; linestyle after you are hit
invincibletime=150 ; timer for how long you stay invincible
; DO NOT EDIT THESE VARS!
device, decomposed=1 ; magical color setting
usergothit=0 ; you don't start hit, do ya?
thekey='string'
ans='string'
Xenemypos=replicate(0.0,maxenemies)
Yenemypos=replicate(0.0,maxenemies)
Xenemyvel=replicate(0.0,maxenemies)
Yenemyvel=replicate(0.0,maxenemies)
Tenemytim=replicate(0,maxenemies)
Xpointpos=replicate(0,maxpoints)
Ypointpos=replicate(0,maxpoints)
Tpointtim=replicate(0,maxpoints)
enemynum=0
pointnum=0
totaluserpoints=0
saveuserlinestyle=userlinestyle
;INTRO GAME SCREEN
plot,[0,100],[0,100],/
nodata,background=backgroundcolor,xminor=1,yminor=1,xmargin=
[0,0],ymargin=[0,0],ticklen=0,xticks=1,yticks=1
xyouts,50,60, "DODGE THE NEUTRINOS 4.0",alignment=.
5,charsize=3.5
xyouts,50,50, "click a difficulty to continue",alignment=.
5,charsize=2.5
xyouts,50,45, "hit p to pause (while playing).",alignment=.
5,charsize=2
xyouts,50,40, "hit any key to EXIT (while
playing).",alignment=.5,charsize=1
xyouts,25,25, "EASY",alignment=.5,charsize=1
xyouts,50,25, "MEDIUM",alignment=.5,charsize=1
xyouts,75,25, "HARD",alignment=.5,charsize=1
;GET DIFFICULTY
cursor,xpos,ypos,/up
if abs(xpos-25) lt abs(xpos-50) and abs(xpos-25) lt abs
(xpos-75) then difficulty=1
if abs(xpos-50) lt abs(xpos-25) and abs(xpos-50) lt abs
(xpos-75) then difficulty=2
if abs(xpos-75) lt abs(xpos-25) and abs(xpos-75) lt abs
(xpos-50) then difficulty=3
plot,[0,100],[0,100],/
nodata,background=backgroundcolor,xminor=1,yminor=1,xmargin=
[0,0],ymargin=[0,0],ticklen=0,xticks=1,yticks=1
if difficulty eq 1 then xyouts,50,50, "EASY",charsize=2
if difficulty eq 2 then xyouts,50,50, "MEDIUM",charsize=2
if difficulty eq 3 then xyouts,50,50, "HARD",charsize=2
WAIT,1
;ASK FOR USER COLOR
plot,[0,100],[0,100],/
nodata,background=backgroundcolor,color=enemycolor,xminor=1, yminor=1,xmargin=
[0,0],ymargin=[0,0],ticklen=0,xticks=1,yticks=1
xyouts,50,50, "click your color",alignment=.
5,charsize=2.5,color=enemycolor
xyouts,10,25, "RED",alignment=.5,charsize=1,color=red
xyouts,20,25, "BLUE",alignment=.5,charsize=1,color=blue
xyouts,30,25, "GREEN",alignment=.5,charsize=1,color=green
xyouts,40,25, "ORANGE",alignment=.5,charsize=1,color=orange
xyouts,50,25, "BLACK",alignment=.5,charsize=1,color=enemycolor
xyouts,60,25, "WHITE",alignment=.5,charsize=1,color=enemycolor
;GET USER COLOR
cursor,xpos,ypos,/up
if xpos le 15 then usercolor=red
if xpos le 25 and xpos gt 15 then usercolor=blue
if xpos le 35 and xpos gt 25 then usercolor=green
if xpos le 45 and xpos gt 35 then usercolor=orange
if xpos le 55 and xpos gt 45 then usercolor=black
if xpos le 65 and xpos gt 55 then usercolor=white
if xpos gt 65 then usercolor=white
plot,[0,100],[0,100],/
nodata,background=backgroundcolor,xminor=1,yminor=1,xmargin=
[0,0],ymargin=[0,0],ticklen=0,xticks=1,yticks=1
xyouts,50,50, "COLOR!",alignment=.5,charsize=2.5,color=usercolor
WAIT,.5
while levelnum lt maxnumlevels do begin ;
;LEVEL VARIABLES...
levellength=long(300*levelnum+500+32*difficulty*levelnum)/1. 28
diffnum=fix(20+levelnum*1.5+difficulty*2) ; PERCENT CHANCE OF ENEMY
SPAWN.
pointspawnrate=25+levelnum ; USES TIMER=THIS TO MAKE POINTS.
pointduration=120-levelnum ; Duration of the points
if difficulty eq 1 then newvel=.10 ; how fast the enemies go
if difficulty eq 2 then newvel=.133
if difficulty eq 3 then newvel=.180
if difficulty eq 1 then upvel=.0521
if difficulty eq 2 then upvel=.06927
if difficulty eq 3 then upvel=.09375
;RESET ENEMIES AND POINTS
Xenemypos=replicate(0.0,maxenemies)
Yenemypos=replicate(0.0,maxenemies)
Xenemyvel=replicate(0.0,maxenemies)
Yenemyvel=replicate(0.0,maxenemies)
Tenemytim=replicate(0,maxenemies)
Xpointpos=replicate(0,maxpoints)
Ypointpos=replicate(0,maxpoints)
Tpointtim=replicate(0,maxpoints)
usergothit=0
userlinestyle=saveuserlinestyle
pointspawntimer=0 ;this counts up to point spawn rate
invincibletimer=0 ;counts down to 0 and if hit it = invincibletime
;INTRO TO EACH LEVEL..
plot,[0,100],[0,100],/
nodata,background=backgroundcolor,xminor=1,yminor=1,xmargin=
[0,0],ymargin=[0,0],ticklen=0,xticks=1,yticks=1
xyouts,50,50, "Beginning level "+strcompress(string(levelnum),/
remove_all),alignment=.5,color=enemycolor
xyouts,50,45, "This will last "+strcompress(string(fix
(levellength)/50),/remove_all)+" seconds",alignment=.
5,color=enemycolor
xyouts,50,40, "Enemies/sec= " +strcompress(string(diffnum*
(32.0/100.0)),/remove_all),alignment=.5,color=enemycolor
xyouts,50,35, "score = "+strcompress(string(fix
(totaluserpoints)),/remove_all),alignment=.5,color=enemycolo r
wait,2
for thetime=long(0),long(levellength),long(1) do begin
;DRAW LEVEL
plot,[0,100],[0,100],/
nodata,background=backgroundcolor,color=enemycolor,/ys,/
xs,xminor=1,yminor=1,xmargin=[0,0],ymargin=
[0,0],ticklen=0,xticks=1,yticks=1
;DRAW HUD
xyouts,2,98, "score = "+strcompress(string(fix
(totaluserpoints)),/remove_all),color=enemycolor
xyouts,2,96, "lives = " +strcompress(string(fix(numlives)),/
remove_all),color=enemycolor
;GET AND DRAW USER...
cursor,xpos,ypos,/nowait
;CHECK IF USER OUT OF RANGE.
IF xpos lt usersizex then xpos=usersizex
IF xpos gt 100.-usersizex then xpos=100.-usersizex
IF ypos lt usersizey then ypos=usersizey
IF ypos gt 100.-usersizey then ypos=100.-usersizey
oplot,[xpos-usersizex,xpos-usersizex,xpos+usersizex,xpos
+usersizex,xpos-usersizex],$
[ypos-usersizey,ypos+usersizey,ypos+usersizey,ypos-
usersizey,ypos-usersizey],linestyle=userlinestyle,color=user color
;DRAW ENEMIES...
index=WHERE(Tenemytim gt 0,check)
if check ne 0 then oplot,Xenemypos[index],Yenemypos
[index],psym=enemypsym,thick=enemythick,color=enemycolor
;DRAWPOINTS
index=where(Tpointtim ge 1,check)
if check ne 0 then begin
oplot,Xpointpos[index],Ypointpos
[index],psym=pointpsym,thick=pointthick,color=thetime*long(3 60)
Tpointtim[index]=Tpointtim[index]-1
endif
;CHECK FOR PAUSE...
input=get_kbrd(0)
if input ne "" then thekey=input
if thekey eq "." then goto, hax ; the . key causes cheets to occur.
(but doesn't allow point gain)
if thekey ne 'string' then begin ; string is the default value
if thekey ne 'p' then begin
print, "EXITING."
plot,indgen(100),indgen(100) ; plot a line to look like you were
doing something productive
goto, theend
endif
print,'paused.. enter to continue, or type exit to exit.'
read,ans
if ans eq 'exit' then goto, theend
thekey='string'
endif
;CHECK FOR HIT...
if usergothit then begin
invincibletimer--
if invincibletimer ge 100 then xyouts,50,50, "YOU GOT
HIT!",alignment=.5,charsize=2
if invincibletimer le 0 then begin
usergothit=0
userlinestyle=saveuserlinestyle
endif
goto, afterhit ; don't check for hits if already hit!!!
endif
hittest=WHERE((Xenemypos gt xpos-usersizex and Xenemypos lt
xpos+usersizex) $
and (Yenemypos gt ypos-usersizey and Yenemypos lt
ypos+usersizey),check)
if check ne 0 then begin
numlives--
usergothit=1
userlinestyle=invinciblestyle
invincibletimer=invincibletime
if numlives eq 0 then begin
test6,totaluserpoints,/dead ; this is the failure program when the
game ends.
goto, theend ; that 1 is because the user DIED.
endif
endif
afterhit:
;CHECK FOR POINT GAIN...
hittest=WHERE((Xpointpos gt xpos-usersizex and Xpointpos lt
xpos+usersizex) $
and (Ypointpos gt ypos-usersizey and Ypointpos lt
ypos+usersizey),check)
if check ne 0 then begin
totaluserpoints=totaluserpoints+n_elements(hittest)*difficul ty
Xpointpos[hittest]=0
Ypointpos[hittest]=0
Tpointtim[hittest]=0
endif
hax:
;WAIT
wait,0.02 ; 50 FPS 32 fps .03125
;RECALCULATE ENEMY LOCATION...
index=where(Tenemytim ge 1,check)
if check ne 0 then begin
Xenemypos[index]=Xenemypos[index]+Xenemyvel[index] + float(xenemyvel
[index])*abs(sin(tenemytim[index]/15.0)*3.0)
Yenemypos[index]=Yenemypos[index]+Yenemyvel[index] + yenemyvel[index]
*abs(cos(tenemytim[index]/15.0)*3.0)
Tenemytim[index]=Tenemytim[index]+1
endif
;GENERATE NEW ENEMIES...
rn1=FIX(100*RANDOMU(S, 1))
if rn1 le diffnum then begin
enemynum++
if enemynum ge maxenemies-1 then enemynum=0
rn2=FIX(4*RANDOMU(S, 1)) ;RANDOM NUMBER BETWEEN 0 AND
3
newpos=FIX(100*RANDOMU(S, 1))
Tenemytim[enemynum]=1
if rn2 eq 0 then begin;LEFT SIDE
Xenemypos[enemynum]=0.0
Yenemypos[enemynum]=newpos
Xenemyvel[enemynum]=newvel
Yenemyvel[enemynum]=upvel
endif
if rn2 eq 1 then begin;RIGHT SIDE
Xenemypos[enemynum]=100.0
Yenemypos[enemynum]=newpos
Xenemyvel[enemynum]=newvel*(-1)
Yenemyvel[enemynum]=upvel
endif
if rn2 eq 2 then begin;TOP SIDE
Xenemypos[enemynum]=newpos
Yenemypos[enemynum]=100.0
Xenemyvel[enemynum]=upvel
Yenemyvel[enemynum]=newvel*(-1)
endif
if rn2 eq 3 then begin;BOTTOM SIDE
Xenemypos[enemynum]=newpos
Yenemypos[enemynum]=0.0
Xenemyvel[enemynum]=upvel
Yenemyvel[enemynum]=newvel
endif
endif
;DELETE OLD ENEMIES
del=WHERE(Xenemypos gt 101 or Xenemypos lt -1,check)
if check ne 0 then begin
Xenemypos[del]=0.0
yenemypos[del]=0.0
Xenemyvel[del]=0.0
yenemyvel[del]=0.0
Tenemytim[del]=0
endif
del=WHERE(Yenemypos gt 101 or Yenemypos lt -1,check)
if check ne 0 then begin
Xenemypos[del]=0.0
yenemypos[del]=0.0
Xenemyvel[del]=0.0
yenemyvel[del]=0.0
Tenemytim[del]=0
endif
;GENERATE POINTS... generates at a constant rate.
if pointspawntimer ge pointspawnrate then begin
pointnum++
pointspawntimer=0
if pointnum ge maxpoints-1 then pointnum=0
Tpointtim[pointnum]=pointduration
Xpointpos[pointnum]=25+FIX(50*RANDOMU(S, 1))
Ypointpos[pointnum]=25+FIX(50*RANDOMU(S, 1))
endif
pointspawntimer++
;END OF LEVEL
endfor
;END OF LEVEL BONUS
if difficulty eq 1 then totaluserpoints=totaluserpoints+fix
(levelnum*10)
if difficulty eq 2 then totaluserpoints=totaluserpoints+fix
(levelnum*7.5)
if difficulty eq 3 then totaluserpoints=totaluserpoints+fix
(levelnum*5)
;INCREASE IN SIZE AFTER LEVEL ENDS
usersizex=usersizex+.05*difficulty
usersizey=usersizey+.05*difficulty
levelnum++
endwhile
;AFTER USER WINS GAME
test6,totaluserpoints ; ending screen, high scores...
theend:
print, "END OF PROGRAM."
end
|