comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » AVALANCHE.PRO .... games in IDL FTW
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
AVALANCHE.PRO .... games in IDL FTW [message #69130] Mon, 14 December 2009 00:04
munka is currently offline  munka
Messages: 36
Registered: December 2009
Member
If you have ever needed to plot a whole bunch of things, you may of
put a plot command in a for/while loop. If you forgot to put
something like wait,1 in your loop, you might have gotten something
that looks like an animation almost. I noticed this, and this
"animation" in combination with the cursor function, you can make some
sweet games... like avalanche. I got bored and wrote out this game in
IDL (It's less than 200 lines!)

I realize there is some crappy programming going on in this program,
but oh well! I've only known of IDL (or programming for that matter)
for less than 3 years. (I'm an undergrad in physics/astronomy)

Stuff like
for i=0,maxenemies-1,1 do Xenemypos[i]=0.0
instead of:
Xenemypos=replicate(0.0,maxenemies)
and the use of goto statements......... :O
But don't worry about that....

So, I don't really have any questions. I'm just here to share the
wealth and show y'all this program. I have a better game written with
the same... "engine"...... but I've been adding comments to it,
because it is a bit more complicated. I'll post that on here a
probably sometime later this week. If you have questions or comments,
feel free to email me at billfreeman44 [at] yahoo.com. I don't check
my gmail very often.

Also, all this was possible because of Dr. Fanning's amazingly helpful
website ;)

Enjoy!
~Bill

(and if you look closely, you might even be able to cheat! :D )

pro avalanche
;VARIABLES
difficulty=1 ;set by user in game (see into game screen)
levelnum=1
maxnumlevels=50
usersizex=.5
usersizey=.5
maxenemies=1001
enemypsym=2

thetime=long(0)
thekey='string'
ans='string'
Xenemypos=fltarr(maxenemies)
Yenemypos=fltarr(maxenemies)
Yenemyvel=fltarr(maxenemies)
Tenemytim=fltarr(maxenemies)
for i=0,maxenemies-1,1 do Xenemypos[i]=0.0
for i=0,maxenemies-1,1 do Yenemypos[i]=0.0
for i=0,maxenemies-1,1 do Yenemyvel[i]=1./10*RANDOMU(S, 1)
for i=0,maxenemies-1,1 do Tenemytim[i]=0.0
enemynum=0
thetime=long(1)

;INTRO GAME SCREEN
plot,[0,100],[0,100],/nodata
xyouts,50,60, "AVALANCHE",alignment=.5,charsize=3.5
xyouts,50,50, "click a difficulty to begin",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
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

while levelnum lt maxnumlevels do begin

levelstart:
;LEVEL VARIABLES...
levellength=long(320);length of level in frames
diffnum=100.;fix(35+levelnum*1.5+difficulty*2);percent chance of
enemy spawn

;LEVEL BEGIN
for thetime=long(0),long(levellength),1 do begin

;DRAW LEVEL
plot,[0,100],[0,100],/nodata,xminor=1,yminor=1,xmargin=[0,0] ,ymargin=
[0,0],ticklen=0,xticks=1,yticks=1

;DRAW SCORE
xyouts,2,98, "score = "+strcompress(string(fix(((levelnum+float
(thetime)/float(levellength))*1000.-1000.)*difficulty)))

;INTRO TO EACH LEVEL..
if thetime lt 32 then begin
xyouts,50,70, "Beginning level "+strcompress(string(levelnum),/
remove_all),alignment=.5
xyouts,50,65, "This will last "$
+strcompress(string(fix(levellength)/32),/remove_all)+"
seconds",alignment=.5
xyouts,50,60, "Enemies/sec= "+strcompress(string(diffnum*
(32.0/100.0)),/remove_all),alignment=.5
endif

;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=0

;DRAW ENEMIES...
index=WHERE(Tenemytim ge 1)
check=size(index)
if check[0] ne 0 then begin
oplot,Xenemypos[index],Yenemypos[index],psym=enemypsym
endif

;CHECK FOR PAUSE...
input=get_kbrd(0)
if input ne "" then thekey=input
if thekey eq '.' then goto,hax
if thekey ne 'string' then begin
if thekey ne 'p' then begin
print, "EXITING."
plot,indgen(100),indgen(100)
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 thekey eq '.' then goto,hax
hittest=WHERE((Xenemypos gt xpos-usersizex and Xenemypos lt xpos
+usersizex) $
and (Yenemypos gt ypos-usersizey and Yenemypos lt
ypos+usersizey))
check=size(hittest)
if check[0] ne 0 then begin
oplot,indgen(100),indgen(100),linestyle=difficulty
print, "HIT!"
PRINT, "YOU FAIL..."
print, "Total score = ",fix(((levelnum+float(thetime)/float
(levellength))*1000.-1000.)*difficulty)
goto, theend
endif
hax:

;WAIT
wait,0.03125;32 fps

;RECALCULATE ENEMY LOCATION...
index=where(Tenemytim ge 1)
check=size(index)
if check[0] ne 0 then begin
Xenemypos[index]=Xenemypos[index]
Yenemypos[index]=Yenemypos[index]+Yenemyvel[index]-difficult y/3.0
Tenemytim[index]=Tenemytim[index]+1
endif

;GENERATE NEW ENEMIES...
rn1=FIX(levelnum*difficulty*RANDOMU(S, 1))
while rn1 le levelnum*difficulty do begin
enemynum++
if enemynum ge maxenemies-1 then enemynum=0
newvel= fix(RANDOMU(S, 1)*32.0)/32.0+levelnum/maxnumlevels
newpos=FIX(100*RANDOMU(S, 1))
Tenemytim[enemynum]=1
Xenemypos[enemynum]=newpos
Yenemypos[enemynum]=100.0
Yenemyvel[enemynum]=newvel*(-1)
rn1++
endwhile

;DELETE OLD ENEMIES
del=WHERE(Yenemypos gt 101 or Yenemypos lt -1)
check=size(del)
if check[0] ne 0 then begin
Xenemypos[del]=0.0
yenemypos[del]=0.0
yenemyvel[del]=0.0
Tenemytim[del]=0
endif

;LEVEL END
endfor

;END OF LEVEL CHANGES
usersizex=usersizex+.1*difficulty
usersizey=usersizey+.1*difficulty
levelnum++
endwhile

print, "you win!"
theend:
print, "END OF PROGRAM."
end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Displaying a matrix in the most literal sense
Next Topic: How import data from prompt to a widget?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:47:43 PDT 2025

Total time taken to generate the page: 0.16055 seconds