UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: LemonWizard on September 27, 2012, 01:03:26 AM

Title: Sprite based animation and jumping with running
Post by: LemonWizard on September 27, 2012, 01:03:26 AM
Well... here is something a bit uglier coded but it works and looks kinda cool.
I plan to turn this into a full fledged game so don't steal it. but feel free to use it or play around with it just dont take credit
Who knows you might come up with a cool platformer out of it yea? Because it's fairly basic. it's one of the most basic things I've made in a while.
JUMP N SHOOT MAN!! haha jk jk

<Controls>
UP=jump
Left=Run
Right=Run

Here's the code:

[pbcode]
; PROJECT : The_Project
; AUTHOR  : Laptop
; CREATED : 9/26/2012
; EDITED  : 9/26/2012
; ---------------------------------------------------------------------
runframe=1
leapframe=1
jumping=false
landed=true
falling=false
jumpstarted=false


stickmany#=getscreenheight()-200-64
stickmanx#=0

dim stickmanrunningright(8)
dim stickmanrunningleft(8)
for temp=1 to 8
   
   stickmanrunningright(temp)=loadnewfximage("frame"+str$(temp+8)+".png")
   imagemaskcolour stickmanrunningright(temp), rgb(255, 255, 255)
   stickmanrunningleft(temp)=newfximage(getimagewidth(stickmanrunningright(temp)), getimageheight(stickmanrunningright(temp)))
   rendertoimage stickmanrunningright(temp)
   getimage  stickmanrunningleft(temp), 0, 0, getimagewidth(stickmanrunningright(temp)), getimageheight(stickmanrunningright(temp))
   mirrorimage stickmanrunningleft(temp), 1, 0
   imagemaskcolour stickmanrunningleft(temp), rgb(255, 255, 255)
   
next temp

dim stickmanleapleft(8)
dim stickmanleapright(8)
for temp=1 to 8
   
   stickmanleapright(temp)=loadnewfximage("frame"+str$(temp)+".png")
   imagemaskcolour stickmanleapright(temp), rgb(255, 255, 255)
   stickmanleapleft(temp)=newfximage(getimagewidth(stickmanleapright(temp)), getimageheight(stickmanleapright(temp)))
   rendertoimage stickmanleapright(temp)
   getimage stickmanleapleft(temp), 0, 0, getimagewidth(stickmanleapright(temp)), getimageheight(stickmanleapright(temp))
   mirrorimage stickmanleapleft(temp), 1, 0
   imagemaskcolour stickmanleapleft(temp), rgb(255, 255, 255)
next temp
   


rendertoscreen

stickframetimer=timer()+8
leapframetimer=timer()+8

fallspeed#=0.10
maxfallspeed#=2

main:
;;




keypressed=false



select facing
   case 1
      if jumpstarted=false
drawimage stickmanrunningright(frame), stickmanx#, stickmany#, 1
endif
      case 2
         if jumpstarted=false
         drawimage stickmanrunningleft(frame), stickmanx#, stickmany#, 1
      endif
         
endselect


      

   select facing
      case 1
         if jumpstarted=true
         drawimage stickmanleapright(leapframe), stickmanx#, stickmany#, 1
         endif
         case 2
            if jumpstarted=true
            drawimage stickmanleapleft(leapframe), stickmanx#, stickmany#, 1
            endif
      endselect


   

         
      
      ;stickmanx=mousex()
      ;stickmany=mousey()
                  
         print stickmanx
         print stickmany
         print jumptime
         print "landed "+str$(landed)
         print "jumping "+str$(jumping)
         ;box stickmanx, stickmany, stickmanx+30, stickmany+30 ,1


if rightkey()
   stickmanx#=stickmanx#+1
   keypressed=true
   facing=1
endif

if leftkey()
   stickmanx#=stickmanx#-1
   keypressed=true
   facing=2
endif




if timer()>stickframetimer
   if keypressed=true
   frame=frame+1
   if frame>8 then frame=1
   stickframetimer=timer()+8
endif
endif


if landed=true
   if falling=false
      if jumping=false
if upkey()
   jumping=true
   jumptime=125
   falling=false
   landed=false
   jumpstarted=true
   leapframe=1
endif
endif
endif
endif


   
   if jumping=true
      
      if leapframe>5
      jumptime=jumptime-2
      stickmany#=stickmany#-1
      endif
      
         
         if jumptime<=0
            jumptime=0
            jumping=false
            falling=true
            landed=false
         endif
            
      
   endif
   
   
      if falling=true
         stickmany#=stickmany#+fallspeed#
         fallspeed#=fallspeed#+0.15
         if fallspeed#>maxfallspeed# then fallspeed#=maxfallspeed#
         if stickmany#>getscreenheight()-200-64
            stickmany#=getscreenheight()-200-64
            landed=true
            falling=false
            jumptime=0
            jumping=false
            fallspeed#=0.10
      endif
   endif
         
   

if jumpstarted=true
   if timer()>leapframetimer
      leapframe=leapframe+1
      if landed=true
         if leapframe>8 then leapframe=8
         if facing=1
            stickmanx#=stickmanx#+2
         endif
         
         if facing=2
            stickmanx#=stickmanx#-2
         endif
               
      endif
      
      if landed=false
         if leapframe>6 then leapframe=6
      endif
            
      
      
      leapframetimer=timer()+8
      
   endif
endif
      
   
if jumpstarted=true
   if leapframe=8
      jumpstarted=false
endif
endif
   
      


ink rgb(100, 0, 0)
line 0, getscreenheight()-200, getscreenwidth(), getscreenheight()-200

sync
cls rgb(255,255,255)



goto main   



[/pbcode]

Here's all the frame images in a zip file along with the source and the compiled exe.
MAY RUN FAST so your better off just trying the code and using the SETFPS command.

enjoy! AND PLEASE comment and stuff. I mean really!! I see like 20 downloads on some of my files and no comments. or anything, sometimes. :(

Title: Re: Sprite based animation and jumping with running
Post by: LemonWizard on September 27, 2012, 08:17:03 PM
*points to the amount of downloads on the file*
*points to the words asking for people to comment *

*points to the lack of commentary on the demo*

*annoyed stare at readers*
Please comment on anything you download. It doesn't take that long.
Title: Re: Sprite based animation and jumping with running
Post by: OldNESJunkie on September 27, 2012, 09:30:00 PM
Sorry, meant to post earlier, but got a little crazy at work so....
Anyways, pretty good start to me it seems. I love the stick figure games, so hopefully you make this into a complete game.
Title: Re: Sprite based animation and jumping with running
Post by: stevmjon on September 28, 2012, 12:42:30 AM
hey lemonwizard

it is fun to make your character run around and jump.

change line 98 to :  Print stickmanx#
change line 99 to : Print stickmany#

use cos to change the jump so it is not so linear. keep this growing, so the community can see your progress.

   stevmjon