// Project: Curve2
// Created: 2017-02-25
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Curve2" )
SetWindowSize( 1024, 768, 0 )
global width=1024
global height=768
// set display properties
SetVirtualResolution( width, height )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
type _player
x#, y# as float
endtype
global player as _player[2]
player[1].x#=70
player[1].y#=500
player[2].x#=800
player[2].y#=500
global x# as float
global y# as float
global speed# as float
global angle# as float
global xSpeed# as float
global ySpeed# as float
global accel# as float
global arrowangle# as float
global playerleft
global playermovementsstep# as float
initialise()
meter = createsprite(createmeter())
arrow = CreateSprite(createarrow())
status = createtext("Player ")
SetTextSize(status,50)
ball=MakeColor(255,255,255)
player1=makecolor(255,0,0)
player2=makecolor(0,255,0)
playerflip=1
arrowangleup=1
playball=0
do
SetTextString(status, "Player " + str(playerflip) + " Turn")
SetTextPosition(status, width/2 - GetTextTotalWidth(status) / 2, 10)
SetSpritePosition(meter,0,height-GetSpriteHeight(meter))
SetSpriteAngle(meter, 270)
SetSpriteAngle(arrow, arrowangle#)
SetSpritePositionByOffset(arrow,0,height)
SetSpriteOffset(arrow,GetSpriteWidth(arrow)/2-50,GetSpriteHeight(arrow)/2)
DrawEllipse(player[1].x#, player[1].y#, 10,10,player1,player1,1)
DrawEllipse(player[2].x#, player[2].y#, 10,10,player2,player2,1)
moveplayer2()
if playball=0
if arrowangleup=0 then inc arrowangle#,3
if arrowangleup=1 then dec arrowangle#,3
if arrowangle#>=360
arrowangle#=360
arrowangleup=1
endif
if arrowangle#<=270
arrowangle#=270
arrowangleup=0
endif
if GetPointerPressed()=1
playball=1
endif
else
// send a ball
inc x#, xSpeed#
inc ySpeed# , accel#
inc y# , ySpeed#
drawellipse(x#, y#, 5, 5, ball,ball,1)
if y#>height
if playerflip=1
playerflip=2
angle# = -random(270,360)
else
playball=0
playerflip=1
angle#=arrowangle#
endif
speed# = random(20,30)
xSpeed# = speed# * cos(270-angle#)
ySpeed# = speed# * sin(270-angle#)
y#=player[playerflip].y#
x#=player[playerflip].x#
endif
endif
if player[1].x#>width/2 then player[1].x# = width/2
if player[1].x#<0 then player[1].x# = 0
if playermove=1 then player[1].x# = player[1].x# + playermovementsstep#
if playermove=2 then player[1].x# = player[1].x# - playermovementsstep#
if GetRawKeyReleased(39) then playermove=0
if GetRawKeyReleased(37) then playermove=0
if GetRawKeyPressed(39) then playermove=1
if GetRawKeyPressed(37) then playermove=2
Print( ScreenFPS() )
Sync()
loop
function moveplayer2()
if playerleft = 0 then player[2].x# = player[2].x# - playermovementsstep#
if playerleft = 1 then player[2].x# = player[2].x# + playermovementsstep#
if player[2].x# < width / 2
player[2].x# = width / 2
playerleft=1
endif
if player[2].x# > width - 10
player[2].x# = width -10
playerleft=0
endif
endfunction
function createarrow()
size=180
box=MakeColor(255,0,0)
render()
SetClearColor(0,0,0)
ClearScreen()
swap()
DrawBox(0,0,size,30,box,box,box,box,1)
img=getimage(0,0,size,30)
endfunction img
function createmeter()
size=180
swap()
DrawEllipse(0,0,size,size,makecolor(255,255,255),makecolor(255,255,255),1)
for a=1 to size step 10
DrawEllipse(0,0,a,a, makecolor(0,0,0),makecolor(0,0,0),0)
next
render()
img=getimage(0,0,size,size)
clearscreen()
endfunction img
function initialise()
accel# = .90
arrowangle#=270
angle# = 0
speed# = 20
xSpeed# = speed# * cos(angle#)
ySpeed# = speed# * sin(angle#)
x#= player[1].x#
y#= player[1].y#
playermovementsstep#=5
endfunction
Cursors "<" and ">" to move your player and press mouse button to fire