Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. #include "raylib.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void)
  6. {
  7. // Initialization
  8. //--------------------------------------------------------------------------------------
  9. const int screenWidth = 1280;
  10. const int screenHeight = 720;
  11. const int velocidady = 8;
  12. const int ballSize = 25;
  13. const int maxVelocity = 20;
  14.  
  15.  
  16.  
  17. Rectangle paladerecha;
  18.  
  19. paladerecha.width = 20;
  20. paladerecha.height = 100;
  21. paladerecha.x = screenWidth - 50 - paladerecha.width;
  22. paladerecha.y = screenHeight/2 - paladerecha.height/2;
  23.  
  24.  
  25. Rectangle palaizquierda;
  26.  
  27. palaizquierda.width = 20;
  28. palaizquierda.height = 100;
  29. palaizquierda.x = 50;
  30. palaizquierda.y = screenHeight/2 - palaizquierda.height/2;
  31.  
  32.  
  33. Vector2 ball;
  34. ball.x = screenWidth/2;
  35. ball.y = screenHeight/2;
  36.  
  37. Vector2 ballVelocity;
  38. ballVelocity.x = 8;
  39. ballVelocity.y = 8;
  40.  
  41. InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
  42.  
  43. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  44. //--------------------------------------------------------------------------------------
  45.  
  46. // Main game loop
  47. while (!WindowShouldClose()) // Detect window close button or ESC key
  48. {
  49. // Update
  50. //----------------------------------------------------------------------------------
  51. // Gestiono pulsaciones botones
  52. if (IsKeyDown(KEY_Q)){
  53. palaizquierda.y -= velocidady;
  54. }
  55.  
  56. if (IsKeyDown(KEY_A)){
  57. palaizquierda.y += velocidady;
  58. }
  59.  
  60. if (IsKeyDown(KEY_UP)){
  61. paladerecha.y -= velocidady;
  62. }
  63.  
  64. if (IsKeyDown(KEY_DOWN)){
  65. paladerecha.y += velocidady;
  66. }
  67.  
  68. //Consulto Limites
  69. if(palaizquierda.y<0){
  70. palaizquierda.y = 0;
  71. }
  72.  
  73. if(palaizquierda.y > (screenHeight - palaizquierda.height)){
  74. palaizquierda.y = screenHeight - palaizquierda.height;
  75. }
  76.  
  77. if(paladerecha.y<0){
  78. paladerecha.y = 0;
  79. }
  80.  
  81. if(paladerecha.y > (screenHeight - paladerecha.height)){
  82. paladerecha.y = screenHeight - paladerecha.height;
  83. }
  84.  
  85. //Gestionamos el movimiento de la Bola
  86. ball.x += ballVelocity.x;
  87. ball.y += ballVelocity.y;
  88.  
  89. if((ball.x > screenWidth - ballSize) || (ball.x < ballSize) ){
  90. ballVelocity.x *=-1;
  91. }
  92.  
  93. if((ball.y > screenHeight - ballSize) || (ball.y < ballSize) ){
  94. ballVelocity.y *=-1;
  95. }
  96.  
  97.  
  98. if(CheckCollisionCircleRec(ball, ballSize, paladerecha)){
  99. if(ballVelocity.x>0){
  100. if(abs(ballVelocity.x)<maxVelocity){
  101. ballVelocity.x *=-1.5;
  102. ballVelocity.y *= 1.5;
  103. }else{
  104. ballVelocity.x *=-1;
  105. }
  106. }
  107. }
  108.  
  109. if(CheckCollisionCircleRec(ball, ballSize, palaizquierda)){
  110. if(ballVelocity.x<0){
  111. if(abs(ballVelocity.x)<maxVelocity){
  112. ballVelocity.x *=-1.5;
  113. ballVelocity.y *= 1.5;
  114. }else{
  115. ballVelocity.x *=-1;
  116. }
  117. }
  118. }
  119.  
  120. //----------------------------------------------------------------------------------
  121.  
  122. // Draw
  123. //----------------------------------------------------------------------------------
  124. BeginDrawing();
  125.  
  126. ClearBackground(BLUE);
  127.  
  128. // Pinto Pala Derecha
  129. DrawRectangleRec(paladerecha, GREEN);
  130.  
  131. // Pinto Pala Izquierda
  132. DrawRectangleRec(palaizquierda, GREEN);
  133.  
  134. // Pintamos la pelota
  135. DrawCircleV(ball, ballSize, GREEN);
  136.  
  137. EndDrawing();
  138. //----------------------------------------------------------------------------------
  139. }
  140.  
  141. // De-Initialization
  142. //--------------------------------------------------------------------------------------
  143. CloseWindow(); // Close window and OpenGL context
  144. //--------------------------------------------------------------------------------------
  145.  
  146. return 0;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement