(http://www.underwaredesign.com/PlayBasicSig.png) (http://www.playbasic.com)
Challenge #28 - Flappy Bird Styled Character Movement
Flappy bird was one of those break out hits that come along every now again and captivate the public. What makes it interesting today (for us) it is feels a lot like the types of video games people made way back in the early days of computer games, with simple visuals but brutally honest game play, where the player lives or dies by the pixel.
For this challenge we'll just focus on the players movement. So stripping away everything but the main character, you need to construct a similar style of character movement where the player moves not necessarily in straight lines, but an arc of some type and with the least amount of controls possible. To make it more stimulating you can add objects to the scene that player needs to navigate to reach a goal. You don't need any artwork, just use a circles / lines / box for the main display or some of the existing stock art that's on the boards or in the help files.
So for those that take this challenge on, you'll learn many fundamentals ranging from
input controls /
sinus /
projectile motion /
computer animation &
collision if add obstacles. All of which will translate into your everyday BASIC programming skills.
Good luck !
As always we'll award Extra Brownie points to the most creative submissions .
Submission * Submissions can be written in
any version of PlayBASIC (http://www.playbasic.com)
* Submission can only be accepted in
Source Code form only.
* No external media is permitted for this challenge.
*
Zip up your Submissions and please try to keep it smaller than
500K !
*
Authors automatically give consent for their submission(s) to distributed and used for promotional purposes via UnderwareDesign.com, PlayBasic.com code tank.
* Authors can submit as many times as they like.
* To make a submission, zip up your projects and either post it in this thread, or create your own thread in either the Source Codes or Show Case forums and post a link bellow.
Dead Line Anytime before the next ice age
Prizes * The best submissions will be periodically highlighted through the PlayBasic IDE news service / News Letters/ FaceBook (http://www.facebook.com/pages/PlayBasic/127905400584274), Twitter (http://www.twitter.com/PlayBasic) or the PlayBASIC youtube channel (http://www.youtube.com/playbasic).
Return to Challenge Index (http://www.underwaredesign.com/forums/index.php?topic=3225.0)
I made as small a version as i could.
I would prob be able to shave more code by checking coordinates rather than the sprite method.
I await my $50000 a day
[pbcode]
; PROJECT : flappy
; AUTHOR : PC
; CREATED : 28/02/2015
Explicit on
global sw=GetScreenWidth()
global sh=GetScreenHeight()
global img=NewFXImage (30,sh)
global spr=newsprite(0,0,img)
global score=-1
SpriteCollision spr,1
SpriteCollisionmode spr,6
global speed#=2
Constant gravity#=0.1
type tOb
x#,h#,width#
EndType
dim Ob as tob
type tBird
x#,y#,yv#
EndType
dim Bird as tbird
bird.x#=50
bird.y#=sh/2
obstacle()
setfps(50)
repeat
cls
text 0,0,"Speed:"+str$(int(speed#))
text 0,10,"Score:"+str$(score)
if ob.x#<-30 then obstacle()
ob.x#-=speed#
if spacekey()
bird.yv#-=0.25
else
bird.yv#+=gravity#
endif
bird.y#+=bird.yv#
if circlehitsprite(bird.x#,bird.y#,10,spr) then end
circlec bird.x#,bird.y#,10,1,$00ff00
positionsprite spr,ob.x#,0
drawallsprites
speed#+=0.001
sync
until false
Function obstacle()
inc score
ob.x#=sw
ob.h#=sh/2+rndrange(-sh/4,sh/4)
RenderToImage img
cls $ff0000
boxc 0,ob.h#,30,ob.h#+60,1,0
RenderToScreen
EndFunction
[/pbcode]
Hello monkeybot!
Just a few rows of code, but nevertheless so funny! :D
Well, I would give you my vote!
Regards,
Sigtrygg
I've never played in Flappy Bird, but i see it in youtube.
It's my version.
That's looks pretty much like Flappy Bird styled movement to me. So you can both have a shiny virtual star for your collections! ;D
Thanks Kevin!
Wohoo fame at last.
This is a cut'n'paste version of the ATLUS's example with a few clean ups.
[pbcode]
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// --------------[ ORIGINAL CODE BY ATLUS ]---------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// this is ATLUS's example with a few fixes and the external media included
// into the source
setfps 57
openscreen 800, 600, 32, 1
ThisImage=LoadDataStatementImage("fluppi.bmp")
ImageMaskColour ThisImage, RGB(255, 174, 201)
CreateSprite 1
SpriteImage 1, ThisImage
SpriteDrawMode 1, 2
centerspritehandle 1
playerX# = GetScreenWidth()/4.0
playerY# = GetScreenHeight()/3.0
gravity# = 2.8
fallingspeed# = 0
flyspeed# = 0
maxflyspeed# = 4.2
stepflyspeed# = 2.5
jumpState = 0
startY# = 0
y1 = 0
y2 = 200
x1 = 600
x2 = 750
anglesprite# = 0
do
cls RGB(74, 227, 220)
//circle playerX#, playerY#, 30, 1
if spacekey()
if JumpState = 0
JumpState = 1
startY# = playerY#
endif
endif
if JumpState = 1
anglesprite# = -30
If GetDistance2D(playerX#,playerY#, playerX#, startY#) > 100
JumpState = 0
anglesprite# = 30
endif
fallingspeed# = 0
flyspeed# += stepflyspeed# * gravity#
playerY# -= flyspeed#
if flyspeed# > maxflyspeed# then flyspeed# = 1
FlushKeys
endif
fallingspeed# += gravity# * 0.2
if fallingspeed# > 13 then fallingspeed# = 13
playerY# += fallingspeed#
RotateSprite 1, anglesprite#
PositionSprite 1, playerX#, playerY#
// BoxC x1,y1,x2,y2, 1, RGB(26, 189, 38)
//debug block
playerY# = getBack(playerY#)
print JumpState
print startY#
drawallsprites
sync
loop
psub getBack(a#)
if a# > GetScreenHeight()
a# = GetScreenHeight()/3.0
endif
EndPsub a#
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// --------------[ LOAD (PALETTE MAPPED) DATA STATEMENT IMAGE ]---------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
Function LoadDataStatementImage(Filename$)
Index=FindData(Filename$)
if Index>-1
olddatapos=getdatapointer()
restore index+1
width =Readdata()
height =Readdata()
palettesize =Readdata()
Dim Palette(PaletteSize)
For lp=0 to PaletteSize-1
Palette(lp)=readdata()
next
ThisImage=newimage(Width,Height,2)
oldsurface=getsurface()
rendertoimage THisIMage
lockbuffer
ThisRGb=Point(0,0)
For ylp=0 to height-1
For xlp=0 to width-1
fastDot xlp,ylp,Palette(ReadData())
next
next
unlockbuffer
rendertoimage oldsurface
restore OldDataPos
endif
EndFUnction ThisImage
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// --------[ fluppi.bmp IMAGE LOAD Converted to DATA STATEMENTS ]------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
Data "fluppi.bmp"
Data 58
Data 46
Data 134
Data 0,12422966,15198251,15396144,15578669,15623243,15657264,15689291,15710254,15754827,15776046,15776302,15789359,15842093,15908651,15951435,15951691,15973421,16016715,16082763,16119717,16148555,16148556,16170797,16171053,16171309,16171564,16182565,16213579,16314149,16345419,16367916
Data 16368172,16368940,16379173,16380194,16380195,16380196,16380197,16380199,16380200,16380452,16381481,16382952,16383287,16383606,16383787,16383789,16383790,16383798,16433964,16434731,16444965,16445988,16446244,16447478,16447527,16447531,16447990,16448503,16448724,16448739,16448745,16448747
Data 16448750,16448754,16448760,16448949,16448978,16448987,16449328,16449334,16499756,16511780,16512035,16512036,16514282,16514283,16514291,16514297,16514524,16514798,16514861,16565548,16577827,16578851,16580060,16580088,16580089,16580331,16580385,16580388,16580395,16580396,16580465,16580534
Data 16580592,16645369,16645882,16645883,16646138,16646139,16709411,16710966,16711409,16711675,16738891,16739659,16756425,16764203,16774947,16775202,16775970,16776225,16776226,16776230,16776482,16776700,16776993,16776994,16777002,16777003,16777004,16777012,16777013,16777178,16777179,16777201
Data 16777204,16777207,16777210,16777212,16777214,16777215
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,122,47,47,47,47,93,122,121,0,0,0,0,133,105,105,105,133,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,103,44,44,44,71,0,0,0,0,0,0,0,133,100,100,100,133,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,70,70,70,57,40,40,40,40,115,0,0,0,0,0,0,0,100,100,100,100,100,105,131,133,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,120,122,82,47,48,56,35,36,36,36,113,0,0,0,0,133,131,105,100,100,100,100,100,132,133,133,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,37,37,37,37,37,42,36,37,37,37,114,0,0,0,0,133,88,98,105,100,100,100,105,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,38,37,37,37,37,114,0,0,0,0,117,133,58,105,100,100,100,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,111,74,37,37,37,37,114,0,0,0,0,133,133,58,105,100,100,100,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,37,37,114,0,0,0,0,133,133,133,133,100,100,100,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,0,43,43,43,43,43,43,43,43,43,104,0,0,0,0,0,37,37,37,114,0,0,0,0,133,133,133,133,100,100,100,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,0,89,89,89,89,89,89,89,89,89,128,0,0,0,0,0,102,73,37,116,0,0,0,0,133,55,97,133,133,105,100,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,127,62,62,62,62,62,62,62,62,62,127,0,0,0,0,0,0,0,54,112,0,0,0,0,0,0,0,133,133,100,105,133,0,0,0,0,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,127,62,62,62,62,62,62,62,62,62,76,0,0,0,0,0,0,0,114,53,29,27,85,0,0,0,0,117,133,133,133,101,88,59,59,87,101,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,129,64,63,62,62,62,62,62,62,62,62,81,96,130,0,0,0,0,37,37,54,75,119,0,0,0,0,133,133,99,133,133,133,133,133,133,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,125,68,61,63,62,62,62,62,62,62,77,69,68,126,0,0,0,0,37,37,37,37,114,0,0,0,0,0,0,133,133,133,133,133,133,133,133,133,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,123,48,67,65,62,62,62,62,62,62,78,45,46,123,0,0,0,0,114,37,37,37,53,37,37,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,120,91,95,66,64,64,64,64,64,64,79,94,90,120,0,0,0,0,116,37,37,37,37,37,37,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,0,0,0,0,6,2,20,80,60,60,60,60,60,60,86,0,0,0,0,0,0,0,112,37,37,37,54,37,37,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108
Data 108,108,108,108,0,0,0,0,0,0,0,124,49,49,49,49,49,49,124,0,0,0,0,0,0,0,53,37,0,0,0,0,0,0,0,0,0,0,0,28,28,28,28,28,28,28,28,28,28,28,28,30,0,0,0,0,108,108
Data 108,108,108,108,108,0,0,0,0,0,0,120,92,92,92,92,92,92,120,0,0,0,0,118,84,54,41,41,0,0,0,0,0,0,0,107,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,107,0,0,0,0,108,108
Data 108,108,108,108,108,0,0,0,0,0,0,12,3,3,3,3,3,0,0,0,0,0,0,110,34,34,34,52,0,0,0,0,0,0,0,7,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,9,0,108,108,108,108,108
Data 108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,11,25,51,33,33,32,109,0,0,0,0,22,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,32,32,50,31,32,32,32,32,0,0,0,0,107,107,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,32,32,32,32,32,32,32,32,0,0,0,0,15,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,1,24,10,10,10,8,23,32,32,32,32,32,32,32,32,32,32,32,0,0,0,0,19,18,18,18,18,18,18,18,18,18,18,18,18,21,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,72,83,32,0,0,0,0,107,106,106,106,106,106,106,106,106,106,106,106,106,107,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,0,24,10,10,10,8,23,50,32,32,32,32,32,32,32,32,32,32,0,0,0,0,19,18,18,18,18,18,18,18,18,18,18,18,18,21,0,0,0,0,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,32,32,32,32,32,32,32,32,32,32,32,17,4,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,26,13,13,13,13,13,13,13,13,13,13,32,32,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,0,0,0,0,0,0,0,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
Data 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108
[/pbcode]
Thanks, why so slow?
runs the same here, given it's 99.9999% the same code..
Ok, i'll try test it again in home.
update: Very slow run on Windows 8.1