Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.cpp
- #include "pch.h"
- #include <iostream>
- #include "enemigo.h"
- using namespace std;
- using namespace System;
- enemigo enemigos[10]; // -> enemigos[0] = enemgios()
- bool pregunta = false;
- void update() {
- for (int i = 0; i < 10; i++) {
- enemigos[i].update();
- }
- }
- void render() {
- for (int i = 0; i < 10; i++) {
- enemigos[i].render();
- }
- }
- void erase() {
- for (int i = 0; i < 10; i++) {
- enemigos[i].erase();
- }
- }
- int main()
- {
- Console::CursorVisible = false;
- enemigos[0] = enemigo(2, 3, &pregunta, 1);
- enemigos[1] = enemigo(1, 1, &pregunta, 1);
- enemigos[4] = enemigo(6, 8, &pregunta, 2);
- while (1) {
- erase();
- update();
- render();
- _sleep(100);
- }
- return 0;
- }
- //enemigo.h
- #pragma once
- #include <iostream>
- using namespace System;
- using namespace std;
- struct enemigo
- {
- int x = 3;
- int y = 3; // posicion
- int dx = 1;
- bool* pregunta;
- int estado = 0;// 0 = vivo , 1 = muriendo , 2= muerto
- int count = 0;
- enemigo(int x, int y, bool *pregunta, int dx) {
- this->x = x;
- this->y = y;
- this->pregunta = pregunta;
- this->dx = dx;
- }
- enemigo() {
- }
- void update() {
- if (estado != 0) return;
- if (x == 0 || x == 100) dx *= -1;
- x += dx;
- }
- void render() {
- Console::SetCursorPosition(this->x, this->y);
- if (estado == 0)
- cout << "*";
- if (estado == 1) {
- cout << "O";
- count++;
- }
- if (estado == 2)
- cout << "_";
- if (count == 3) estado = 2;
- }
- void erase() {
- Console::SetCursorPosition(this->x, this->y);
- cout << " ";
- }
- void colission() {
- if (estado != 0) return;
- *pregunta = 1;
- estado = 1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement