Quantcast
Channel: I Teach History: Programming
Viewing all 51 articles
Browse latest View live

Article 24

$
0
0
Today we are adding "shooting" to our game. This is our "ShootingManager" class from today:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class ShootingManager here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ShootingManager extends Actor
{
/**
* Act - do whatever the ShootingManager wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
killBadGuys();
}

public void remove()
{
Actor walls = getOneIntersectingObject(Platform.class);
if(getX() <=1 || getX() >= getWorld().getWidth() -1)
{
getWorld().removeObject(this);
}
else if(walls != null)
{
getWorld().removeObject(this);
}
}

public boolean amIshot(Class clss)
{
Actor actor = getOneObjectAtOffset(0,0, clss);
return actor !=null;
}

public void kill(Class clss)
{
Actor actor = getOneObjectAtOffset(0,0, clss);
if(actor != null)
{
getWorld().removeObject(actor);
}
}

public void killBadGuys()
{
if(amIshot(BadGuys.class))
{
kill(BadGuys.class);
getWorld().removeObject(this);
}
else
{
remove();
}
}
}
And here is the current Player code:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class Player here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player extends Actor
{
private int vSpeed = 0;
private int acceleration = 1;
private boolean jumping;
private int jumpStrength = 16;
private int speed = 4;

private int direction = 1; // 1 = right and -1 = left
private int shootingCounter = 20; // Delay shooting

private GreenfootImage run1r = new GreenfootImage("run1r.png");
private GreenfootImage run2r = new GreenfootImage("run2r.png");
private GreenfootImage run3r = new GreenfootImage("run3r.png");
private GreenfootImage run4r = new GreenfootImage("run4r.png");
private GreenfootImage run1l = new GreenfootImage("run1l.png");
private GreenfootImage run2l = new GreenfootImage("run2l.png");
private GreenfootImage run3l = new GreenfootImage("run3l.png");
private GreenfootImage run4l = new GreenfootImage("run4l.png");
private int frame = 1;
private int animationCounter = 0;

/**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkFall();
checkKey();
platformAbove();
checkRightWalls();
checkLeftWalls();
shooting();
shootingCounter --;
animationCounter++;
}

public void checkKey()
{
if(Greenfoot.isKeyDown("up") && jumping == false)
{
jump();
}
if(Greenfoot.isKeyDown("right"))
{
direction = 1;
moveRight();
}
if(Greenfoot.isKeyDown("left"))
{
direction = -1;
moveLeft();
}
}

public boolean shooting()
{
if(Greenfoot.isKeyDown("space") && shootingCounter <= 0 && direction ==1)
{
getWorld().addObject(new ShootRight(), getX(), getY());
shootingCounter = 20;
return true;
}
if(Greenfoot.isKeyDown("space") && shootingCounter <= 0 && direction ==-1)
{
getWorld().addObject(new ShootLeft(), getX(), getY());
shootingCounter = 20;
return true;
}
return false;
}

public void moveRight()
{
setLocation(getX()+speed, getY());
if(animationCounter % 4 == 0)
{
animateRight();
}
}

public void animateRight()
{
if(frame == 1)
{
setImage(run1r);
}
else if(frame == 2)
{
setImage(run2r);
}
else if(frame == 3)
{
setImage(run3r);
}
else if(frame == 4)
{
setImage(run4r);
frame = 1;
return;
}
frame++;
}

public void moveLeft()
{
setLocation(getX()-speed, getY());
if(animationCounter %4 == 0)
{
animateLeft();
}
}

public void animateLeft()
{
if(frame == 1)
{
setImage(run1l);
}
else if(frame == 2)
{
setImage(run2l);
}
else if(frame == 3)
{
setImage(run3l);
}
else if(frame == 4)
{
setImage(run4l);
frame = 1;
return;
}
frame++;
}

public boolean platformAbove()
{
int spriteHeight = getImage().getHeight();
int yDistance = (int)(spriteHeight/-2);
Actor ceiling = getOneObjectAtOffset(0, yDistance, Platform.class);
if(ceiling != null)
{
vSpeed = 1;
bopHead(ceiling);
return true;
}
else
{
return false;
}
}

public boolean checkRightWalls()
{
int spriteWidth = getImage().getWidth();
int xDistance = (int)(spriteWidth/2);
Actor rightWall = getOneObjectAtOffset(xDistance, 0, Platform.class);
if(rightWall == null)
{
return false;
}
else
{
stopByRightWall(rightWall);
return true;
}
}

public void stopByRightWall(Actor rightWall)
{
int wallWidth = rightWall.getImage().getWidth();
int newX = rightWall.getX() - (wallWidth + getImage().getWidth())/2;
setLocation(newX - 5, getY());

}

public boolean checkLeftWalls()
{
int spriteWidth = getImage().getWidth();
int xDistance = (int)(spriteWidth/-2);
Actor leftWall = getOneObjectAtOffset(xDistance, 0, Platform.class);
if(leftWall == null)
{
return false;
}
else
{
stopByLeftWall(leftWall);
return true;
}
}

public void stopByLeftWall(Actor leftWall)
{
int wallWidth = leftWall.getImage().getWidth();
int newX = leftWall.getX() + (wallWidth + getImage().getWidth())/2;
setLocation(newX + 5, getY());

}

public void bopHead(Actor ceiling)
{
int ceilingHeight = ceiling.getImage().getHeight();
int newY = ceiling.getY() + (ceilingHeight + getImage().getHeight())/2;
setLocation(getX(), newY);
}

public void fall()
{
setLocation(getX(), getY() + vSpeed);
if(vSpeed <=9)
{
vSpeed = vSpeed + acceleration;
}
jumping = true;
}

public boolean onGround()
{
int spriteHeight = getImage().getHeight();
int yDistance = (int)(spriteHeight/2) + 5;
Actor ground = getOneObjectAtOffset(0, getImage().getHeight()/2, Platform.class);
if(ground == null)
{
jumping = true;
return false;
}
else
{
moveToGround(ground);
return true;
}
}

public void moveToGround(Actor ground)
{
int groundHeight = ground.getImage().getHeight();
int newY = ground.getY() - (groundHeight + getImage().getHeight())/2;
setLocation(getX(), newY);
jumping = false;
}


public void checkFall()
{
if(onGround())
{
vSpeed = 0;
}
else
{
fall();
}
}

public void jump()
{
vSpeed = vSpeed - jumpStrength;
jumping = true;
fall();
}
}


Continuing the Platformer

$
0
0
I modified the "Player" code so that the player has to pick up a key before being able to exit through the door:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class Player here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player extends Actor
{
private int vSpeed = 0;
private int acceleration = 1;
private boolean jumping;
private int jumpStrength = 16;
private int speed = 4;
private boolean haskey;

private int direction = 1; // 1 = right and -1 = left
private int shootingCounter = 20; // Delay shooting

private GreenfootImage run1r = new GreenfootImage("run1r.png");
private GreenfootImage run2r = new GreenfootImage("run2r.png");
private GreenfootImage run3r = new GreenfootImage("run3r.png");
private GreenfootImage run4r = new GreenfootImage("run4r.png");
private GreenfootImage run1l = new GreenfootImage("run1l.png");
private GreenfootImage run2l = new GreenfootImage("run2l.png");
private GreenfootImage run3l = new GreenfootImage("run3l.png");
private GreenfootImage run4l = new GreenfootImage("run4l.png");
private int frame = 1;
private int animationCounter = 0;

/**
* Act - do whatever the Player wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkKey();
checkFall();
shooting();
platformAbove();
checkRightWalls();
checkLeftWalls();
grab();
exit();
shootingCounter --;
animationCounter++;
}

public void checkKey()
{
if(Greenfoot.isKeyDown("right"))
{
direction = 1;
moveRight();
}
if(Greenfoot.isKeyDown("left"))
{
direction = -1;
moveLeft();
}
if(Greenfoot.isKeyDown("up") && jumping == false)
{
jump();
}
}

public boolean shooting()
{
if(Greenfoot.isKeyDown("space") && shootingCounter <= 0 && direction ==1)
{
getWorld().addObject(new ShootRight(), getX(), getY());
shootingCounter = 20;
return true;
}
if(Greenfoot.isKeyDown("space") && shootingCounter <= 0 && direction ==-1)
{
getWorld().addObject(new ShootLeft(), getX(), getY());
shootingCounter = 20;
return true;
}
return false;
}

public void moveRight()
{
setLocation(getX()+speed, getY());
if(animationCounter % 4 == 0)
{
animateRight();
}
}

public void animateRight()
{
if(frame == 1)
{
setImage(run1r);
}
else if(frame == 2)
{
setImage(run2r);
}
else if(frame == 3)
{
setImage(run3r);
}
else if(frame == 4)
{
setImage(run4r);
frame = 1;
return;
}
frame++;
}

public void moveLeft()
{
setLocation(getX()-speed, getY());
if(animationCounter %4 == 0)
{
animateLeft();
}
}

public void animateLeft()
{
if(frame == 1)
{
setImage(run1l);
}
else if(frame == 2)
{
setImage(run2l);
}
else if(frame == 3)
{
setImage(run3l);
}
else if(frame == 4)
{
setImage(run4l);
frame = 1;
return;
}
frame++;
}

public boolean platformAbove()
{
int spriteHeight = getImage().getHeight();
int yDistance = (int)(spriteHeight/-2);
Actor ceiling = getOneObjectAtOffset(0, yDistance, Platform.class);
if(ceiling != null)
{
vSpeed = 1;
bopHead(ceiling);
return true;
}
else
{
return false;
}
}

public boolean checkRightWalls()
{
int spriteWidth = getImage().getWidth();
int xDistance = (int)(spriteWidth/2);
Actor rightWall = getOneObjectAtOffset(xDistance, 0, Platform.class);
if(rightWall == null)
{
return false;
}
else
{
stopByRightWall(rightWall);
return true;
}
}

public void stopByRightWall(Actor rightWall)
{
int wallWidth = rightWall.getImage().getWidth();
int newX = rightWall.getX() - (wallWidth + getImage().getWidth())/2;
setLocation(newX - 5, getY());

}

public boolean checkLeftWalls()
{
int spriteWidth = getImage().getWidth();
int xDistance = (int)(spriteWidth/-2);
Actor leftWall = getOneObjectAtOffset(xDistance, 0, Platform.class);
if(leftWall == null)
{
return false;
}
else
{
stopByLeftWall(leftWall);
return true;
}
}

public void stopByLeftWall(Actor leftWall)
{
int wallWidth = leftWall.getImage().getWidth();
int newX = leftWall.getX() + (wallWidth + getImage().getWidth())/2;
setLocation(newX + 5, getY());
}

public void bopHead(Actor ceiling)
{
int ceilingHeight = ceiling.getImage().getHeight();
int newY = ceiling.getY() + (ceilingHeight + getImage().getHeight())/2;
setLocation(getX(), newY);
}

public void fall()
{
setLocation(getX(), getY() + vSpeed);
if(vSpeed <=9)
{
vSpeed = vSpeed + acceleration;
}
jumping = true;
}

public boolean onGround()
{
int spriteHeight = getImage().getHeight();
int yDistance = (int)(spriteHeight/2) + 5;
Actor ground = getOneObjectAtOffset(0, getImage().getHeight()/2, Platform.class);
if(ground == null)
{
jumping = true;
return false;
}
else
{
moveToGround(ground);
return true;
}
}

public void moveToGround(Actor ground)
{
int groundHeight = ground.getImage().getHeight();
int newY = ground.getY() - (groundHeight + getImage().getHeight())/2;
setLocation(getX(), newY);
jumping = false;
}

public void checkFall()
{
if(onGround())
{
vSpeed = 0;
}
else
{
fall();
}
}

public void jump()
{
vSpeed = vSpeed - jumpStrength;
jumping = true;
fall();
}

public void grab()
{
if (canSee(Key.class) )
{
get(Key.class);
haskey = true;
//Greenfoot.playSound("keyfound.wav");
}
}

public void exit()
{
if (canSee(Door.class) && haskey == true)
{
// Open door / Exit to new level
haskey = false; // Use key from inventory
//Greenfoot.playSound("keyfound.wav");
}
}

/**
* Return true if we can see an object of class 'clss' right where we are.
* False if there is no such object here.
*/
public boolean canSee(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
return actor != null;
}

/**
* Try to grab an object of class 'clss'. This is only successful if there
* is such an object where we currently are. Otherwise this method does
* nothing.
*/
public void get(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
if(actor != null) {
getWorld().removeObject(actor);
}
}
}
I also added some code to the "BadGuys" superclass so that I could use "cansee" and "eat" (which I changed to "get"):
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class BadGuys here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class BadGuys extends Actor
{
/**
* Act - do whatever the BadGuys wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}

/**
* Return true if we can see an object of class 'clss' right where we are.
* False if there is no such object here.
*/
public boolean canSee(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
return actor != null;
}

/**
* Try to grab an object of class 'clss'. This is only successful if there
* is such an object where we currently are. Otherwise this method does
* nothing.
*/
public void get(Class clss)
{
Actor actor = getOneObjectAtOffset(0, 0, clss);
if(actor != null) {
getWorld().removeObject(actor);
}
}
}

Adjusting the World in Platformer

$
0
0
The top of the MyWorld code looks like this:


import greenfoot.*;

public class MyWorld extends World
{
/** MAP LEGEND **/
// b = block m = monster
// p = platform k = key
// w = wall c = character (player)
// d = door

String[] map = { "",
"d m c m ",
"ppp ",
"",
"",
" pp ",
" k ",
" ppppppppp ",
"",
" pp ",
" m ",
" m ",
" pppp m ",
" ppppp ",
" ppp ",
"",
" m m ",
" w w ",
"bbbbbbbbbbbbbbbbbbbbbbbbb" };

public MyWorld()
{
super(800, 600, 1, false); // Set world size
prepare();
}
private void prepare()
{
The next piece looks like this (I can't seem to paste it as code:

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

And then this piece:

{
int kind = "cbpwmdk".indexOf(""+map[i].charAt(j)); // All "kinds" in order
if (kind < 0) continue;
Actor actor = null;
if (kind == 0) actor = new Player();
if (kind == 1) actor = new Block();
if (kind == 2) actor = new Platform2();
if (kind == 3) actor = new Wall();
if (kind == 4) actor = new Monster();
if (kind == 5) actor = new Door();
if (kind == 6) actor = new Key();
addObject(actor, 16+j*32, 16+i*32); // Start at pixel 16 and add objects at 32 pixel increments
}
}
}

Beginning a New Game: The Mario Platformer Scroller

$
0
0
Today we are going to begin a new game using methods and classes similar to our Platformer. This time we'll be covering some new methods -- including setting the background colors, showing mirror images of graphics, setting up a separate Start Screen, having levels, and telling the program the "scale" of the graphics we use. While we work through this scenario, try to keep the layout, format, and images that I use. We will be customizing them after we are done, but let's avoid unnecessary delays while we work though this. It can be a fairly dense, complicated code at times and it's much easier to find our errors if we're all looking for the same image names, class names, etc.

Starting a New Platformer: Mario! (Part 1)

$
0
0
We're going to build a new scrolling platformer, but this time we're taking it old-school and recreating a Mario game.



  1. Create a New Scenario
  2. Go to Scenario > Scenario Information
    1. Edit the contents of the Readme
  3. Save the Mario images to your Images folder.
  4. Copy the Counter Class (below)
  5. Create a series of new classes (see right)
  6. Edit the Levels class to be 1050x500
import greenfoot.*;  
import java.awt.Color;
import java.awt.Font;

/**
* Generic counter class, it is used to count statistics such as remaining lives, number of coins and amount of points.
* @author
* @version 1.1
*/
public class Counter extends Actor
{
private static final Color TRANSPARENT = new Color(0, 0, 0, 0);
public int value;
private Color textColor = Color.WHITE;
protected int target;
private String prefix;

public Counter()
{
value = 0;
target = 0;
this.prefix = prefix;
updateImage();
GreenfootImage image = getImage();
Font font = image.getFont();
}

public void act()
{
if (value < target) {
value++;
updateImage();
}
else if (value > target) {
value--;
updateImage();
}
}

private void updateImage()
{
int fontSize =24;
setImage(new GreenfootImage(prefix+""+value, fontSize, textColor, TRANSPARENT));
}

public void setTextColor(Color color)
{
textColor = color;
updateImage();
}

public void setPrefix(String text)
{
prefix = text;
updateImage();
}

public Counter(String text)
{
prefix = text;
updateImage();
}

public void add(int score)
{
target += score;
updateImage();
}

public void subtract(int score)
{
target -= score;
updateImage();
}

public void setValue(int newValue)
{
target = newValue;
value = newValue;
updateImage();
}

public int getValue()
{
return target;
}
}
Open your Mario class and add the following method before the "Act" method:

private final GreenfootImage idle = new GreenfootImage("mario-idle.gif");
public Mario()
{
setImage(idle);
idle.scale(38,50);
}
Next, close the Mario class and Compile your code. Now, add a new Mario to your empty world.

Scrolling Mario Platformer (Part 2)

$
0
0
Open the Mover class, and replace everything inside the "public class Mover extends Actor" with:
protected int speed;
Next, we will add some move methods.

protected int speed;

/**
* Move an object to the right
*/
protected void moveRight()
{
setLocation (getX() + speed, getY());
}
/**
* Move an object to the left
*/
protected void moveLeft()
{
setLocation (getX() - speed, getY());
}

Next we want to adjust the Mario class so that he idles facing left or right:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class Mario here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Mario extends Mover
{
private final GreenfootImage idleRight = new GreenfootImage("mario-idle.gif");
private final GreenfootImage idleLeft = new GreenfootImage(idleRight);

public Mario()
{
this.speed = 7;

setImage(idleRight);
idleRight.scale(38,50);

idleLeft.scale(38,50);
idleLeft.mirrorHorizontally();

}

/**
* Act - do whatever the Mario wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkKeys();
}

/**
* This method checks which key has been pressed and then responds with an action.
*/
private void checkKeys()
{
if (Greenfoot.isKeyDown("right"))
{
walkRight();
}
else if (Greenfoot.isKeyDown("left"))
{
walkLeft();
}
}

/**
* Moves Mario right and applies the right-facing images.
*/
private void walkRight()
{
moveRight();
setImage(idleRight);
}
/**
* Moves Mario left and applies the left-facing images.
*/
private void walkLeft()
{
moveLeft();
setImage(idleLeft);
}
}

Scrolling Mario Platformer (Part 3)

$
0
0
Now that we have a Mario that will run back and forth, it's time to do some fine-tuning. Here we will make sure the player isn't trying to move if they are pressing both the Left AND Right keys:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class Mario here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Mario extends Mover
{
private final GreenfootImage idleRight = new GreenfootImage("mario-idle.gif");
private final GreenfootImage walk1Right = new GreenfootImage("mario-walk1.gif");
private final GreenfootImage walk2Right = new GreenfootImage("mario-walk2.gif");
private final GreenfootImage walk3Right = new GreenfootImage("mario-walk3.gif");

private final GreenfootImage idleLeft = new GreenfootImage(idleRight);
private final GreenfootImage walk1Left = new GreenfootImage(walk1Right);
private final GreenfootImage walk2Left = new GreenfootImage(walk2Right);
private final GreenfootImage walk3Left = new GreenfootImage(walk3Right);

private boolean facingRight;
private boolean isKeyPressed;

public Mario()
{
this.speed = 7;
this.facingRight = true;

setImage(idleRight);

idleRight.scale(38,50);
walk1Right.scale(48,50);
walk2Right.scale(36,50);
walk3Right.scale(44,50);

idleLeft.scale(38,50);
walk1Left.scale(48,50);
walk2Left.scale(36,50);
walk3Left.scale(44,50);

idleLeft.mirrorHorizontally();
walk1Left.mirrorHorizontally();
walk2Left.mirrorHorizontally();
walk3Left.mirrorHorizontally();
}

/**
* Act - do whatever the Mario wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
checkKeys();
}

/**
* Checks keys and responds with an action
*/
private void checkKeys()
{
isKeyPressed = false;

if (Greenfoot.isKeyDown("right") && Greenfoot.isKeyDown("left"))
{
stopWalking();
}
else if (Greenfoot.isKeyDown("right"))
{
animationCounter ++;
walkRight();
isKeyPressed = true;
facingRight = true;
}
else if (Greenfoot.isKeyDown("left"))
{
animationCounter ++;
walkLeft();
isKeyPressed = true;
}
if (!isKeyPressed)
{
stopWalking();
}
}

/**
* Moves Mario right and applies the right-facing images.
*/
private void walkRight()
{
moveRight();
if(animationCounter < 4)
{
setImage(idleRight);
}
else if(animationCounter < 8)
{
setImage(walk1Right);
}
else if(animationCounter < 12)
{
setImage(walk2Right);
}
else if(animationCounter < 16)
{
setImage(walk3Right);
animationCounter = 0;
return;
}
}

/**
* Moves Mario left and applies the left-facing images.
*/
private void walkLeft()
{
moveLeft();
if(animationCounter < 4)
{
setImage(idleLeft);
}
else if(animationCounter < 8)
{
setImage(walk1Left);
}
else if(animationCounter < 12)
{
setImage(walk2Left);
}
else if(animationCounter < 16)
{
setImage(walk3Left);
animationCounter = 0;
return;
}
}

/**
* Stop Mario from walking and apply correct idle image.
*/
private void stopWalking()
{
}
}
And the Mover class:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class Mover here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Mover extends Actor
{
protected int speed;
protected int animationCounter;

/**
* Move an object to the right
*/
protected void moveRight()
{
setLocation (getX() + speed, getY());
}
/**
* Move an object to the left
*/
protected void moveLeft()
{
setLocation (getX() - speed, getY());
}
}

Mario Game Assets


Game: Flappy Dragon

$
0
0
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.

Cute Flappy Bird Hack...

Finish Flappy Game...

$
0
0
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. 

Assignment Today: Work on Mario Game

$
0
0
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.

Quarter Final: Greeps Challenge

$
0
0
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.  :)

Beginning with the Eclipse IDE

$
0
0
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:

Continuing with Eclipse: New Territory Explored

$
0
0
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.

Where We Are in Eclipse

$
0
0
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) {
}
}
}

Soldiering on with Eclipse...

$
0
0
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
}
}

Guest Speaker: Academy of Art University

$
0
0
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.

Eclipse Part 5: Buffer Strategy

Eclipse: Graphics Initialization, Buffered Images & Rasters

$
0
0
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.


Viewing all 51 articles
Browse latest View live


Latest Images