Advertisement
sebasvp2005

Untitled

May 22nd, 2024
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1.  
  2. // main.cpp
  3. #include "pch.h"
  4. #include <iostream>
  5. #include "enemigo.h"
  6. using namespace std;
  7. using namespace System;
  8.  
  9. enemigo enemigos[10]; // -> enemigos[0] = enemgios()
  10.  
  11.  
  12. bool pregunta = false;
  13.  
  14. void update() {
  15.     for (int i = 0; i < 10; i++) {
  16.         enemigos[i].update();
  17.     }
  18. }
  19. void render() {
  20.     for (int i = 0; i < 10; i++) {
  21.         enemigos[i].render();
  22.     }
  23. }
  24. void erase() {
  25.     for (int i = 0; i < 10; i++) {
  26.         enemigos[i].erase();
  27.     }
  28. }
  29.  
  30.  
  31.  
  32. int main()
  33. {
  34.     Console::CursorVisible = false;
  35.     enemigos[0] = enemigo(2, 3, &pregunta, 1);
  36.     enemigos[1] = enemigo(1, 1, &pregunta, 1);
  37.     enemigos[4] = enemigo(6, 8, &pregunta, 2);
  38.    
  39.  
  40.     while (1) {
  41.         erase();
  42.         update();
  43.         render();
  44.        
  45.         _sleep(100);
  46.     }
  47.  
  48.  
  49.  
  50.     return 0;
  51. }
  52.  
  53. //enemigo.h
  54.  
  55. #pragma once
  56. #include <iostream>
  57. using namespace System;
  58. using namespace std;
  59.  
  60. struct enemigo
  61. {
  62.     int x = 3;
  63.     int y = 3; // posicion
  64.  
  65.     int dx = 1;
  66.  
  67.     bool* pregunta;
  68.  
  69.     int estado = 0;//  0 = vivo , 1 = muriendo , 2= muerto
  70.     int count = 0;
  71.  
  72.     enemigo(int x, int y, bool *pregunta, int dx) {
  73.         this->x = x;
  74.         this->y = y;
  75.         this->pregunta = pregunta;
  76.         this->dx = dx;
  77.     }
  78.  
  79.     enemigo() {
  80.  
  81.     }
  82.  
  83.     void update() {
  84.         if (estado != 0) return;
  85.         if (x == 0 || x == 100) dx *= -1;
  86.         x += dx;
  87.     }
  88.     void render() {
  89.  
  90.         Console::SetCursorPosition(this->x, this->y);
  91.         if (estado == 0)
  92.             cout << "*";
  93.         if (estado == 1) {
  94.             cout << "O";
  95.             count++;
  96.         }
  97.         if (estado == 2)
  98.             cout << "_";
  99.         if (count == 3) estado = 2;
  100.     }
  101.     void erase() {
  102.         Console::SetCursorPosition(this->x, this->y);
  103.         cout << " ";
  104.     }
  105.  
  106.     void colission() {
  107.         if (estado != 0) return;
  108.         *pregunta = 1;
  109.         estado = 1;
  110.     }
  111. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement