CLEAR ALL
' initialization
BITMAP 1 LOAD SHEET "SpaceShooter.xml" STRIP ".png"
SPRITE 1 BIND BITMAP 1 SELECT "playerShip2_orange"
SPRITE 1 SCALE 100,100 SHOW SCALE TO 1,1,500
FOR i=2 TO 51:SPRITE i BIND BITMAP 1 SELECT "laserred06" PRIORITY 0:NEXT i
x=640
y=400
heading=0
st=20
wrap=100
wrap2=wrap*2
np=50
DIM px(np),py(np),ph(np),pk(np)
' setup
SCREEN 5
FOR i=128 TO 31 STEP -4
    FOR j=1 TO 100
        INK RGB(i,i,i)
        PLOT RANGE(0,639),RANGE(0,399)
    NEXT j
NEXT i
LOCATE 1,1
INK RGB(255,255,255)
PRINT "Use the arrow keys to move the ship, Space to fire, Esc to quit."
' main loop
DO UNTIL KEY.PRESSED(VK_ESC)
    ROLL BITMAP LEFT 1
    SPRITE 1 MOVE x,y ROTATE heading
    IF KEY.DOWN(VK_LEFT) THEN
        heading=heading-5
        IF heading<0 THEN heading=heading+360
    END IF
    IF KEY.DOWN(VK_RIGHT) THEN
        heading=heading+5
        IF heading>=360 THEN heading=heading-360
    END IF
    IF KEY.DOWN(VK_UP) THEN
        x=x+SIN(heading*PI/180)*st
        y=y-COS(heading*PI/180)*st
        IF x<-wrap THEN x=x+WINDOW.WIDTH+wrap2
        IF x>=WINDOW.WIDTH+wrap THEN x=x-WINDOW.WIDTH-wrap2
        IF y<-wrap THEN y=y+WINDOW.HEIGHT+wrap2
        IF y>=WINDOW.HEIGHT+wrap THEN y=y-WINDOW.HEIGHT-wrap2
    END IF
    IF KEY.DOWN(VK_SPACE) THEN
        ARRAY FIND pk(),0 SLICE 1,np TO i
        IF i<>-1 THEN
            px(i)=x
            py(i)=y
            ph(i)=heading
            pk(i)=1
            SPRITE 2+i-1 SHOW ROTATE heading SCALE 0.5,0.5 TINT RGB(255,255,0)
        END IF
    END IF
    FOR i=1 TO np
        IF pk(i)=1 THEN
            px(i)=px(i)+SIN(ph(i)*PI/180)*st*2
            py(i)=py(i)-COS(ph(i)*PI/180)*st*2
            SPRITE 2+i-1 MOVE px(i),py(i)
            IF px(i)<0 OR px(i)>WINDOW.WIDTH THEN pk(i)=0
            IF py(i)<0 OR py(i)>WINDOW.HEIGHT THEN pk(i)=0
            IF pk(i)=0 THEN SPRITE 2+i-1 HIDE
        END IF
    NEXT i
    PAUSE
LOOP
END
