本文整理汇总了Golang中github.com/banthar/Go-SDL/sdl.Surface类的典型用法代码示例。如果您正苦于以下问题:Golang Surface类的具体用法?Golang Surface怎么用?Golang Surface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Surface类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: DrawTextLines
// draw lines of text aligned around center of screen
func DrawTextLines(strings []string) {
var dstrect, srcrect *sdl.Rect
var line *sdl.Surface
var w, h, prevH uint16
centerX := int16(Width / 2)
centerY := int16(Height / 2)
for _, str := range strings {
line = RenderText(str, Red)
line.GetClipRect(srcrect)
w, h = uint16(line.W), uint16(line.H)
dstrect = &sdl.Rect{
X: centerX - int16(w/2),
Y: (centerY + int16(prevH)) - int16(h/2),
W: w,
H: h,
}
prevH += h
Screen.Blit(dstrect, line, srcrect)
line.Free()
}
}
开发者ID:manveru,项目名称:raptgo,代码行数:28,代码来源:raptgo.go
示例2: loop
func loop(screen *sdl.Surface) {
for {
screen.Flip()
event := sdl.PollEvent()
if event != nil {
if _, ok := event.(*sdl.QuitEvent); ok {
log.Println("Caught quit event. Quiting SDL.")
break
}
}
}
}
开发者ID:jqln-0,项目名称:colorshow,代码行数:12,代码来源:window.go
示例3: Draw
func (o *Object) Draw(surface *sdl.Surface, gc *GameContext) {
windowStartX := int16(gc.PlayerPosition - 320)
// "move" the object according to the window
drawRect := &sdl.Rect{
X: o.Rect.X - windowStartX,
Y: o.Rect.Y,
W: o.Rect.W,
H: o.Rect.H,
}
surface.FillRect(drawRect, o.Color)
}
开发者ID:githubnemo,项目名称:Jinx,代码行数:13,代码来源:level.go
示例4: initFillBox
func initFillBox(screen *sdl.Surface) {
/*{{{*/
for i := range paint_chan {
if i.f.T == i.c {
continue
}
i.f.T = i.c
screen.FillRect(i.f.toRect(), uint32(i.c))
// Do updates of screen in the main loop.
//screen.UpdateRect(i.f.ToFourTuple());
}
/*}}}*/
}
开发者ID:kse,项目名称:aStar-demo,代码行数:14,代码来源:drawing.go
示例5: playGame
func playGame(screen *sdl.Surface, bg *glh.Texture, font *gltext.Font) (int, bool) {
movingUp := false
b := bird.NewBird(240, 380)
score := 0
var pipes []*pipe.Pipe
ticker := 0
for {
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
quit := manageEvents(screen, &movingUp)
if quit {
return score, true
}
renderBackground(screen, bg)
ticker++
if ticker > 100 {
pipes = append(pipes, pipe.NewPipe(int(screen.W), int(screen.H)))
ticker = 0
}
if movingUp {
b.MoveUp()
} else {
b.MoveDown()
}
for _, p := range pipes {
if p.X < 0 {
p.Destroy()
pipes = pipes[1:]
}
if p.CollidesWith(b.X, b.Y, b.Width, b.Height) {
return score, false
}
if p.GonePast(b.X, b.Y) {
score++
}
p.Tick()
p.Render()
}
b.Render()
font.Printf(240, 50, strconv.Itoa(score))
screen.Flip()
time.Sleep((1 / 30) * time.Second)
sdl.GL_SwapBuffers()
}
}
开发者ID:Tohie,项目名称:GoFlappyBird,代码行数:48,代码来源:flappybird.go
示例6: gameloop
func gameloop(screen *sdl.Surface) {
gc := &GameContext{screen, 320, 16}
for {
e := sdl.WaitEvent()
screen.FillRect(nil, 0x0)
gc.drawFloor()
gc.drawPlayer()
gc.drawObjects()
switch re := e.(type) {
case *sdl.QuitEvent:
return
case *sdl.MouseMotionEvent:
screen.FillRect(&sdl.Rect{
int16(re.X),
int16(re.Y),
50, 50}, 0xffffff)
screen.Blit(&sdl.Rect{
int16(re.X),
int16(re.Y),
0, 0}, playerTexture, nil)
fmt.Println(re.X, re.Y)
case *sdl.KeyboardEvent:
if re.Type == sdl.KEYDOWN {
keyname := sdl.GetKeyName(sdl.Key(re.Keysym.Sym))
fmt.Println("pressed:", keyname)
switch keyname {
case "right":
gc.moveRight()
case "left":
gc.moveLeft()
case "q":
return
}
} else if re.Type == sdl.KEYUP {
gc.resetPlayerSpeed()
}
default:
//fmt.Println("What the heck?!")
}
gc.Dump()
screen.Flip()
}
}
开发者ID:githubnemo,项目名称:Jinx,代码行数:55,代码来源:main.go
示例7: Line
// Draw a line
func Line(screen *sdl.Surface, x1 int, y1 int, x2 int, y2 int, color sdl.Color) {
if x1 == x2 || y1 == y2 {
return
}
startx, stopx := minmax(x1, x2)
starty, stopy := minmax(y1, y2)
xdiff := stopx - startx
ydiff := stopy - starty
if xdiff > ydiff {
// We're going along X
y := float32(starty)
ystep := float32(ydiff) / float32(xdiff)
if y1 != starty {
// Move in the other direction along Y
ystep = -ystep
y = float32(stopy)
}
// Draw the line
for x := startx; x < stopx; x++ {
screen.Set(x, int(y), color)
y += ystep
}
} else {
// We're going along Y
x := float32(startx)
xstep := float32(xdiff) / float32(ydiff)
if x1 != startx {
// Move in the other direction along X
xstep = -xstep
x = float32(stopx)
}
// Draw the line
for y := starty; y < stopy; y++ {
screen.Set(int(x), y, color)
x += xstep
}
}
}
开发者ID:xyproto,项目名称:rasterizer,代码行数:42,代码来源:rasterizer.go
示例8: drawGrid
/*
* Draw a grid on the display and return info about the Tile
*/
func drawGrid(screen *sdl.Surface) {
/*{{{*/
vid := sdl.GetVideoInfo()
// First the vertical
for i := 0; i < int(vid.Current_w); i += SIZE {
screen.FillRect(
&sdl.Rect{int16(i), int16(0), 1, uint16(vid.Current_h)},
0x000000)
screen.UpdateRect(int32(i), 0, 1, uint32(vid.Current_h))
}
// Then the horizontal
for i := 0; i < int(vid.Current_h); i += SIZE {
screen.FillRect(
&sdl.Rect{0, int16(i), uint16(vid.Current_w), 1},
0x000000)
screen.UpdateRect(0, int32(i), uint32(vid.Current_w), 1)
}
return
/*}}}*/
}
开发者ID:kse,项目名称:aStar-demo,代码行数:26,代码来源:drawing.go
注:本文中的github.com/banthar/Go-SDL/sdl.Surface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论