Showing posts with label 5SD022. Show all posts
Showing posts with label 5SD022. Show all posts

Saturday, January 18, 2014

Day 23, Last Day!

Today I checked for memory leaks and I found six of them!!!! well actually it was more like two.

In one place I created a textobject and a sprite was created a few lines before that as well at the same time but not used or deleted.
And the animated sprites caused a leak when i deleted them because i deleted the sprite from the parent class and not the animated sprite in the actual object. I had already made the function and all for deleting it. I just forgot to change it in the cleanup funtion. So with those two fixed we are now leak free!
A thanks to my classmate Tomas for the tip of using Visual leak detector (https://vld.codeplex.com/)

I also went through some of the code and removed some lines of code not in use.

So we are now officially finished with this game! Hurrah!
Here are some screens of the first four levels:







And in some screens you see the bigger player. Here is another screen of that:



Day 22

Ok so...I thought I was finished with programming for this project but nope, Thanks to my classmate Tomas that spotted that my collision for box vs circle was wrongly made I went through the code and found also that circle vs circle was wrong.
I fixed circle vs circle fairly easy and I have the solution for box vs circle in my grasp but I just can't get the offset to work on the ball after the collision has occured and I am out of time. I also did a last minute change on the collision boxes for my borders and made 3 big ones instead of many small ones to decrease the chance of the ball wandering off.
I have decided one thing for the next game I make.....no bouncing balls in high speed.
Picutres of the finished game will come up as soon as I have time to add some.

I haven't started my report so I will spend the next 24 hours or so writing it.
Everything need to be handed in latest on sunday.


Friday, January 17, 2014

Day 21

I have been working all day and all night. Its now 5 in the morning and I need to sleep some before school later today. :-)
Finally we have something that feels like a game!
I added 10 levels to the game. I also added 3 more powerups with animation. So now you can get multiball, long pad, sticky pad and extra life. I polished the start screen little as well so it looks more "gamey" I added music and sound where it was needed. I didn't have time to get the MusicManager working as required, oh well, There is always a next project.

I really enjoy playing the game now. Its quite difficult. I haven't managed to get further than the 5th level.
Sure there are some bugs here and there but its something I can live with for the moment.

I will add screenshots tomorrow. Tomorrow I will be testing and polishing and writing the report.

Thursday, January 16, 2014

Day 20

So, I managed to fix collision between box vs circle and circle vs circle. I added an ingame brick that is round and have a Circle Collider so when the Ball Object hit it the code call a funtion to check circle vs circle. I also added collision between the balls but that caused alot of strange collisions so i removed that.

I added the WinState that Stefan made after I done som modifications like adding some TTF text to it.
I will probably add the highscore state Stefan made as well if I have time tomorrow.

I have also been fixing smaller things as well like the particle effect not stopping until it hits some bricks. I added that it also stops if the ball hit the wall. I shortened down the timer for the particles as well to about 2 seconds lifetime after they are created to prevent to many particles on screen.

I think the last day I will do work on my code is friday because i also need to start writing my report  for this project, Now in the last minute I am adding levels(smart eh?) and a transition between them.  I also added the ability to pause the game. I want to add more powerups as well because we only have one at the moment. I want to make it feel like a complete playable game I can be happy with when I leave it behind next week.


Wednesday, January 15, 2014

Day 19 (or rather night)

I worked half the night last night with adding different kinds of collisions. We already have a simple Box vs Box Collision. I moved the code that checked overlap between the boxes from the BoxCollider class to a function in the CollisionManager. I then added a CircleCollision class that holds one X-Y position and a radius.
I also added two functions in the CollisionManager to for check of overlap between circle vs circle and box vs circle. With all in place, I changed the BallObejct so when its created it gets a circle collider instead of a box collider.

I have learned the hard way how sensitive collision is for errors. One varible wrong and you screw up EVERYTHING!!!. I thought i lost it all and was almost about to get back the old code from our backups when i suddenly around 3 o'clock at night kind of solved it?? Don't ask me how but now it kind of works between box vs circle. I have to "fine tune" the code little bit more and then test and try to tune circle vs circle as well.

Oh, I forgot to take screenshots of the strange behaviours.

Monday, January 13, 2014

Day 18, Particle effect!

I finally added a particle effect. I made a new class called ParticleObject and added some functions and a vector to the GameObjectManager to handle the Particles. one particle is a 2 x2 sprite and they are drawn out and move in different directions after the ball. They start as soon as the ball is fired away and follow the ball until it hit the first brick and then they get deleted after about 3 seconds. I struggled most of the day to get everything to work. I'm not super happy about the looks but I'm satisified it works without any major crashes or memory leaks.

Early this morning I also fixed some bugs.

  • fixed a bug that caused some bricks not to get destroyed when hit.
  • fixed a bug that sent you to Game Over on your last life even though balls were still in play.

Here are some Pictures of the particle effect:





Day 17,

Today I fixed a huge bug I managed to miss last night. The bug caused all kinds of strange collision behavoirs when more balls were added to the game. With one ball everything worked fine. With two balls everything moved sligtly faster. The player pad started vibrating when touching the wall and the balls increased in speed in a strange way. With three balls in play everything went haywire. Bolls bouncing all over the screen they even bounced outside the game area. The player could move outside the border as well. luckily i could find the bug pretty fast and fix it...phew!

Then I went on to merge the SoundManager with the MusicManager that Stefan had made into an AudioManager when I learnt in class that they can be combined. It makes it easier to keep track of.

I then added a small config.txt file where the screen resolution is loaded from when the engine Initialize() is run.

I also moved some code from the GameState to the CollisionManager where I feel it belongs better. I added a function that is called in Gamestate that check all Collisions "CheckAllCollisions()"

Oh I almost forgot, I added Highscore into the game that is saved in a textfile. A check if you have beaten the highscore is done when you win or lose. If you have its then saved to a textdocument and loaded next time you play.

I also think I will skip adding an option state because time is running up. Only one week until the game and report have to be finished. I got about 4-5 days of programming left and I want to focus on features that give me a higher grade. Features like adding a GUI, particle/visual effects and maybe some more forms of collisions. and then we also need to clean up the code and remove unused code or "left overs" that might be hanging around. And we need to polish what we got.

Saturday, January 11, 2014

Day 16, Animation in place!

Thanks to Stefan we got our Animation class. The class files was in our shared Dropbox when i woke up and ready to be implemented. I had to change in some other files to get it to work.
I then added a ItemObject class that are the powerups you get. For now there is only one powerup and it gives you an extra ball. Original arkanoid gives you 2 new balls I think but I think we settle for 1 new ball.

With the new ItemObject i had to change the BrickObject class so they drop the items when destroyed. I also had to change the alot of the BallObject class so its now a vector in  our GameObjectManager that holds the balls instead of just one object like it was before. I put a limit of maximum 3 balls on screen at the same time. I had to do some smaller changes here and there to make it all work together. Was kind of tricky to get it to work without crashes. Here is a screen of what we got so far:


Next up is Highscore that can be saved and loaded to/from a file and also some tweaking music and soundmanagers and putting some sounds here and there. We also need to add a win state and I want an option state as well. Then I want visual effects in as well. We are running out of time and only have one week left now but I think we will pull it off.

Friday, January 10, 2014

Day 15, SCORE!!!!!

First I  had some problem implementing sound. The soundeffects played for a while then stopped but with some help from Jerry (co-teacher) I think we nailed it down so it works for now. haven't tested it too much.

And then....SCORE!! Yes after many hours of struggling i finally managed to nail it! We now got score in our game. If my way of doing it is the right way. I'm not sure??.....but it works!


The way it works is that an unsigned int keep track of the score. 100 points for each destroyed brick. It then change the int to a string with the function std::to_string();
After that is done I have to track down the text object that holds the score. I used a text string to "tag" the object since all textobjects are stored in a  <vector> I then delete that object and text and create a new object with the right score.

It works like a charm!
I also managed to get other text in game as well as you can see on the screenshot.
I then updated my black GameOverState to one with text. And with that I say good night and.......


Wednesday, January 8, 2014

Day 14,

I met with Stefan today as well, He finished up the sound/music classes and made the basic outline for the SoundManager and MusicManager. I will try to implement them to our project tomorrow.
We agreed that Stefan should carry on work on either ball vs ball collision or the animation class.

I didn't get much done. I worked some with adding TrueTypeFonts to the project so we can display score.
I will continue work on the score and how to save and load it to file for a highscore system.

Tuesday, January 7, 2014

Day 13,

I met with my partner for the first day in 3 weeks. We agreed that he should start with Music and Sound classes. And then move on to the Sound and MusicManagers together tomorrow when we meet again. I will continue work with text handling and the score system.

I didn't get much programming done today. But I did alot of testing and little tweaking with the collision between ball and bricks. It works better now but i still have some strange bugs.

I added some variables and functions to keep track if the brick is hit, damaged or destroyed. With those in place the game behave a little bit better than just destroying the bricks as soon as they had a collision with the ball.

Day 12, Some progress

I have left yesterdays mess behind me and today it went very well.
I cleaned up some stuff from yesterday and added some new things.
I  added a ButtonObject class that will take care of objects that can be clicked with the mouse like Start/Quit buttons. I had to do some work on the InputManager as well to get it all to work.

So I worked on the StartState and added the buttons and functionallity.
The buttons can be clicked but with no sound or animation. The menu button don't lead anywhere at the moment.


I also added some functionallity in game. You now lose a life when the ball goes outside the screen past the player. When all lives are lost, (Start + 3 lives) the GameState is stopped and you are sent to a black screen for 3 seconds(Game Over screen...work in progress).
Same goes when you destroy all bricks and win. Then you're also sent to the black screen.

I want a text on the win and game over screen and a score and some other text so I started working on how to solve that. I read up some on TTF and SDL and decided to download that.
I made a Textobject class and a TextManager that works basiclly as the Sprite class and SpriteManager class from the school workshop with Tommi.

I also drew some new sprites that i will use for animation and also an instruction sprite.



Tomorrow I will probably keep working on getting text into the game.


Monday, January 6, 2014

Day 11, What a mess!

The day started out well. I got some brilliant ideas about the code layout to get everything in order with the GameObjectManager so it could handle all kinds of GameObjects even from derived classes.
My plan was to put all my created GameObjects, PlayerObject, BallObject, BrickObject in my <GameObject*> vector.
I think I coded for 8 hours non stop, changing bascilly all code to a more dynamic way.
I must have been delusional because i went way ahead of my skill level and falled short when it came to accessing all derived Objects from said vector. I read up on Internet sources and I thought I had found a way.
Something like this (taken from Stackoverflow):
(edit: you can see the text below if you select the area with your mouse, don't know why it turned white)
std::vector<A*> aVector;
aVector.push_back(new B());
B* b = (B*)aVector[0];
cout << b->j;
(http://stackoverflow.com/questions/13569661/c-reach-derived-class-variables-from-vector)

where A is the parent class and B is the derived /inherited class.

B* b = (B*)aVector[0];
This line was my salvation. or so I thought. Instead it almost became my doom.
I got all sorts of crashes. I just didn't get it to work after alot of trying I gave up. Luckily I had made 2 backups.
When I went back to the backup and opened up the project to my FEAR it was the same project I just closed!! I checked and double checked and triple checked! I opened the second backup as well and it was also the same! I started sweating.....OMG!!! ALL IS LOST!!! all work the last few weeks. GONE!

It just couldn't be!....how could it? I made the backups way before the major changes. Why did all projects look the same! I think I spent an hour just panicing. But being a programmer and all I started to break down the problem and decided to open each cpp file one by one in notepad next to Visual studio so I could check the code line by line. Thank god I did! I shortly realized that when you copy a whole Visual Studio project/solution and it got the same name as the original folder it somehow opens the most recent file even if they are in different folders on your computer. It was so strange.
I created a new project with a different name and copied all the cpp and heather files to the new project. The joy to see my original code. I could breathe again. I was saved!

Tip: If you want to backup your project. just copy your cpp and .h files and all art and stuff. Do NOT copy the whole solution/project.

I spent the rest of the day repairing and improving the backup I salvaged.
This whole mess made me grow in understanding alot. why some crashes happen and how to code in a better way. Sure I didn't get much done compared to last time but I learned alot and I'm happy for this little incident.

(Sorry for bad English and writing. no spellchecking tonight. I'm too tired)

Friday, January 3, 2014

Day 10, Something looking like Arkanoid

I have been working since 06:00 in the morning both with programming and graphical things.
I developed the CollisonManager some more so it can handle both ball and player collision.
It still have some bugs like the ball getting stuck or bouncing in some strange ways. and  it rarely push through the game border and gets away. I'm thinking of changing how the collision is handled for the border.
I added a BrickObject class to keep track of the bricks. For example like how they are destroyed and how they are loaded.
In GameObjects I also added a boolean flag to check if an Object is destroyable or not.
Here is a screen of what we got so far:


Next I need to work on adding more states and devolping them and I also need to add a win and lose condition.
I have already worked some on the StartState (renamed from  MenuState) but it have no functionallity yet except pressing "spacebar" to move to next state.
After that I guess I will focus on lifes/Gamerounds with states in states, or maybe add animation in some way.

I have also managed to "break" my Visual Studio so I can't use breakpoints when debugging.
I guess its my great coding abilities that managed that. hopefully I sort out that problem soon :-)

Wednesday, January 1, 2014

Day 9, New Year, Box Collision solved!

New year and new thoughts. I solved the collision problem we had! Hurrah!
When collision was checked it checked all the objects in the ObjectManager including checking collision against PlayerObject vs PlayerObject. The Player sprite and collider is is 27 x 6 pixels so the 6 pixels wrong came from that somehow. When I took that out of the equation it worked perfectly! PlayerObject shouldn't be able to collide with  itself anyway.

I then rebuilt the whole Ball class we had so it inherit from the GameObject class and have a BoxCollider to start with to test functionallity of the game. The collision of the ball is okay but sometimes the ball get stuck in the wall. It might be because I made it so speed is added to the ball with every collision. Something that needs more testing.



 I also made it so that the ball stays on the playerObject until it gets shot even if the player moves.


I also started working with a CollisionManager so we can handle more kinds of collisions and handle it in a better way. I will continue this work tomorrow. If time permits I will also look at seperating loading of the bricks and the destruction of them.



Tuesday, December 31, 2013

Day 8, Collision is making my head explode

I have added a PlayerObject class so I can finally move around my bar/pad (felt really good) but as soon as I implemented collision with the Playerobject it all went crazy. 
I have been debugging for hours to track down the little bugger and I have narrowed it down but I still can't seem to find the problem. 
For some reason my playerobject get an offset of 6 pixels(collision box of player compared to player position)  and runs off up on the screen even though i haven't added Y-axis movement.
The same problem exists on the code I did on my teachers platform workshop but not in the code that my teacher uploaded on the student portal from the same workshop.
So I guess I have to read some code and compare it to mine. 

Monday, December 23, 2013

Day 7, Day before Christmas

I managed to get a little work done. I made a basic level class that is used to draw the level in the GameState. I played around with sprites as well and added fullscreen as soon as you enter the gamestate.
Here is a screen of what we got so far.


It's nice to get a visual of all the code done so far. Sure it's not a game yet but it's a start.
Now its time for some glögg and Christmas celebrations with my family.

Friday, December 20, 2013

Day 6

I have now made an InputManager and a GameObject Manager, I'm not sure I have constructed and implemented them the right way but it kind of works right now. I have also played around with the States. Its hard to understand what goes where, for example. where do I put UpdateEvents? Should that go in the Engine class or should i write an UpdateEvent method for each GameState? Right now I put it in the InputManager in a method called UpdateInputs, This method is called in each state.
I think i will put it in each State instead. for example:
 The MenuState might only take mouse events while the Gamestate is played with keyboard. loading screens or game over screens dont take any event at all except maybe quit by X in the window.

I have also started with the collider class and next i will work on drawing the gamestate.
I'm not sure how i will go about it.  I feel that i want to draw the background first and the actual boxes you shoot down should be drawn after the background. Since i want to be able to change levels.

or maybe I will just load everything after each level when changing states.

I guess learning programming is a lot of trial and error.

Tuesday, December 17, 2013

Day 5

I stayed home this morning to work on the project alone. I managed to understand the use of states and I made the frame for a virtual State class. I also made a MenuState class, GameState class and a StateManager class keeping track of it all. It felt good when i figured out how to implement it all. I'm not sure I'm doing it "the right way" but it works in its basic form but the classes still need much work.
The way i see it the code we make will be put in the different states gradually over time.

The morning felt great but in class this afternoon i got slapped in the face again with a dynamic way of creating animations of sprites.

Sure I have managed to animate and move a sprite before but in simple non dynamic way. right now I feel that i won't touch animation until we got some basic things in our project finished.

Monday, December 16, 2013

Day 4

Me and Stefan met after class to do some work. He had apparently done the vector class, input class and a pong version of a ball class already. The ball class might need some work to fit with the GameObjects class but its a start.

Today at class we learned about Inheritance, Polymorphism and how to handle different States using a StateManager. e.g. game states or AI-states. So that messed up a lot of how the program structure is built and I think its good if we rework all that we got so far and adapt that to what we just learned.

Since Stefan is doing classes on the side we thought best he started with music and sound classes and managers to both those classes.

We had apparently missed that the GameObject class needed a Manager class, same with the input class so that needs to be added as well. I think I will start with a StateManager class and then implementing everything after that.

The Project plan needs to be updated as well. its far from a real project plan. we will probably start look more deeper into how to actually build the game when some of the basic structure is in place.