<repo_name>bjorgan/salmongame<file_sep>/README.md
salmongame
==========

Multiplayer game for simulating the trials and tribulations of an average salmon. 

Currently in the very rough and very initial planning stages. 
<file_sep>/src/rivers.cpp

enum Direction{DIRECTION_UP, DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_DOWN};
const int NUM_DIRECTIONS = 4;


struct River{
	int width;
	int direction;
	int x, y;
};



int main(){
	int map_x = 100;
	int map_y = 100;
	float *map = new float[map_x*map_y]();
	
	int initial_river_width = 50;


	vector<River> rivers;
	River river;
	rivers.push_back(river);
	rivers[0].width = initial_river_width;
	rivers[0].direction = DIRECTION_UP;
	rivers[0].x = map_x/2;
	rivers[0].y = map_y/2;
	int num_steps = 20;

	float branch_chance = 0.3; //branching chance
	float continue_direction_chance = 0.5; //chance of continuing in the same direction
	for (int i=0; i < num_steps; i++){
		for (int j=0; j < rivers.size(); j++){
			int offset = 0;

			//draw river along its width
			for (int k=0; k < rivers[j].width; k++){
				switch (rivers[j].direction){
					case DIRECTION_UP:
						offset = k;
					break;
					case DIRECTION_LEFT:
						offset = k*map_x;
					break;
					case DIRECTION_RIGHT:
						offset = -k*map_x;
					break;
					case DIRECTION_DOWN:
						offset = -k;
					break;
				}
				int ind = rivers[j].y*map_x + rivers[j].x + offset;
				if ((ind < map_x*map_y) && (ind >= 0)){
					map[ind] = 1;
				}
			}

			//choose new direction for river
			float randNum = rand()/RAND_MAX;
			if (randNum < continue_direction_chance){
				rivers[j].direction = rand() % NUM_DIRECTIONS;
			}

			//choose new x,y in the new direction
			switch(rivers[j].direction){
				case DIRECTION_UP:
					rivers[j].y++;
				break;
				case DIRECTION_LEFT:
					rivers[j].x--;
				break;
				case DIRECTION_RIGHT:
					rivers[j].x++;
				break;
				case DIRECTION_DOWN:
					rivers[j].y--;
				break;
			}
		}

		//branch rivers
		int num_rivers = rivers.size();
		vector<River> branched_rivers;
		for (int j=0; j < num_rivers; j++){
			float randNum = rand()/RAND_MAX;

			//branch river
			if (randNum < branch_chance){
				River river;
				branched_rivers.push_back(river);
				branched_rivers[branched_rivers.size()-1].x = rivers[j].x;
				branched_rivers[branched_rivers.size()-1].y = rivers[j].y;
				branched_rivers[branched_rivers.size()-1].direction = rand() % NUM_DIRECTIONS;
				branched_rivers[branched_rivers.size()-1].width = ceil(rivers[j].width/2);
				rivers[j].width = ceil(rivers[j].width/2);
			}
		}

		//add branched rivers to main rivers
		for (int j=0; j < branched_rivers.size(); j++){
			rivers.push_back(branched_rivers[j]);
		}
	}

	for (int i=0; i < map_x; i++){
		for (int j=0; j < map_y; j++){
			cout << map[j*map_x + i] << " ";
		}
		cout << endl;
	}


}
<file_sep>/src/main.cpp
#include <vector>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;

<file_sep>/src/area.cpp
#include "area.h"
using namespace std;

Area::Area(vector<int> riverXCorners, vector<int> riverYCorners) : riverXCorners(riverXCorners), riverYCorners(riverYCorners){
	
}

bool Area::isInsideRiver(int x, int y){
	
}
<file_sep>/CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(salmon)
set(CMAKE_BUILD_TYPE Release)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

add_executable(salmons src/main.cpp)
<file_sep>/src/character.cpp
#include "character.h"
#include <sys/time.h>

Character::Character(int x, int y) : x(x), y(y){
}

Bear::Bear(int x, int y) : Character(x, y){
	width = 100;
	height = 200;
	
	//properties of the bear's eyes
	eye_width = 10;
	eye_height = 15;
	eye_dist = 10;

	eye_y_diff = -60;
	eye_x_diff = 0;
}

void Bear::drawSprite(SDL_Surface *screen){
	int eye_y = get_y() + eye_y_diff;
	int eye_x = get_x() + eye_x_diff;
	int x = get_x();
	int y = get_y();

	//body
	boxRGBA(screen, x - width/2, y - height/2, x + width/2, y + height/2, 255, 0, 0, 150);

	//left eye
	boxRGBA(screen, eye_x - eye_dist/2 - eye_width , eye_y, x - eye_dist/2, eye_y - eye_height, 255, 255, 0, 255);

	//right eye
	boxRGBA(screen, eye_x + eye_dist/2 , eye_y, x + eye_dist/2 + eye_width, eye_y - eye_height, 255, 255, 0, 255);
}

Salmon::Salmon(int x, int y) : Character(x, y){
	width = 200;
	height = 100;
}

void Salmon::drawSprite(SDL_Surface *screen){
	int x = get_x();
	int y = get_y();

	//body
	boxRGBA(screen, x - width/2, y - height/2, x + width/2, y + height/2, 200, 200, 200, 255);
}

//void Character::move(Direction direction){
//	if (!dead){
//		switch direction{
//			case MOVE_UP:
//				y += step;
//			break;
//			case MOVE_DOWN:
//				y -= step;
//			break;
//			case MOVE_LEFT:
//				x -= step;
//			break;
//			case MOVE_RIGHT:
//				x += step;
//			break;
//		}
//	}
//}
//void Character::getCoordinates(int *x, int *y){
//	*x = this->x;
//	*y = this->y;
//}
//void Character::increaseHealth(int inc){
//	health += inc;
//	if (health > MAX_HEALTH){
//		health = MAX_HEALTH;
//	}
//}
//void Character::decreaseHealth(int dec){
//	health -= dec;
//	if (health <= MIN_HEALTH){
//		health = MIN_HEALTH;
//		this->die();
//	}
//}
//void Character::die(){
//	dead = true;
//}
//
//
//void Bear::move(Direction direction){
//	Character::move(direction);
//}
//void Bear::smashAttack(){
//}
//void Bear::die(){
//	Character::die();
//}
//
//
//void Laks::move(Direction direction){
//	Character::move(direction);
//}
//void Laks::smashAttack(){
//	
//}
//void Laks::die(){
//	Character::die();
//}
<file_sep>/include/character.h
#ifndef CHARACTER_H_DEFINED
#define CHARACTER_H_DEFINED



#include <SDL/SDL.h>
#include <SDL/SDL_gfxPrimitives.h>

class Character{
	public:
		Character(int x, int y);
		virtual void drawSprite(SDL_Surface *screen) = 0; //draw character sprite on screen

		int get_x(){return x;};
		int get_y(){return y;};
		void set_x(int x){this->x = x;};
		void set_y(int y){this->y = y;};
	private:
		int x, y;	
};

class Bear : public Character{
	public:
		Bear(int x, int y);
		virtual void drawSprite(SDL_Surface *screen);
	private:	
		int width;
		int height;
		
		int eye_width;
		int eye_height;
		int curr_eye_height;
		int eye_dist;

		int eye_y_diff;
		int eye_x_diff;
};

class Salmon : public Character{
	public:
		Salmon(int x, int y);
		virtual void drawSprite(SDL_Surface *screen);
	private:
		int width;
		int height;
};






/*		virtual void move(Direction direction); //move one step in specified direction
		virtual void smashAttack() = {}; //special attack
		void getCoordinates(int *x, int *y); //get current coordinates
		void increaseHealth(int inc); //increase healthbar
		void decreaseHealth(int dec); //decrease healthbar
		virtual void die(); //die
	private:
		int x, y; //current coordinates of character
		int health; //health bar
};
enum Direction{MOVE_UP, MOVE_DOWN, MOVE_LEFT, MOVE_RIGHT};

int MAX_HEALTH = 100;
int MIN_HEALTH = 0;


class Bear : public Character{
	public:
		virtual void move(Direction direction);
		virtual void smashAttack();
		virtual void die();
};


class Laks : public Character{
	public:
		virtual void move(Direction direction);
		virtual void smashAttack();
		virtual void die();
};*/


#endif
<file_sep>/include/area.h
#include <vector>

class Area{
	public:
		Area(std::vector<int> riverXCorners, std::vector<int> riverYCorners);
		bool isInsideRiver(int x, int y); //whether given coordinate is within defined river
	private:
		//corners of path defining river
		std::vector<int> riverXCorners;
		std::vector<int> riverYCorners;
};
