本文整理汇总了Golang中github.com/0xe2-0x9a-0x9b/Go-SDL/sdl.Surface类的典型用法代码示例。如果您正苦于以下问题:Golang Surface类的具体用法?Golang Surface怎么用?Golang Surface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Surface类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: drawPiece
func drawPiece(s *sdl.Surface, col, row int, p c4.Piece) {
// Load images
if redImage == nil {
redImage = sdl.Load("red.png")
}
if blackImage == nil {
blackImage = sdl.Load("black.png")
}
if noneImage == nil {
noneImage = sdl.Load("empty.png")
}
// Select image
var image *sdl.Surface
if p == c4.Red {
image = redImage
} else if p == c4.Black {
image = blackImage
} else {
image = noneImage
}
// Draw image
s.Blit(
&sdl.Rect{
int16(SCREEN_WIDTH * col / c4.MaxColumns),
int16(SCREEN_HEIGHT * (c4.MaxRows - row - 1) / c4.MaxRows),
0,
0},
image,
nil)
}
开发者ID:TJSomething,项目名称:cs773c-connect4-minimax,代码行数:32,代码来源:main.go
示例2: apply_surface
func apply_surface(x, y int16, src, dest *sdl.Surface) {
var offset sdl.Rect
offset.X = x
offset.Y = y
dest.Blit(&offset, src, nil)
}
开发者ID:pakohan,项目名称:sdl-tutorial,代码行数:8,代码来源:main.go
示例3: undrawColor
func undrawColor(ss *sdl.Surface, w, h int32, col uint32) {
var x, y int32
for y = 0; y < h; y++ {
for x = 0; x < w; x++ {
col := sdlGet(x, y, ss) & (^col)
sdlSet2(x, y, col, ss)
}
}
ss.Flip()
}
开发者ID:radekp,项目名称:alfi,代码行数:11,代码来源:main.go
示例4: wrap
func wrap(cSurface *C.SDL_Surface) *sdl.Surface {
var s *sdl.Surface
if cSurface != nil {
var surface sdl.Surface
surface.SetCSurface(unsafe.Pointer(cSurface))
s = &surface
} else {
s = nil
}
return s
}
开发者ID:Zwobot,项目名称:Go-SDL,代码行数:13,代码来源:ttf.go
示例5: render
func (p *Piece) render(screen *sdl.Surface) {
if p == nil {
return
}
for i := 0; i < 4; i++ {
x := p.pos.x + p.tet.position[p.rot][i].x
y := p.pos.y + p.tet.position[p.rot][i].y
rect := sdl.Rect{
int16(x * PixPerBrick),
int16(y * PixPerBrick),
uint16(PixPerBrick),
uint16(PixPerBrick)}
screen.FillRect(&rect, colorToUint32(colorTable[p.tet.color]))
}
}
开发者ID:phooky,项目名称:golang,代码行数:15,代码来源:tetris.go
示例6: draw_sdl
func draw_sdl(o *Object, s *sdl.Surface) {
var ss *sdl.Surface
if o.Collides {
ss = surfaceb
} else {
ss = surface
}
s.Blit(
&sdl.Rect{int16(float64(o.Pos.X) * ssw),
int16(float64(o.Pos.Y) * ssh),
uint16(float64((o.Pos.X + o.Size.X)) * ssw),
uint16(float64((o.Pos.Y + o.Size.Y)) * ssh)},
ss,
&sdl.Rect{0, 0, uint16(o.Size.X), uint16(o.Size.Y)})
}
开发者ID:MerlijnWajer,项目名称:Gollision,代码行数:16,代码来源:draw.go
示例7: setDist
// Set distance of nearby points (from point ax,ay -> bx,by) in given dir (0=N,
// 1=S, 2=E, 3=W)
func setDist(ss *sdl.Surface, rmc [][]int32, dist [][][]int32, aX, aY, bX, bY, dir, w, h, r, currBestDist, lastSetX, lastSetY int32, done, found bool, round int) (newDone, newFound bool, newBest int32, setX, setY int32) {
newDone, newFound, newBest, setX, setY = done, found, currBestDist, lastSetX, lastSetY
if !inRect(bX, bY, w, h) {
return
}
dA := dist[aX][aY]
_, best := bestDist(dA)
best += 4 * (r + 1) * (r + 1)
if best >= currBestDist { // we alredy have better distance (smaller is better)
return
}
dB := dist[bX][bY]
rmCount := removeCount(ss, rmc, w, h, bX, bY, r)
if currBestDist == DistMax && rmCount > 0 && best < DistMax {
//fmt.Printf("==== found rmCount=%d best=%d bX=%d bY=%d\n", rmCount, best, bX, bY)
newBest = best
newFound = true
}
//fmt.Printf("setDist aX=%d aY=%d bX=%d bY=%d rmCount=%d\n", aX, aY, bX, bY, rmCount)
if best < dB[dir] && rmCount != -1 { // part of model would be removed
if aX&7 == 0 && aY&7 == 0 {
if round > 20 {
fmt.Printf("setDist x=%d y=%d value=%d dB[dir]=%d\n", aX, aY, best, dB[dir])
}
sdlSet(aX, aY, ColDebug, ss)
if aX&63 == 0 && aY&63 == 0 {
ss.Flip()
}
}
dB[dir] = best - rmCount // favourize paths that remove more material
newDone = false
setX, setY = bX, bY
}
return
}
开发者ID:radekp,项目名称:alfi,代码行数:45,代码来源:main.go
示例8: renderLine
func (renderer *SDLRenderer) renderLine(pos int, line string) {
x := renderer.commandLineRect.X
y := int16(renderer.commandLineRect.Y) - int16(renderer.fontHeight*uint(pos))
w := renderer.commandLineRect.W
h := renderer.commandLineRect.H
renderer.internalSurface.FillRect(&sdl.Rect{x, y, w, h}, 0)
if len(line) == 0 {
return
}
var textSurface *sdl.Surface
if renderer.Blended {
textSurface = ttf.RenderUTF8_Blended(renderer.Font, line, renderer.Color)
} else {
textSurface = ttf.RenderUTF8_Solid(renderer.Font, line, renderer.Color)
}
if textSurface != nil {
renderer.internalSurface.Blit(&sdl.Rect{x, y, w, h}, textSurface, nil)
textSurface.Free()
}
}
开发者ID:robert-dale-schell,项目名称:clingon,代码行数:24,代码来源:sdlrenderer.go
示例9: findAndRemove
// Find path from cX,cY to tX,tY so that no part of model is removed
func findAndRemove(ss *sdl.Surface, tc *Tco, rmc [][]int32, cX, cY, w, h, r int32) (bool, bool, int32, int32) {
//fmt.Printf("findPath cX=%d cY=%d tX=%d tY=%d\n", cX, cY, tX, tY)
// The algorithm is flood-fill like:
// For earch pixel we remember shortest distance to target point in 4
// directions (N,S,E,W). Starting at point (tX,tY) all the distances are 0,
// e.g. for (tX+1,cY) the distnace in W is 1, others are 3 etc..
//
//
// S=1
// T W=1 W=2
// N=1 N=3
//
// It works like that: N=3 means if you go N the shortest path to T is 3
// (after going twice west). From the same point it also implies that W=3
// (after going WN), S=5 (e.g. after going NNWW), E=5 (after WNWW).
dist := make([][][]int32, w)
for x := range dist {
dist[x] = make([][]int32, h)
for y := range dist[x] {
if int32(x) == cX && int32(y) == cY {
dist[x][y] = []int32{0, 0, 0, 0, 0, 0, 0, 0} // value for each dir + removeCount for given point
} else {
dist[x][y] = []int32{DistMax, DistMax, DistMax, DistMax, DistMax, DistMax, DistMax, DistMax}
}
}
}
undrawDebug(ss, w, h)
currBestDist := DistMax
found := false
lastSetX, lastSetY := cX, cY
for round := 0; ; round++ {
done := true
var centerX, centerY int32
undrawBlue(ss, w, h)
//drawLine(ss, rmc, cX, cY, tX, tY)
if round%8 == 0 {
centerX, centerY = cX, cY
} else if round%8 == 0 {
centerX, centerY = 0, 0
} else if round%8 == 1 {
centerX, centerY = 0, w-1
} else if round%8 == 2 {
centerX, centerY = 0, h-1
} else if round%8 == 3 {
centerX, centerY = w-1, h-1
} else {
centerX, centerY = lastSetX, lastSetY
}
for x, y, a, ok := nearRectBegin(centerX, centerY, w, h, 0); ok; x, y, a, ok = nearRectNext(centerX, centerY, x, y, a, w, h) {
/*fmt.Printf(" N S E W NW NE SE SW| N S E W NW NE SE SW| N S E W NW NE SE SW| N S E W NW NE SE SW| N S E W NW NE SE SW\n")
for i := cY - 3; i <= cY+3; i++ {
for j := cX - 3; j <= cX+3; j++ {
if !inRect(i, j, w, h) {
continue
}
dumpDists(dist[j][i])
fmt.Printf("| ")
}
fmt.Println()
}
fmt.Printf("x=%d y=%d a=%d done=%t currBestDist=%d\n", x, y, a, done, currBestDist)
fmt.Scanln()*/
done, found, currBestDist, lastSetX, lastSetY = setDist(ss, rmc, dist, x, y, x, y+1, dirN, w, h, r, currBestDist, lastSetX, lastSetY, done, found, round)
done, found, currBestDist, lastSetX, lastSetY = setDist(ss, rmc, dist, x, y, x, y-1, dirS, w, h, r, currBestDist, lastSetX, lastSetY, done, found, round)
done, found, currBestDist, lastSetX, lastSetY = setDist(ss, rmc, dist, x, y, x-1, y, dirE, w, h, r, currBestDist, lastSetX, lastSetY, done, found, round)
done, found, currBestDist, lastSetX, lastSetY = setDist(ss, rmc, dist, x, y, x+1, y, dirW, w, h, r, currBestDist, lastSetX, lastSetY, done, found, round)
done, found, currBestDist, lastSetX, lastSetY = setDist(ss, rmc, dist, x, y, x+1, y+1, dirNW, w, h, r, currBestDist, lastSetX, lastSetY, done, found, round)
done, found, currBestDist, lastSetX, lastSetY = setDist(ss, rmc, dist, x, y, x-1, y-1, dirSE, w, h, r, currBestDist, lastSetX, lastSetY, done, found, round)
done, found, currBestDist, lastSetX, lastSetY = setDist(ss, rmc, dist, x, y, x-1, y+1, dirNE, w, h, r, currBestDist, lastSetX, lastSetY, done, found, round)
done, found, currBestDist, lastSetX, lastSetY = setDist(ss, rmc, dist, x, y, x+1, y-1, dirSW, w, h, r, currBestDist, lastSetX, lastSetY, done, found, round)
}
fmt.Printf("round=%d done=%t found=%t currBestDist=%d, lastSetX=%d lastSetY=%d\n", round, done, found, currBestDist, lastSetX, lastSetY)
if done {
break
}
}
dstMin := DistMax
tX, tY := int32(-1), int32(-1)
removed := false
for x, y, a, ok := nearRectBegin(cX, cY, w, h, 1); ok; x, y, a, ok = nearRectNext(cX, cY, x, y, a, w, h) {
if removeCount(ss, rmc, w, h, x, y, r) <= 0 {
continue
}
removed = true
dst := DistMax
if found {
//.........这里部分代码省略.........
开发者ID:radekp,项目名称:alfi,代码行数:101,代码来源:main.go
注:本文中的github.com/0xe2-0x9a-0x9b/Go-SDL/sdl.Surface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论