First commit

master
Bog13 9 years ago
commit 554442b331
  1. 3
      .gitignore
  2. 14
      CMakeLists.txt
  3. BIN
      assets/BearRoaring.wav
  4. BIN
      assets/Explosion2.wav
  5. BIN
      assets/bubbleunderwater.wav
  6. BIN
      assets/explosion.WAV
  7. BIN
      assets/explosion.jpg
  8. BIN
      assets/screamingMan.wav
  9. BIN
      assets/screamingMan2.wav
  10. BIN
      assets/tilesetNew.png
  11. BIN
      assets/tilesetNew2.png
  12. 59
      src/Case.cpp
  13. 49
      src/Case.h
  14. 193
      src/Hero.cpp
  15. 86
      src/Hero.h
  16. 214
      src/Kraken.cpp
  17. 95
      src/Kraken.h
  18. 107
      src/Level.cpp
  19. 44
      src/Level.h
  20. 161
      src/main.cpp

3
.gitignore vendored

@ -0,0 +1,3 @@
*~*
*\#*
build/

@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.5)
project(kraken)
file(GLOB
sources
src/*.cpp)
add_executable(kraken.elf
${sources})
find_package(PkgConfig)
pkg_check_modules(SFML sfml-all)
target_link_libraries(kraken.elf ${SFML_LDFLAGS})

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

@ -0,0 +1,59 @@
#include "Case.h"
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <string>
#include <iostream>
#define TILE_WIDTH 30
#define TILE_HEIGHT 30
using namespace sf;
Case::Case()
{
//ctor
}
Case::Case(sf::RenderWindow* window, float x, float y)
{
m_positionX=x;
m_positionY=y;
m_value=0;
m_statut=false;
m_window=window;
}
void Case::Settexture(std::string name)
{
if(!m_texture.loadFromFile(name.c_str())){std::cout<<"|!|Texture loading failed :" << name << std::endl;}
m_sprite.setTexture(m_texture);
m_sprite.setTextureRect(IntRect(m_value*(TILE_WIDTH+1),0,TILE_WIDTH, TILE_HEIGHT));
std::cout<< "0) Texture loaded "<<std::endl;
}
void Case::draw(int whichOneX,int whichOneY,int x, int y)
{
{m_sprite.setTextureRect(IntRect(whichOneX*(TILE_WIDTH+1),whichOneY*(TILE_HEIGHT+2),TILE_WIDTH, TILE_HEIGHT));}
m_sprite.setPosition(x*TILE_WIDTH,y*TILE_HEIGHT);
m_window->draw(m_sprite);
}
void Case::drawFree(int whichOneX,int whichOneY,float x, float y)
{
{m_sprite.setTextureRect(IntRect(whichOneX*(TILE_WIDTH+1),whichOneY*(TILE_HEIGHT+1),TILE_WIDTH, TILE_HEIGHT));}
m_sprite.setPosition(x,y);
m_window->draw(m_sprite);
}
Case::~Case()
{
//dtor
}

@ -0,0 +1,49 @@
#ifndef CASE_H
#define CASE_H
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <string>
class Case
{
public:
Case();
Case(sf::RenderWindow* window, float x=0, float y=0);
virtual ~Case();
float GetpositionX() { return m_positionX; }
void SetpositionX(float val) { m_positionX = val; }
float GetpositionY() { return m_positionY; }
void SetpositionY(float val) { m_positionY = val; }
void Setposition(float x, float y){m_positionX=x;m_positionY=y;}
int Getvalue(){return m_value;}
sf::RenderWindow* Getwindow() { return m_window; }
void Setwindow(sf::RenderWindow* val) { m_window = val; }
sf::Texture Gettexture() { return m_texture; }
void Settexture(std::string name) ;
sf::Sprite Getsprite() { return m_sprite; }
void Setsprite(sf::Sprite val) { m_sprite = val; }
/// /// /// /// ///
void draw(int whichOneX,int whichOneY,int x, int y);
void drawFree(int whichOneX,int whichOneY,float x, float y);
bool ifClicked();
protected:
float m_positionX;
float m_positionY;
int m_value;
bool m_statut;
sf::RenderWindow* m_window;
sf::Texture m_texture;
sf::Sprite m_sprite;
};
#endif // CASE_H

@ -0,0 +1,193 @@
#include "Hero.h"
#include "Case.h"
#include "Level.h"
#include "Kraken.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <string>
#include <vector>
#include <iostream>
#define TILE_WIDTH 30
#define TILE_HEIGHT 30
Hero::Hero(Kraken* kraken, float pozX, float pozY)
{
m_speedX=0;
m_speedY=0;
m_pozX=pozX;
m_pozY=pozY;
m_attacking=false;
m_start.x=pozX;
m_start.y=pozY;
m_statut=1;
m_kraken=kraken;
hidden=false;
circle.setRadius(0);
circle.setPosition(m_pozX,m_pozY);
test=0;
m_dead=false;
m_clock.restart();
hasAttacked=false;
//ctor
}
void Hero::die()
{
m_dead=true;
}
bool Hero::attack()
{
sf::Time time;
time=m_clock.getElapsedTime();
if(time.asSeconds()<=0.3)
{
time=m_clock.getElapsedTime();
int coinH(0), coinV(0);
if(m_statut==0){m_speedX=0.5;}
if(m_statut==1){m_speedX=-0.5;}
if(m_statut==2){m_speedY=-0.5;}
if(m_statut==3){m_speedY=0.5;}
if(m_speedX>0){coinH=m_pozX+TILE_WIDTH+m_speedX;}
else if (m_speedX<0) {coinH=m_pozX+m_speedX; }
else if(m_speedX==0) {coinH=m_pozX+TILE_WIDTH/2;}
if(m_speedY>0){coinV=m_pozY+TILE_HEIGHT+m_speedY;}
else if (m_speedY<0) {coinV=m_pozY+m_speedY;}
else if (m_speedY==0) {coinV=m_pozY+2*TILE_HEIGHT/3;}
if (next(coinH,coinV)==3 || next(coinH,coinV)==5 ) {die();}
justMove();
if(m_pozX>=m_kraken->Gethead().getPosition().x - TILE_WIDTH && m_pozX<=m_kraken->Gethead().getPosition().x +3*TILE_WIDTH && m_pozY<=m_kraken->Gethead().getPosition().y+3*TILE_HEIGHT && m_pozY>=m_kraken->Gethead().getPosition().y && hasAttacked==false){m_kraken->Damaged(); hasAttacked=true;}
}
else {m_speedX=0;m_speedY=0;
m_attacking=false;hasAttacked=false;}
}
void Hero::Settexture(std::string name)
{
if(!m_texture.loadFromFile(name.c_str())){std::cout<<"Echec chargement texture Hero"<<std::endl;}
m_sprite.setTexture(m_texture);
}
void Hero::draw()
{
///Chosing the picture
if(m_speedX>0 && m_speedY==0){m_statut=0;}
if(m_speedX<0 && m_speedY==0){m_statut=1;}
if(m_speedY>0 && m_speedX==0){m_statut=3;}
if(m_speedY<0 && m_speedX==0){m_statut=2;}
///
///Draw the hero
if(hidden==false)
{
m_sprite.setTextureRect(sf::IntRect(6*(TILE_WIDTH+1)+m_statut*(TILE_WIDTH+1),0,TILE_WIDTH,TILE_HEIGHT));
m_sprite.setPosition(m_pozX,m_pozY);
m_kraken->Getlevel()->Getcase()->Getwindow()->draw(m_sprite);
}
///LIFE
if (m_color==2){m_sprite.setColor(sf::Color::Green);}
else if (m_color==3){m_sprite.setColor(sf::Color::Red);}
///DEAD
if (m_dead)
{
// m_kraken->restart();
//circle.setFillColor(sf::Color::Red);
test=0;
sf::Texture Texplosion;
if(!Texplosion.loadFromFile("explosion.jpg")){std::cout<<"Error loading texture explosion"<<std::endl;};
sf::Sprite explosion;
explosion.setTexture(Texplosion);
circle.setTexture(&Texplosion);
for(int i(0);i<200;i++)
{
test+=0.25;
circle.setPosition(m_pozX-0.25*i,m_pozY-0.25*i);
circle.setRadius(test);
SetspeedX(0); SetspeedY(0);
m_kraken->Getlevel()->Getcase()->Getwindow()->draw(circle);
m_kraken->Getlevel()->Getcase()->Getwindow()->display();
// for(int j(0);j<1000;j+=0.1){}
}
SetpozX(m_start.x);
SetpozY(m_start.y);
m_attacking=false;
m_dead=false;
m_speedX=0;
m_speedY=0;
}
}
void Hero::justMove()
{
if(next(m_pozX+TILE_WIDTH+m_speedX,m_pozY+2*TILE_HEIGHT/3+m_speedY)==5){m_speedX=0;} ///RIGHT
if(next(m_pozX+m_speedX,m_pozY+2*TILE_HEIGHT/3+m_speedY)==5){m_speedX=0;} ///LEFT
if(next(m_pozX+m_speedX+TILE_WIDTH/2, m_pozY+2*TILE_HEIGHT/3+m_speedY)==5){m_speedY=0;} ///UP & DOWN
if(m_kraken->Getlevel()->getCoord(convertCoordX(m_pozX+TILE_WIDTH/2),convertCoordY(m_pozY+2*TILE_HEIGHT/3))=='4')
{
for(int i(0);i<100;i++)
{
m_speedX=0; m_speedY=0;
m_statut=i%4;
m_sprite.setTextureRect(sf::IntRect(6*(TILE_WIDTH+1)+m_statut*(TILE_WIDTH+1),0,TILE_WIDTH,TILE_HEIGHT));
m_kraken->Getlevel()->Getcase()->Getwindow()->draw(m_sprite);
m_kraken->Getlevel()->Getcase()->Getwindow()->display();}
SetpozY(m_kraken->Getlevel()->findAnother2('4').first*TILE_WIDTH);
SetpozX(m_kraken->Getlevel()->findAnother2('4').second*TILE_HEIGHT);
}
m_pozX+=m_speedX;
m_pozY+=m_speedY;
}
void Hero::update()
{
if (m_attacking && m_dead==false){attack();}
else if(m_attacking==false){justMove();}
if(m_kraken->getcounter()==2 && hidden==false){if(m_kraken->isThereCollision(convertCoordX(m_pozX+TILE_WIDTH/2),convertCoordY(m_pozY+TILE_HEIGHT/2))){
m_dead=true; m_kraken->setVector(std::vector<int>(10,10));
}}
if(next(m_pozX+TILE_WIDTH/2,m_pozY+TILE_HEIGHT/2)==3){
m_sprite.setTextureRect(sf::IntRect(11*(TILE_WIDTH+1),0,TILE_WIDTH,TILE_HEIGHT));
m_sprite.setPosition(m_pozX,m_pozY);
m_kraken->Getlevel()->Getcase()->draw(0,6,convertCoordX(m_pozX+TILE_WIDTH/2),convertCoordY(m_pozY+TILE_HEIGHT/2));
hidden=true;}
else if (next(m_pozX,m_pozY)!=3) {draw();hidden=false;}
}
Hero::~Hero()
{
//dtor
}

@ -0,0 +1,86 @@
#ifndef HERO_H
#define HERO_H
#include "Case.h"
#include "Level.h"
#include "Kraken.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <string>
#include <vector>
#define TILE_WIDTH 30
#define TILE_HEIGHT 30
class Hero
{
public:
Hero(Kraken* kraken, float pozX, float pozY);
virtual ~Hero();
float GetspeedX() { return m_speedX; }
void SetspeedX(float val) { m_speedX = val; }
float GetspeedY() { return m_speedY; }
void SetspeedY(float val) { m_speedY = val; }
float GetpozX() { return m_pozX; }
void SetpozX(float val) { m_pozX = val; }
float GetpozY() { return m_pozY; }
void SetpozY(float val) { m_pozY = val; }
bool Getattacking() { return m_attacking; }
void Setattacking(bool val) { m_attacking = val; }
sf::Vector2f Getstart() { return m_start; }
void Setstart(sf::Vector2f val) { m_start = val; }
sf::Texture Gettexture() { return m_texture; }
void Settexture(std::string name);
sf::Sprite Getsprite() { return m_sprite; }
void Setsprite(sf::Sprite val) { m_sprite = val; }
int Getstatut() { return m_statut; }
void Setstatut(int val) { m_statut = val; }
/// // /// /// // /// // /// // ///
void draw();
void update();
bool attack();
void justMove();
void die();
int convertCoordX(float a) {return int(a/TILE_WIDTH);}
int convertCoordY(float a) {return int(a/TILE_HEIGHT);}
int next(float a, float b){return m_kraken->Getlevel()->getCoord(convertCoordX(a),convertCoordY(b))-'0';}
void restartClock() {m_clock.restart();}
void setAttacking(bool val){m_attacking=val;}
bool isDead() {return m_dead;}
protected:
float m_speedX;
float m_speedY;
float m_pozX;
float m_pozY;
bool m_attacking;
bool hasAttacked;
bool underWater;
sf::Vector2f m_start;
sf::Texture m_texture;
sf::Sprite m_sprite;
int m_statut;
Kraken* m_kraken;
bool hidden;
bool m_dead;
int m_color;
sf::CircleShape circle;
float test;
sf::Clock m_clock;
};
#endif // HERO_H

@ -0,0 +1,214 @@
#include "Kraken.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include "Case.h"
#include "Level.h"
#include "Kraken.h"
#include "Hero.h"
#include <string>
#include <vector>
#include <iostream>
#define TILE_WIDTH 30
#define TILE_HEIGHT 30
Kraken::Kraken(Level* level,int width, int height, int numberTenta)
{
m_level=level;
m_clock.restart();
m_tentacleClock.restart();
m_maxX=width;
m_maxY=height;
pozX=rand()%(m_maxX-3)*TILE_WIDTH+1;
pozY=rand()%(m_maxY-6)*TILE_HEIGHT+1;
m_head.setPosition(pozX,pozY);
m_counter=0;
m_life=5;
m_damaged=false;
m_dead=false;
m_numberTenta=numberTenta;
m_coords=std::vector<int>(10,0);
m_temp.restart();
rapidity=1;
}
void Kraken::Settexture(std::string name)
{
if(!m_texture.loadFromFile(name)){std::cout<<"Echec de l'ouverture texture Kraken" << std::endl;}
m_head.setTexture(m_texture);
m_tentacle.setTexture(m_texture);
///Head
}
void Kraken::drawTheHead(int a)
{
m_head.setTextureRect(sf::IntRect(a*2*(1+TILE_WIDTH),TILE_HEIGHT,TILE_WIDTH*2, TILE_HEIGHT*3));
// m_head.setPosition(x*TILE_WIDTH,y*TILE_HEIGHT);
m_level->Getcase()->Getwindow()->draw(m_head);
int x= int(m_head.getPosition().x/TILE_WIDTH);
int y=int(m_head.getPosition().y/TILE_HEIGHT);
for (int i(x-1);i<=x+2;i++)
{
for(int j(y-1);j<=y+3;j++)
{
m_level->setCoordCase(i,j,'5');
}
}
m_level->setCoordCase(x,y+3,'2');
m_level->setCoordCase(x+1,y+3,'2');
m_level->setCoordCase(x-2,y+4,'1');
m_level->setCoordCase(x-1,y+4,'1');
m_level->setCoordCase(x,y+4,'1');
m_level->setCoordCase(x+1,y+4,'1');
m_level->setCoordCase(x+2,y+4,'1');
m_level->setCoordCase(x+3,y+4,'1');
}
void Kraken::placeTheHeadAnywhere()
{
{
pozX=rand()%(m_maxX-3)*TILE_WIDTH+3;
pozY=rand()%(m_maxY-6)*TILE_HEIGHT+1;
m_head.setPosition(pozX,pozY);}
}
void Kraken::drawATentacle()
{
m_tentacleTime=m_tentacleClock.getElapsedTime();
int counteur;
bool pick(false), ended(true);
///Go
if(m_tentacleTime.asMilliseconds()%2000<=50 && m_tentacleTime.asMilliseconds()%2000>=25){pick=true; ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=100*rapidity && m_tentacleTime.asMilliseconds()%2000>=50){counteur=0;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=200*rapidity){counteur=1;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=300*rapidity){counteur=2;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=400*rapidity){counteur=3;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=500*rapidity){counteur=4;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=600*rapidity){counteur=5;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=700*rapidity){counteur=6;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=800*rapidity){counteur=7;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=900*rapidity){counteur=8;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=1000*rapidity){counteur=9;ended=false;}
///Back
else if(m_tentacleTime.asMilliseconds()%2000<=1100*rapidity){counteur=8;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=1200*rapidity){counteur=7;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=1300*rapidity){counteur=6;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=1400*rapidity){counteur=5;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=1500*rapidity){counteur=4;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=1600*rapidity){counteur=3;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=1700*rapidity){counteur=2;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=1800*rapidity){counteur=1;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=1900*rapidity){counteur=0;ended=false;}
else if(m_tentacleTime.asMilliseconds()%2000<=1999*rapidity){counteur=0;ended=true;}
else {m_tentacleClock.restart();}
if(pick){
m_coords.erase(m_coords.begin(),m_coords.end());
setNumberTenta(rand()%6+1);
for(int i(0);i<2*m_numberTenta-1;i+=2){
m_coords.push_back(abs(pickX()));
m_coords.push_back(abs(pickY()));
}
}
m_tentacle.setTextureRect(sf::IntRect(counteur*(TILE_WIDTH+1),4*(TILE_HEIGHT+2),TILE_WIDTH, TILE_HEIGHT*2));
for(int i(0);i<m_numberTenta*2;i+=2){
m_tentacle.setPosition(m_coords[i]*TILE_WIDTH,m_coords[i+1]*TILE_HEIGHT);
m_level->Getcase()->Getwindow()->draw(m_tentacle);}
if (ended){for(int i(0); i<m_coords.size();i++){m_coords[i]=0;}}
}
bool Kraken::isThereCollision(int x, int y)
{
bool temp(false);
for(int i(0);i<m_coords.size()-2;i+=2){
if(m_coords[i]==x && m_coords[i+1]==y)
{std::cout<<" touche "; temp=true;}
}
return temp;
}
void Kraken::update()
{
///HEAD
m_time=m_clock.getElapsedTime();
if(m_time.asSeconds()<5*rapidity){m_counter=0;}
else if(m_time.asMilliseconds()<=8000*rapidity){m_counter=1;}
else if(m_time.asMilliseconds()<=10000*rapidity){m_counter=2;}
else {m_clock.restart();}
if(m_life==1){m_counter=2;}
///
///DAMAGED
if(isDamaged()){
sf::Time test;
test=m_temp.getElapsedTime();
m_time=m_clock.getElapsedTime();
if (test.asMilliseconds()%4000<=2000){m_counter=3;}
else if (test.asMilliseconds()%4000>2000) {m_counter=3;m_damaged=false; m_life-=1; if(m_life<=0){m_counter=4;} placeTheHeadAnywhere(); m_damaged=false; }
//rapidity-=0.17;
}
///
///DEAD
if(isDead()){m_counter=4;}
///
if(m_counter==2){drawATentacle();}
drawTheHead(m_counter);
///TENTACLE
}
Kraken::~Kraken()
{
//dtor
}

@ -0,0 +1,95 @@
#ifndef KRAKEN_H
#define KRAKEN_H
#include "Case.h"
#include "Level.h"
#include "Kraken.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <string>
#include <vector>
#include <iostream>
#define TILE_WIDTH 30
#define TILE_HEIGHT 30
class Kraken
{
public:
Kraken(Level* level, int width=50, int height=50, int numberTenta=0);
virtual ~Kraken();
Level* Getlevel() { return m_level; }
void Setlevel(Level* val) { m_level = val; }
sf::Texture Gettexture() { return m_texture; }
void Settexture(std::string name);
sf::Sprite Gethead() { return m_head; }
void Sethead(sf::Sprite val) { m_head = val; }
sf::Sprite Gettentacle() { return m_tentacle; }
void Settentacle(sf::Sprite val) { m_tentacle = val; }
int getcounter(){return m_counter;}
sf::Vector2f getposition(){return sf::Vector2f(pozX,pozY);}
std::vector<std::string> Gettab() { return m_tab; }
void Settab(std::vector<std::string> val) { m_tab = val; }
void placeTheHeadAnywhere();
void setNumberTenta(int a){m_numberTenta=a;}
/// /// /// /// /// // /// /// /// ///
void setCoord(float x, float y){m_heroCoordX=x; m_heroCoordY=y;}
void drawTheHead(int a=0);
void drawATentacle();
void update();
bool isThereCollision(int x, int y);
void setVector(std::vector<int> tab){m_coords=tab;}
const bool isDamaged(){return m_damaged;}
void Damaged(){ m_temp.restart(); m_damaged=true;}
bool isAttacking() {if (m_counter==2) return true; return false;}
const bool isDead(){if(m_life==0){return true;} else {return false;}}
void setDead(bool val){m_dead=val;}
int pickX(){return rand()%10+int(m_heroCoordX/TILE_WIDTH)-5;}
int pickY(){return rand()%10+int(m_heroCoordY/TILE_HEIGHT)-5;}
// void restart() {m_clock.restart();}
protected:
float m_heroCoordX;
float m_heroCoordY;
int pozY;
int pozX;
Level* m_level;
sf::Clock m_clock;
sf::Clock m_tentacleClock;
sf::Clock m_temp;
sf::Time m_tentacleTime;
sf::Texture m_texture;
sf::Sprite m_head;
sf::Sprite m_tentacle;
sf::Time m_time;
std::vector<std::string> m_tab;
int m_maxX;
int m_maxY;
int m_counter;
int m_life;
int m_numberTenta;
bool m_damaged;
bool m_dead;
float rapidity;
std::vector<int> m_coords;
};
#endif // KRAKEN_H

@ -0,0 +1,107 @@
#include "Level.h"
#include "Case.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <ctime>
#include <vector>
using namespace sf;
Level::Level(Case* aCase, int width, int height)
{
m_width=width;
m_height=height;
m_case=aCase;
srand(time(NULL));
}
char Level::findAnother(char val)
{
int x(0),y(0);
while (m_tab[y][x]!=val)
{
x=rand()%(m_width+1), y=rand()%(m_height+1);
}
return m_tab[y][x];
}
std::pair<int,int> Level::findAnother2(char val)
{
int x(0),y(0);
while (m_tab[y][x]!=val)
{
x=rand()%(m_width+1), y=rand()%(m_height+1);
}
return std::pair<int,int> (x,y);
}
void Level::create()
{
std::string line;
for(int i(0);i<m_width;i++)
{
m_tab.push_back(line);
for (int j(0);j<m_height-1;j++)
{
int temp(rand()%26);
if (temp==0){m_tab[i]+='3';}
if (temp==1){m_tab[i]+='4';}
if (temp==2){m_tab[i]+='5';}
else {m_tab[i]+='0';}
//std::cout<<m_tab[i][j];
}
}
for (int i(0);i<m_width;i++)
{
m_tab[i][0]='5';
m_tab[i][m_height-2]='5';
}
for (int i(0);i<m_height;i++)
{
m_tab[0][i]='5';
m_tab[m_width-1][i]='5';
}
}
const void Level::draw()
{
for(int i(0);i<m_width;i++)
{
for (int j(0);j<m_height;j++)
{
m_case->draw(m_tab[i][j]-'0',0,i,j);
}
}
}
const void Level::show()
{
for(int i(0);i<m_height;i++)
{
for (int j(0);j<m_width;j++)
{
std::cout<<m_tab[j][i];
}
std::cout<<std::endl;
}
std::cout<<std::endl<<std::endl;
}
Level::~Level()
{
//dtor
}

@ -0,0 +1,44 @@
#ifndef LEVEL_H
#define LEVEL_H
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include "Case.h"
#include <string>
#include <vector>
class Level
{
public:
Level(Case* aCase, int width=20, int height=20);
virtual ~Level();
int Getwidth() { return m_width; }
void Setwidth(int val) { m_width = val; }
int Getheight() { return m_height; }
void Setheight(int val) { m_height = val; }
Case* Getcase() { return m_case; }
void Setcase(Case* val) { m_case = val; }
/// /// /// /// /// /// /// /// /// /// /// /// ///
void setCoordCase(int x, int y, char val) {m_tab[x][y]=val;}
char getCoord(int x, int y){ return m_tab[x][y];}
char findAnother(char val) ;
std::pair<int,int> findAnother2(char val);
void create();
const void show();
const void draw();
protected:
int m_width;
int m_height;
std::vector<std::string> m_tab;
Case* m_case;
};
#endif // LEVEL_H

@ -0,0 +1,161 @@
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <ctime>
#include "Case.h"
#include "Level.h"
#include "Kraken.h"
#include "Hero.h"
#define TILE_WIDTH 30
#define TILE_HEIGHT 30
#define ASSETS_PATH "../assets/"
using namespace sf;
void funct(std::string name)
{
SoundBuffer Ssound;
if(!Ssound.loadFromFile(name.c_str())){std::cout<<"bug music (loading)"<<std::endl;};
Sound sound(Ssound);
sound.play();
while(sound.getStatus()==Sound::Playing){}
}
int main()
{
RenderWindow window(VideoMode::getDesktopMode(),"Kraken's Game");
srand(time(NULL));
Thread bearRoaring(&funct,ASSETS_PATH "BearRoaring.wav");
Thread bubble(&funct,ASSETS_PATH "bubbleunderwater.wav");
Thread explosion(&funct,ASSETS_PATH "Explosion2.wav");
Thread scream(&funct,ASSETS_PATH "screamingMan.wav");
Case theCase(&window);
theCase.Settexture(ASSETS_PATH "tilesetNew.png");
Level theLevel(&theCase,int(VideoMode::getDesktopMode().width/TILE_HEIGHT), int(VideoMode::getDesktopMode().height/TILE_HEIGHT));
theLevel.create();
Kraken theBeast(&theLevel,int(VideoMode::getDesktopMode().width/TILE_HEIGHT), int(VideoMode::getDesktopMode().height/TILE_HEIGHT),2);
theBeast.Settexture(ASSETS_PATH "tilesetNew2.png");
Hero Josh(&theBeast,70,70);
theLevel.setCoordCase(int(70/TILE_WIDTH),int(70/TILE_HEIGHT),'3');
Josh.Settexture(ASSETS_PATH "tilesetNew2.png");
View beastView;
beastView.setCenter(theBeast.getposition().x+TILE_WIDTH*2,theBeast.getposition().y+TILE_HEIGHT);
beastView.setSize(2*TILE_WIDTH,3*TILE_HEIGHT);
beastView.setViewport(FloatRect(0.9f,0,0.2f,0.25f));
beastView.zoom(2.0f);
View joshView;
joshView.setCenter(Josh.GetpozX(),Josh.GetpozY());
joshView.setSize(10*TILE_WIDTH,10*TILE_HEIGHT);
bool attack(false);
// joshView.setViewport(FloatRect(0, 0, 0.8f, 1));
/* RectangleShape rect;
rect.setSize(Vector2f(200,200));
rect.setPosition(Vector2f(beastView.getCenter().x-beastView.getSize().x/2,beastView.getCenter().y-beastView.getSize().y));
rect.setFillColor(Color::Black); */
//
while (window.isOpen())
{
Event event;
while(window.pollEvent(event))
{
switch(event.type)
{
case (Event::Closed): window.close();
case Event::KeyReleased:
{
if (event.key.code==Keyboard::Up || event.key.code==Keyboard::Down) {Josh.SetspeedY(0);}
if (event.key.code==Keyboard::Right || event.key.code==Keyboard::Left) {Josh.SetspeedX(0);}
//if (event.key.code==Keyboard::Space) {attack=true;}
}
case Event::KeyPressed:
{
if(event.key.code==Keyboard::Space){attack=true; }
}
}
// if(Keyboard::isKeyPressed(Keyboard::Add)){}
if(Keyboard::isKeyPressed(Keyboard::Up)) {Josh.SetspeedY(-0.2);}
if(Keyboard::isKeyPressed(Keyboard::Down)) {Josh.SetspeedY(0.2);}
if(Keyboard::isKeyPressed(Keyboard::Right)) {Josh.SetspeedX(0.2);}
if(Keyboard::isKeyPressed(Keyboard::Left)) {Josh.SetspeedX(-0.2);}
if(Keyboard::isKeyPressed(Keyboard::Space)) {attack=false;}
// for(int j(0);j<1000;j+=0.1){}
}
if (attack)
{
//scream.launch();
Josh.restartClock();Josh.Setattacking(true); attack=false;
}
/*
///SOUND
if (Josh.isDead()){explosion.launch();}
if (theBeast.isAttacking()) {bearRoaring.launch();}
if(theLevel.getCoord(int((Josh.GetpozX()+TILE_WIDTH/2)/TILE_WIDTH),int((Josh.GetpozY()+TILE_HEIGHT/2)/TILE_HEIGHT))=='4') {bubble.launch();}
*/
window.clear(Color(0,100,250));
theBeast.setCoord(Josh.GetpozX(),Josh.GetpozY());
///
///Big map
joshView.setCenter(Josh.GetpozX(),Josh.GetpozY());
window.setView(joshView);
theLevel.draw();
Josh.draw();
Josh.update();
theBeast.update();
///LITTLE MAP
window.setView(beastView);
beastView.setCenter(theBeast.getposition().x+TILE_WIDTH*2,theBeast.getposition().y+TILE_HEIGHT);
theLevel.draw();
Josh.draw();
Josh.update();
theBeast.update();
///
window.display();
}
return 0;
}
Loading…
Cancel
Save