For the rest of the year, I’m going to highlight some impressive final projects in Computer Programming and BC Calculus.
The computer programming students have had the majority of the term to work on their projects and one of the requirements was to write a blog post about their experience.
Here’s a crosspost of a game called Dark Sky. A fun 2D overhead game which has a cool unique game setup. The enemies only come toward you if you make move and make noise. Really polished game.

The Original Idea (Before)

The Current Game (After)

## Game Demo and Controls

http://www.greenfoot.org/scenarios/11624

Left Arrow or A moves the player left.

Right Arrow or D moves the player right.

Up Arrow or W moves the player up.

Down Arrow or S moves the player down.

Holding Shift while moving allows you to “sneak”.

Pressing B when over a shop item allows you to purchase it.

Left/Right Click to fire your weapon.

## Enemies and Bosses

The enemies of the game began as a simple graphic bug graphic as shown in the “Before” image and were only planned to be used for testing rather than actually being in the game. The bugs became the base for most enemies and the bosses of the game. The code for collision was spread to almost every enemy and modified to suit the enemy’s size. It would select a random direction and go a certain distance. If it hits a wall/enemy/portal, it turns in the opposite direction. If it goes the certain distance, it changes into a different random direction or continues on its path.

Example for Big enemy:
``` if (x < 50 && randdirection == 0) // Turns the Big left { if (Wallleft == null && Bigleft == null && Launcherleft == null && Portalleft == null) // Checks for collision { setLocation(getX() - speed,getY()); // Moves the Big left setRotation(270); // Rotates the graphic to look to the left } else { rand = 1; //Turns the Big right } } ```

Some of the enemies also react to “sound”. The sound level changes depending on your movement. If you move without holding shift, the sound level is loud. If you hold shift, you move slower but the sound level is low. If you don’t move at all, there is no sound level. The Big enemy reacts if any sound is made, and stays stationary if no sound is made.

Example:

```if (!Greenfoot.isKeyDown("shift")) { mode = 2; if (!Greenfoot.isKeyDown("up") && !Greenfoot.isKeyDown("w") && !Greenfoot.isKeyDown("down") && !Greenfoot.isKeyDown("s") && !Greenfoot.isKeyDown("left") && !Greenfoot.isKeyDown("a") && !Greenfoot.isKeyDown("right") && !Greenfoot.isKeyDown("d")) { mode = 1; } } else { mode = 3; if (!Greenfoot.isKeyDown("up") && !Greenfoot.isKeyDown("w") && !Greenfoot.isKeyDown("down") && !Greenfoot.isKeyDown("s") && !Greenfoot.isKeyDown("left") && !Greenfoot.isKeyDown("a") && !Greenfoot.isKeyDown("right") && !Greenfoot.isKeyDown("d")) { mode = 1; } }```

## The Player

The player has the biggest amount of work put into it than any part of the game. The code for the player controls many aspects of the game including purchasing items, movement, going into different worlds, healthbar, etc. The design of the player graphic went through several iterations before becoming the blue robot that is in the present game. The player, as told below in the problems section and the before image, started off as a human. The weapons for the game were going to be things like a bow, sword, rock, and other things. Then I realized three things. One, making the weapons on the player would be infuriating as I would have to change the hands and the arms. Two, the footstep sound effect (Discussed in problems section) wasn’t working as well as I hoped. Three, the player graphic didn’t really look too much like a human. So I changed it into a robot due to it being easier to make, the weapons wouldn’t be as hard to put on, and the sound effects would be easier.

Weapons and Beginning Area

The weapons of the game have different characteristics but share some general code (Mostly collision code). The first weapon I give the player to use is the laser. It is meant to be a simple weapon with not very good range to start the player off. The weapon is also not given to the player at the start, as it is in pickup form in front of the player. This is to teach the player that when you move the enemies move. The bigs also usually go on ice which shows what ice does when you step on it.

## Problems

When you run into a problem with your code, its like running into a brick wall. Whether that wall has two paths only a few feet away to proceed or one path that is three miles away depends on the problem.

Sounds

One of the very first and most persistent problems I ran into was sound. The most common was movement. There are two sounds for movement, which is for sneaking and for regular movement. When I first implemented these sounds, they were meant to be footsteps (Due to the player being a human at this point) but ended up being a continuous noise whenever I walked. I fixed the problem by putting in a “timing” system which basically plays a sound whenever an integer is divisible by a certain number.

```wait = wait + 1; if (wait % 14 == 0) { Greenfoot.playSound("moveslow.wav"); }```

The problems didn’t stop there, as the sound began to sound annoying. Then, when I decided to change the player into the robot, I had to make new sounds. The sound for regular movement I made almost made my ears explode, but I used them for the time being and kept the sound on low. The sneaking one was great though. Eventually I decided that the sound for regular movement was too loud and I made it so the sneaking sound was used for both regular movement and sneaking until I made a new sound. The sneaking sound was kept until very recently (5/27/14) when I made a new sound which kind of sounded like running over rocks. That was made into the sneaking movement sound. The original regular movement sound was lowered and was made into the collision sound for the lightspike enemy.

Portals

The other thorn in my side was the portals. In the holes between two walls is a portal class that is meant to take you to the next level. Of course, the first time I tried to do this the portal didn’t work. I would briefly be in the second world but then it would kick me right back into the first world. The problem that I thought it was is that the getOneIntersectingObject() function was causing something to go wrong. Surprisingly, using a different collision function fixed it. The next problem was to transfer health, weapons, and other variables into the different world. It took about 2-3 days until I figured out I could just use a constructor to transfer the variables. As time went on, more and more variables had to be added to both the player constructor and the world constructor.  Then another problem arose. Putting more than one portal in a room did not work. I figured out a solution that I didn’t like using, but is still used now. The portals are rotated and those rotations decide where the portal is taking you depending on what world your in (Ex. 180 degrees would be the portal in the “after” image at the top). I also had to use an integer to specify where I wanted the world to put me (ex. 1 = put me in preset location 1).

## Unused Content

Things are usually made to be used in a game but some aren’t ever put in due to problems with functionality or it no longer being relevant to the game. When I made the game, I had different ideas on what the enemies were going to be, how the game would work as a whole, and other functions and mechanics. These are some things that I never got around to using.

Shield

The Shield was going to be an essential part of the game along with the health bar. It would regenerate over time and would give you enough time to either get away or get more health. It wasn’t implemented because, due to the fact you could increase you health and a module idea(Adding effects like regeneration, speed boost, etc. to the player) I had, I decided it wasn’t necessary.

Level-Up System

Before the store system was made, I was going to develop a level-up system. Basically, you would collect experience points from an enemy and each enemy would yield a different amount. After the player collects a certain amount of experience, the player could “purchase” a skill from the experience screen. It was never completed and was replaced with the store.

“Rock” Weapon

The “Rock” weapon was a weapon idea to drop from the special variation of the Giga boss. Ideas of what I was going to make this weapon be was a larger rocket/explosion, launching a huge rock, or firing a wave-looking projectile. It was never added and was replaced with the rocket launcher drop.

Special Graphic for the Lightspike

Originally the lightspike had a special graphic that was bigger than the original sprite. This was too give the player a challenge and the special variety would appear 1/7 times. It was removed when the collision code was not working. The lightspike no longer has a special image and the special image was reworked into the lite enemy of the game.

Enemy Robot

The enemy robot is an enemy that I just never got around to adding. It was to act like the player using both the laser weapon and the blaster weapon. Of course, it looks visually different that the player, making it seem it was more designed for battle than the player.

(Blaster weapon for player)

Also, the enemy was also going to have a shield with it as well.

Alternative Constructor for Launcher Enemy

The Launcher enemy has a constructor to turn and change the way I wanted it to. (ex. 2-sided turret that is rotated 90-degrees). This constructor was used until a better and more efficient one was made.
```public Launcher(int rot, boolean u , boolean d, boolean l, boolean r, int amt, int s, int wt) //amount of turret sides, rotation { rotate = rot; setRotation(rotate); if (rotate != 0 && rotate != 90 && rotate != 180 && rotate != 270 && rotate != 360) { System.out.println("The allowed rotations are 0,90,180,270,360. Setting to 0 degree rotation."); setRotation(0); } (More variables equaling the constructor variables here) if (amount == 5) { setImage("launcher2alt.png"); } if (amount == 4) { setImage("launcher4.png"); } (More setting images code here) if (amount != 1 && amount != 2 && amount != 3 && amount != 4 && amount != 5) { System.out.println("Not an acceptable amount of sides. Set to default 4 sided mode."); setImage("launcher4.png"); } ```

The current constructor also isn’t really used, as there is only one variation of the launcher present in any of the worlds at the moment.

For the rest of the year, I’m going to highlight some impressive final projects in Computer Programming and BC Calculus.
The computer programming students have had the majority of the term to work on their projects and one of the requirements was to write a blog post about their experience.
Here’s a crosspost of a implementation of 3D Pong in processing. Neat idea, and although there are some bugs, really fun:

# The New and Improved Pong (Now in the Third Dimension)

Making the game, I personally thought was pretty fun. Given, there were a couple of rough patches, but what code doesn’t have any rough patches? In the end, the game turned out almost exactly like I wanted it to. Just pong (because who doesn’t like pong) in the third dimension with a couple of other game variables added in. There were a couple of things I would’ve liked to add in like optional two-player mode, but in the end, I hope whoever plays it gets a little bit of enjoyment out of it.

This is the original version of pong (to the left) versus my first person version(to the right) next to each other so you can really see the difference of the two up close.

## Playing the Code

If you don’t have processing downloaded on your computer yet, here is a link to the game here on openprocesing.com. Though the game does work a little bit better by just running it in processing. (also, when you’re in processing, you can change the size of the game and it’ll change corresponding to the size). So, you can just copy the code from the link.

## Controls

The controls are quite simple. You can simply move the player paddle by using the W, A, S, and D keys. Then you can change the AI paddle speed/difficulty by using the Up and Down arrow keys while you are playing. I just used some booleans that would become true if the key was pressed and false if it was released. I did this same code for the other keys too.

```void keyPressed()
//code recognizing that "W" is being pushed
{
//setting the keys
if (key == 'W' || key =='w'){
r = true;
}
}
void keyReleased()
//code recognizing that "W" is not being pushed
{
//again setting the keys
if (key == 'W' || key == 'w'){
r = false;
}
}```

## Problems with the code

There were a couple (probably more than a couple) of problems that I ran into during this project like I had previously mentioned. One of the biggest problems was when the ball would randomly hit any of the walls it would get stuck on that wall but could still move forward and backward. So the X ad Y coordinates of the ball were locked in place. I ended up fixing it by putting method in whenever the ball hit one of the walls:

```void changingspeed()
{
boolean ballspeedneg = false;
boolean ballxspeedneg = false;
boolean ballyspeedneg = false;
//these lines are making the next x, y, or z speed negative if the previous one was also negative
//so that the ball doesn't change direction out of nowhere when it hits a wall
if (ballspeed < 0){
ballspeedneg = true;
}
if (ballxspeed < 0){
ballxspeedneg = true;
}
if (ballyspeed < 0){
ballyspeedneg = true;
}
if (ballspeed > 0){
ballspeedneg = false;
}
if (ballxspeed > 0){
ballxspeedneg = false;
}
if (ballyspeed > 0){
ballyspeedneg = false;
}
//these three functions are pretty much finding the x, y, and z speed of the ball depending on the level
ballxspeed = getballxspeed(level);
ballyspeed = getballyspeed(level);
ballspeed = getballzspeed(level);
if (ballspeedneg == true){
ballspeed *= -1;
}
if (ballxspeedneg == true){
ballxspeed *= -1;
}
if (ballyspeedneg == true){
ballyspeed *= -1;
}
}```

What these lines of code do is first make a boolean true if the ball’s speed was negative. Then, it would use some functions to figure out what the ball’s speed should be because it changes corresponding to the level. Then if the boolean said that the previous speed was negative it multiplies the new speed by -1 (because it turned out the ball’s speed was constantly being changed from negative to positive so it would stay in the same place).

## Level System of the Game

To change the level in the game, all I did was first make a variable (I used “bounces”) that would increase by one whenever it hit the player’s paddle like so:

```if (ballz >= 270)
{
//ball only bounces off paddle
backward = true;
forward = false;
if (ballx >= paddlex - 75 && ballx <= paddlex + 75 && bally <= paddley + 40 && bally >= paddley - 40){```
`//counts the number of times the paddle has succesfully deflected the paddle`
``` bounces += 1;
ballspeed *= -1;
changingspeed();
}```

Then there was a method I made called “levelincrease” that would change the level according to how many times the ball has been succesfully deflected off of the player’s paddle

```void levelincrease()
//this is increasing the level as the number of succesful bounces increase
{
if (bounces > 1){
level = 2;
}
if (bounces > 2){
level = 3;
}
if (bounces > 3){
level = 4;
}
if (bounces > 4){
level = 5;
}
if (bounces > 5){
level = 6;
}
if (bounces > 6){
level = 7;
}
if (bounces > 7){
level = 8;
}
if (bounces > 8){
level = 9;
}
if (bounces > 9){
level = 10;
}
else{
level = level;
}
}```

This part of the code is in fact very easy to change, so if you wanted to, you could substitute the numbers shown and make levels longer or shorter depending on what you wanted. I also made the level you are currently on be displayed on the top part of the screen while you are playing the game.

## Hardest part of the Project

Easily the hardest part of the project was utilizing the two commands;

```pushMatrix();
//and
popMatrix();```

These two lines of code close off the translations for each shape you are adding in to the game. So, for example if you want to translate a cube 3 units to the left, without using the two commands, you would just end up moving the whole virtual world 3 units to the left. It also didn’t help that I did not understand this until half way through the project (mostly why it was so difficult for me). So basically to negate this movement of the whole world when you only intend for one shape to move, you just have to put “pushMatrix();” before you translate and fill a shape, and then “popMatrix();” once you draw the shape afterwards.

## Switching to 2 Player Mode

Switching it to two player mode was not hard at all. All I did was put an “if” statement into the 2nd paddle’s code that says if “twoplayer” is true than, the second paddle uses the arrow keys and if  “nottwoplayer” is true than the paddle automatically follows to the balls location without leaving its “z” coordinate.

``` if (start == true && level != 0 && nottwoplayer == true)
{
}

if (start == true && level != 0 && twoplayer == true)
{
}```

Although there isn’t a seperate mode or gametype for each of the game styles, while you are in game, pressing the “p” button will change to two player and pressing “o” will change to single player.

## Reasons for this Project

Pong is usually seen as an “easy” or “simple” project, because it completely is. But, I like the idea of the game and how much you can change it. So for this project, I knew I wanted to do something in 3D, but I didn’t want to do something that could have some very large problems because I would probably not know how to fix them considering I am still relatively new to the whole “coding in more than 2 dimensions” area. So I did pong because people are familiar with the idea, it would be understandable to manipulate on larger scales, there are unlimited things you can do with this game, and its fun! Then, I chose to use processing because I knew the language very well, and its the only program that can run 3D things that we learned about this year. I also just like the format of it. But overall, I thought this was a really fun project to do, and I hope that others can have as much fun with it as I did.

By: Andrew Shaw

For the rest of the year, I’m going to highlight some impressive final projects in Computer Programming and BC Calculus.
The computer programming students have had the majority of the term to work on their projects and one of the requirements was to write a blog post about their experience.
Here’s a crosspost of a implementation of Blackjack. Some really cool work with arrays of images was worked on here. The end result may not exactly look crazy impressive, but the guts are there to make this much prettier:

For my final project in computer programming, I decided that I wanted to create a simulation of blackjack, the popular card game. I thought that it would be a fun project to work on, as I felt that there would be enough portions of it that would challenge me, while at the same time not being insurmountable.

Before you get a chance to try out what I have, blackjack does have somewhat flexible rules, my version only uses a single deck of cards and the house will stand on a soft 17. Additionally, I had planned for there to be a way to bet in the game, but I unfortunately did not have time to properly implement that. Now that I’ve talked about it, here is the link to my game.

## Dealing Cards

The way in which I selected cards to deal was in part taken from an earlier program that I wrote for BlueJ, which I used in GreenFoot. I have a value between 1 and 52 for each card in a standard 52 card deck, and I made this chart to help clarify for me which card had which value:

The next thing that I had to deal with was ensuring that the same card was never dealt out twice (ex. 2 cases of 6 of hearts in the same hand). To do this I added have the following code ahead of where I add the value of the card to the ArrayLists in which I had the players’ hands:

```while ((house.contains(tempCard) == true) || (player1.contains(tempCard) == true))
{
tempCard = dealCard();
}```

This essentially just looks at the ArrayLists that have the values of the hands ( house and player1 respectively) and sees if the new value is already present. If it is, the program simply finds a new value through the dealCard() method, and will continue this until it finds a value that is not already present. The rest of the code is mostly adding the card to the necessary ArrayLists and creating the Card object:

```//Deals give the card to the players based on whose turn it is.
if (playerTurn1 == true)
{
//Puts the value out of 52 into an ArrayList

//finds the value the card would have in blackjack, nad then adds it to another ArrayList
if ((tempCard % 13 == 0) || (tempCard % 13 == 12) || (tempCard % 13 == 11))
{
}
else if (tempCard % 13 == 1)
{
}
else
{
}

//Creates a Card object in the world, increases the deal count, and has a slight delay.
deal ++;
Greenfoot.delay(5);
}
//the code here is the same as directly above, just for the house instead of player1.
else if (houseTurn == true)
{
if ((tempCard % 13 == 0) || (tempCard % 13 == 12) || (tempCard % 13 == 11))
{
}
else if (tempCard % 13 == 1)
{
}
else
{
}
addObject(new Card(tempCard), 0 + xHouseAdd, getHeight()/4 );
deal ++;
Greenfoot.delay(5);
}```

## Images of Cards

As I decided to do my project in GreenFoot,  I also needed to create a visual representation of the cards. I immediately ruled out creating 52 separate classes for the cards, as that would be excessively long. I eventually decided to create an ArrayList of GreenFoot Images, and get the image from the list based on the value each card has. This was still rather long and tedious, even if it was better than the alternatives it was essentially the following code repeated 52 times with the file name changed:

```GreenfootImage g = new GreenfootImage("40px-Playing_card_spade_A.svg.png");

I had gotten this ArrayList sorted out but I then had another issue, and this ended up halting my progress for several days. I needed to find a way to have the Card class have access to both the ArrayList of images as well as the value that each specific card had when it was created. I first attempted to pass both the value of the card and the ArrayList of GreenFoot images to the Card class, however I ran into an issue where I needed the specific instance of the World class. I searched for a way to do this, but they few results I managed to find were fairly long and I did not understand them at all. I eventually abandoned this approach in favor creating an entirely new class, Methods, and making my Card and Deck classes subclasses of Methods. I thought that by doing this Deck and Card would have the values of any variable I had assigned in methods, but I later learned that this was not how the relationship between subclasses and superclass worked, and I had to change my approach again. Eventually, I went back to my original plan of attempting to pass information, and after refining my original searches I was successful. The second was that I did eventually find way to get the specific instance of my CardWorld class in a fairly concise manner:

```((CardWorld) getWorld()).genericMethodHere();
```

This was able to solve my primary issue with this, however another soon appeared, specifically when I dealt the initial four cards of the round (2 for each player) all of the images were the same, even though their values in the ArrayLists were different. I finally found that this was a result of how I was passing the cards their values. The value was stored in a variable that I was passing, but because the cards were being created in the same method they could not ask for the variable until after they were all created, and so they all received the same variable value. I resolved this issue fairly simply by adding a constructor to my Card class, which allowed me to give the Card its value as soon as it was created. The final code to assign the cards their images is below, and I find that it now works extremely well for what I need:

```images = ((CardWorld) getWorld()).GiveImages();
setImage(images.get(CardVal - 1));```

This may seem like an extremely long long section on an issue that seems fairly simple to resolve, and I agree. This is due to the fact that what was in reality a few very simple to solve issues holding me up for a quite a few days. I am certain that if had resolved this earlier I could have made much more progress, and I regret that I was not able to.

## The Game

After I had ensured that dealing cards was fully functional, I then set out to add in the rules of the game. The first thing that I worked out was the turns for the players (ex. the player chooses to hit or stand, then the house). This was somewhat tricky to work out, however in the end it eventually just came down to some variables being added to determine which player to deal to. After this I had to come up with a way to add up the total value of the cards in a player’s hand, rather than using multiple for loops, I just made the following function, with a parameter for the ArrayList to be added:

```public int handSums(ArrayList<Integer> hand)
{
int sum = 0;
//add up the cards for the given hand.
for (int i = 0; i < hand.size(); i++)
{
sum += hand.get(i);
}
return sum;
}```

This function ended up being invaluable to me, as I continued with my project I used this many times I then created buttons that would allow the player to choose whether they wanted to hit, stand, or double down. The latter was added as an option because of the betting system I hoped to add, this would have dealt one more card to the player, doubled their bet,  It currently only deals one card and ends the turn.

The code for the house was even simpler however, essentially just drawing until their hand total is over 17:

```public void houseDeal()
{
while (handSums(houseVal) < 17)
{
nextCard();
}
roundOver = true;
}```

## Winning and Losing

After I had the turns working correctly and players’ hands being added properly, the next thing I needed to do was determine whether the player won or lost. For the most part this was simply a lot of if statements for various circumstances, then running a method to pop up a message informing the player if they won, as well as if they or the house had gotten a blackjack (Ace and King/Queen/Jack/10). There was one portion of this that was somewhat tricky however. In Blackjack, the value of an Ace is normally 11, but if the hand an Ace is in has a total value of over 21, that Ace’s value can be changed to a one. Because of this I had to design a method to do this:

```public void checkAce(ArrayList<Integer> hand)
{
if ((handSums(hand) > 21) && (hand.contains(11) == true))
{
hand.set(hand.indexOf(11),1);
}
}```

The method itself was fairly simple, what was harder was determining where and when I needed to implement it. There were a number of places it was needed, and finding the correct spot to check for the Ace was very difficult at times.

## Rounds

The final thing I implemented in my program was the ability to transition from one round to another. Before this the program would start, the players would hit or stand, the winner would be determined, and then the program would end; if you wanted to play another round you would have to restart the program entirely. I mainly accomplished this by passing some variables in order to tell the different classes to prepare for a new round, but I also had one main method which primarily clears the ArrayLists for the hands, reset some starting variables, and delete all of the cards on the screen:

```public void clearHands()
{
for (int i = (house.size() - 1); i >= 0; i--)
{
house.remove(i);
}
for (int i = (houseVal.size() - 1); i >= 0; i--)
{
houseVal.remove(i);
}
for (int i = (player1.size() - 1); i >= 0; i--)
{
player1.remove(i);
}
for (int i = (playerVal1.size() - 1); i >= 0; i--)
{
playerVal1.remove(i);
}
List<Card> cards = getObjects(Card.class);
removeObjects(cards);
removeObjects(getObjectsAt(getWidth()/2, getHeight()/2,RoundButton.class));
startRound = true;
roundOver = false;
}```

At first I had the round changing on its own after a brief delay, but I experienced some issues with this, namely the last card for the player, and any additional cards the house was dealt would not be assigned their images, instead the winner was announced and delay would happen, then the next round would start without assigning the images. I determined that this was basically because the program was stuck in a loop until the next round could start, and so the cards never had the opportunity to assign their images. I solved this issue by creating a new button instead of ending the round, effectively eliminating the loop before the next round started. When the player clicks the button the button then calls the function to end the round,clear the hands, and finally delete the button itself.

This not only solves the problem with the loop, but also allows the player to take as much time as they need to bring up the terminal to see who won, as well as to look at what cards they and the house had. The latter effect was not intended, but I find that I actually like the way this currently works much more.

## Conclusion

I feel that my project went fairly well for me, and while I wish I could have done much more (betting, nicer images, making the whole program cleaner, etc.), I am still pleased with what I have accomplished. I had several challenges along the way, some of which caught me up far longer than they should have (passing information between classes), but beyond those, I feel the project went very well, and I had an enjoyable time creating, and hope to someday return to it.

For the rest of the year, I’m going to highlight some impressive final projects in Computer Programming and BC Calculus.
The computer programming students have had the majority of the term to work on their projects and one of the requirements was to write a blog post about their experience.
Here’s a crosspost of a pair of programmers who wrote a LOT of impressive code in processing. And here’s part 2, from the other student’s point of view.
You’re going to need to download the code and run it on your own computer. Totally worth it.

# The Code Behind Galactic Wing

Game Designer, Lead Programmer/Developer, Sound Designer, and Music Producer – Nicklas Kenyon

Graphic Designer, Lead Artist,  and Programmer/Developer – Caleb Perry

Galactic Wing and Processing
Galactic Wing was written in Processing (It’s free at https://processing.org/download/).

Some of the code you see uses functions built into Processing.
For this review of my project I am going to explain the major parts of code, because the code itself is quite lengthy.

### How the Code is Organized

Setup looks like this:

```void setup(){
size(1280,720);
background(0);
//loads images at the start of the game.
//Setup_FileRW creates the file reader, and then loads the save file.
Setup_FileRW();
//Assigns default or saved values before the game starts
Setup_AssignValues();
//Creates new instances of all lists that are requiered in the game.
Setup_CreateLists();
//If a Lists needs objects at the beginning of the game, those objects are added using the Setup_FillLists method
Setup_FillLists();
//Runs the initial setup of Music Players
Setup_MusicPlayers();
}
```

Setup is composed of several separate setup packages so that the setup does not get cluttered. With all of the separate functions, I can keep better track of where things are, and when they happen. This same idea of organizing the code into several different functions and methods is used throughout the entire code.

Void draw also follows this organization

```void draw(){
//if the console isn't being used, continue running whichever gamemode is selected
if (consoleactive==false){
//if the gamemode is 0, run the MainMenu package, which displays the main menu, and checks to see what the user wants to do.
if (gamemode==0){
}
//When campaign mode is made, gamemode 1 will run a campaign mode package.
if (gamemode==1){
CAMPAIGNMODE();
}
// If the gamemode is 2, the Chaos Mode package is run, which is a survival stlye gamemode
// in which the player tries to dodge more and more asteroids as time goes on.
if (gamemode==2){
CHAOSMODE();
}
//if the gamemode is 3, the Hangar package is run, which brings up a view of the hangar, where the user can select and unlock ships.
if (gamemode==3){
HANGAR();
}
if (gamemode==4){
//opens tribute mode
TRIBUTEMODE();
}
if (gamemode!=3){
//resets Hangar fade mode
//resets Opacity for all images to completely Opaque.
tint(255,255);
}
}
//runs the console package
console_package();
//Plays the music
PlayMusic();
//Runs the Character Package
CHARACTER();
}
```

Each of the fully capitalized methods in void draw are what I like to call “packages” (i.e. “CAMPAIGNMODE()”).

Going into detail about each function would become monotonous and boring, so I will just touch on some other important aspects of the game.

### The Save/Load System

The saving and loading of a save file is a game feature I am very proud of. Thankfully, Processing has some built in functions that make this a bit easier.

The code looks like this:

```PrintWriter savefile;
int fivescores = 0;
String savefile_string;
PFont filefont;
int count = 0;
boolean FileIsRead = false;
// void Setup_File_RW() is in the "Setup" tab.

void SaveGame(){
writesavefile();
}

}
}

void writesavefile(){

savefile = createWriter("savefile.txt");
savefile.print("Gold="+Gold+"~");
savefile.print("Rank="+Rank+"~");
savefile.print("Experience="+Experience+"~");
savefile.print("End of File~");
println("Saved");
savefile.flush();
savefile.close();
}

try{

} catch (IOException e) {
e.printStackTrace();
savefile_string = null;
}
if (savefile_string == null) {
//nothings gonna happens
}
else {
String[] savefile_list = split(savefile_string, "~");
println("SFList: "+savefile_list.length);

//Gold
String SaveData_String_Gold = savefile_list[0];
String[] SaveData_Array_Gold = split(SaveData_String_Gold,"=");
;
Gold = int(SaveData_Array_Gold[1]);
println("Gold: "+Gold);
//Rank
String SaveData_String_Rank = savefile_list[1];
String[] SaveData_Array_Rank = split(SaveData_String_Rank,"=");
//Rank = int(SaveData_Array_Rank[1]);
println("Rank: "+Rank);
//Experience
String SaveData_String_Experience = savefile_list[2];
String[] SaveData_Array_Experience = split(SaveData_String_Experience,"=");
Experience = int(SaveData_Array_Experience[1]);
println("Experience: "+Experience);
}
}
```

As you can see, the save file takes user variables, such as Gold, and saves them. When the game starts, the save file is loaded.

This is what the save file looks like:

This is a very simple way of storing information, but for the purposes of this game, it is sufficient.

### The Command Console

The Command Console took forever.

At first, I was just checking an ArrayList of Strings. When I wanted to get more advanced and have the text scroll, and be able to view input history, I decided to make a “Input” class, that had a String variable and a “y” variable for the text’s y position in the history view.

Code:

```class CommandInputs{
//y position of the string in the console view
int ypos;
// the text that the user has input into the console.
String inputtext;
CommandInputs(int y, String text){
ypos=y;
inputtext=text;
}
void moveup(){
//move the line up by the height of the font (i'm using font size 12, so I give a little bit of space by adding 14)
ypos+= 14;
}
}
```

Here is a demo of the console:

### Collision Detection

Currently, the game uses a radius based method of collision detection. Another, “pixel-perfect” method of collision detection is in the making, but is not functional enough to put into the game at this time.

A bit of sample code

```//if an asteroid hits another asteroid, it bounces off
void check(Asteroid b){
float d = dist(xpos, ypos, b.xpos, b.ypos);
if (d <= ((diam+b.diam)/2)){
if (diam<=b.diam){
xspeed *= -1;
}
}
}

```

As is the case in many 2D games, I decided to uses a pixel sheet to design and create my maps. The map reader gets the color information from each pixel in a map sheet, and then decides what object to place in that relative position based on the color.

Examples

Red pixels are stationary asteroids.
Green pixels are moving asteroids.

## What about Gameplay?

There are two game modes in Galactic Wing; Chaos Mode and Campaign Mode.

Chaos mode is a survival style game mode in which you get one ship and try to stay alive, dodging asteroids and shooting gold as more and more asteroids enter your area of space.

Your ammo is replenished with each wave of asteroids.

Campaign mode is in early development but features a progression through different asteroid fields of increasing difficulty.

As you play, you will gain experience and be promoted to new ranks. The greater your rank, the more ships you can control.

As you play, you will gain gold, experience, and rank. With gold, you can buy new ships in the hangar.

### The Controls

The controls for Galactic Wing are a bit unique. Instead of holding down the WASD keys to move, you press them to increase or decrease you x and y speeds.

To fire a laser, press the space bar.

If you manage to go into the hangar, you can press the “f” key to go back. The hangar is in development, so enter at your own risk.

To open the console, press the “/” key. When you are done typing in your command, press enter to submit it and close the console.

To go back to the main menu at any time, press the “m” key.

# Second Post

## What is Galactic Wing?

Galactic Wing is a Top Down Shooter that puts you in command of your very own fleet of weaponized space shuttles. You destroy asteroids and gold comets in order to earn gold. This gold can be spent in the hangar where you can upgrade all the ships in your fleet. The game comes with two game modes, Chaos Mode and Story/Campaign Mode. Chaos mode is where you simply have your fleet of ships with a constantle increasing number of asteroids in your vicinity; fight to survive. Campaign mode is where you have a combination of timed obstacle courses (still UC) and battles following a level type system. Its pretty much the best game processing has ever seen.

## How I contributed to Galactic Wing

Galactic Wing was already in the making way before I was inducted into the project, so most of the core code was already there, however a hangar was yet to be constructed and there were no signs of any artwork. So my contribution to Galactic Wing was to create all the artwork for the game and to construct a hangar where the user could go to to buy new upgrades for his fleet.

## What problems did I run into?

In order to not have variables for each and every ship(which would have been 40 variables in total), I decided to use class for the ships. this wasn’t really a problem, there were just some growing pains when trying to figure outt he weird way you have to use classes in processing

This is the code for the Ships class including the supporting method for the first hangar.

```class Ships {
boolean shipbought = false;//pretty self explainitory
String shipname;
int shipdamage;
int shiparmor;
int shipspeed;
int engineerXmin;
int engineerXmax;
int shipprice;
int Gold;
Ships (String name, int damage, int armor, int speed,int Xmin,int Xmax,int price,int gold)
{
Gold = gold;
shipprice = price;
shipspeed = speed;
shipdamage = damage;
shiparmor = armor;
shipname = name;
engineerXmin = Xmin;
engineerXmax = Xmax;
}
void displayh1() {
if ((backgroundnum == 1)&&(engineerX > engineerXmin)&&(engineerX < engineerXmax))
{//The following 70 lines of code are dedicated to displaying info about the ship, weather you can buy the ship(or if you've already bought the ship), and the price of the ship.
/*1*/ rectMode(CORNER);
stroke(100);
strokeWeight(15);
fill(120,120,120,127);
tint(255,127);
rect(100,20,1000,520,40);
tint(255,255);
textAlign(LEFT,CENTER);
fill(0,0,200);
text(""+ shipname +"",210,50);
textFont(InfoTextTest);
rectMode(CORNER);
strokeWeight(3);
fill(150);
rect(210,200,803,15);
rect(210,300,803,15);
rect(210,400,803,15);
noStroke();
if(shipdamage < 33) {
fill(red);
rectMode(LEFT);
}
else if(shipdamage <66) {
fill(yellow);
}
else if(shipdamage <=100) {
fill(green);
}
rectMode(CORNER);
//offset in the x and y by 2 to compensate for the stroke on the outlined boxes
rect(212,202,float(shipdamage)/100*800,12);
text("Damage: "+ shipdamage +"",250,150);
if(shiparmor < 33) {
fill(red);
}
else if (shiparmor <66) {
fill(yellow);
}
else if(shiparmor <=100) {
fill(green);
}
rect(212,302,float(shiparmor)/100*800,12);
text("Armor: "+ shiparmor +"",250,250);
if(shipspeed < 33){
fill(red);
}
else if(shipspeed <66) {
fill(yellow);
}
else if(shipspeed = shipprice) {
Gold = Gold - shipprice;
shipbought = true;
s2.Gold = s1.Gold;//These 5 lines of code solves a problem where you would have your money instantly replenished to the default value whenever you bought a ship.
s3.Gold = s1.Gold;
s4.Gold = s1.Gold;
s5.Gold = s1.Gold;
s1.Gold = Money;
println(""+ Money +"");
}
if((Gold <= shipprice)&&(shipbought == false)) {
fill(50);
rectMode(LEFT);
rect(445,485,800,530);
fill(200,0,0);
text("INSUFFICIENT FUNDS",450,500);
}
}
}
}
}```

Another problem was trying to use a totally public variable to draw your gold value from. This was issue because you had to pass a variable through the class, which would then be translated to another variable that would actually be used in the proceeding code. So, in order to fix that issue I created a variable called money that would be public and another variable called gold which would be seen only inside the 3 classes for each hangar. So at the end of the frame the class would make their money count equal to each other across the board first. Then outside the class I would call the variable for gold of the hangar the gold was spent in  (ex. “Ships.gold” or “sx.Gold” for each individual ship, where x is the ship number) and would make that equal to money so that upon the next variable passing, the Money variable would be updated to the value each hangar’s gold value was last seen at. It seems simple now but at the time I just couldn’t figure it out.

I have since found a few much simpler ways of doing this.

Another problem that I had was having the background display the correct image. This issue arose when I had multiple parameters inside the draw() sequence that led to different backgrounds than the one I wanted being displayed, or if the program came to the correct background to be displayed, it would instead just display a black image. Processing didn’t seem to like that, so instead what I did was I made a main variable called background that was an empty PImage. This would be set using the parameters talked about before only this time I would would do this process outside of the draw(). So inside the draw() i had only one background command but the image variable passed through that background command would be the thing to change change.

So this isn’t the real code, but it looked something like this:

```PImage background;
PImage hangar1;
PImage hangar2;

void setup() {
size(1280,720);
hangar1 = image(*image directory*);
hangar2 = image(*image directory*);

void draw() {
checkhangar();
background(background);

void checkhangar() {
if(guy is in hangar 1) {
background = hangar1;
}
if(guy is in hangar 2) {
background = hangar2;
}
}```

I’m not really sure why the first method that was malfunctioning wasn’t working, but either way that’s how I fixed the issue.

## Pixel art in Photoshop

Making the ships for Galactic Wing was one of the most fun things I’ve done in Photoshop because it was both gratifying and informative. It was informative because in order to mae the ships small enough while still making them look sharp, I needed to learn how to make pixel art.

Each ship in galactic wing had to be 50 x 50 in order to work with collision so I made a template in 50 x 50 in order to go through the whole process.

Whence we create a ship in the 50×50 state we need to scale it so we can display it in the hangar while keeping is crisp and not blurry beyond recognition.

So we go to Image > Image Size, then we will put in the desired resolution. Then in the drop down box in the bottom of the window we will select the option “Nearest Neighbor (preserve hard edges)” then press OK.

For the rest of the year, I’m going to highlight some impressive final projects in Computer Programming and BC Calculus.
The computer programming students have had the majority of the term to work on their projects and one of the requirements was to write a blog post about their experience.
Here’s a crosspost of a fantastic drawing program that one (female, yay!) student wrote in processing.org:

# A Basic Drawing Program

Although I cannot stress enough that this is just a basic program, as it lacks the ability to undo (Which would be difficult to code I’d imagine, for me at least). I found myself mildly surprised at how effective this was at performing certain tasks. This could actually create something that looked half decent, if you knew how.

##### You can access the code here:

http://www.openprocessing.org/sketch/150625

## Directions

The gui offers a few basic colors to pick from without bothering to deal with the sliders, there’s also a few basic brush widths to pick from. However if you want to try them out, the sliders alter a certain variable that makes up the color.

```color custom = color(0+r,0+g,0+b,255+opac);
```

Also, for those of you that actually made a file for this, you can save the pictures you create with the save button.

##### Keyboard Shortcuts:

e – Increases brush width
q – Decreases brush width
z – Clears the canvas
c – Color picker
r – Increases the red value
t – Decreases the red value
b – Increases the blue value
n – Decreases the blue value
g – Increases the green value
h – Decreases the green value
d – Makes shades of gray darker
f – Makes shades of gray lighter
o – Makes brush strokes more solid
p – Makes brush strokes more see-through

## Saving feature

Although you can play this game from the window, I highly recommend downloading processing and pasting the code (Which is found on the site) into your own file. Without the file on your computer the saving feature will not work.
How it saves:

```void saving(boolean save)
{
if (save == true)
{
//Start of borrowed code
save("Test.png");
PImage img = loadImage("Test.png");
PImage myImage = img.get(152,0,648,800); //Get a portion of the loaded image with displaying it
myImage.save("Final.png"); //Save the portion of the image without displaying it
//End of borrowed code
}
}

//This is checked whenever the mouse clicks:

//Save button
if (((mouseX > 0) && (mouseX < 100)) && ((mouseY > 700) && (mouseY < 750)))
{
save = true;
}
```

Basically it makes the entire window an image, then it takes that image and only takes the canvas, which is everything to the right of the x value of 150. It then saves both of these images as “Test” and “Final”. If you do not rename the “Final” file, it will be overwritten, so be careful. Although you should still save often, because there is no going back once an error is made, unless you have the skill to fix it.

This is the “Test” file

This is the “Final” file

## The Rainbow In One Stroke

Unlike most drawing programs, this allows for something quite useful, changing colors as you draw. The thing is this code is very simple, I’m actually surprised I don’t see it in other drawing programs.

```//Makes it less red as it decreases
if (key == 't')
{
if (r>3)
{
r = r - 4;
color custom = color(0+r,0+g,0+b,0+opac);
choosenColor = custom;
}
}
//Makes it less blue as it decreases
if (key == 'n')
{
if (b>3)
{
b = b - 4;
color custom = color(0+r,0+g,0+b,0+opac);
choosenColor = custom;
}
}
//Makes it less green as it decreases
if (key == 'h')
{
if (g>3)
{
g = g - 4;
color custom = color(0+r,0+g,0+b,0+opac);
choosenColor = custom;
}
}
//The opposite is used for increasing the values
```

When they are used they can produce a nice transition of colors, which are very convenient in creating things such as backgrounds and skies.

An example of the color transition.

An example of color changing, please note this is all one line.

### Avoid Mistakes

I have to admit, it would of been smarter to line these buttons in another drawing program, or maybe create an entire gui image and just use that instead. I had to deal with the tedious task of placing each button, at odd intervals no less. It would of been less time consuming, and it wouldn’t take so long to edit it if something was off. Even the size, I ended up creating it too big for my laptop screen, making it a pain to use, but it’s even more of  a pain to relocate every button and where to press to get a certain effect.

### Gallery

Just a few pictures I whipped up real quick, they’re not too bad?

All of these below are from before I fixed the cropping

They set this up before the bell while I was out making copies. Sigh.

More progress:

Here’s a gift I got from a student after a long weekend:

Here’s a peek into a students calc project: