A personal repository of random information in compensation for a fatigued biological computer
20110108
Jake who is 11, wants to write computer games. But where to start... He found 2 books at library, one on animating with Flash (but required Macromedia tools) and one on Games programming in C++ for teens. But needed something more relevant to now.
Found Java judo. Shame its unsupported now but that gets us up and running as need gratuitious results fast.
JUDO notes:
http://judo.sourceforge.net/docs/JUDOColorValues.html
http://judo.sourceforge.net/docs/JUDOAppAPI.html#graphics
drawCircle(x, y, radius); // where x & y are top left of circle bounding box
delay(0.5) = delay 0.5 seconds
input:
readString()
readInt()
readDouble()
readBoolean()
readColor()
output:
print()
printLine()
====================================
In todays first 3 hr session we covered (with my perception of how much sunk in)
General:
- What is a program? A sequence of instructions that tells the machine what to do
- Machines dumb. Only do what program tells them.
- Programs can run within programs, ie Judo runs within Windows, Skyrim runs within XBox 360 OS (does it?)
- The TV runs a program visible when you use the onscreen menus
Variables:
- what is a variable (80%)
- what is a value (70%)
- data types
- - int (100%)
- - double (100%)
- - string (50%)
- - boolean (100%)
- declaring a variable first (50% but only because need to show compiler erroros if not declared yet)
- assigned a value to a variable (80%)
- - also at declaration time for initial value (50%)
- - assigning a new value to a variable using arithmetic (80%)
output:
- print, println (80%)
- concatenating a "xxx" string with the value of a variable using + (80%)
input: (40%, perhaps conceptual disucssion needed of whats happening while program is waiting at cursor)
- readString()
- readInt()
loops:
- while (question) (50%, only marked low as need to reinforce the fact the code block gets run through each time until no longer true
- infinite loop
- - while (1) (10% need to explain why 1 is true!)
comments:
- - // this is a comment (100%)
Questions:
- if (test) (80% perhaps)
- else (80% perhaps)
Code blocks:
- { .. } (40%)
=================
Still need to explain functions and passing variables
- need longer variable names but at his 2wpm typing speed I shortened them...
=================
Specifically:
Todays goal being to bounce a ball around the screen
- did some println examples
- variable declarations
- int value;
- variable assignment
- value = 5;
- variable reassignment with arithmetic
- value = value + 1;
did some input examples
drew a circle
- set background colour
- set colour
drew a circle using variables for x & y
- x = 5;
- y = 10;
drew a line of overlapping circles
- x = 10;
- inside a while(x < 420) drew a circle, x = x + 2;
drew a line of circles with a delay
- inside each iteration of the while loop above added delay(0.2);
drew a moving circle
- inside each iteration of the while loop above, set pen colour to background and did drawCircle before x = x + 2 to erase previous circle
bounce circle horizontally:
Incrementally:
- add new boolean variable for horizontal direction
- moved erase circle and draw circle from main loop to own functions
- add check for curent direction and add/subtract to/from x accordingly for movement
- add check for right hand side allowing for circle diameter
- add check for left hand side
bounce vertically as well:
Incrementally:
- repeat per horizontal but for vertical..
==============
When we started on the actual bouncing we spent various times on the white board mapping out pseudo code, we also drew the circle and a bounding box to try to explain why we needed to add circle diameter for testing right side and bottom..
And our final program..
void jakeEraseCircle(int cxe, int cye, int cre)
{
setColor(darkGoldenrod);
drawCircle(cxe, cye, cre);
}
void jakeDrawCircle(int cxd, int cyd, int crd)
{
setColor(orange);
drawCircle(cxd, cyd, crd);
delay(0.005);
}
void main() {
int cx = 8;
int cy = 5;
boolean cright = true; // true = going right, false = left
boolean cdown = true; // true = going down, false = up
int cradius = 30;
setBackgroundColor(darkGoldenrod);
while(true)
{
// move
jakeEraseCircle(cx, cy, cradius);
if (cright)
cx = cx + 2;
else
cx = cx - 2;
if (cdown)
cy = cy + 2;
else
cy = cy - 2;
jakeDrawCircle(cx, cy, cradius);
// check right
if (cx + (2 * cradius) >= 500)
cright = false;
// check left
if (cx <= 0)
cright =true;
//check down
if (cy + (2 *cradius)>=400)
cdown = false;
//check up
if (cy <= 0)
cdown =true;
}
}
2013020
void jakeEraseCircle(int cxe, int cye, int cre) { setColor(darkGoldenrod); drawCircle(cxe, cye, cre); } void jakeDrawCircle(int cxd, int cyd, int crd) { setColor(orange); drawCircle(cxd, cyd, crd); delay(0.005); } void main() { int cx = 8; int cy = 5; boolean cright = true; // true = going right, false = left boolean cdown = true; // true = going down, false = up boolean cBigger = true; int cradiusSmall = 5; int cradiusBig = 40; int cradius = cradiusSmall; setBackgroundColor(darkGoldenrod); // getColor(red, green, blue) 0-255 while(true) { // move jakeEraseCircle(cx, cy, cradius); if (cright) cx = cx + 1; else cx = cx - 1; if (cdown) cy = cy + 1; else cy = cy - 1; if (cBigger) cradius = cradius + 1; else cradius = cradius - 1; jakeDrawCircle(cx, cy, cradius); // check right if (cx + (2 * cradius) >= 500) cright = false; // check left if (cx <= 0) cright =true; //check down if (cy + (2 *cradius)>=400) cdown = false; //check up if (cy <= 0) cdown =true; // check biggest if (cradius >= cradiusBig) cBigger = false; if (cradius <= cradiusSmall) cBigger = true; } }