Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Declare loadAssets()
  2. Declare onLoadSuccess()
  3. Declare onLoadError()
  4. Declare gameLoop()
  5. Declare resizeScreen(Center.b = #False)
  6.  
  7. Structure newSprite
  8.   id.i
  9.   x.i
  10.   y.i
  11.   vy.i
  12. EndStructure
  13.  
  14. Global ball.newSprite
  15.  
  16. Global background, demo
  17.  
  18. OpenScreen(400, 600, 32, "")
  19.  
  20. ;If you want to remove the blue background
  21. !$('html').css('background-image', 'none');
  22.  
  23. ;If you want to Change background color
  24. !$('html').css('background-color', '#E2C29E');
  25.  
  26. BindEvent(#PB_Event_Loading, @onLoadSuccess())
  27. BindEvent(#PB_Event_LoadingError, @onLoadError())
  28. BindEvent(#PB_Event_RenderFrame, @gameLoop())
  29. loadAssets()
  30.  
  31. Procedure loadAssets()
  32.   background = LoadSprite(#PB_Any, "assets/sprites/background.png", #PB_Sprite_AlphaBlending)
  33.   demo = LoadSprite(#PB_Any, "assets/sprites/demo.png", #PB_Sprite_AlphaBlending)
  34.   ball\id = LoadSprite(#PB_Any, "assets/sprites/ball.png", #PB_Sprite_AlphaBlending)
  35. EndProcedure
  36.  
  37. Procedure onLoadSuccess()
  38.   Static CountElement
  39.  
  40.   CountElement + 1
  41.  
  42.   If IsSprite(ball\id)
  43.     With Ball
  44.       \x = 200
  45.       \y = 150
  46.       \vy = 3
  47.     EndWith
  48.   EndIf
  49.  
  50.   If IsSprite(demo)
  51.     RotateSprite(demo, -15, #PB_Absolute)
  52.   EndIf
  53.  
  54.   If CountElement = 3
  55.     FlipBuffers()
  56.   EndIf
  57. EndProcedure
  58.  
  59. Procedure onLoadError()
  60. EndProcedure
  61.  
  62. Procedure gameLoop()
  63.   resizeScreen(#True)
  64.  
  65.   ClearScreen(RGB(205, 92, 92))
  66.   DisplayTransparentSprite(background, 0, 0)
  67.   DisplayTransparentSprite(demo, 10, 20)
  68.   RotateSprite(ball\id, 1, #PB_Relative)
  69.   DisplayTransparentSprite(ball\id, ball\x, ball\y)
  70.  
  71.   With ball
  72.     \y + \vy
  73.     If \y < 0 Or \y > ScreenHeight() - 100
  74.       \vy * -1
  75.     EndIf
  76.   EndWith
  77.  
  78.   FlipBuffers()
  79. EndProcedure
  80.  
  81. Procedure resizeScreen(Center.b = #False)
  82.    !var canvas = document.getElementsByTagName("CANVAS")[0];
  83.    !var canvasRatio = canvas.height / canvas.width;
  84.    !var windowRatio = window.innerHeight / window.innerWidth;
  85.    !var width;
  86.    !var height;
  87.  
  88.    !if (windowRatio < canvasRatio) {
  89.    !    height = window.innerHeight;
  90.    !    width = height / canvasRatio;
  91.    !} else {
  92.    !    width = window.innerWidth;
  93.    !    height = width * canvasRatio;
  94.    !}
  95.  
  96.    !canvas.style.width = width + 'px';
  97.    !canvas.style.height = height + 'px';
  98.    
  99.    If Center = #True
  100.    !    var style = canvas.style;
  101.    !    style.marginLeft = "auto";
  102.    !    style.marginRight = "auto";
  103.    !    var parentStyle = canvas.parentElement.style;
  104.    !    parentStyle.textAlign = "center";
  105.    !    parentStyle.width = "100%";
  106.     EndIf
  107. EndProcedure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement