
DIM	titlescreen%	:titlescreen=1	
DIM walrus%     	:walrus=2		 
DIM ingamebg%		:ingamebg=0
DIM gameover%		:gameover=3		
DIM stickman%       :stickman=4      
DIM eraser1%		:eraser1=5
DIM eraser2%		:eraser2=6

DIM stickman_gfx_size%   
DIM stickman_gfx_loc%  
   
DIM pad1%               :   pad1=0                                  ' This will be used to store the state of the jagpad.
dim score
dim FRCOUNT, CURRENT
dim Stickmanx
dim Stickmany
dim Eraser1y
dim Eraser1x
dim Eraser2y
dim Eraser2x
dim Eraser1speed
dim Eraser1movement
dim Eraser2movement
dim col
dim STICK
dim PY
dim countr
dim Stickintroanimframe
dim Stickmanturnhead
dim Headturnanimframe
dim Fframe
dim Eraser1timerlimit
dim Eraser1timer
dim Eraser1timerseconds
dim Deathtimer
dim NumberofErasers
dim Eraser2speed
dim Eraser2timerlimit
dim Eraser2timer
dim Eraser2timerseconds
dim randy
dim scoretimer

Deathtimer=0
score=0
scoretimer=0
Stickmanturnhead=0
Headturnanimframe=0
Eraser1speed=2
Eraser1timerlimit=4
Eraser1timerseconds=5

Eraser2speed=2
Eraser2timerlimit=4
Eraser2timerseconds=5

NumberofErasers=1

	stickman_gfx_loc=RGETOBJ(stickman,R_sprite_gfxbase)	
	stickman_gfx_size=RGETOBJ(stickman,R_sprite_framesz)

		RSETOBJ(walrus,R_sprite_active,R_is_active)

basic_r_indx=0
basic_r_size=0
raptor_fade_delay=1
countr=0
dim sfxcount as short


		

MODPLAY((int)strptr(MOD_TSSONG))  

REM MAIN LOOP
do
	Stickmany=RGETOBJ(stickman,R_sprite_y)

	Stickmanx=RGETOBJ(stickman,R_sprite_x)
	IF Stickmanturnhead=0 and Stickmanx>(88<<16) THEN 
		RSETOBJ(stickman,R_sprite_xadd,0)	
		Stickmanturnhead=1
	endif

	if Stickmanturnhead=0 then
		RSETOBJ(stickman,R_sprite_gfxbase,stickman_gfx_loc+(stickman_gfx_size*1))
	endif
	
	if Stickmanturnhead=0 and Headturnanimframe>20 then 
		RSETOBJ(stickman,R_sprite_gfxbase,stickman_gfx_loc+(stickman_gfx_size*0))
	endif
	
	if Stickmanturnhead=0 and Headturnanimframe=40 then 
			Headturnanimframe=0
	endif
	
	if Stickmanturnhead<3 then Headturnanimframe++
	
	if Stickmanturnhead=1 then

	if Headturnanimframe>20 then Fframe=2
	if Headturnanimframe>40 then Fframe=3
	
	if Headturnanimframe>80 then Fframe=4
	if Headturnanimframe>100 then Fframe=3	
	if Headturnanimframe>120 then Fframe=2
	
	if Headturnanimframe>140 then Fframe=3
	if Headturnanimframe>160 then Fframe=4	
	if Headturnanimframe=180 then

        MODPLAY(0)
        SNDKILL(0)
        SNDKILL(1)
        SNDKILL(2)
        SNDKILL(3)
        VSYNC
        U235SE_modregdump[0]=0
        U235SE_modregdump[2]=0
        U235SE_modregdump[3]=0
        U235SE_modregdump[4]=0
        U235SE_modregdump[5]=0	
		endif
	
	if Headturnanimframe>180 then 
		Fframe=3
	
		
	
	MODPLAY((int)strptr(MOD_ALTTSMUSIC)) 
		RSETOBJ(titlescreen,R_sprite_active,R_is_active)
		RSETOBJ(walrus,R_sprite_active,R_is_inactive)
		RSETOBJ(ingamebg,R_sprite_active,R_is_inactive)	

	endif
	
	if Headturnanimframe>220 then Fframe=2
	if Headturnanimframe>240 then 
		Headturnanimframe=0 
		Stickmanturnhead=2 

	endif
	
	RSETOBJ(stickman,R_sprite_gfxbase,stickman_gfx_loc+(stickman_gfx_size*Fframe))
	
	endif
	
	        pad1=GETPAD(1)                                              ' Read the jagpad state.
    
    IF pad1=PAD_B and Stickmanturnhead<3 THEN                                          ' If B was pressed, we can move the titles off screen and begin the game.
					
	rlist[5+CURRENT].y=INT((int)(RND*200)<<16)		
	
		Stickmanturnhead=3

	ENDIF
	
	if Stickmanturnhead=4 then 
		call move_stickman	
		call move_eraser1
		call check_collision
	endif
	
	if NumberofErasers=2 then
		call move_eraser2
		endif	
		
	if Stickmanturnhead=3 then call ingamestuff
	
	VSYNC 
		randy = int(RND*184)+40
	
	
		if Stickmanturnhead=5 then 	
		MODVOL(0)
		Stickmanturnhead=6
		endif
		
		if Stickmanturnhead=6 then call game_is_over
	
	if Stickmanturnhead=2 then
		RSETOBJ(gameover,R_sprite_active,R_is_inactive)	
		RSETOBJ(titlescreen,R_sprite_active,R_is_active)	
		RSETOBJ(walrus,R_sprite_active,R_is_inactive)	
		RSETOBJ(stickman,R_sprite_xadd,$32000)
		RSETOBJ(stickman,R_sprite_gfxbase,stickman_gfx_loc+(stickman_gfx_size*1))
		
	RLOCATE 116,17
	PRINT "score=";score	
		
	endif
	
	if Stickmanturnhead=2 and Headturnanimframe>20 then 
		RSETOBJ(stickman,R_sprite_gfxbase,stickman_gfx_loc+(stickman_gfx_size*0))
	endif
	
	if Stickmanturnhead=2 and Headturnanimframe=40 then 
			Headturnanimframe=0
	endif	

	IF Stickmanturnhead=2 and Stickmanx>(344<<16) THEN 
		RSETOBJ(stickman,R_sprite_x,0)
	endif		

loop

sub ingamestuff
	
	if Stickmanturnhead=3 then
		RSETOBJ(ingamebg,R_sprite_active,R_is_active)	
		RSETOBJ(walrus,R_sprite_active,R_is_inactive)
		RSETOBJ(titlescreen,R_sprite_active,R_is_inactive)
		
		Eraser2x=0
		NumberofErasers=1
		Stickmany=98
		score=0
	
		RSETOBJ(stickman,R_sprite_x,(170<<16))
		RSETOBJ(stickman,R_sprite_y,(130<<16))	
		RSETOBJ(stickman,R_sprite_xadd,0)	
	
		Eraser1x=0


		
		RSETOBJ(eraser1,R_sprite_y,(randy<<16))
		RSETOBJ(eraser1,R_sprite_x,(Eraser1x<<16))
				
        MODPLAY(0)
        SNDKILL(0)
        SNDKILL(1)
        SNDKILL(2)
        SNDKILL(3)
        VSYNC
        U235SE_modregdump[0]=0
        U235SE_modregdump[2]=0
        U235SE_modregdump[3]=0
        U235SE_modregdump[4]=0
        U235SE_modregdump[5]=0				
				
				
		Stickmanturnhead=4	
	
		endif
			
end sub

sub move_eraser1



			MODPLAY((int)strptr(MOD_INGAMESONG)) 	
			MODVOL(15)


	RLOCATE 116,17
	PRINT "score=";score
	
	scoretimer++
	if (scoretimer=59) then
	score++
	scoretimer=0
	
	endif

	RSETOBJ(eraser1,R_sprite_active,R_is_active)


	if (score=10) and (Eraser1timer=1) then
	call getNewEraser
	endif

	if Eraser1timerseconds>Eraser1timerlimit then 
	Eraser1movement = int(RND*4)
	Eraser1timerlimit = int(RND*3)
	Eraser1timerseconds=0
	endif
	
	if Eraser1y=>(220<<16) then 
		Eraser1y=219<<16
		Eraser1movement=1
		endif
	if Eraser1y=<(40<<16) then 
		Eraser1y=41<<16
		Eraser1movement=2
		endif
	if Eraser1x=>(270<<16) then
		Eraser1x=269<<16
		Eraser1movement=3
		endif
	if Eraser1x=<(84<<16) then 
		Eraser1x=85<<16
		Eraser1movement=4	
		endif
	
	Eraser1timer++
	
	if (Eraser1timer>50) then
	Eraser1timer=0, Eraser1timerseconds++
	endif
	
	if Eraser1movement=1 then 	
	RSETOBJ(eraser1,R_sprite_xadd,0)
	RSETOBJ(eraser1,R_sprite_yadd,-Eraser1speed<<16)
	endif
	
	if Eraser1movement=2 then 
	RSETOBJ(eraser1,R_sprite_xadd,0)	
	RSETOBJ(eraser1,R_sprite_yadd,Eraser1speed<<16)
	endif	

	if Eraser1movement=3 then 	
	RSETOBJ(eraser1,R_sprite_yadd,0)	
	RSETOBJ(eraser1,R_sprite_xadd,-Eraser1speed<<16)
	endif
	
	if Eraser1movement=4 then 
	RSETOBJ(eraser1,R_sprite_yadd,0)	
	RSETOBJ(eraser1,R_sprite_xadd,Eraser1speed<<16)
	endif	

	Eraser1y=RGETOBJ(eraser1,R_sprite_y)	
	Eraser1x=RGETOBJ(eraser1,R_sprite_x)
end sub

sub move_eraser2

	if Eraser2timerseconds>Eraser2timerlimit then 
	Eraser2movement = int(RND*4)
	Eraser2timerlimit = int(RND*3)
	Eraser2timerseconds=0
	endif
	
	if Eraser2y=>(220<<16) then 
		Eraser2y=219<<16
		Eraser2movement=1
		endif
	if Eraser2y=<(40<<16) then 
		Eraser2y=41<<16
		Eraser2movement=2
		endif
	if Eraser2x=>(270<<16) then 
		Eraser2x=269<<16
		Eraser2movement=3
		endif
	if Eraser2x=<(84<<16) then 
		Eraser2x=85<<16
		Eraser2movement=4	
		endif
	
	Eraser2timer++
	
	if (Eraser2timer>50) then
	Eraser2timer=0, Eraser2timerseconds++
	endif
	
	if Eraser2movement=1 then 	
	RSETOBJ(eraser2,R_sprite_xadd,0)
	RSETOBJ(eraser2,R_sprite_yadd,-Eraser2speed<<16)
	endif
	
	if Eraser2movement=2 then 
	RSETOBJ(eraser2,R_sprite_xadd,0)	
	RSETOBJ(eraser2,R_sprite_yadd,Eraser2speed<<16)
	endif	

	if Eraser2movement=3 then 	
	RSETOBJ(eraser2,R_sprite_yadd,0)	
	RSETOBJ(eraser2,R_sprite_xadd,-Eraser2speed<<16)
	endif
	
	if Eraser2movement=4 then 
	RSETOBJ(eraser2,R_sprite_yadd,0)	
	RSETOBJ(eraser2,R_sprite_xadd,Eraser2speed<<16)
	endif	

	Eraser2y=RGETOBJ(eraser2,R_sprite_y)	
	Eraser2x=RGETOBJ(eraser2,R_sprite_x)
end sub

sub check_collision
	IF RHIT(eraser1,eraser1,stickman,stickman)<>-1 THEN 
			Deathtimer++
		    SNDPLAY(0,5)                                                    ' Play sound 1 on channel 5
			VSYNC
            SNDFREQ(5,8000)                                                ' Set replay freq on channel 5 to 12000Hz
			VSYNC
            SNDPLAY(0,6)                                                    ' Play sound 1 on channel 5
            VSYNC
			SNDFREQ(6,8000)                                                ' Set replay freq on channel 5 to 12000Hz
			VSYNC
	
		RSETOBJ(stickman,R_sprite_x,(0<<16))
		RSETOBJ(stickman,R_sprite_y,(207<<16))
		RSETOBJ(eraser1,R_sprite_active,R_is_inactive)	
		RSETOBJ(eraser2,R_sprite_active,R_is_inactive)			
		
		Stickmanturnhead=5
	endif
	
	IF RHIT(eraser2,eraser2,stickman,stickman)<>-1 THEN 
			Deathtimer++
		    SNDPLAY(0,5)                                                    ' Play sound 1 on channel 5
			VSYNC
            SNDFREQ(5,8000)                                                ' Set replay freq on channel 5 to 12000Hz
			VSYNC
            SNDPLAY(0,6)                                                    ' Play sound 1 on channel 5
            VSYNC
			SNDFREQ(6,8000)                                                ' Set replay freq on channel 5 to 12000Hz
			VSYNC
	
		RSETOBJ(stickman,R_sprite_x,(0<<16))
		RSETOBJ(stickman,R_sprite_y,(207<<16))
		RSETOBJ(eraser1,R_sprite_active,R_is_inactive)			
		RSETOBJ(eraser2,R_sprite_active,R_is_inactive)	
		
		Stickmanturnhead=5
	endif	
	
	end sub

sub game_is_over
		RSETOBJ(gameover,R_sprite_active,R_is_active)

		Deathtimer++
	
		if Deathtimer>295 then
			RSETOBJ(stickman,R_sprite_flip,R_is_normal) 

        MODPLAY(0)
        SNDKILL(0)
        SNDKILL(1)
        SNDKILL(2)
        SNDKILL(3)
        VSYNC
        U235SE_modregdump[0]=0
        U235SE_modregdump[2]=0
        U235SE_modregdump[3]=0
        U235SE_modregdump[4]=0
        U235SE_modregdump[5]=0

 
			MODPLAY((int)strptr(MOD_ALTTSMUSIC)) 	
			MODVOL(15)
			Deathtimer=0
			RSETOBJ(gameover,R_sprite_active,R_is_inactive)
			Stickmanturnhead=2
			endif
		
	end sub
		
sub move_stickman
		
	if Stickmanturnhead=4 then
		RSETOBJ(stickman,R_sprite_gfxbase,stickman_gfx_loc+(stickman_gfx_size*1))
	endif
	
	if Stickmanturnhead=4 and Headturnanimframe>20 then 
		RSETOBJ(stickman,R_sprite_gfxbase,stickman_gfx_loc+(stickman_gfx_size*0))
	endif				
  
	if Headturnanimframe>40 then Headturnanimframe=0
		
    IF (pad1 BAND PAD_LEFT AND Stickmanx=>(84<<16)) THEN 
		Headturnanimframe++
        RSETOBJ(stickman,R_sprite_x,Stickmanx-(2<<16))
        RSETOBJ(stickman,R_sprite_flip,R_is_flipped)                  
    ENDIF
	
    IF (pad1 BAND PAD_RIGHT AND Stickmanx=<(284<<16)) THEN        
		Headturnanimframe++
        RSETOBJ(stickman,R_sprite_x,Stickmanx+(2<<16))
        RSETOBJ(stickman,R_sprite_flip,R_is_normal)                  
    ENDIF	
	
    IF (pad1 BAND PAD_UP AND Stickmany=>(44<<16)) THEN 
		Headturnanimframe++
        RSETOBJ(stickman,R_sprite_y,Stickmany-(2<<16))                
    ENDIF
	
    IF (pad1 BAND PAD_DOWN AND Stickmany=<(200<<16)) THEN        
		Headturnanimframe++
        RSETOBJ(stickman,R_sprite_y,Stickmany+(2<<16))               
    ENDIF		
	
				
end sub

REM so I don't forget how to get the joypad.

sub ihatethis
	
endsub

sub getNewEraser
			NumberofErasers++

			if (NumberofErasers=2) then

		
		RSETOBJ(eraser2,R_sprite_y,(randy<<16))
		RSETOBJ(eraser2,R_sprite_x,(Eraser2x<<16))
		rem RSETOBJ(eraser2,R_sprite_y,(Eraser2y<<16))		
			RSETOBJ(eraser2,R_sprite_active,R_is_active)		
			endif
			
endsub

REM NEW ENEMY
sub newenemy
    rlist[2+CURRENT].x=352<<16
    rlist[2+CURRENT].y=INT((integer)(RND*200)<<16)
    rlist[2+CURRENT].was_hit=R_cant_hit
    rlist[2+CURRENT].hitpoint=1
    rlist[2+CURRENT].xadd=-2<<16
    rlist[2+CURRENT].active=1

    'The commented lines below are functionally equivalent to
    'those above. However they are slower

    'RSETOBJ(2+CURRENT,R_sprite_x,352<<16)
    'RSETOBJ(2+CURRENT,R_sprite_y,INT((integer)(RND*200)<<16))
    'RSETOBJ(2+CURRENT,R_sprite_was_hit,R_cant_hit)
    'RSETOBJ(2+CURRENT,R_sprite_hitpoint,1)
    'RSETOBJ(2+CURRENT,R_sprite_xadd,-2<<16)
    'RSETOBJ(2+CURRENT,R_sprite_active,1)
    CURRENT=CURRENT+1
    IF CURRENT=20 THEN
        CURRENT=0
    ENDIF
    FRCOUNT=0
end sub

