PlayerManager – prototype class

Just a quick note. I have managed to write Player Manager class which is kind a prototype.. the two issues that I am having are how to get an offset of a map.. if I am trying to set up offset to static DXDVECTOR3 variable inside Level class linker is complaining, passing as attribute well it is a option but then I need to modify other classes.

Second problem is click in a frame. actually I have just figured this out :).. wow sometimes one sec break and step back can do the trick.

Anyway deep beta presents PlayerManager prototype class – probably it will be totally modified but as far as now I have something like that:

// PlayerManager.h

#pragma once
#ifndef PLAYERMANAGER_H
#define PLAYERMANAGER_H

[...]
#include "Entity.h"
#include "Level.h"

class PlayerManager
{
private:
  //players entities
  static std::map playersEntities;
  static std::map playersSelectedEntities;	
public:
  static PlayerManager* instance;
  static void init();
  static void registerPlayersEntity(Entity* playersEntity); // called in players unity type constructor
  static void removePlayersEntity(Entity* playersEntity);
  static Entity* getPlayersEntity(int id);
  static void clearSelected();
  static void addEntityToSelected(POINT mousePosition);

  PlayerManager();
  ~PlayerManager();
};
#endif
// PlayerManager.cpp
#include "PlayerManager.h"
#include "Collision.h"

PlayerManager* PlayerManager::instance =0;
std::map PlayerManager::playersEntities = std::map();
std::map PlayerManager::playersSelectedEntities = std::map();

PlayerManager::PlayerManager(){}

void PlayerManager::init(){
  PlayerManager::instance = new PlayerManager();
}

PlayerManager::~PlayerManager(){
  //clear selected units list
  std::map::iterator iter = playersSelectedEntities.begin();
  for(; iter != playersSelectedEntities.end(); ++iter){
    delete iter->second;
    iter->second = 0;
  }
  playersSelectedEntities.clear();
  playersEntities.clear();
}

//register entity in players list
void PlayerManager::registerPlayersEntity(Entity* entity){
  //register entity called only once and after registration in entity manager
  // we have entity ID and I am pretty sure it will not dublicate.
  playersEntities[entity->getID()] = entity;
}


void PlayerManager::removePlayersEntity(Entity* entity){
  //removes selecred entity from players entities lise
  std::map::iterator iter = playersEntities.find(entity->getID());
  if(iter != playersEntities.end())
    playersEntities.erase(iter);
}

Entity* PlayerManager::getPlayersEntity(int id){
  //returns pointer to entity defined by id
  std::map::iterator iter = playersEntities.find(id);
  if(iter != playersEntities.end())
    return iter->second;
  return 0;
}

void PlayerManager::addEntityToSelected(POINT mousePosition){
  D3DXVECTOR3 position(0.0f,0.0f,0.0f);
  float radius = 1.0f;

  D3DXVECTOR3 mPosition(mousePosition.x, mousePosition.y, 0.0f);

  Circle mouseCircle = {mPosition, radius };
  Circle unitCircle = {position, radius };
  mouseCircle.position.x = mousePosition.x; // need to figure out how to apply offset
  mouseCircle.position.y = mousePosition.y;
  mouseCircle.position.z = 0.0f;
  mouseCircle.radius = 2.0f;
	
  std::map::iterator iter = playersEntities.begin();
  for(; iter != playersEntities.end(); ++iter){
    unitCircle.position = iter->second->getPosition();
    unitCircle.radius = 20.0f; // need to set this global instead of calculated based on number images etc like TILEBASEWIDTH or something
    CollisionResults collisionResult = TestCollisionCircle(mouseCircle, unitCircle);
    if(collisionResult == OVERLAPPING){
      std::cout < < "AWESOME";
    }else {
      PlayerManager::clearSelected();
      std::cout << "NOT";
    }
  }
}

void PlayerManager::clearSelected(){
  std::map::iterator iter = playersSelectedEntities.begin();
  for(; iter != playersSelectedEntities.end(); ++iter){
    if(iter->second){
      delete iter->second;
      iter->second = 0;
    }
  }
  playersSelectedEntities.clear();	
}

Zombeesh overview 1 – Collision detection circle based

After less than one week – weekend not counted in (I have had over 24hrs of sleep during weekend, I really hate to be sick) I have cought up with university material. Material covered:

  • Tile system for map loaded from a file
  • offset for moving map
  • entity manager for all objects on the map – plus improvement
  • messaging system – communication between instances of objects
  • collision detection – and my own improvement
  • moving around the map – mouse based
  • font manager

Plans for next week

  • Selecting objects by mouse click – hoping to select more than one element
  • collision detection applied for object on a map
  • placing building on the map
  • shooting to zombies and other stuff.

Meanwhile I will post some code – I haven’t done that for a while.

Collision detection class with improvements

// Collision.h
#pragma once
#ifndef COLLISION_H
#define COLLISION_H

const float TOUCH_DISTANCE = 0.000000000001;

static enum CollisionResults {
  NO_COLLISION, TOUCHING, OVERLAPPING
};

struct Circle{
  D3DXVECTOR3& position;
  float radius;
};

struct BoundingBox{
  D3DXVECTOR3& position;
  D3DXVECTOR3& size;
};

bool TestCollision(const BoundingBox& a, const BoundingBox& b);

CollisionResults TestCollisionCircle(const Circle& a, const Circle& b);
#endif

Pretty easy stuff here – two structs for BoundingBox and Circle enum for collision between circles – I have added it because I want to base selecting objects and – well all collision on two circles.

// Collision.cpp
#include "Collision.h"

bool TestCollision(const BoundingBox& a, const BoundingBox& b){
  float t;
  if((t = a.position.x - b.position.x) > b.size.x || -t > a.size.x)
    return false;
  if((t = a.position.y - b.position.y) > b.size.y || -t > a.size.y)
    return false;
  if((t = a.position.z - b.position.z) > b.size.z || -t > a.size.z)
    return false;
  return true;
}

CollisionResults TestCollisionCircle(const Circle& a, const Circle& b){
  //for math
  CollisionResults colliding;
  float distance_squared;
  float radii_squared;

  //a*a + b*b = c*c
  distance_squared = ((a.position.x - b.position.x)* (a.position.x - b.position.x))+
                     ((a.position.y - b.position.y)* (a.position.y - b.position.y));

  //Multiplication is faster than taking a square root
  radii_squared = (a.radius + b.radius) * (a.radius + b.radius);

  if( -TOUCH_DISTANCE < radii_squared - distance_squared &&radii_squared - distance_squared < TOUCH_DISTANCE) 		
    colliding = TOUCHING;
  else if(radii_squared > distance_squared)
    colliding = OVERLAPPING;
  else
    colliding = NO_COLLISION;

  return colliding;
}

pretty simple stuff here as well – Pythagorean theorem based. if distance between two points is bigger than sum of radius of circles then there is no collision if it is equal there is a collision but if it is smaller they overlap – so we have covered all 3 states first two for collision detection on the map and third one for selecting. simple

Backup plan

right,
I have spent too much time on trying to figure out 3D Picking and meshes.

I need to prepare backup plan – only 6weeks left till deadline.

here it is:

2D –  Top down – survival.

the idea is pretty the same as in 3D version – but I am considering get rid of building and as a production supplies – I mean we will have a farmers family that want to survive on their farm, yes sheep will be there.. here is scenario.

player controls 4 people team in where every unit has special skills – range, male dps, meal tank, healer – pretty standard rpg group.

I am considering as well game play ideally that would be multi player with server and clients but as far as now player will be able to control on of units and the rest will have some sort of AI. RPG elements will allow leveling for a team, and some perks will drop from zombies, wave time based play stays the same.

I have started developing engine from scratch.. again.. well this time I will base on university engine that we are developing at practicals by end of this week I should have:

  • Working framework
  • Tailed base map
  • Entity manager
  • Collision detection
  • Messaging system
  • Basic.. really basic AI
  • loads of small things like sprite renderer, game clock, animation engine, etc

Oh one big change.. I have decided to use DirectX9 instead on 10/11.. we are covering this one at university.. and I really do not have time to learn this one on my own.. probably later on I will do anyway.. but.. I am really tight with my time frames.

Global Game Jam..

Over 30h without sleep.. and loads things to do..

tired.. no exhausted.. but excited.. we almost reached 2nd stage for a game development.. all relationships, behaviours are set up and ready to go.. now.. level modelling tweaking and balancing game play..
it is kind a hard to manage and catch up with 8people team.. really. but we are doing pretty well!

pictures and demo tomorrow!

Day 10: Height Map

I am satisfied with that height map – no multi textures, blending, water or even trees.. I need to concentrate on logic now, polishing details will be last thing.

plan for today/tomorrow.

picking + adding objects on the map..

good luck Luke..

thanks Luke.

edit:
ok 2 more thing left before I ll be ready to go with picking and objects,

1. need to set up camera in 45 degree
2. I need to think of optimisation.. some sort of quad tree or so..

Day7: Quick overview

Just quick overview for end of day 7.

  • Input handler gets mouse position and escape button
  • Drawing 3D maya objects
  • Sound player
  • drawing 2D over 3d object
  • Font engine – well subsystem but..
  • High precision timing
  • FPS
  • CPU usage
  • Lighting

Still loads left to do but as for one week it is fairly enough!