Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 13 Sep 2012
Offline Last Active Apr 23 2016 11:51 AM

Topics I've Started

Critique My Implementation Of Pong?

27 November 2014 - 04:09 PM

Hi everyone!


I am a semi-experienced programmer but a very novice game programmer. To learn I have been building a simple implementation of pong, after it is done I plan to move onto some other simple game implementation. I was wondering if anyone wanted to critique my work? I realize it is probably very bad, so don't worry about hurting my feelings :). My hope is to build a few simple game implementations and replace piece by piece the OpenGL wrapper and math library I am using so I can learn more about those subjects. I just wanted to hear some thoughts from some of you guys.




All the source is in Pong3D/*. If you follow the readme you can run it if you so desire. The Visual Studio files are included in the repo. Game rules/score tracking have not been implemented yet. Just simple back and forth super exhilarating pong action!


Thanks and Happy Thanksgiving(to those who celebrate)

Pointer to Pointer Issue

26 February 2014 - 10:59 AM

*EDIT* As Ardvajk pointed out, while printing I am using the variable 'used' which == elements in the map. I should be using the number of bins or buckets in my array. 


Hey everyone, I'm having some strange issues I was hoping someone could help with. Basically I am inserting into a HashSet at the same index in an array [0] in my case. And when I loop through to print all the elements in the set I get some strange output for the bucket at index [1] even though I believe it to be completely empty. Also, this is a homework assignment, so just some guidance and not an outright answer would be appreciated smile.png


I am building a HashSet where the map is basically a pointer to a pointer of nodes. Hopefully I'm not posing a wall of code here next, as that would be annoying. But I have to post quite a bit for you to see what's going on. The declaration looks as such:

Node** set      = nullptr;
Node (T v,  Node* n = nullptr) : value(v), next(n){} // Relevant constructor

In my constructor for the HashSet I initialize the set to such:

template<class T>
HashSet<T>::HashSet(int (*func)(const T& element), double load) : hash(func), load_factor(load) {
	set = new LN*[bins];
	for(int i = 0; i < bins; i++) set[i] = nullptr;

My insert statement looks like this:

template<class T>
int HashSet<T>::insert(const T& element) {
  //write code here
		int index = hash_compress(element);
	        Node* temp = set[index];
		if(temp == nullptr)
			temp = new LN(element);
			set[index] = temp;
			Node* new_node = new LN(element, set[index]);
			set[index] = new_node;

Ok, that's all I will post. As I don't want to post too much, but I am happy to give more code if needed. Basically in my test, you will have to trust that int index = 0 for two inserts. After the second insert, the item gets properly inserted into bucket 0 but basically fills bucket 1 with a ton of garbage. To be exact, when I go to print it out all of my environment variables and the alphabet print out, it's kind of funny looking smile.png


My print method basically looks like this:

for(int i = 0; i < bins; i++) // used to be i < used
		Node* temp = set[i];
		std::cout << "[" << i << "]" << std::endl;
		std::cout << "{" << std::endl;
		while(temp != nullptr)
			std::cout << temp->value << std::endl;
			temp = temp->next;
		std::cout << "}" << std::endl;

Memory Leak Question C++

06 December 2013 - 12:28 PM

I was working on a project with a friend the other day and he had code that looked similar to this:

std::unordered_map<std::string, Person* person> map;

for(int i = 0; i < N; i++)
    Person person_to_add;
    /* create members for person */
    map[person_to_add.name] = &person_to_add;

map["Tom"].email = "something";

This is funny, because to me, this code is completely wrong. Person_to_add goes out of scope after each iteration of the loop so it's address should be pointing to some location on the stack, no? 


Anyway, what is curious, and why we had a hard time finding the bug was that the project will go on working as normal this way, it will just result in a memory leak. What am I missing here? Does the c++ container dynamically allocate 'Person' at some point and never free it? Or is there something else going on?



Platform Architecture Help

28 November 2013 - 11:32 AM

Hi there. (The title meant to say Platformer* not Platform)


I am currently building a platformer. I use sweep and prune to detect collision and for the screen culling. It works great, I just wanted some ideas for a good way of detecting the 'response' when two individual objects collide. Currently(which I want to change) I have a struct that looks something like this:

struct WorldObject
    Vector position;
    Rect intersection_rect;
    Drawable sprite;
    CustomResponse* response;

Where my data structure for sweep and prune holds a group of these CollidableObjects and the response is basically implemented in the object that the player is colliding with. So a moving platforms response would accept the Player as a parameter, and respond by changing the player's position by adding or subtracting its movement. It would then end this response when the player no longer collides with it.


I don't really like this strategy. It adds a lot of functionality, which I don't feel really relates, to one struct. I was wondering how you guys have  done this in the past? How did you query for the 'types' of objects intersecting, how did you find the drawable based on your culling from sweep and prune, etc. Thanks!


Oh, by the way. Happy Thanksgiving!! smile.png

Beginning Isometric RTS

01 June 2013 - 10:00 AM

I've layed the groundworks for a 2D isometric rts. But I have a couple basic questions if anyone would be willing to point me to an article or offer me advice.


1. Movement: So the movement I have implmented now is a basic Euler integration where I increment acceleration, velocity then position. Now that I have a tile map, sprite sheet and a few characters on screen I've quickly realized I can't have 2D movement with 360 degrees of freedom. I must restrict movement to the tiles on my map(duh!). Is the best way to do this going from point a->b simply to increment a.x and a.y until it = b.x and b.y? And have the character move from grid point to grid point? 


2. Storing Units: What type of data structures would be best to use for this type of game. There are many actions that are going to require a quick look up on a few units. Selecting units, collision detection, etc... How have you guys implemented this? I was thinking of perhaps doing some sort of map where the key is from ymin -> ymax where each bucket is +50px from the last or something. Then sorting from xmin->xmax in each bucket with the same +50px offset.