-- pretend.exw -- defender-style demo video game for Win32Lib -- (c) 1999 David Cuny -- currently, the only things you can do are go up and down (arrow key), -- or fire an ineffective missile (space bar) -- to do: -- fix mountain display logic -- add game logic ----------------------------------------------------------------------------- include win32lib.ew include sort.e include get.e without warning ----------------------------------------------------------------------------- -- the game graphics constant scire = xpmToPixmap( { "54 12 4 1", " c None", " c None", "g c #aaaaaa", "x c #ffffff", " xxxxx ", " xxgggggxx ", " xg gx ", " xx ", " xx ", " xx xx xx xg gx xx ", " xx xggx xggx xg gx xggx xx ", " xx x x x xgx x x xg ", " xx xg xg gx xx xggggxxx ", " gx x x x xx x xg ", " xxgggggxx xggx xggx xx xggx xx ", " xxxxx xx xx xx xx "} ), one = xpmToPixmap( { "8 8 2 1", " c None", "x c #ffffff", " xx ", " xxx ", " x xx ", " xx ", " xx ", " xx ", " xx ", " xxxxxx "} ), two = xpmToPixmap( { "8 8 2 1", " c None", "x c #ffffff", " xxxx ", " x xx ", " xx ", " xx ", " xx ", " xx ", " xx ", " xxxxxx "} ), three = xpmToPixmap( { "8 8 2 1", " c None", "x c #ffffff", " xxxx ", " x xx ", " xx ", " xx ", " xx ", " xx ", " x xx ", " xxxx "} ), four = xpmToPixmap( { "8 8 2 1", " c None", "x c #ffffff", " x ", " x x ", " x x ", " xxxxxx ", " x ", " x ", " x ", " x "} ), five = xpmToPixmap( { "8 8 2 1", " c None", "x c #ffffff", " xxxxxx ", " x ", " x ", " xx ", " xxx ", " x ", " x x ", " xxxx "} ), six = xpmToPixmap( { "8 8 2 1", " c None", "x c #ffffff", " xxxx ", " x x ", " x ", " x ", " xxxxx ", " x xx ", " x x ", " xxxx "} ), seven = xpmToPixmap( { "8 8 2 1", " c None", "x c #ffffff", " xxxxxx ", " x x ", " x ", " x ", " x ", " x ", " x ", " x "} ), eight = xpmToPixmap( { "8 8 2 1", " c None", "x c #ffffff", " xxxx ", " x x ", " x x ", " xx ", " xx ", " x x ", " x x ", " xxxx "} ), nine = xpmToPixmap( { "8 8 2 1", " c None", "x c #ffffff", " xxxx ", " x x ", " xx xx ", " xxxxx ", " x ", " x ", " x x ", " xxxx "} ), zero = xpmToPixmap( { "8 8 2 1", " c None", "x c #ffffff", " xxxx ", " x x ", " x x ", " x x ", " x x ", " x x ", " x x ", " xxxx "} ), Missile = xpmToPixmap( { "2 2 2 2", " c None", "X c #ffffff", "XX", "XX" } ), Landerdot = xpmToPixmap( { "2 2 2 2", " c None", "X c #00ffff", "XX", "XX" } ), Mutantdot = xpmToPixmap( { "2 2 2 2", " c None", "X c #ff0000", "XX", "XX" } ), Mandot = xpmToPixmap( { "2 2 2 2", " c None", "X c #0000ff", "XX", "XX" } ), Mutant = xpmToPixmap( { "16 12 4 1", "y c #ffaa00", "b c #8888ff", "r c #FF3366", "G c #00AA00", " bbbr ", " rrbbbrrr ", " GrrbbbrrrG ", " GGr yrry GG ", " GGr rr GG ", " GGrrrrrrrrGG ", " GGryyyyrGG ", " GGGrrGGG ", " GG rr GG ", " GG rr GG ", " GG rr GG ", " GG rr GG " } ), Lander = xpmToPixmap( { "16 12 4 1", "b c #8888ff", "y c #ffaa00", "g c #88ff88", "G c #009900", " yyyy ", " GGybbyGG ", " GGbbggbbGG ", " GGb yggy bGG ", " GGb gg bGG ", " GGbggggggbGG ", " GGbggggbGG ", " GGbbbbGG ", " GG GG GG ", " GG GG GG ", " GG GG GG ", " GG GG GG " } ), Ship1 = xpmToPixmap( { "22 7 4 1", " c None", "x c #777777", "p c #ff66ff", "o c #cccccc", " x ", " xxx ", " xxxxx ", "xxxxxxxxxxxxxxpp ", "xxxxxxxxxxxxxxxxxxxoo ", "ppppppxxooxxxxxxxxxooo", " pppppxxoo " } ), Ship3 = xpmToPixmap( { "22 7 4 1", " c None", "x c #777777", "p c #ff66ff", "o c #cccccc", " x ", " xxx ", " xxxxx ", "xxxxxxxxxxxxxxpp ", "xxxxx xxxxxxxoo ", "pppppp oxxxxxxxxxooo", " pppppxxoo " } ), Ship4 = xpmToPixmap( { "22 7 4 1", " c None", "x c #777777", "p c #ff66ff", "o c #cccccc", " x ", " x ", " xx ", "xxx xpp ", "xxx xoo ", "pp oo", " p oo " } ), Ship2 = xpmToPixmap( { "22 7 4 1", " c None", "x c #777777", "p c #ff66ff", "o c #cccccc", " x ", " xxx ", " xxxxx ", " ppxxxxxxxxxxxxxx", " ooxxxxxxxxxxxxxxxxxxx", "ooxxxxxxxxxxooxxpppppp", " ooxxpppppp" } ), Ship5 = xpmToPixmap( { "22 7 4 1", " c None", "x c #777777", "p c #ff66ff", "o c #cccccc", " x ", " xxx ", " xxxxx ", " ppxxxxxxxxxxxxxx", " ooxxxxxxx xxxxx", "ooxxxxxxxxxxo pppppp", " ooxxpppppp" } ), Ship6 = xpmToPixmap( { "22 7 4 1", " c None", "x c #777777", "p c #ff66ff", "o c #cccccc", " x ", " x ", " xx ", " ppx xxx", " oox xxx", "oo pp", " oo p" } ), Ship7 = xpmToPixmap( { "8 4 4 1", " c None", "x c #777777", "p c #ff66ff", "o c #cccccc", " x ", "xxxp ", "xxxxxxo ", "ppxx " } ), Man = xpmToPixmap( { "6 10 4 1", " c None", "y c #ffaa00", "p c #cc00cc", "P c #ff44ff", " pp ", " yP ", " yPPP ", " PPPP ", " PPPP ", " PPPP ", " pp ", " pp ", " pp ", " pp " } ), Explode = xpmToPixmap( { "16 12 4 1", " c None", "y c #ffaa00", "r c #FF3366", "o c #ffaabb", " ry yr ", " ro roor or ", " ro rryyyrr or ", " or yyyyy ro", " or yyy ro", " or rooor ro ", " or orrrro ro ", " ror ror ", " or y y ro ", " or y y ro ", " or y y ro ", "or y y ro" } ), Explode1 = xpmToPixmap( { "16 12 4 1", " c None", "y c #ffaa00", "r c #FF3366", "o c #ffaabb", " ry yr ", " ro roor or ", " ro or", " or yyyyy r", " or y y r", " or yyyyy ro", " or ro ", " ror ror ", " or ro ", " or y y ro ", "or y y ro", "r y y r" } ), Explode2 = xpmToPixmap( { "16 12 4 1", " c None", "y c #ffaa00", "r c #FF3366", "o c #ffaabb", " ro roor or", " ", " ro yy yy o", " ", " ", " or ro", " or yy yy ro ", " ror ror ", " or ro ", " or y y ro ", "or y y ro", "r y y r" } ) ----------------------------------------------------------------------------- -- the game counts constant RefreshRate = 50, WinWide = 400, WinHigh = 300, WorldWide = WinWide * 7, Peaks = 40, Mutants = 20, Landers = 10, Men = 25, Maxshots = 8, scx = 280, scy = 0 integer shipX, -- ship x position shipY, -- ship y position shipDX, -- ship's x direction shipDY, -- ship's y direction liveshot, -- limit shots for collision detection level, -- level of play lives -- umm number of times your ship can be destroyed before EOF shipX = floor( WinWide/2 ) shipY = 150 shipDX = 10 shipDY = 0 liveshot = 0 sequence mountains,missiles,score score = {0,0,0,0} missiles = {} mountains = {} atom count, boom, ai -- count for men and boom for ship explosion ai for landers and mutants ----------------------------------------------------------------------------- -- sprite data structures constant Class = 1, Live = 2, X = 3, Y = 4, DX = 5, DY = 6, Timer = 7, NewSprite = repeat( 0, 7 ) sequence sprites, sprite sprites = {} count = 0 level = 0 lives = 3 boom = 0 ----------------------------------------------------------------------------- -- the gui constant Win = create( Window, "Pretender", 0, Default, Default, WinWide, WinHigh+26, 0 ), Buffer = create( Pixmap, "", 0, 0, 0, WinWide, WinHigh, 0 ) ----------------------------------------------------------------------------- procedure initialize(integer self, integer event, sequence parms) integer halfHigh sequence peaks -- create the sprites sprites = {} for i = 1 to Mutants+Landers+Men do -- create a new sprite sprite = NewSprite -- default attributes sprite[Live] = 1 sprite[X] = rand( WorldWide ) sprite[Y] = rand( WinHigh ) sprite[DX] = 0 sprite[DY] = 0 sprite[Timer] = 0 -- what class object is this? if i < Mutants then sprite[Class] = Mutant sprite[DX] = rand( 3 ) - 2 sprite[DY] = rand( 3 ) - 2 elsif i < Mutants+Landers then sprite[Class] = Lander sprite[DX] = rand( 3 ) - 2 sprite[DY] = rand( 3 ) - 2 else sprite[Class] = Man sprite[Y] = WinHigh - 10 sprite[DY] = 0 end if -- store it sprites = append( sprites, sprite ) end for -- create the mountain peaks peaks = {} halfHigh = floor( WinHigh/4 ) for i = 1 to Peaks do -- place a mountain randomly, height is less than half the screen peaks = append( peaks, { rand( WorldWide ), WinHigh - rand( halfHigh ) - 8 } ) end for -- sort the mountains in x order peaks = sort( peaks ) -- create the line segments for the mountains mountains = {} for i = 1 to Peaks - 1 do -- make a line segment from two adjacent points if (peaks[i+1][1] - peaks[i][1]) < 20 then peaks[i+1][1] += 20 end if mountains = append( mountains, peaks[i] & peaks[i+1] ) end for -- the first peak wraps to the last peak mountains = append( mountains, peaks[Peaks] & ( peaks[1] + {WorldWide, 0 } ) ) -- set the timer to go off once a second setTimer( Win, 1, RefreshRate ) -- set the window background color setWindowBackColor( Win, Black ) end procedure setHandler(Win, w32HOpen, routine_id( "initialize" )) ----------------------------------------------------------------------------- procedure levelup() integer halfHigh sequence peaks -- create the sprites sprites = {} for i = 1 to Mutants+(3*level)+Landers+(2*level)+Men do -- create a new sprite sprite = NewSprite -- default attributes sprite[Live] = 1 sprite[X] = rand( WorldWide ) sprite[Y] = rand( WinHigh ) sprite[DX] = 0 sprite[DY] = 0 sprite[Timer] = 0 -- what class object is this? if i < Mutants+level*3 then sprite[Class] = Mutant sprite[DX] = rand( 3 ) - 2 sprite[DY] = rand( 3 ) - 2 elsif i < Mutants+3*level+Landers+2*level then sprite[Class] = Lander sprite[DX] = rand( 3 ) - 2 sprite[DY] = rand( 3 ) - 2 else sprite[Class] = Man sprite[Y] = WinHigh - 10 sprite[DY] = 0 end if -- store it sprites = append( sprites, sprite ) end for -- create the mountain peaks peaks = {} halfHigh = floor( WinHigh/4 ) for i = 1 to Peaks do -- place a mountain randomly, height is less than half the screen peaks = append( peaks, { rand( WorldWide ), WinHigh - rand( halfHigh ) - 8 } ) end for -- sort the mountains in x order peaks = sort( peaks ) -- create the line segments for the mountains mountains = {} for i = 1 to Peaks - 1 do -- make a line segment from two adjacent points if (peaks[i+1][1] - peaks[i][1]) < 20 then peaks[i+1][1] += 20 end if mountains = append( mountains, peaks[i] & peaks[i+1] ) end for -- the first peak wraps to the last peak mountains = append( mountains, peaks[Peaks] & ( peaks[1] + {WorldWide, 0 } ) ) -- set the timer to go off once a second setTimer( Win, 1, RefreshRate ) -- set the window background color setWindowBackColor( Win, Black ) end procedure ----------------------------------------------------------------------------- procedure gameover() -- make the sequence of score a number, then see if its higher than highscore while get_key() = -1 do end while abort(0) end procedure ----------------------------------------------------------------------------- procedure drawBackground() -- clear the pixmap setPenColor( Buffer, Black ) drawRectangle( Buffer, 1, 0, 0, WinWide, WinHigh ) -- move the line segments, and render them setPenColor( Buffer, Green ) for i = 1 to length( mountains ) do -- add to x values mountains[i][1] -= shipDX mountains[i][3] -= shipDX -- does the line segment wrap? if mountains[i][1] > WorldWide then mountains[i][1] -= WorldWide mountains[i][3] -= WorldWide elsif mountains[i][3] < 0 then mountains[i][1] += WorldWide mountains[i][3] += WorldWide end if -- is the line segment visible in window? -- if mountains[i][3] < WinWide then -- render it drawLine( Buffer, mountains[i][1], mountains[i][2], mountains[i][3], mountains[i][4] ) -- end if end for --400*7 = 2800 or 280 is the midpoint drawLine( Buffer, 120, 1, 120, 31) drawLine( Buffer, 120, 31, 160, 31) drawLine( Buffer, 160, 31, 160, 1) drawLine( Buffer, 160, 1, 120, 1) end procedure ----------------------------------------------------------------------------- procedure moveSprites() -- handle the sprite logic sequence keep, miss atom shots, cnt, cnta, cntb -- when there are only men left, time for next level if ( length( sprites ) - count ) > 0 then -- 1 if -- handle the sprites cnt=0 for i = 1 to length( sprites ) do -- 1 for -- get sprite sprite = sprites[i] if sprite[Class] = Lander and sprite[Timer] > 0 then -- 2 if --cnt+=1 --position(cnt,10) --print(1, sprite[X]) --puts(1, " , ") --print(1, sprite[Y]) --puts(1, " , ") --find a man, lower onto him and rise back to top of screen --if the lander makes it to the top he escapes with the man if sprite[Timer] > 1 then --3 if if sprite[Y]<5 then --4 if sprite[Live] = 0 sprite[Timer] = 0 end if else --3 if for j = 1 to length( sprites ) do if sprites[j][Class]=Man and sprites[j][X]>sprite[X]-74 and sprites[j][X]sprite[X]+6 then --5 if sprite[DX]=2 elsif sprites[j][X]=sprite[X]+6 then sprite[DX]=0 else sprite[DX]=-2 end if --4 if if sprite[Y]>=275 and sprites[j][X]>sprite[X]+4 and sprites[j][X] 2 then --4 if sprite[Live] -= 1 elsif sprite[Live] = 2 then sprite[Live] = 0 end if --3 if if sprite[Live] > 5 then --4 if sprite[Class] = Explode elsif sprite[Live] >= 3 then sprite[Class] = Explode1 elsif sprite[Live] = 2 or sprite[Live] = 0 then sprite[Class] = Explode2 --3 if end if if sprite[Class] != Man and sprite[Class] != Missile and sprite[Timer] = 0 and sprite[Live]=1 then --closed ai = rand(1000)-500 if ai<0 and ai >=-2 then sprite[DX]-=1 end if if ai<2 and ai>=0 then sprite[DX]+=1 end if if ai>499 or ai<-499 and sprite[Class]=Lander then sprite[Timer]=1 end if if ai<=-246and ai>-249 then sprite[DY]+=1 end if if ai>=246 and ai<249 then sprite[DY]-=1 end if if sprite[DX]>8 then sprite[DX]=8 end if if sprite[DY]>6 then sprite[DY]=6 end if if sprite[DX]<-8 then sprite[DX]=-8 end if if sprite[DY]<-6 then sprite[DY]=-6 end if end if --closed -- move along the x axis sprite[X] += sprite[DX] - shipDX if sprite[X] < 0 then sprite[X] += WorldWide --closed elsif sprite[X] > WorldWide then sprite[X] -= WorldWide end if --closed -- move along the y axis -- add velocity sprite[Y] += sprite[DY] -- reached top or bottom? if sprite[Y] > WinHigh - 10 then sprite[Y] = WinHigh - 10 if sprite[Class]!=Man then sprite[DY] = -sprite[DY] else sprite[DY] = 0 end if elsif sprite[Y] < 0 then if sprite[Class]=Man then sprite[Live]=0 end if --closed sprite[Y] = 0 sprite[DY] = -sprite[DY] end if --closed -- is the sprite visible? if sprite[X] < WinWide then --closed -- display sprite and the scire? erm.. its the score --?sprite transBlt( Buffer, sprite[X], sprite[Y], sprite[Class] ) end if --closed transBlt( Buffer, scx, scy, scire ) -- a sequence for the score? how stupid am I? here's the proof ... for j = 1 to length( score ) do --closed if score[j] = 0 then transBlt( Buffer, scx + 48 + 8 * j, scy + 4, zero) elsif score[j] = 2 then transBlt( Buffer, scx + 48 + 8 * j, scy + 4, two) elsif score[j] = 3 then transBlt( Buffer, scx + 48 + 8 * j, scy + 4, three) elsif score[j] = 4 then transBlt( Buffer, scx + 48 + 8 * j, scy + 4, four) elsif score[j] = 5 then transBlt( Buffer, scx + 48 + 8 * j, scy + 4, five) elsif score[j] = 6 then transBlt( Buffer, scx + 48 + 8 * j, scy + 4, six) elsif score[j] = 7 then transBlt( Buffer, scx + 48 + 8 * j, scy + 4, seven) elsif score[j] = 8 then transBlt( Buffer, scx + 48 + 8 * j, scy + 4, eight) elsif score[j] = 9 then transBlt( Buffer, scx + 48 + 8 * j, scy + 4, nine) elsif score[j] = 1 then transBlt( Buffer, scx + 48 + 8 * j, scy + 4, one) end if end for --closed -- update it end if --2 if sprites[i] = sprite end for --0 for -- remove the dead sprites keep = {} miss = keep shots = 0 count = 0 -- go through each sprite for i = 1 to length( sprites ) do --closed -- still alive? if sprites[i][Live] then cnta=floor(sprites[i][X]/10)+120 if cnta > 280 then cnta -= 280 end if cntb=floor(sprites[i][Y]/10) if sprites[i][Class]=Mutant then transBlt(Buffer,cnta, cntb, Mutantdot) elsif sprites[i][Class]=Lander then transBlt(Buffer,cnta, cntb, Landerdot) elsif sprites[i][Class]=Man then transBlt(Buffer,cnta, cntb, Mandot) end if if sprites[i][Class] = Missile and sprites[i][Timer] > 1 then miss = append( miss, sprites[i] ) -- trouble gettin rid of spent missiles, dunno where, here's where I fixed it. keep = append( keep, sprites[i] ) shots += 1 -- add to the "keep" list elsif sprites[i][Class] != Missile then keep = append( keep, sprites[i] ) if sprites[i][Class] = Man then count += 1 end if end if end if end for --closed -- replace lists, and liveshot again, I lost control of liveshot, this is where I fixed it sprites = keep missiles = miss liveshot = shots --position(15,1) --print(1, sprites) else -- first, 5 bonus points for each man that survived, more score fun... for i = 1 to count do --closed score[4] += 5 if score[4] >= 10 then score[3] += 1 score[4] -= 10 if score[3] >= 10 then score[2] += 1 score[3] -= 10 if score[2] >= 10 then score[1] += 1 score[2] -= 10 end if end if end if --closed end for level += 1 levelup() end if --1 if for i = 1 to lives do transBlt( Buffer, 10*i+280, 14, Ship7 ) end for end procedure ----------------------------------------------------------------------------- procedure moveShip() atom cnt -- calculate new ship position shipY += shipDY if shipY < 5 then shipY = 5 elsif shipY > WinHigh - 10 then shipY = WinHigh - 10 end if -- draw the ship in the center of the screen -- make sure to check which way its moving first -- to display the correct ship direction if boom = 0 then if shipDX >= 0 then transBlt( Buffer, shipX, shipY, Ship1 ) else transBlt( Buffer, shipX, shipY, Ship2 ) end if elsif boom > 0 and boom <= 8 then if boom > 6 then transBlt( Buffer, shipX, shipY, Ship1 ) elsif boom > 4 then transBlt( Buffer, shipX, shipY, Ship3 ) elsif boom > 2 then transBlt( Buffer, shipX, shipY, Ship4 ) else transBlt( Buffer, shipX, shipY, Missile ) end if boom -= 1 if boom = 1 then boom = 0 end if else if boom > 14 then transBlt( Buffer, shipX, shipY, Ship2 ) elsif boom > 12 then transBlt( Buffer, shipX, shipY, Ship5 ) elsif boom > 10 then transBlt( Buffer, shipX, shipY, Ship6 ) else transBlt( Buffer, shipX, shipY, Missile ) end if boom -= 1 if boom = 9 then boom = 0 end if end if transBlt(Buffer, 140, floor(shipY/10), Missile) transBlt(Buffer, 141, floor(shipY/10), Missile) end procedure ----------------------------------------------------------------------------- procedure ckbang() -- detect if you have shot anything with yer missiles if liveshot > 0 then for j = 1 to liveshot do for i = 1 to length(sprites) do if sprites[i][Class] != Missile and sprites[i][Class] != Explode and sprites[i][Class] != Explode1 and sprites[i][Class] != Explode2 then if ((missiles[j][X]+missiles[j][DX]) >= (sprites[i][X]+sprites[i][DX]) and (missiles[j][X]+missiles[j][DX]) <= (sprites[i][X]+sprites[i][DX]+16) and (missiles[j][Y]+missiles[j][DY]) >= (sprites[i][Y]+sprites[i][DY]) and (missiles[j][Y]+missiles[j][DY]) <= (sprites[i][Y]+sprites[i][DY]+12)) or ((missiles[j][X]) >= (sprites[i][X]) and (missiles[j][X]) <= (sprites[i][X]+16) and (missiles[j][Y]) >= (sprites[i][Y]) and (missiles[j][Y]) <= (sprites[i][Y]+12)) then sprites[i][Live] = 8 sprites[i][DX]=floor(sprites[i][DX]/2) sprites[i][DY]=floor(sprites[i][DY]/2) -- get some score if ya did shoot something; 10 for mutants and 20 for landers if sprites[i][Class] = Mutant then score[3] += 1 if score[3] = 10 then score[2] += 1 score[3] = 0 if score[2] = 10 then score[1] += 1 score[2] = 0 end if end if elsif sprites[i][Class] = Lander then if sprites[i][Timer]>2 then for k = 1 to length(sprites) do if (sprites[i][Timer]=sprites[k][Timer]) and sprites[k][Class]=Man then sprites[k][DY]=-2 sprites[k][Timer]=2 end if end for end if score[3] += 2 if score[3] >= 10 then score[2] += 1 score[3] -= 10 if score[2] = 10 then score[1] += 1 score[2] = 0 end if end if end if sprites[i][Class]=Explode end if end if end for end for end if end procedure ----------------------------------------------------------------------------- procedure ckboom() for i = 1 to length(sprites) do if sprites[i][Class]=Man and sprites[i][Timer]=3 and sprites[i][Y]>275 then sprites[i][Timer]=0 sprites[i][Y]=290 sprites[i][DX]=0 end if if sprites[i][Class] != Missile and sprites[i][Class] != Explode and sprites[i][Class] != Explode1 and sprites[i][Class] != Explode2 and sprites[i][Class]!=Man then if (shipX >= sprites[i][X] and shipX <= sprites[i][X]+16 and shipY >= sprites[i][Y] and shipY <= sprites[i][Y]+12) or (shipX+22 >= sprites[i][X] and shipX+22 <= sprites[i][X]+16 and shipY+7 >= sprites[i][Y] and shipY+7 <= sprites[i][Y]+12) then if shipDX > 0 then boom = 8 else boom = 16 end if if lives = 1 then gameover() else lives -= 1 end if levelup() end if elsif sprites[i][Class]=Man and sprites[i][Timer]=2 then if (shipX >= sprites[i][X] and shipX <= sprites[i][X]+6 and shipY >= sprites[i][Y] and shipY <= sprites[i][Y]+10) or (shipX+22 >= sprites[i][X] and shipX+22 <= sprites[i][X]+6 and shipY+7 >= sprites[i][Y] and shipY+7 <= sprites[i][Y]+10) then sprites[i][Timer]=3 sprite[X]=shipX+9 sprite[Y]=shipY+7 sprite[DX]=shipDX sprite[DY]=shipDY score[3]+=5 if score[3]>10 then score[3]-=10 score[2]+=1 end if if score[2]>10 then score[2]-=10 score[1]+=1 end if end if end if end for end procedure ----------------------------------------------------------------------------- procedure Tick( integer self, integer event, sequence parms ) sequence s drawBackground() moveSprites() moveShip() ckbang() ckboom() -- draw the screen copyBlt( Win, 0, 0, Buffer ) end procedure setHandler(Win, w32HTimer, routine_id( "Tick" )) ----------------------------------------------------------------------------- procedure KeyDown( integer self, integer event, sequence parms) integer key integer shift -- handle key presses key = parms[1] shift = parms[2] if key = VK_UP then -- move ship up shipDY -= 2 elsif key = VK_DOWN then -- move ship down shipDY += 2 elsif key = VK_LEFT then -- move ship back shipDX -= 3 elsif key = VK_RIGHT then -- move ship forward shipDX += 3 elsif key = VK_SPACE then if liveshot < Maxshots and boom = 0 then liveshot += 1 --? (liveshot <= Maxshots) -- for now, just shoot missiles -- create a new sprite sprite = NewSprite -- set up attributes sprite[Class] = Missile sprite[Live] = 1 sprite[X] = shipX+22 -- magic number. gotta fix sprite[Y] = shipY+5 -- below the ship if shipDX >= 0 then sprite[DX] = 10 + shipDX else sprite[DX] = shipDX - 10 sprite[X] = shipX end if -- move faster than ship in either direction sprite[DY] = 0 -- don't move up or down sprite[Timer] = 20 -- disappear in 20 moves if sprite[DX] = 0 then sprite[DX] = 6 end if -- add it to the sprites missiles = append( missiles, sprite ) sprites = append( sprites, sprite ) else liveshot=Maxshots end if end if if shipDX > 10 then shipDX = 10 elsif shipDX < -10 then shipDX = -10 end if if shipDY > 6 then shipDY = 6 elsif shipDY < -6 then shipDY = -6 end if end procedure setHandler(Win, w32HKeyDown, routine_id( "KeyDown" )) ----------------------------------------------------------------------------- --procedure KeyUp( integer self, integer event, sequence parms) -- integer key -- integer shift -- -- key = parms[1] -- shift = parms[2] -- handle key presses -- -- if find(key ,{VK_UP,VK_DOWN}) then -- stop moving -- shipDY = 0 -- end if --end procedure --setHandler(Win, w32HKeyUp, routine_id( "KeyUp" )) ----------------------------------------------------------------------------- procedure Paint( integer self, integer event, sequence parms) -- display the bitmap in the window copyBlt( Win, 0, 0, Buffer ) end procedure setHandler(Win, w32HPaint, routine_id( "Paint" )) WinMain( Win, Normal )