OHH! Those were helpful for me too. But more questions has been discovered. Form the "Board" class.
1. What does "addArray" method do?
2. What does this line "System.arraycopy(snake, 0, newSnake, 0, snake.length);" mean?
3. What the sign "<>" is used and what the line "List<Item> item = getObjects(Item.class);" does actually?
From the "Item" class:
1. by referring this line "Actor item = getOneIntersectingObject(Wall.class);"- why "Wall.class" is used to get an intersecting object? Souldn't it be "Snake.class"?
Okay!! Thanks! Can you please explain these codes in your ball class for me ? (is given below):
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Ball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Ball extends Actor
{
/**
* Act - do whatever the Ball wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
//double power = 30;
//private double angle = 30;
private double h0 = 1;
private double h = h0;
private double tStart;
private double xStart;
private double yStart;
private double g = 30;
private double SCALE = 7;
double v0y;
double v0x;
private boolean first = true;
public Ball(int angle, int power)
{
v0y = power * Math.sin(Math.toRadians(angle));
v0x = power * Math.cos(Math.toRadians(angle));
}
public void act()
{
if(first)
{
first = !first;
tStart = System.currentTimeMillis();
xStart = getX();
yStart = getY();
} else {
double t = (System.currentTimeMillis() -tStart) / 1000;
h = h0 +(v0y*t) - ( (g*t*t) / 2);
setLocation((int)(xStart + SCALE * (v0x*t)),(int)(yStart - SCALE *h));
}
removeBall();
}
public void removeBall()
{
World background = getWorld();
if (getY() > background.getHeight())
{
background.removeObject(this);
}
}
}
Question 1:
Why do we need "private double" here?
2:
"private boolean first = true"- what is this for?
3:
first = !first;
tStart = System.currentTimeMillis();-
what does those codes mean? and what does "TimeMillis" do here?
2012/11/22
Lab 6 – Snake
2012/11/18
Snake
2012/11/10
Lab 5 – Shot from a cannon
2012/11/9
Lab 5 – Shot from a cannon
2012/11/9
Lab 5 – Shot from a cannon
2012/11/9
Lab 5 – Shot from a cannon