Wednesday, April 20, 2016

CS 2420 - Assignment 8 - Components

This week's assignment is a bit more fun that usual since we are got to build a "game."

The point of this week's assignment to learn how to use components to build a game, instead of hard coding everything like we usually do. We also had a chance to review inheritance and understand how it works.

This time around there is too much code involved for me to put it here like I usually do, but if you are interested in looking at the code you can look here:

https://github.com/fushinoryuu/EAE2420/tree/master/DataStructuresAndSorts/Assignment8

I created these main class files: Component, Entity, Grid, Point, and Power Up.

The Grid was essentially a 2D array and everything ran through this file, it represented the map the player was going to play on. It also updated itself on the position of each enemy and the player and then displayed itself on the console.

The player and the enemies in the game all inherited from the Entity class and used a bunch of components to make each unique. For example, enemies had a component that allowed them to wrap around the Grid but the player was bound and couldn't go past the edges of the grid. To do this there was two components and I just had to make sure to give one to the player and the other to the enemies.

Power Ups are a type of component, but they don't inherit from the component class. I made it so they would modify the player's action. For example I had a Teleport Power Up. When they stepped on it, they would get randomly taken to an empty spot in the map.

I had a lot of fun with this assignment, but it took a little longer than I anticipated.

Anyways, that's all for now. Thanks for reading!

No comments:

Post a Comment