Attendance: 

Alex D, Jeremy B, Chris N, Thomas A, Clayton T, Samy R, Maro R, Laura H, 
Nick F, Jiachen W, Adam K, Seth W, Jay K, Josh P, Biao Z, Yangjun L, Steve B,
Santiago S, Anna McN, Andrew D, Peng Pong C, Rodrigo Manuel V, Rishu S, Dimas, 
Donovan M, Josh M, Scott M, Tian J, Yongtao Chu, Alex T, Ryan P, Joel P, Tony,
Austin M, Yingzhen, Zhengyu, Megan, Nikita, Ethan Y, Morgan N, Cheng C, Qin N,
Brad V, Sam Lee B (excused), Sam Robert McKay, Jordan G (*), Quintin L, Danny N., 
Wonyong H. (Mr. Hao -- excused).

C211: 

http://www.cs.indiana.edu/classes/c211-dgerman/sum2014/hwFive.html

https://cdn1.iconfinder.com/data/icons/all_google_icons_symbols_by_carlosjj-du/128/spaceship.png

(require 2htdp/image)
(require 2htdp/universe)

(define spaceship (circle 30 "solid" "blue"))

(define (render world) 
  (place-image spaceship 150 world (empty-scene 400 400)))

(define (main initial) ; a world is here just a number
  (big-bang initial
            (on-tick sub1) ; taking off
            (to-draw render)
            (on-key (lambda (world key) 0))
            (stop-when zero?)))

(main 325)

I would like to move the spaceship in two dimensions. 

(require 2htdp/universe)

(define spaceship (circle 30 "solid" "blue"))

(define (render world) 
  (place-image spaceship 150 world (empty-scene 400 400)))

(define (main initial) ; a world is here just a number
  (big-bang initial
            (on-tick sub1) ; taking off
            (to-draw render)
            (on-key (lambda (world key) 
                      (cond ((equal? key "up"   ) (sub1 world))
                            ((equal? key "down" ) (+ 2 world))
                            ((equal? key "left" ) world)
                            ((equal? key "right") world)
                            (else world))))
            (stop-when zero?)))

(main 325)


This only modifies position on the vertical. 

What do I need for movement on the horizontal? 

(require 2htdp/image)
(require 2htdp/universe)

(define-struct world (x y))

(define spaceship (circle 30 "solid" "blue"))

(define (render world) 
  (place-image spaceship (world-x world) (world-y world) (empty-scene 400 400)))

(define (main initial) ; a world is here just a number
  (big-bang initial
            (on-tick (lambda (world) world)) 
            (to-draw render)
            (on-key (lambda (world key) 
                      (cond ((equal? key "up"   ) (make-world (world-x world) (sub1 (world-y world))))
                            ((equal? key "down" ) (make-world (world-x world) (add1 (world-y world))))
                            ((equal? key "left" ) (make-world (sub1 (world-x world)) (world-y world)))
                            ((equal? key "right") (make-world (add1 (world-x world)) (world-y world)))
                            (else world))))
            (stop-when (lambda (world) false))))

(main (make-world 200 325))

I need to add momentum and/or and a scoreboard. 

(require 2htdp/image)
(require 2htdp/universe)

(define-struct world (x y vx vy))

(define spaceship (circle 30 "solid" "blue"))

(define (render world) 
  (place-image
   (text (string-append "(" (number->string (world-x world)) ", " (number->string (world-y world)) ")") 
         24 
         "Olive") 
   100 100 
   (place-image spaceship (world-x world) (world-y world) (empty-scene 400 400))))

(define (main initial) ; a world is here just a number
  (big-bang initial
            (on-tick (lambda (world)
                       (make-world (+ (world-vx world) (world-x world))
                                   (+ (world-vy world) (world-y world))
                                   (world-vx world)
                                   (world-vy world))))
            (to-draw render)
            (on-key (lambda (world key) 
                      (cond ((equal? key "up"   ) (make-world (world-x world) 
                                                              (world-y world) 
                                                              (world-vx world)
                                                              (sub1 (world-vy world))))
                            ((equal? key "down" ) (make-world (world-x world) 
                                                              (world-y world) 
                                                              (world-vx world)
                                                              (add1 (world-vy world))))
                            ((equal? key "left" ) (make-world (world-x world) 
                                                              (world-y world) 
                                                              (sub1 (world-vx world))
                                                              (world-vy world)))
                            ((equal? key "right") (make-world (world-x world) 
                                                              (world-y world) 
                                                              (add1 (world-vx world))
                                                              (world-vy world)))
                            (else world))))
            (stop-when (lambda (world) false))))

(main (make-world 200 200 1 1))

Now let's see what we need to do in Java.

import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 

class BigBang extends JComponent implements KeyListener, ActionListener {
  Timer timer;
  World world; 
  BigBang(int delay, World world) {
    this.world = world; 
    this.timer = new Timer(delay, this); 
  }
  BigBang(World world) {
     this(1000, world);
  }
  public void start() {
    this.timer.start();  
  }
  public void actionPerformed(ActionEvent e) {
    world.update();  
    if (world.done()) 
      this.timer.stop(); 
  }
  public void keyPressed (KeyEvent e) { } 
  public void keyReleased(KeyEvent e) { } 
  public void keyTyped   (KeyEvent e) { } 
  public void paintComponent(Graphics g) {
    world.draw(g);  
  }
}

import java.awt.*;

class World {
  public void update() { 
    System.out.println("I am getting older."); 
  } 
  public void draw(Graphics g) { } 
  public boolean done() { return false; }
}

import javax.swing.*;
import java.awt.event.*; 

class Game extends BigBang {
  Game(World world) {
    super(world);  
  }
  public void keyPressed(KeyEvent e) {
    System.out.println("Ouch");  
  }
  public static void main(String[] args) {
    JFrame f = new JFrame("Lab this week"); 
    f.setVisible(true);
    f.setSize(400, 400); 
    Game g = new Game(new World()); 
    f.getContentPane().add( g ); 
    f.addKeyListener(g); 
    g.start(); 
  }
}

--