Zombie close to the player

Mob is Zombie
Player is player
The thing is I am trying to make that Zombie will spawn far and I want it to slowly come close to the player but the Zombie spawns where the player is which is the problem(I don't know if that it will come to the player) and starts to damage me.
I don't know if the code is clean for you guys but this is my style of typing code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <iostream>
#include "windows.h"
#include<string>

using namespace std;

string space = "";
string plrspace = "";
int x = 1;
int y = 19;
int away = 78;

class Player{
    public:
        char head = 'o';
        char torso = 'I';
        char leftarm = '/';
        char rightarm = '\\';
        char leftleg = '/';
        char rightleg = '\\';
        int Health = 100;
        void LoadCharacter(){
            Player::head = 'o';
            Player::torso = 'I';
            Player::leftarm = '/';
            Player::rightarm = '\\';
            Player::leftleg = '/';
            Player::rightleg = '\\';
            Player::Health = 100;
        }
        void Move(){
            for(int i=1;i<78;i++){
                if(i==x){
                    system("cls");
                    cout << "Health: " << Player::Health << endl;
                    for(int py=0;py<(y+1);py++){
                        cout << endl;
                    }
                    cout << space << " " << Player::head << endl;
                    cout << space << Player::leftarm << Player::torso << Player::rightarm << endl;
                    cout << space << Player::leftleg << " " << Player::rightleg << endl;
                    space = "";
                    break;
                }
                space=space+" ";
            }
        }
};

Player player;
bool disable = false;

class Mob{
    public:
        char head = 'o';
        char torso = 'I';
        char leftarm = '-';
        char rightarm = '-';
        char leftleg = '/';
        char rightleg = '\\';
        int Health = 100;
        void LoadCharacter(){
            Mob::head = 'o';
            Mob::torso = 'I';
            Mob::leftarm = '-';
            Mob::rightarm = '-';
            Mob::leftleg = '/';
            Mob::rightleg = '\\';
            Mob::Health = 100;
        }
        void Attack(){
            if(player.rightarm=='-'){
                Mob::Health = Mob::Health - 5;
                Sleep(1000);
            }else{
                disable = true;
                player.Health = player.Health - 10;
                Sleep(1000);
                disable = false;
            }
        }
        void Move(){
            system("cls");
            for(int py=0;py<(y+1);py++){
                cout << endl;
            }
            for(int i=1;i>(away+1);i++){
                plrspace=plrspace+" ";
            }
            player.Move();
            cout << plrspace << " " << Mob::head << endl;
            cout << plrspace << Mob::leftarm << Mob::torso << Mob::rightarm << endl;
            cout << plrspace << Mob::leftleg << " " << Mob::rightleg << endl;
            away = away - 1;
        }
};


bool started = false;
Mob zombie;

int main(){

    while(started==false){
        zombie.Move();
        if(GetAsyncKeyState(VK_LEFT) && disable == false){
            int test = x - 1;
            if(test>0 && test<78){
                x--;
                player.Move();
                Sleep(50);
            }
        }
        if(GetAsyncKeyState(VK_RIGHT) && disable == false){
            int test = x + 1;
            if(test>0 && test<78){
                x++;
                player.Move();
                Sleep(50);
            }
        }
        if(GetAsyncKeyState(VK_UP) && disable == false){
            int test = y - 1;
            if(test>-1 && test<20){
                y--;
                player.Move();
                Sleep(50);
            }
        }
        if(GetAsyncKeyState(VK_DOWN) && disable == false){
            int test = y + 1;
            if(test>-1 && test<20){
                y++;
                player.Move();
                Sleep(50);
            }
        }
        if(GetAsyncKeyState(VK_SPACE) && disable == false){
            player.rightarm = '-';
            player.Move();
            disable = true;
            Sleep(1000);
            player.rightarm = '\\';
            player.Move();
            disable = false;
        }
        if(plrspace==""){
            zombie.Attack();
        }
    }
    return 0;
}
It doesn't answer your question, but your game is totally buggy. I would use some UI.
Last edited on
Topic archived. No new replies allowed.