News:

Function Finder  Find all the functions within source code files

Main Menu

Challenge #28 - Flappy Bird Styled Character Movement

Started by kevin, February 16, 2015, 07:45:45 AM

Previous topic - Next topic

kevin





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
 
  * 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/ FaceBookTwitter or the PlayBASIC youtube channel.



monkeybot

#1
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


PlayBASIC Code: [Select]
; 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







Sigtrygg

Hello monkeybot!

Just a few rows of code, but nevertheless so funny!  :D
Well, I would give you my vote!

Regards,

Sigtrygg

ATLUS

I've never played in Flappy Bird, but i see it in youtube.
It's my version.

kevin

 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


ATLUS



kevin


This is a cut'n'paste version of the ATLUS's example with a few clean ups.

PlayBASIC Code: [Select]
 // ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// --------------[ 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())
Login required to view complete source code

ATLUS


kevin

runs the same here, given it's 99.9999% the same code..

ATLUS

Ok, i'll try test it again in home.

update: Very slow run on Windows 8.1