Exemplo n.º 1
0
func (m *SpacewarPDP1) Init(ctxt draw.Context) {
	m.ctxt = ctxt
	m.kc = ctxt.KeyboardChan()
	m.screen = ctxt.Screen()
	m.dx = m.screen.Width()
	m.dy = m.screen.Height()
	m.colorModel = m.screen.ColorModel()
	m.pix = make([][]uint8, m.dy)
	for i := range m.pix {
		m.pix[i] = make([]uint8, m.dx)
	}
	m.cmap = make([]image.Color, 256)
	for i := range m.cmap {
		var r, g, b uint8
		r = uint8(min(0, 255))
		g = uint8(min(i*2, 255))
		b = uint8(min(0, 255))
		m.cmap[i] = m.colorModel.Convert(image.RGBAColor{r, g, b, 0xff})
	}
}
Exemplo n.º 2
0
func Play(pp []Piece, ctxt draw.Context) {
	display = ctxt
	screen = ctxt.Screen()
	screenr = draw.Rect(0, 0, screen.Width(), screen.Height())
	pieces = pp
	N = len(pieces[0].d)
	initPieces()
	rand.Seed(int32(time.Nanoseconds() % (1e9 - 1)))
	whitemask = draw.White.SetAlpha(0x7F)
	tsleep = 50
	timerc = time.Tick(int64(tsleep/2) * 1e6)
	suspc = make(chan bool)
	mousec = make(chan draw.Mouse)
	resizec = ctxt.ResizeChan()
	kbdc = make(chan int)
	go quitter(ctxt.QuitChan())
	go suspproc()
	points = 0
	redraw(false)
	play()
}
Exemplo n.º 3
0
func app(inContext draw.Context)
{
    vl_screen := inContext.Screen();

    screenr := draw.Rect(0, 0, vl_screen.Width(), vl_screen.Height());
    draw.Draw(vl_screen, screenr, draw.White, nil, draw.ZP);

    squareSize := 30;

    var cell *SMazeCell = new(SMazeCell);
    cell.draw(inContext, squareSize);

    inContext.FlushImage();

    fmt.Printf("Press the any key to exit.\n");
    for
    {
        select
        {
            case r := <- inContext.KeyboardChan():
                switch r
                {
                    case 'q', 'Q', 0x04, 0x7F, 32 :
                        fmt.Printf("Exiting because of keyboard event %d\n", r);
                        os.Exit(0);
                    default :
                        fmt.Printf("Exiting because of keyboard event %d\n", r);
                }
            case <- inContext.MouseChan():
                // No-op.
            case <- inContext.ResizeChan():
                // No-op.
            case <- inContext.QuitChan():
                fmt.Printf("Exiting because of QuitChan\n");
                return;
        }
    }
}
Exemplo n.º 4
0
func (inpMazeCell *SMazeCell) draw(inContext draw.Context, inSquareSize int)
{
    vl_screen := inContext.Screen();

    upXLeft, upYLeft := 100, 100;
    squareSize := inSquareSize;

    fullCell := draw.Rect(upXLeft, upYLeft, squareSize + upXLeft, squareSize + upYLeft);
    draw.Draw(vl_screen, fullCell, draw.Black, nil, draw.ZP);

    // inset set the color of the inside
    draw.Draw(vl_screen, fullCell.Inset(1), draw.White, nil, draw.ZP);

    //hide a wall with a rectangle... POOR SOLUTION !!
    if inpMazeCell.northOpen
    {
        // up wall
        hiderup := draw.Rect(upXLeft, upYLeft,
                             upXLeft + squareSize, upYLeft + 1);
        draw.Draw(vl_screen, hiderup, draw.White, nil, draw.ZP);
    }
    else
    {
        // do not hide
    }

    if inpMazeCell.westOpen
    {
        // right wall
        hiderright := draw.Rect(upXLeft + squareSize - 1, upYLeft,
                                upXLeft + squareSize, upYLeft + squareSize);
        draw.Draw(vl_screen, hiderright, draw.White, nil, draw.ZP);
    }
    else
    {
        // do not hide
    }

    if inpMazeCell.southOpen
    {
        // down wall
        hiderdown := draw.Rect(upXLeft, upYLeft + squareSize - 1,
                              upXLeft + squareSize, upYLeft + squareSize);
        draw.Draw(vl_screen, hiderdown, draw.White, nil, draw.ZP);
    }
    else
    {
        // do not hide
    }

    if inpMazeCell.eastOpen
    {
        // left wall
        hiderleft := draw.Rect(upXLeft, upYLeft,
                               upXLeft + 1, upYLeft + squareSize);
        draw.Draw(vl_screen, hiderleft, draw.White, nil, draw.ZP);
    }
    else
    {
        // do not hide
    }
}