Thursday, October 30, 2014

Exploring GreenFoot

This week we will be exploring GreenFoot -- an alternative IDE which focuses on 2D graphics for Java applications.

GreenFoot can be found here: http://www.greenfoot.org/door

We will be exploring the Joy of Code video series here: http://blogs.kent.ac.uk/mik/category/joy-of-code/page/2/

We used the Hedgehog program here: http://www.greenfoot.org/static/joc/material/hedgehogs.zip

And Trick the Turtle here: http://www.greenfoot.org/static/joc/material/trick-the-turtle.zip

Thursday, October 23, 2014

Computer Logic

Artificial intelligence isn't true intelligence.  Computers do not yet have the ability to think; to learn.  A computer is only able to do what it is told.  If you're playing a game, the character in the game basically follows a flow chart to know what to do.  If you walk into the virtual room, the character you encounter will react in certain ways -- if you have already found the magic sword the guard may attack... or if you are a magician the guard may run afraid... or if you have joined a guild the guard may welcome you in and show you the attack plans.  The guard will only follow the instructions given.  The guard will never think of something on his own... or be in a bad mood and act a certain way...  or decide to take the treasure for himself.

As a programmer, you have to think of all of the possibilities and program for those choices.  We aren't [yet] making a cool video game where characters are interacting with each other, but we will be creating programs with logic problems.  Flowcharting helps, but we have to remember to be specific.  If you have ever used Siri on an iPhone or iPad, you're probably encountered this.

You may have also played with "bots" in "shooter games" (like Counter Strike or Team Fortress) where the bots get confused over simple situations.  Sometimes you'll find them running at full speed, but they are stuck in a corner or behind a box.  The programmer neglected to write a "what if" scenario for whatever got them stuck.  Computers (and "artificial thinkers") can only do what you tell them to do.

Here's an example [from a JAVA for Dummies book] illustrating this principle:

Just yesterday, I was chatting with my servant, RoboJeeves. (RoboJeeves is an upscale model in the RJ-3000 line of personal robotic life-forms.) Here’s how the discussion went:
Me: RoboJeeves, tell me the velocity of an object after it’s been falling for three seconds in a vacuum.
RoboJeeves:
All right, I will. “The velocity of an object after it’s been falling for three seconds in a vacuum.” There, I told it to you.
Me:
RoboJeeves, don’t give me that smart-alecky answer. I want a number. I want the actual velocity.
RoboJeeves:
Okay! “A number; the actual velocity.”
Me:
RJ, these cheap jokes are beneath your dignity. Can you or can’t you tell me the answer to my question?
RoboJeeves:
Yes.
Me:
“Yes,” what?
RoboJeeves:
Yes, I either can or can’t tell you the answer to your question.
Me:
Well, which is it? Can you?
RoboJeeves:
Yes, I can.
Me:
Then do it. Tell me the answer.
RoboJeeves:
The velocity is 153,984,792 miles per hour.
Me:
(After pausing to think . . .) RJ, I know you never make a mistake, but that number, 153,984,792, is much too high.
RoboJeeves:
Too high? That’s impossible. Things fall very quickly on the giant planet Mangorrrrkthongo. Now, if you wanted to know about objects falling on Earth, you should have said so in the first place.
Here's an interesting video from a game developer doing "AI":

Flow Charting

The first example is lengthy, but the first 6+ minutes are the part I want you to focus on -- unless of course you want to learn C++ programming.  The professor does a great job of demonstrating a basic problem that we need to solve, lays it out in steps, and then applies to steps to a flow chart.





This is a flow chart of making decisions in your life:
This is a useful tool for figuring out what to do:

Here's a funny flow chart in action:  http://www.youtube.com/watch?v=k0xgjUhEG3U
And lastly... this little gem. :)

Programming is about solving problems.  The entire purpose of writing a program is to solve a problem which, in general, consists of multiple steps:
  1. Understanding the problem.
  2. Breaking the problem into manageable pieces.
  3. Designing a solution.
  4. Considering alternatives to the solution and refining the solution.
  5. Implementing the solution.
  6. Testing the solution and fixing any problems.
After we understand a given problem, we can break the problem into manageable pieces and design a solution.  For example, if we wanted a program to figure out the least possible number of coins to give a customer as change, we might want to first subtract the amount owed from the amount paid, then figure out how many quarters would go into that, take the remainder and figure out how many dimes would go into that, and then move on to nickels and then pennies.  For more complex problems, making a flow chart can help to organize your thoughts and identify potential issues before you begin programming.

Below are some potential "problems" for you to solve using flow charts.

Flow Chart Practice: 
  1. A movie theater wants a program that will show admission price based on age.  They want to charge children (under 12) and seniors (65 and older) $5.25.  Everybody else will pay $9.25.  They want to ask "How old are you?", let the person put in their age (in years), tell them the price, then tell them to "Enjoy the show!".
  2. A daycare provider wants to give gumballs to their kids, but they want a program that will ask the worker, "How many gumballs?" and then "How many kids?".  Then it should divide the gumballs per kid (gumballs/kids).  Finally it should say, "Each kid gets X gumballs."
  3. You decide to write an app for a SmartPhone.  You want to do a Magic 8 Ball app where you ask a question and it gives you a "Yes" or "No" answer.
  4. You want to write a program that will pick a random number between 1 and 1000.  Ask the player to guess a number and tell them if they are too high, too low, or if they get the number correct.  The program should keep running until they guess the number correctly.

Getting Started

Your homework is to install the JAVA software [on your home computer] as follows:
  1. Install JDK on your home computer and/or laptop (wherever you plan to work on Java programming)
  2. Install the Java API (Docs)
  3. Install BlueJ on your computer/device.
  4. Install GreenFoot on your computer/device.
And now for a brief intro about the importance of updating your Java.
And demonstrating some of the JAVA epicness... hardcore.

Wednesday, October 22, 2014

About Programming

Why Is Computer Programming Important:


The Early Days of Programming

During the early 1980s, Chris worked for a computer software firm. The firm wrote code for word processing machines. (At the time, if you wanted to compose documents without a typewriter, you bought a “computer” that did nothing but word processing.) Chris complained about being asked to write the same old code over and over again. “First, I write a search-and-replace program. Then I write a spell checker. Then I write another search-and-replace program. Then, a different kind of spell checker. And then, a better search-and-replace.”

How did Chris manage to stay interested in his work? And how did Chris’s employer manage to stay in business? Every few months, Chris had to reinvent the wheel. Toss out the old search-and-replace program, and write a new program from scratch. That’s inefficient. What’s worse, it’s boring.

For years, computer professionals were seeking the Holy Grail — a way to write software so that it’s easy to reuse. Don’t write and rewrite your search-and replace code. Just break the task into tiny pieces. One piece searches for a single character, another piece looks for blank spaces, a third piece substitutes one letter for another. When you have all the pieces, just assemble these pieces to form a search-and-replace program. Later on, when you think of a new feature for your word processing software, you reassemble the pieces in a slightly different way. It’s sensible, it’s cost efficient, and it’s much more fun.

The late 1980s saw several advances in software development, and by the early 1990s, many large programming projects were being written from prefab components. Java came along in 1995, so it was natural for the language’s founders to create a library of reusable code. The library included about 250 programs, including code for dealing with disk files, code for creating windows, and code for passing information over the Internet. Since 1995, this library has grown to include more than 3,000 programs. This library is called the API — the Application Programming Interface.

Every Java program, even the simplest one, calls on code in the Java API.  This Java API is both useful and formidable. It’s useful because of all the things you can do with the API’s programs. It’s formidable because the API is so extensive. No one memorizes all the features made available by the Java API. Programmers remember the features that they use often, and look up the features that they need in a pinch. They look up these features in an online document called the API Specification (known affectionately to most Java programmers as the API documentation, or the Javadocs).

The API documentation describes the thousands of features in the Java API.  As a Java programmer, you consult this API documentation on a daily basis. You can bookmark the documentation at the Sun Microsystems Web site and revisit the site whenever you need to look up something. But in the long run (and in the not-so-long run), you can save time by downloading your own copy of the API docs.

Saturday, June 14, 2014


public class ComputerScience 
{
   public static void main(String[] args)
   {
      System.out.println("Welcome to AP Computer Science!");
   }
} 

Wednesday, May 28, 2014

Thursday, May 15, 2014

I solved *my* problem...

Turns out my problem was just a minor issue -- I put "Sprite.sheet.SIZE" when it should have just been "sheet.SIZE".  :sigh:

Anyway, here's my Sprite class if you are interested:
package com.version001.rain.graphics;

public class Sprite {

 public final int SIZE;
 private int x, y;
 public int[] pixels;
 private SpriteSheet sheet;
 
 public static Sprite grass = new Sprite(16, 0, 0, SpriteSheet.tiles); // Sprite.grass is 16x16 and in column 0, row 0

 public Sprite(int size, int x, int y, SpriteSheet sheet) {
  SIZE = size;
  pixels = new int[SIZE * SIZE];
  this.x = x * size;
  this.y = y * size;
  this.sheet = sheet;
  load();
 }

 private void load() {
  for (int y = 0; y < SIZE; y++) {
   for (int x= 0; x < SIZE; x++) {
    pixels[x + y * SIZE] = sheet.pixels[(x + this.x) + (y + this.y) * sheet.SIZE ];
   }
  }
 }
}

Wednesday, May 14, 2014

Episode 20

Once we complete Episode 20 I will post the code here.

The following sprite sheets include an original "blank" sheet showing 16x16 sprites on a 256x256 pixel grid as well as one with a "grass" texture and a "water" texture.
The following code makes up our program so far:
GAME:

package com.version001.rain;

import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;

import javax.swing.JFrame;

import com.version001.rain.graphics.Screen;
import com.version001.rain.input.Keyboard;

public class Game extends Canvas implements Runnable {
 private static final long serialVersionUID = 1L;

 public static int width = 300;
 // public static int height = width / 16 * 9;
 public static int height = 168;
 public static int scale = 3;
 public static String title = "Rain";


 private Thread thread;
 private JFrame frame;
 private Keyboard key;
 private boolean running = false;

 private Screen screen;

 private BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); //creating image
 private int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData(); //accessing image

 public Game() {
  Dimension size = new Dimension(width * scale, height * scale);
  setPreferredSize(size);

  screen = new Screen(width, height);
  frame = new JFrame();
  key = new Keyboard();

  addKeyListener(key);

 }

 public synchronized void start() {
  running = true;
  thread = new Thread(this, "Display");
  thread.start();
 }

 public synchronized void stop() {
  running = false;
  try {
   thread.join();
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
 }


 public void run() {
  long lastTime = System.nanoTime();
  long timer = System.currentTimeMillis();
  final double ns = 1000000000.0 / 60.0;
  double delta = 0;
  int frames = 0;
  int updates = 0;
  while (running) {
   long now = System.nanoTime();
   delta += (now-lastTime) / ns;
   lastTime = now;
   while (delta >= 1) {
    update();
    updates++;
    delta--;
   }
   render();
   frames++;

   if(System.currentTimeMillis() - timer > 1000) {
    timer += 1000;
    System.out.println(updates + " ups " + frames + " fps");
    frame.setTitle(title + "  |  " + updates + " ups " + frames + " fps");
    updates = 0;
    frames = 0;
   }
  }
  stop();
 }

 int x = 0, y = 0;

 public void update() { 
  key.update();
  if (key.up) y--;
  if (key.down) y++;
  if (key.left) x--;
  if (key.right) x++;  
 }

 public void render() {
  BufferStrategy bs = getBufferStrategy();
  if (bs == null) {
   createBufferStrategy(3);
   setFocusable(true);  // ADD THIS TO MAKE KEYS WORK!
   return;
  }

  screen.clear();
  screen.render(x, y);

  for (int i = 0; i < pixels.length; i++) {
   pixels[i] = screen.pixels[i];
  }

  Graphics g = bs.getDrawGraphics();
  g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
  g.dispose();
  bs.show();
 }

 public static void main(String[] args) {
  Game game = new Game();
  game.frame.setResizable(false);
  game.frame.setTitle(Game.title);
  game.frame.add(game);
  game.frame.pack();
  game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  game.frame.setLocationRelativeTo(null);
  game.frame.setVisible(true);

  game.start();
 }
}

Screen:
package com.version001.rain.graphics;

import java.util.Random;

public class Screen {

 private int width, height;
 public int[] pixels;
 public final int MAP_SIZE = 64;
 public final int MAP_SIZE_MASK = MAP_SIZE - 1;

 public int[] tiles = new int[MAP_SIZE * MAP_SIZE];

 private Random random = new Random();

 public Screen(int width, int height) {
  this.width = width;
  this.height = height;
  pixels = new int[width * height];

  for (int i = 0; i < MAP_SIZE * MAP_SIZE; i++) {
   tiles[i] = random.nextInt(0xffffff);
   tiles[0] = 0;
  }
 }

 public void clear() {
  for (int i = 0; i < pixels.length; i++) {
   pixels[i] = 0;
  }
 }

 public void render(int xOffset, int yOffset) {

  for (int y = 0; y < height; y++) {
   int yy = y + yOffset;
   //if (yy < 0 || yy >= height) break;
   for (int x = 0; x < width; x++) {
    int xx = x + xOffset;
    //if (xx < 0 || xx >= width) break;
    int tileIndex = ((xx >> 4) & MAP_SIZE_MASK) + ((yy >> 4) & MAP_SIZE_MASK) * MAP_SIZE;
    pixels[x + y * width] = tiles[tileIndex];


   }
  }
 }
}

Keyboard:
package com.version001.rain.input;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class Keyboard implements KeyListener {

 private boolean[] keys = new boolean[120];
 public boolean up, down, left, right;

 public void update() {
  up = keys[KeyEvent.VK_UP] || keys[KeyEvent.VK_W];
  down = keys[KeyEvent.VK_DOWN] || keys[KeyEvent.VK_S];
  left = keys[KeyEvent.VK_LEFT] || keys[KeyEvent.VK_A];
  right = keys[KeyEvent.VK_RIGHT] || keys[KeyEvent.VK_D];

  for (int i = 0; i < keys.length; i++){
   if (keys[i]){
    System.out.println("KEY: " + i);
   }
  }
 }

 public void keyPressed(KeyEvent e) {
  keys[e.getKeyCode()] = true;
 }

 public void keyReleased(KeyEvent e) {
  keys[e.getKeyCode()] = false;
 }

 public void keyTyped(KeyEvent e) {

 }

}

SpriteSheet:
package com.version001.rain.graphics;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

public class SpriteSheet {

 private String path;
 final int SIZE;
 public int[] pixels;

 public SpriteSheet(String path, int size){
  this.path = path;
  SIZE = size;
  pixels = new int[SIZE * SIZE];
  load();
 }

 private void load() {
  try {
   BufferedImage image = ImageIO.read(SpriteSheet.class.getResource(path));
   int w = image.getWidth();
   int h = image.getHeight();
   image.getRGB(0, 0, w, h, pixels, 0, w);
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}

Sprite:
package com.version001.rain.graphics;

public class Sprite {

 private final int SIZE;

 private int x, y;
 public int[] pixels;
 private SpriteSheet sheet;

 public Sprite(int size, int x, int y, SpriteSheet sheet) {
  SIZE = size;
  pixels = new int[SIZE * SIZE];
  this.x = x * size;
  this.y = y * size;
  this.sheet = sheet;
  load();
 }

 private void load() {
  for (int y = 0; y < SIZE; y++) {
   for (int x= 0; x < SIZE; x++) {
    pixels[x+y*SIZE] = sheet.pixels[(x + this.x) + (y + this.y)* sheet.SIZE ];
   }
  }
 }
}

Friday, April 25, 2014

Eclipse: Screen Class & Rendering Pixels

Today we worked through two more video tutorials by The Cherno.  We created a new Screen class and then began work on rendering pixels.

We watched Tutorial 8: https://www.youtube.com/watch?v=e61rMGZi8V4&list=ELshNxV9QFUOo

And then moved on to Tutorial 9:

I'm not going to be sharing code throughout this tutorial, but since we are just getting our foundations built at this point, I'm going to post the current state of our programs:

The Game class:  (Remember that package names may be different for you)
package com.version001.rain;

import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;

import javax.swing.JFrame;

import com.version001.rain.graphics.Screen;

public class Game extends Canvas implements Runnable {
 private static final long serialVersionUID = 1L;

 public static int width = 300;
 public static int height = width / 16 * 9;
 public static int scale = 3;

 private Thread thread;
 private JFrame frame;
 private boolean running = false;

 private Screen screen;

 private BufferedImage image = new BufferedImage(width, height,
   BufferedImage.TYPE_INT_RGB);
 private int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer())
   .getData();

 public Game() {
  Dimension size = new Dimension(width * scale, height * scale);
  setPreferredSize(size);

  screen = new Screen(width, height);

  frame = new JFrame();

 }

 public synchronized void start() {
  running = true;
  thread = new Thread(this, "Display");
  thread.start();
 }

 public synchronized void stop() {
  running = false;
  try {
   thread.join();
  } catch (final InterruptedException e) {
   e.printStackTrace();
  }
 }

 @Override
 public void run() {
  while (running) {
   // System.out.println("Running...");
   update();
   render();
  }
 }

 public void update() {
 }

 public void render() {
  BufferStrategy bs = getBufferStrategy();
  if (bs == null) {
   createBufferStrategy(3); // Triple Buffering
   return;
  }

  screen.render();

  for (int i = 0; i < pixels.length; i++) {

   pixels[i] = screen.pixels[i];

  }

  Graphics g = bs.getDrawGraphics(); // graphics = buffer strategy :
  // linking two together

  // All graphics displayed between here and g.dispose();
  // g.setColor(new Color(0, 0, 0)); // Sets the color with RGB ** removed
  // for updated code
  // g.fillRect(0, 0, getWidth(), getHeight()); // Fills a rectangle the
  // size of the screen ** removed for updated code
  g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
  g.dispose(); // Removes graphics at end of each frame
  bs.show(); // Display buffers available to release memory or it will
  // crash
 }

 public static void main(String[] args) {
  Game game = new Game();
  game.frame.setResizable(false); // Do not allow user to resize window
  game.frame.setTitle("Rain");
  game.frame.add(game);
  game.frame.pack();
  game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Close when you hit X button
  game.frame.setLocationRelativeTo(null); // Centers our window
  game.frame.setVisible(true); // Makes window visible.

  game.start(); // Starts the game
 }
}
The Screen class:
package com.version001.rain.graphics;

public class Screen {

 private int width, height;
 public int[] pixels;

 public Screen(int width, int height) {
  this.width = width;
  this.height = height;
  pixels = new int[width * height];
 }

 public void render() {
  // This loop draws a pixel across every column (X) and the continues down for every row (y)
  for (int y = 0; y < height; y++) { 
   for (int x = 0; x < width; x++) {
    pixels[x + y * width] = 0xff00ff;
   }
  }
 }

}

Tuesday, April 22, 2014

Eclipse: Graphics Initialization, Buffered Images & Rasters

1.
2.

He goes through some discussion of color and uses this web site: www.colorpicker.com

He also goes through some setup in Preferences  Just know that these computers will probably not remember changes to the Preferences, but here's the screen he goes to:

Finally, he is explaining what a "raster" image is -- even though it sounds like he's saying Rasta.  :)  Just know that a raster image is made up of a bunch of different colored squares (called pixels):
When you look at a raster graphic close up, you will see the pixelization much more clearly.  Some graphics [called vectors] are drawn mathematically with lines/curves, but it's really the difference between a photo and a cartoon at this point.


Monday, April 21, 2014

Friday, April 18, 2014

Guest Speaker: Academy of Art University

As we have discussed, we have a guest speaker from Academy of Art University with us today.  I expect everybody to be respectful, polite, and attentive during the presentation.

Thursday, April 17, 2014

Soldiering on with Eclipse...

Today we continued with Eclipse by watching video #4 of The Cherno's game tutorial. I have to say that I'm more than a bit humbled by the amount of Java I don't know because I have been relying on programs like BlueJ and GreenFoot to set up the windows and manage the workspace for me. That being said, I'm trying to push through it, but please understand that I'm struggling with some of this new material as well.

I believe that once we get past the initial "set up the game" process, we'll be back into regular programming with loops and variables and math. :) Let's keep pushing in hopes that we get it.

Our code [after today] looked like this:
package com.version001.rain;

import java.awt.Canvas;
import java.awt.Dimension;

import javax.swing.JFrame;

public class Game extends Canvas implements Runnable {
 private static final long serialVersionUID = 1L;

 public static int width = 300;
 public static int height = width / 16 * 9;
 public static int scale = 3;

 private Thread thread;
 private JFrame frame;
 private boolean running = false;
 
 public Game() {
  Dimension size = new Dimension(width * scale, height * scale);
  setPreferredSize(size);  
  
  frame = new JFrame();
 }

 public synchronized void start() {
  running = true;
  thread = new Thread(this, "Display");
  thread.start();
 }

 public synchronized void stop() {
  running = false;
  try {
   thread.join();
  } catch (final InterruptedException e) {
   e.printStackTrace();
  }
 }

 public void run() {
  while (running) {
   System.out.println("Running...");
  }
 }
 
 public static void main(String[] args) {
  Game game = new Game();
  game.frame.setResizable(false); // Do not allow user to resize window
  game.frame.setTitle("Rain");
  game.frame.add(game);
  game.frame.pack();
  game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Close when you hit X button
  game.frame.setLocationRelativeTo(null); // Centers our window
  game.frame.setVisible(true); // Makes window visible.
  
  game.start(); // Starts the game
 }
}

Wednesday, April 16, 2014

Where We Are in Eclipse

So far we have just begun to scratch the surface of the Eclipse IDE.  Even though we just have a few lines of code, we've started exploring some new methods and new techniques.  As I mentioned, I am new to Eclipse as well, but with practice and trusting the process, we will do just fine.

Here's the code we have so far:

package com.version001.griff;

public class Game implements Runnable {

 public static int width = 300;
 public static int height = width / 16 * 9;
 public static int scale = 3;

 private Thread thread;
 private boolean running = false;

 public synchronized void start() {
  running = false;
  thread = new Thread(this, "Display");
  thread.start();
 }

 public synchronized void stop() {
  running = false;
  try {
   thread.join();
  } catch (final InterruptedException e) {
   e.printStackTrace();
  }
 }

 public void run() {
  while (running) {
  }
 }
}

Tuesday, April 15, 2014

Continuing with Eclipse: New Territory Explored

First, work through the first video (from yesterday) and listen to his explanations and instruction.

Next, follow the instruction in video #2. There will be some new terms and functions here, so pay attention to those.

Finally, follow through Video #3.

Monday, April 14, 2014

Beginning with the Eclipse IDE

Today we began working with Eclipse.  We started with the standard "Hello World" just to get the feel for the interface and, although we had a few little hiccups, things went pretty smoothly.
public class HelloWorld {
 
public static void main(String[] args) {
 System.out.println("Hello World!");
}

}

Next we will begin looking at some decent Eclipse tutorials.  I'll start with a couple I have explored, but if you find others that you really like, let me know and I'll review them for the class.

One example of a tutorial follows:

Friday, March 14, 2014

Quarter Final: Greeps Challenge

Over the next two weeks we will be working on an individual challenge to test our creativity, programming skills and organization.
The story is this:
Alien creatures have landed on Earth - they are the Greeps. Greeps like tomatoes. By some incredible stroke of luck, they have landed in an area where piles of tomatoes are found randomly spread out over the otherwise barren land. Help your Greeps collect as many tomatoes as possible.
  • Rule 1: Only change the class ‘Greep. No other classes may be modified or created.
  • Rule 2: No additional fields. You cannot extend the Greeps’ memory. That is: You are not allowed to add fields to the class (except final fields). You can use the one byte memory that is provided.
  • Rule 3: You cannot move more than once per ‘act’ round.
  • Rule 4: You cannot communicate directly with other Greeps. That is: no field accesses or method calls to other Greep objects are allowed. (Greeps can communicate indirectly via the paint spots on the ground.)
  • Rule 5: No long vision. You are allowed to look at the world only at the immediate location of the Greep. Greeps are almost blind, and cannot look any further.
  • Rule 6: No creation of objects. You are not allowed to create any scenario objects (instances of user-defined classes, such as Greep or Paint). Greeps have no magic powers - they cannot create things out of nothing.
  • Rule 7: No tele-porting. Methods from Actor that cheat normal movement (such as setLocation) may not be used.

For today, I would simply like you to:

  1. Download the zip file
  2. Extract the Greeps folder
  3. Examine what the program is doing
  4. Compare what it's doing with the Rules of the scenario
  5. Begin thinking about what sorts of things you could do to make your Greeps more effective
  6. Change the "Anonymous" name to your name in the Greeps code.
The top score average [without violating any of the rules above] will win some sort of Greeps Challenge Trophy -- which I have not yet created.  :)

Friday, March 7, 2014

Assignment Today: Work on Mario Game

Hi Guys!  Okay, I played around with the game code a little bit yesterday.  I added some basic sound effects, corrected the "remove Goomba" after it dies, etc.  I also made a "Mario Sounds" folder on the L: Drive (server) that you can copy over to your Sounds folder.

What I want you to do is begin adding sound, playing around with some of the code, and on Monday we'll add a couple extra features.

Monday, February 24, 2014

Finish Flappy Game...

Finish up your "Flappy Game".  Some of you are doing under water, some are doing flying animals, and some are going in directions that confuse me..  :)

Get some custom characters, an original background, some cool sound effects, or whatever else it takes to make your game YOUR game. 

Tuesday, February 18, 2014

Cute Flappy Bird Hack...

Monday, February 17, 2014

Game: Flappy Dragon

Okay, I know we have one platformer on standby while we started a new platformer -- but today we're going to work on a quick project anyway.  :)

In this project we will be creating a variation on the "Flappy Bird" theme.

Let's start with the MyWorld code which [of course] is a subclass of World:


import greenfoot.*;

public class MyWorld extends World
{
    String[] map = { "lllllllllllllllllllllllll",
                     "t                     s  ",
                     "                         ",
                     "         d               ",
                     "                         ",
                     "                         ",
                     "                         ",
                     "                         ",
                     "                         ",
                     "                       e ",
                     "                         ",
                     "                         ",
                     "                         ",
                     "                         ",
                     "                         ",
                     "                         ",
                     "                         ",
                     "b                        ",
                     "lllllllllllllllllllllllll" };
                     
    public MyWorld()
    {    
        super(800, 608, 1, false); 
        prepare();
    }

    private void prepare()
    {

        for (int i=0; i<map.length; i++) for (int j=0; j<map[i].length(); j++)

            {
            int kind = "dlsebt".indexOf(""+map[i].charAt(j));
            if (kind < 0) continue;
            Actor actor = null;
            if (kind == 0) actor = new Dragon();
            if (kind == 1) actor = new Laser();
            if (kind == 2) actor = new Score();
            if (kind == 3) actor = new Entrance();
            if (kind == 4) actor = new BottomTower();
            if (kind == 5) actor = new TopTower();
            addObject(actor, 16+j*32, 16+i*32);
        }
    }
}

You'll notice that I utilized the same text-based map creator and that we'll be needing Dragon, a Laser, a Score, an Entrance, a BottomTower, and a TopTower.

Here are some images to get you started, but I would like you to come up with your own sprites after we have the basic game set up.  Then you can decide how you will make your game unique.