SHARE
TWEET

Pixelkollision Blitz3D

a guest Jun 7th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Graphics 800, 600, 16, 2
  2. SetBuffer BackBuffer()
  3.  
  4.  
  5. player_x = 590
  6. player_y = 440
  7. player = LoadImage("Bär.jpeg") ;füge hier ein bild ein, dass im selben verzeichnis liegt wie diese datei // Format "<Bildname>.<Bildtyp>" keine GIF
  8. player_height = 50
  9. player_width = 50
  10.  
  11. enemy_x = 604
  12. enemy_y = 503
  13. enemy = LoadImage("Ente.jpg") ;füge hier ein zweites ein
  14. enemy_height = 50
  15. enemy_width = 50
  16.  
  17. player_move_right = False
  18. player_move_left = False
  19. player_move_up = False
  20. player_move_down = False
  21.  
  22. hit_right = False
  23. hit_left = False
  24. hit_up = False
  25. hit_down = False
  26.  
  27. player_x_speed = 1
  28. player_y_speed = 1
  29.  
  30. ResizeImage player, player_width, player_height ;ändert bildgröße
  31. ResizeImage enemy, enemy_width, enemy_height
  32.  
  33.  
  34. Repeat ;Hauptschleife
  35. Cls
  36.  
  37. DrawImage player, player_x, player_y ;zeichnet Bild
  38. DrawImage enemy, enemy_x, enemy_y
  39.  
  40.  
  41.  
  42. If Not ImagesOverlap(player, player_x+player_x_speed,player_y, enemy, enemy_x, enemy_y) Then player_move_right = True ;kann er nach rechts gehen?
  43. If Not ImagesOverlap(player, player_x-player_x_speed,player_y, enemy, enemy_x, enemy_y) Then player_move_left = True
  44. If Not ImagesOverlap(player, player_x,player_y+player_y_speed, enemy, enemy_x, enemy_y) Then player_move_down = True
  45. If Not ImagesOverlap(player, player_x,player_y-player_y_speed, enemy, enemy_x, enemy_y) Then player_move_up = True
  46.  
  47.  
  48.  
  49. If KeyDown(203) And player_move_left = True Then player_x = player_x - player_x_speed : player_x_speed = player_x_speed + 1 ;nach links bewegen wenn linke pfeiltaste gedrückt
  50. If KeyDown(205) And player_move_right = True Then player_x = player_x + player_x_speed : player_x_speed = player_x_speed + 1
  51. If KeyDown(200) And player_move_up = True Then player_y = player_y - player_y_speed : player_y_speed = player_y_speed + 1
  52. If KeyDown(208) And player_move_down = True Then player_y = player_y + player_y_speed : player_y_speed = player_y_speed + 1
  53.  
  54.  
  55. ;If KeyDown(205) And player_move_right = False Then player_x = player_x + Abs( enemy_x - player_x) - 1  ;Soll Player maximal herankommen lassen, vielleicht auch mit For-Schleife machbar //gelöst
  56.  
  57.  
  58. If ImagesOverlap(player, player_x+player_x_speed,player_y, enemy, enemy_x, enemy_y) Then hit_right = True ;gibt es einen kontakt beim nach rechts bewegen?
  59. If ImagesOverlap(player, player_x-player_x_speed,player_y, enemy, enemy_x, enemy_y) Then hit_left = True
  60. If ImagesOverlap(player, player_x,player_y+player_y_speed, enemy, enemy_x, enemy_y) Then hit_down = True
  61. If ImagesOverlap(player, player_x,player_y-player_y_speed, enemy, enemy_x, enemy_y) Then hit_up = True
  62.  
  63. hit_right_distance = Abs(enemy_x - (player_x+player_width)) ;abstand zwischen linkem rand des feindbildes und rechtem rand des playerbildes
  64. hit_left_distance = Abs(enemy_x+enemy_width - (player_x))
  65. hit_down_distance = Abs(enemy_y - (player_y+player_height))
  66. hit_up_distance = Abs(enemy_y+enemy_height - (player_y))
  67.  
  68.  
  69.  
  70. If hit_right = True Then
  71.     If hit_right_distance < player_x_speed Then player_x = player_x + hit_right_distance ;bewege player bis direkt an den rand des gegners, sodass keine lücken entstehen bei player_x_speed > 1 oder player_y_speed > 1
  72. EndIf
  73. If hit_down = True Then
  74.     If hit_down_distance < player_y_speed Then player_y = player_y + hit_down_distance
  75. EndIf
  76. If hit_left = True Then
  77.     If hit_left_distance < player_x_speed Then player_x = player_x - hit_left_distance
  78. EndIf
  79. If hit_up = True Then
  80.     If hit_up_distance < player_y_speed Then player_y = player_y - hit_up_distance
  81. EndIf
  82.  
  83. If hit_right = True Then Text 0, 0, "from se left" ;etwas verwirrend das hit_right bedeutet, dass der player von links kommend auf den feind trifft
  84. If hit_left = True Then Text 0, 0, "from se right" 
  85. If hit_up = True Then Text 0, 0, "from below"
  86. If hit_down = True Then Text 0, 0, "from se top"
  87.  
  88. ;setze alles zurück
  89.  
  90. player_move_right = False
  91. player_move_left = False
  92. player_move_up = False
  93. player_move_down = False
  94. hit_right = False
  95. hit_up = False
  96. hit_left = False
  97. hit_down = False
  98.  
  99. If player_x_speed > 2 Then player_x_speed = 2 ;setze maximale geschwindigkeiten, am besten statt einem festen wert eine variable verwenden, bspw. max_speed_x / max_speed_y
  100. If player_y_speed > 2 Then player_y_speed = 2
  101.  
  102.  
  103.  
  104. Flip
  105. Until KeyHit(1)
  106. End
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top