int Sąsiedzi(int **tab, int x, int y){ int żywi = 0; int i, j; for (i= (x-1); i<= (x+1); i++){ for (j=(y-1); j<=(y+1); j++){ if (Stan(tab, i, j) == ŻYWA){ ++żywi; } } } if (Stan(tab, x, y)==ŻYWA) { żywi--; } return żywi; }
void Game::action(Window m, SDL_Event& e){ //see? here it is again int health = S[0].getHealth(); int light = S[0].getLight(); int speed = S[0].getSpeed(); int x = S[0].getX(); int y = S[0].getY(); int direction = S[0].getDirection(); switch(e.key.keysym.sym){ case SDLK_w:{ S.erase(S.begin()); Stan s = Stan(m, "img/stan-forward.png", health, light, x, y-speed); S.push_back(s); S[0].setDirection(1); } break; case SDLK_s:{ S.erase(S.begin()); Stan s = Stan(m, "img/stan-backward.png", health, light, x, y+speed); S.push_back(s); S[0].setDirection(2); } break; case SDLK_a:{ S.erase(S.begin()); Stan s = Stan(m, "img/stan-left.png", health, light, x-speed, y); S.push_back(s); S[0].setDirection(3); } break; case SDLK_d:{ S.erase(S.begin()); Stan s = Stan(m, "img/stan-right.png", health, light, x+speed, y); S.push_back(s); S[0].setDirection(4); } break; case SDLK_e:{ slashing = 1; } break; } }
void Game::movement(Window m, SDL_Event& e) { int health = S[0].getHealth(); int light = S[0].getLight(); int speed = S[0].getSpeed(); int x = S[0].getX(); int y = S[0].getY(); switch(e.key.keysym.sym) { case SDLK_w: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-forward.png", health, light, x, y-speed); S.push_back(s); } break; case SDLK_s: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-backward.png", health, light, x, y+speed); S.push_back(s); } break; case SDLK_a: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-left.png", health, light, x-speed, y); S.push_back(s); } break; case SDLK_d: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-right.png", health, light, x+speed, y); S.push_back(s); } break; } }
void Game::Place(Window m){ //this probably needs a function int health = S[0].getHealth(); int light = S[0].getLight(); int speed = S[0].getSpeed(); int x = S[0].getX(); int y = S[0].getY(); int direction = S[0].getDirection(); if(slashing){ switch(direction){ case 1: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-slash-up.png", health, light, x, y); S.push_back(s); S[0].Place(); S[0].setDirection(1); slashing = 0; unslashing = 1; } break; case 2: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-slash-down.png", health, light, x, y); S.push_back(s); S[0].Place(); S[0].setDirection(2); slashing = 0; unslashing = 1; } break; case 3: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-slash-left.png", health, light, x, y); S.push_back(s); S[0].Place(); S[0].setDirection(3); slashing = 0; unslashing = 1; } break; case 4: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-slash-right.png", health, light, x, y); S.push_back(s); S[0].Place(); S[0].setDirection(4); slashing = 0; unslashing = 1; } break; } } else if(unslashing){ switch(direction){ case 1: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-forward.png", health, light, x, y); S.push_back(s); S[0].Place(); S[0].setDirection(1); unslashing = 0; } break; case 2: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-backward.png", health, light, x, y); S.push_back(s); S[0].Place(); S[0].setDirection(2); unslashing = 0; } break; case 3: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-left.png", health, light, x, y); S.push_back(s); S[0].Place(); S[0].setDirection(3); unslashing = 0; } break; case 4: { S.erase(S.begin()); Stan s = Stan(m, "img/stan-right.png", health, light, x, y); S.push_back(s); S[0].Place(); S[0].setDirection(4); unslashing = 0; } break; } } else S[0].Place(); }