David L   , Nick Palumbo, Kevin S , Grant M , Minh T   , K. Kitano, Joe 
Chen T    , Brandon L   , Taylor S, Connor H, Mahamat A, Brian M  , Nick Palmer 
Danielle Z, Erin S.     , Shikun D, Shane B , Ben B    , Haleigh E, Michael 

Rooms for the final have been determined. 

I will post a list of names indicating who goes where soon. 

Lab this week starts this way: 

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

https://s-media-cache-ak0.pinimg.com/736x/cb/1a/b3/cb1ab323a41521e6db985afaad16ccfc.jpg

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

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

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

(define (main initial)
  (big-bang initial 
            (on-tick (lambda (world) world))
            (on-key (lambda (world key) world))
            (stop-when (lambda (world) false))
            (to-draw render)))

(main 150)

Let's make things happen.

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

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

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

(define (main initial)
  (big-bang initial 
            (on-tick sub1) ; (lambda (world) (sub1 world)))
            (on-key (lambda (world key) 0)) ; world))
            (stop-when zero?) ; (lambda (world) false))
            (to-draw render)))

(main 150)

Can we change the position of the spaceship with the keys? 

(require 2htdp/universe)

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

(define-struct world (x y)) 

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

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

(main (make-world 150 150))

How do I make it like I am in a field of forces?


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

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

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

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

(define (main initial)
  (big-bang initial 
            (on-tick (lambda (world) (make-world (+ (world-x world) (world-vx world))
                                                 (+ (world-y world) (world-vy world))
                                                 (world-vx world)
                                                 (world-vy world))))
            (on-key (lambda (world key)
                      (cond ((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)))
                            ((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))))
                            (else world))))
            (stop-when (lambda (world) false))
            (to-draw render)))

(main (make-world 150 150 -1 1))

--

How do I do this in Java? 

http://silo.cs.indiana.edu:8346/c212/spr2015/tetris.rkt

Here's the BigBang: 

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

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

Here's the basic world (should this be an interface?)

import java.awt.*; 

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

And here's the simplest game: 

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

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

It looks like Tetris already, without the game play. 

In lab implement/port the ISL exercises to this framework.

--