My Frogger Template
// Project: Frogger Template by fubarpk
// Created: 2017-03-22
#constant KEY_LEFT = 37 //the left arrow key scancode
#constant KEY_UP = 38 //the up arrow key scancode
#constant KEY_RIGHT = 39 //the right arrow key scancode
#constant KEY_DOWN = 40 //the down arrow key scancode
#constant xMax=1024
#constant yMax=600
#constant timePerGame=120
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Frogger" )
SetWindowSize( xMax,yMax,0)
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( xMax, yMax ) // doesn't have to match the window
SetOrientationAllowed( 0, 0, 1, 1 ) //
//SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
playFrogger()
end
function playFrogger()
deleteSprite(900)
//createSprite(900,ellipse)
createSprite(900,0)
setSpritecolor(900,0,0,0,255)
SetSpriteSize(900,xMax,yMax)
SetSpriteDepth(900,9997)
//SetSpritePositionByOffset(900,xMax/2,yMax/2)
//DeleteSprite(901)
repeat
Print ("My Frogger template click space to Play")
sync()
until GetRawKeyPressed(32) = 1 //click mouse to play
high=0:score=0:bonusTime=0
bonusTime$="Time Left :"+str(bonusTime)
CreateText(1,bonusTime$)
SetTextSize(1,40)
SetTextPosition(1,10,0)
myHigh$="High :"+str(high)
CreateText(2,myHigh$)
SetTextSize(2,40)
SetTextDepth(2,0)
SetTextPosition(2,600,0)
myScore$="Score:"+str(score)
CreateText(3,myScore$)
SetTextSize(3,40)
SetTextDepth(3,0)
SetTextPosition(3,820,0)
frogSpr = CreateSprite(0)
SetSpriteSize(frogSpr,64,64)
changeFrogColor(frogSpr,1)
SetSpriteDepth(frogSpr,15)
do
elapsedTime#=Timer()
resetTimer()
repeat
SetSpriteDepth(900,10000)
score=crossRoadLevel(frogSpr,score)
if high<score then high = score
myScore$="Score:"+str(score):myHigh$="High :"+str(high)
SetTextString(2,myHigh$):SetTextString(3,myScore$)
sync()
//resetTimer()
score=crossRiverLevel(frogSpr,score)
if high<score then high = score
myScore$="Score:"+str(score):myHigh$="High :"+str(high)
SetTextString(2,myHigh$):SetTextString(3,myScore$)
//SetSpriteDepth(901,9998):SetSpriteDepth(902,9999)
SetSpriteAngle(frogSpr,0)
sync()
elapsedTime#=Timer()
until elapsedTime#>timePerGame //limited time per attempt
sync()
setSpritecolor(900,0,0,0,255)
gameOver()
score=0:changeFrogColor(frogSpr,1)
myScore$="Score:"+str(score)
SetTextString(3,myScore$)
loop
endfunction
function crossRoadLevel(frogSpr as integer,score as integer)
setSpritecolor(900,150,150,150,255)
for num = 1 to 5
DeleteSprite(num):deleteSprite(num+5):deleteSprite(num+10)
DeleteSprite(num+15):DeleteSprite(num+20)
rem top road moving right cars and trucks
createSprite(num,0)
SetSpriteSize(num,60,128)
SetSpriteColor(num,Random(1,255),Random(1,255),Random(1,255),255)
SetSpriteAngle(num,90)
createSprite(num+5,0)
SetSpriteSize(num+5,60,148)
SetSpriteColor(num+5,Random(1,255),Random(1,255),Random(1,255),255)
SetSpriteAngle(num+5,90)
rem bottom road moving left cars and trucks
createSprite(num+10,0)
SetSpriteSize(num+10,60,128)
SetSpriteColor(num+10,Random(1,255),Random(1,255),Random(1,255),255)
SetSpriteAngle(num+10,270)
createSprite(num+15,0)
SetSpriteSize(num+15,60,148)
SetSpriteColor(num+15,Random(1,255),Random(1,255),Random(1,255),255)
SetSpriteAngle(num+15,270)
placeVehicles(num)
next num
changeColor=placeBonusFruit(500)
SetSpriteDepth(frogSpr,15)
time#=timer()
repeat
until timer()-time#>1
FrogAnimNum=1
x#=xMax/2:y#=yMax-40
SetSpritePosition(frogSpr,x#,y#)
bonusTime=timePerGame-timer()
while GetSpriteYByOffset(frogSpr)-35>0 and bonusTime >0
bonusTime$="Time Left :"+str(bonusTime)
SetTextString(1,bonusTime$)
x#=GetSpriteX(frogspr):y#=GetSpriteY(frogSpr)
if GetRawKeyState (KEY_Up)
y#=y#-5
endif
if GetRawKeyState (KEY_Down)
y#=y#+5
endif
if GetRawKeyState (KEY_Left)
x#=x#-5
endif
if GetRawKeyState (KEY_Right)
x#=x#+5
endif
SetSpritePosition(frogSpr,x#,y#)
if moveVehicles(frogSpr)=1
x#=xMax/2:y#=yMax-40
SetSpritePosition(frogSpr,x#,y#)
endif
If GetSpriteCollision(frogSpr,500)=1 and GetSpriteVisible(500)=1
changeFrogColor(frogSpr,changeColor)
score=score+250
myScore$="Score:"+str(score)
SetTextString(3,myScore$)
SetSpriteVisible(500,0)
endif
bonusTime=timePerGame-timer()
Sync()
endwhile
if bonusTime>0 then score=score+(10*bonusTime)
endfunction score
function crossRiverLevel(frogSpr as integer,score as integer)
setSpritecolor(900,0,0,140,255)
for num = 1 to 5
DeleteSprite(num):deleteSprite(num+5):deleteSprite(num+10)
DeleteSprite(num+15):DeleteSprite(num+20)
rem top road moving
createSprite(num,0)
SetSpriteColor(num,139,69,19,255)
SetSpriteSize(num,128,64)
SetSpriteDepth(num,20)
createSprite(num+5,0)
SetSpriteColor(num+5,139,69,19,255)
SetSpriteSize(num+5,186,64)
SetSpriteDepth(num+5,20)
rem bottom river moving left Logs
CreateSprite(num+10,0)
SetSpriteColor(num+10,139,69,19,255)
SetSpriteSize(num+10,186,64)
SetSpriteDepth(num+10,20)
CreateSprite(num+15,0)
SetSpriteColor(num+15,139,69,19,255)
SetSpriteSize(num+15,128,64)
SetSpriteDepth(num+15,20)
rem 5 crocodiles
CreateSprite(num+20,0)
SetSpriteColor(num+20,128,128,128,255)
SetSpriteSize(num+20,128,64)
SetSpriteDepth(num+20,20)
placeLogs(num)
next num
//change colour of frog if eats fruit
changeColor=placeBonusFruit(500)
SetSpriteDepth(frogSpr,15)
time#=timer()
repeat
until timer()-time#>1
x#=xMax/2:y#=yMax-40
SetSpritePosition(frogSpr,x#,y#)
bonusTime=timePerGame-timer()
while GetSpriteYByOffset(frogSpr)-35>0 and bonusTime >0
bonusTime$="Time Left :"+str(bonusTime)
SetTextString(1,bonusTime$)
x#=GetSpriteX(frogspr):y#=GetSpriteY(frogSpr)
if GetRawKeyState (KEY_Up)
y#=y#-5
endif
if GetRawKeyState (KEY_Down)
y#=y#+5
endif
if GetRawKeyState (KEY_Left)
x#=x#-5
endif
if GetRawKeyState (KEY_Right)
x#=x#+5
endif
SetSpritePosition(frogSpr,x#,y#)
if moveLogs(frogSpr)=0 and GetSpriteY(frogSpr)<yMax-80
if y#>40
x#=xMax/2:y#=yMax-40
SetSpritePosition(frogSpr,x#,y#)
endif
endif
if x#<-40 or x#>xMax
x#=xMax/2:y#=yMax-40
SetSpritePosition(frogSpr,x#,y#)
endif
If GetSpriteCollision(frogSpr,500)=1 and GetSpriteVisible(500)=1
changeFrogColor(frogSpr,changeColor)
score=score+250
myScore$="Score:"+str(score)
SetTextString(3,myScore$)
SetSpriteVisible(500,0)
endif
bonusTime=timePerGame-timer()
sync()
endwhile
if bonusTime>0 then score=score+(10*bonusTime)
endfunction score
function placeVehicles(num as integer)
//randomly place vehicles watching/repeating for collisions
rem y=105:y=210:y=395:y=495
SetSpritePositionByOffset(num,random2(-xMax,xMax),105)
SetSpritePositionByOffset(num+5,random2(-xMax,xMax),210)
SetSpritePositionByOffset(num+10,random2(xMax,xMax*2),395)
SetSpritePositionByOffset(num+15,random2(xMax,xMax*2),495)
for check= 1 to num
while GetSpriteCollision(num,check)=1 and num <> check
SetSpritePositionByOffset(num,random2(-xMax,xMax),105)
check=1
endwhile
while GetSpriteCollision(num+5,check+5)=1 and num <> check
SetSpritePositionByOffset(num+5,random2(-xMax,xMax),210)
check=1
endwhile
while GetSpriteCollision(num+10,check+10)=1 and num <> check
SetSpritePositionByOffset(num+10,random2(0,xMax*2),395)
check=1
endwhile
while GetSpriteCollision(num+15,check+15)=1 and num <> check
SetSpritePositionByOffset(num+15,random2(0,xMax*2),495)
check=1
endwhile
next check
endfunction
function moveVehicles(frogSpr as integer)
collision=0
for num = 1 to 5
SetSpritePositionByOffset(num,(GetSpriteXByOffset(num)+4),GetSpriteYByOffset(num))
if GetSpriteXByOffset(num)>xMax*2 then SetSpritePositionByOffset(num,-xMax,GetSpriteYByOffset(num))
if GetSpriteCollision( frogSpr, num ) then collision=1
next num
for num = 1 to 5
SetSpritePositionByOffset(num+5,(GetSpriteXByOffset(num+5)+4),GetSpriteYByOffset(num+5))
if GetSpriteXByOffset(num+5)>xMax*2 then SetSpritePositionByOffset(num+5,-xMax,GetSpriteYByOffset(num+5))
if GetSpriteCollision( frogSpr, num+5 ) then collision=1
next num
for num = 1 to 5
SetSpritePositionByOffset(num+10,(GetSpriteXByOffset(num+10))-4,GetSpriteYByOffset(num+10))
if GetSpriteXByOffset(num+10)<-xMax then SetSpritePositionByOffset(num+10,xMax*2,GetSpriteYByOffset(num+10))
if GetSpriteCollision( frogSpr, num+10 ) then collision=1
next num
for num = 1 to 5
SetSpritePositionByOffset(num+15,(GetSpriteXByOffset(num+15))-4,GetSpriteYByOffset(num+15))
if GetSpriteXByOffset(num+15)<-xMax then SetSpritePositionByOffset(num+15,xMax*2,GetSpriteYByOffset(num+15))
if GetSpriteCollision( frogSpr, num+15 ) then collision=1
next num
endfunction collision
function moveLogs(frogSpr as integer)
collision=0
for num = 1 to 5
SetSpritePositionByOffset(num,(GetSpriteXByOffset(num)+4),GetSpriteYByOffset(num))
if GetSpriteXByOffset(num)>xMax*2 then SetSpritePositionByOffset(num,-xMax,GetSpriteYByOffset(num))
if GetSpriteCollision( frogSpr, num )
SetSpritePosition(frogSpr,GetSpriteX(frogSpr)+4,GetSpriteY(frogSpr))
collision=1
endif
next num
for num = 1 to 5
SetSpritePositionByOffset(num+5,(GetSpriteXByOffset(num+5)+4),GetSpriteYByOffset(num+5))
if GetSpriteXByOffset(num+5)>xMax*2 then SetSpritePositionByOffset(num+5,-xMax,GetSpriteYByOffset(num+5))
if GetSpriteCollision( frogSpr, num+5 )
SetSpritePosition(frogSpr,GetSpriteX(frogSpr)+4,GetSpriteY(frogSpr))
collision=1
endif
next num
for num = 1 to 5
SetSpritePositionByOffset(num+10,(GetSpriteXByOffset(num+10))-4,GetSpriteYByOffset(num+10))
if GetSpriteXByOffset(num+10)<-xMax then SetSpritePositionByOffset(num+10,xMax*2,GetSpriteYByOffset(num+10))
if GetSpriteCollision( frogSpr, num+10 )
SetSpritePosition(frogSpr,GetSpriteX(frogSpr)-4,GetSpriteY(frogSpr))
collision=1
endif
next num
for num = 1 to 5
SetSpritePositionByOffset(num+15,(GetSpriteXByOffset(num+15))-5,GetSpriteYByOffset(num+15))
if GetSpriteXByOffset(num+15)<-xMax then SetSpritePositionByOffset(num+15,xMax*2,GetSpriteYByOffset(num+15))
if GetSpriteCollision( frogSpr, num+15 )
SetSpritePosition(frogSpr,GetSpriteX(frogSpr)-4,GetSpriteY(frogSpr))
collision=1
endif
next num
rem crocodiles
for num = 1 to 5
SetSpritePositionByOffset(num+20,(GetSpriteXByOffset(num+20)+2),GetSpriteYByOffset(num+20))
if GetSpriteXByOffset(num+20)>xMax*2 then SetSpritePositionByOffset(num+20,-xMax,GetSpriteYByOffset(num+20))
if GetSpriteCollision( frogSpr, num+20 )
SetSpritePosition(frogSpr,GetSpriteX(frogSpr)+2,GetSpriteY(frogSpr))
collision=1
endif
next num
endfunction collision
function createEllipse()
Render()
DrawEllipse(10,10,10,10,MakeColor(255,255,255),MakeColor(255,255,255),1)
Swap()
img = getimage(0,0,22,22)
sync()
endfunction img
function placeBonusFruit(spr as integer)
If getSpriteExists(spr) then DeleteSprite(spr)
CreateSprite(spr,createEllipse())
SetSpritePositionByOffset(spr,random(10,xMax-10),yMax/2)
SetSpriteDepth (spr,20)
ran=random (1,5)
select ran:
case 1:
SetSpriteColor(spr,113,161,25,255):rem green
endcase
case 2:
SetSpriteColor(spr,92,92,255,255):rem blue
endcase
case 3:
SetSpriteColor(spr,190,152,0,255):rem gold
endcase
case 4:
SetSpriteColor(spr,168,35,168,255):rem Purple
endcase
case 5:
SetSpriteColor(spr,246,125,0,255):rem Orange
endcase
endselect
color=ran
endfunction color
function changeFrogColor(spr as integer,num)
select num:
case 1:
SetSpriteColor(spr,113,161,25,255):rem green
endcase
case 2:
SetSpriteColor(spr,92,92,255,255):rem blue
endcase
case 3:
SetSpriteColor(spr,190,152,0,255):rem gold
endcase
case 4:
SetSpriteColor(spr,168,35,168,255):rem Purple
endcase
case 5:
SetSpriteColor(spr,246,125,0,255):rem Orange
endcase
endselect
endfunction
function placeLogs(num as integer)
//randomly place logs crocs etc repeating for collisions
SetSpritePositionByOffset(num,random2(-xMax,xMax),105)
SetSpritePositionByOffset(num+5,random2(-xMax,xMax),210)
SetSpritePositionByOffset(num+10,random2(xMax,xMax*2),395)
SetSpritePositionByOffset(num+15,random2(xMax,xMax*2),495)
SetSpritePositionByOffset(num+20,random2(-xMax,xMax),302)
for check= 1 to num
while GetSpriteCollision(num,check)=1 and num <> check
SetSpritePositionByOffset(num,random2(-xMax,xMax),105)
check=1
endwhile
while GetSpriteCollision(num+5,check+5)=1 and num <> check
SetSpritePositionByOffset(num+5,random2(-xMax,xMax),210)
check=1
endwhile
while GetSpriteCollision(num+10,check+10)=1 and num <> check
SetSpritePositionByOffset(num+10,random2(0,xMax*2),395)
check=1
endwhile
while GetSpriteCollision(num+15,check+15)=1 and num <> check
SetSpritePositionByOffset(num+15,random2(0,xMax*2),495)
check=1
endwhile
while GetSpriteCollision(num+20,check+20)=1 and num <> check
SetSpritePositionByOffset(num+20,random2(-xMax,xMax),302)
check=1
endwhile
next check
endfunction
function gameOver()
SetTextVisible(1,0)
time#=timer()
repeat
until timer()-time#>1
ClearScreen()
repeat
Print("Game Over click mouse to continue")
sync()
until GetPointerPressed() = 1
SetTextVisible(1,1)
endfunction
now needs no media as its all created by code and should be a good starter.
fubar