Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <draw.h>
4
#include <event.h>
5
 
6
#include "sokoban.h"
7
 
8
void
9
drawscreen(void)
10
{
11
	draw(screen, screen->r, img, nil, ZP);
12
	flushimage(display, 1);
13
}
14
 
15
void
16
drawglenda(void)
17
{
18
	Rectangle r;
19
	Point p;
20
 
21
	p = level.glenda;
22
	p.x *= BoardX;
23
	p.y *= BoardY;
24
	/* leave some room from the edge of the window */
25
	p = addpt(p, Pt(1, 1));
26
 
27
	r = Rpt(p, Pt(p.x + BoardX, p.y+BoardY));
28
	draw(img, r, glenda, nil, ZP);
29
}
30
 
31
void
32
drawwin(void)
33
{
34
	Rectangle r;
35
	Point p;
36
 
37
	p = level.glenda;
38
	p.x *= BoardX;
39
	p.y *= BoardY;
40
	p = addpt(p, Pt(6, 6));
41
	p = addpt(p, Pt(1, 1));
42
 
43
	r = Rpt(p, Pt(p.x + BoardX, p.y+BoardY));
44
	draw(img, r, text, win, ZP);
45
}
46
 
47
void
48
drawboard(Point p)
49
{
50
	Rectangle r;
51
	uint square = level.board[p.x][p.y];
52
 
53
	p.x *= BoardX;
54
	p.y *= BoardY;
55
 
56
	/* leave some room from the edge of the window */
57
	p = addpt(p, Pt(1, 1));
58
 
59
	r = Rpt(p, Pt(p.x + BoardX, p.y+BoardY));
60
 
61
	switch(square) {
62
	case Background:
63
		draw(img, r, bg, nil, ZP);
64
		break;
65
	case Empty:
66
		draw(img, r, empty, nil, ZP);
67
		break;
68
	case Wall:
69
		draw(img, r, wall, nil, ZP);
70
		break;
71
	case Cargo:
72
		draw(img, r, cargo, nil, ZP);
73
		break;
74
	case Goal:
75
		draw(img, r, goal, nil, ZP);
76
		break;
77
	case GoalCargo:
78
		draw(img, r, goalcargo, nil, ZP);
79
		break;
80
	}
81
}
82
 
83
void
84
resize(Point p)
85
{
86
	/* resize to the size of the current level */
87
 
88
	int fd;
89
 
90
	fd = open("/dev/wctl", OWRITE);
91
	if(fd >= 0){
92
		fprint(fd, "resize -dx %d -dy %d", p.x*BoardX+10, p.y*BoardY+10);
93
		close(fd);
94
	}
95
 
96
}
97
 
98
Point
99
boardsize(Point p)
100
{
101
	return Pt(p.x*BoardX+2, p.y*BoardY+2);
102
}
103
 
104
void
105
drawlevel(void)
106
{
107
	int x, y;
108
 
109
	resize(level.max);
110
 
111
	if(img)
112
		freeimage(img);
113
	img = eallocimage(Rpt(Pt(0, 0), boardsize(level.max)), 0, 0);	
114
 
115
	draw(img, insetrect(img->r, 1), empty, nil, ZP);
116
 
117
	for(x = 0; x < MazeX; x++) {
118
		for(y = 0; y < MazeY; y++) {
119
			drawboard(Pt(x, y));
120
		}
121
	}
122
 
123
	drawglenda();
124
}