Guest User

Actonscript 2d scroller

a guest
May 8th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. onClipEvent(load){
  2. velx = 0
  3. vely = 0
  4. speed = 2
  5. fric = 1
  6. cap = 6
  7. gravi = 10
  8. jump = 40
  9. }
  10. onClipEvent(enterFrame){
  11. if(Key.isDown(65)){
  12. velx -= speed
  13. }
  14. if(Key.isDown(68)){
  15. velx += speed
  16. }
  17. if(Key.isDown(87)){
  18. if(hitTest(_root.plat)){
  19. if(vely == 0){
  20. vely -= jump
  21. }
  22. }
  23. }
  24.  
  25. //y
  26. if(vely > 0){
  27. vely -= gravi
  28. }
  29. //if(vely < 0){
  30. //vely += gravi
  31. //}
  32. //x
  33. if(velx > 0){
  34. velx -= fric
  35. }
  36. if(velx < 0){
  37. velx += fric
  38. }
  39.  
  40. //x cap
  41. if(velx > cap){
  42. velx = cap
  43. }
  44. if(velx < (0 - cap)){
  45. velx = (0 - cap)
  46. }
  47.  
  48. //y cap
  49. //if(vely > cap){
  50. //vely = cap
  51. //}
  52.  
  53. //if(vely < (0 - cap)){
  54. //vely = (0 - cap)
  55. //}
  56.  
  57. //no drift
  58. if(velx < .1 && velx > 0){
  59. velx = 0
  60. }
  61. if(vely < .1 && vely > 0){
  62. vely = 0
  63. }
  64.  
  65. //if(hitTest(
  66.  
  67. //gravity
  68. if(!this.hitTest(_root.plat)){
  69. vely += gravi
  70. }
  71.  
  72. trace(hitTest(_root.plat))
  73.  
  74. this._y += vely
  75. this._x += velx
  76.  
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment