I need some simple basic jumping code or stratagies to go on, I am a big fan of the mario bros. side-veiw games and really want to make a simple one but I cant make them jump!
thanx
thanx
if(keyhit(jumpkey)and y=abletojump) yv=32 endif if(y <> abletojump) playery=playery-y/3 yv=yv-1 ;see if the player has hit the top of a block if(player_hit_bottom_of_block) yv=0 while(player_hit_bottom_of_block) playery=playery+2 wend endif ;see if the player has hit the bottom if(player_hit_top_of_block) yv=abletojump while(player_hit_top_of_block playery=playery-2 wend endif endif
;DizzyPC ;Written by Michael Denathorn 2005 ;Event Message Flags Const EVENT_None = $0 Const EVENT_KeyDown = $101 Const EVENT_KeyUp = $102 Const EVENT_ASCII = $103 Const EVENT_MouseDown = $201 Const EVENT_MouseUp = $202 Const EVENT_MouseMove = $203 Const EVENT_Gadget = $401 Const EVENT_Move = $801 Const EVENT_Size = $802 Const EVENT_Close = $803 Const EVENT_Front = $804 Const EVENT_Menu = $1001 Const EVENT_LostFocus = $2001 Const EVENT_GotFocus = $2002 Const EVENT_Timer = $4001 ;Create Window, and set 'Notify' window title AppTitle "DizzyPC" hWin = CenterWindow("DizzyPC - Peacock's Coins",346,300,Desktop(),13) ;Windows menu mainmenu = CreateMenu ("&Game", 0, WindowMenu (hWin)) CreateMenu "&About", 1, mainmenu CreateMenu "", 2, mainmenu CreateMenu "E&xit", 3, mainmenu UpdateWindowMenu hWin ;Create DC canvas = CreateCanvas(10,10,320,202,hWin) SetBuffer CanvasBuffer (canvas) HidePointer canvas ;Frames Per Second fps = CreateTimer (60) ;Load Graphics ;Border border = LoadImage("Border.bmp") ;Dizzy dizzyStand = LoadAnimImage("DizzyStand.bmp",24,24,0,2) MaskImage dizzyStand,255,0,255 MidHandle dizzyStand dizzyLeft = LoadAnimImage("DizzyLeft.bmp",23,24,0,8) If dizzyLeft = 0 Then RuntimeError("Error") MaskImage dizzyLeft,255,0,255 MidHandle dizzyLeft dizzyRight = LoadAnimImage("DizzyRight.bmp",23,24,0,8) MaskImage dizzyRight,255,0,255 MidHandle dizzyRight dizzyJumpUp = LoadAnimImage("DizzyJumpStraight.bmp",24,24,0,8) If dizzyJumpUp = False Then RuntimeError"Error" MaskImage dizzyJumpUp,255,0,255 MidHandle dizzyJumpUp dizzyJumpLeft = LoadAnimImage("DizzyJumpLeft.bmp",24,24,0,8) If dizzyJumpLeft = False Then RuntimeError"Error" MaskImage dizzyJumpLeft,255,0,255 MidHandle dizzyJumpLeft dizzyJumpRight = LoadAnimImage("DizzyJumpRight.bmp",24,24,0,8) If dizzyJumpRight = False Then RuntimeError"Error" MaskImage dizzyJumpRight,255,0,255 MidHandle dizzyJumpRight ;Setup Direction Variables Const dizzyStill = 0 Const dizzyDirLeft = 1 Const dizzyDirRight = 2 Global dizzyDir ;Holds the value stating which way dizzy is facing Global dizzyX# ;Dizzy's X location on the screen Global dizzyY# ;Dizzy's Y location on the screen ;Game area variables and setup backgroundTiles = LoadAnimImage("GroundTiles.bmp",16,16,0,7) MaskImage backgroundTiles,255,0,255 solid = $FF800000 ;Solid color used for checking collisions (check the ReadPixelFast Command) ;Game area variables Const gameAreaOffsetX = 40 Const gameAreaOffsetY = 50 Const areaWidth = 15 Const areaHeight = 9 ;Create an array for a tilemap Dim map(areaWidth-1,areaHeight-1) ;Load the data from the bottom of this source code into the tilemap Restore screen For yloop = 0 To areaHeight-1 For xloop = 0 To areaWidth-1 Read something map(xloop,yloop) = something Next Next ;Setup some variables dizzyX = 159 dizzyY = 100 jump = False jumpYDir = -1 ;Status bar text SetStatusText(hWin,"Presented by www.dabzware.co.uk") ;Main loop Repeat ;System code - to let us handle system events Repeat e = WaitEvent (1) ;Process system events Select e Case EVENT_Close End Case EVENT_Menu item = EventData () Select item Case 1 Notify "DizzyPC - Peacock's Coins (ALPHA)"+Chr$(13)+"Written by Michael Denathorn 2005"+Chr$(13)+Chr$(13)+"www.dabzware.co.uk" Case 3 If Confirm ("Are you sure you want to quit?") End EndIf End Select End Select Until e = EVENT_Timer ;Game code ;Clear the screen Cls ;Draw the border DrawImage border,0,0 ;Draw the two dizzys outside the border DrawImage DizzyStand,48,18,0 DrawImage DizzyStand,GadgetWidth(canvas)-48,18,0 ;Draw Game Area Background (Or tilemap) For yloop = 0 To areaHeight-1 For xloop = 0 To areaWidth-1 DrawImage backgroundTiles,(xloop Shl 4) + gameAreaOffsetX ,(yloop Shl 4) + gameAreaOffsetY,map(xloop,yloop) Next Next ;If the jump button hasnt been pressed If jump = False ;If no Left/Right Buttons have been pressed If KeyDown(203) = False If KeyDown(205) = False ;Draw the animated standing dizzy If MilliSecs() > tmrAnimateStand + 100 Then tmrAnimateStand=MilliSecs() frameStand = ( frameStand + 1 ) Mod 2 End If DrawImage DizzyStand,dizzyX,dizzyY,frameStand dizzyDir = dizzyStill jumpDir = 0 End If End If ;Move dizzy Left ;Check if right button is not pressed If KeyDown(205) = False ;Check if left button is pressed (if so) If KeyDown(203) ;move dizzy back one and animage him dizzyX = dizzyX - 1 If MilliSecs() > tmrAnimateLeft + 100 Then tmrAnimateLeft=MilliSecs() frameLeft = ( frameLeft + 1 ) Mod 8 End If ;Draw dizzy moving left DrawImage DizzyLeft,dizzyX,dizzyY,frameLeft dizzyDir = dizzyDirLeft jumpDir = -1 End If End If ;As above, but check for right key press If KeyDown(205) dizzyX = dizzyX + 1 If MilliSecs() > tmrAnimateRight + 100 Then tmrAnimateRight=MilliSecs() frameRight = ( frameRight + 1 ) Mod 8 End If DrawImage DizzyRight,dizzyX,dizzyY,frameRight dizzyDir = dizzyDirRight jumpDir = 1 End If ;Check if the jump flag is false If jump = False ;Check if space (jump button) is pressed If KeyHit(57) jump = True ;Set jump flag to true jumpheight = dizzyY - 40 ;set jump height jumpYDir = -1 ;setup jump dir frameUp = 0 End If End If End If If dizzyX = 280 dizzyX = 41 End If If dizzyX = 40 dizzyX = 279 End If ;Jump code If jump = True ;Move dizzy in the required 'jump' direction dizzyX = dizzyX + jumpDir dizzyY = dizzyY + jumpYDir If dizzyY = jumpHeight jumpYDir =-jumpYDir End If ;check which way he's jumping, and animate accordingly If MilliSecs() > tmrAnimateJumpUp + 83 Then tmrAnimateJumpUp=MilliSecs() frameUp = ( frameUp + 1 ) Mod 8 End If If jumpDir = 0 DrawImage dizzyJumpUp,dizzyX,dizzyY,frameUp End If If jumpDir < 0 DrawImage dizzyJumpLeft,dizzyX,dizzyY,frameUp End If If jumpDir > 0 DrawImage dizzyJumpRight,dizzyX,dizzyY,frameUp End If End If ;make dizzy fall If jump = False dizzyY = dizzyY + 1 End If ;Check for collision LockBuffer CanvasBuffer(canvas) pixelBottomLeft = ReadPixelFast(dizzyX-6,dizzyY+12) pixelBottomRight = ReadPixelFast(dizzyX+6,dizzyY+12) pixelBankLeft = ReadPixelFast(dizzyX-11,dizzyY+8) pixelBankRight = ReadPixelFast(dizzyX+11,dizzyY+8) UnlockBuffer CanvasBuffer(canvas) If pixelBottomLeft = solid Or pixelBottomRight = solid dizzyY = dizzyY - 1 If frameUp = 7 jump = False End If End If If dizzyDir <> dizzyStill If pixelBankLeft = solid Or pixelBankRight = solid dizzyY = dizzyY - 2 jump = False End If End If If pixelmid = solid dizzyY = dizzyY - 1 jump = False End If SetStatusText(hWin,"X:"+(dizzyX Shr 4)+" - Y:"+(dizzyY Shr 4)) FlipCanvas canvas Forever ;Center window function Function CenterWindow (title$, width, height, group = 0, style = 15) Return CreateWindow (title$, (ClientWidth (Desktop ()) / 2) - (width / 2), (ClientHeight (Desktop ()) / 2) - (height / 2), width, height, group, style) End Function ;Screen area data (Tilemap) .screen Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 Data 0,0,0,0,0,0,0,0,0,0,0,2,1,1,1 Data 0,0,0,0,0,0,0,0,0,0,2,4,6,6,6 Data 0,0,0,0,0,0,0,0,0,2,4,6,6,6,6 Data 1,1,1,1,1,1,1,1,1,4,6,6,6,6,6
Select jump case 0 if keyhit(space) then jump = 1 case 1 y = y - 1 if y < 10 then jump = 2 case 2 y = y + 1 if y > 100 then jump = 0 end select