本文整理汇总了Golang中sdl.Surface类的典型用法代码示例。如果您正苦于以下问题:Golang Surface类的具体用法?Golang Surface怎么用?Golang Surface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Surface类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: line
// non-bressenham line
// TODO: figure out just how much better bressenham is
func line(dst *sdl.Surface, p0, p1 Point, c image.Color) {
d := p1.Sub(p0)
l := d.ToFloat().Length()
inc := int32(1)
if d.X*d.X > d.Y*d.Y {
if d.X < 0 {
inc = -1
}
m := d.ToFloat().Mult(1.0 / l).Slope()
for x := int32(0); x != d.X; x += inc {
y := int32(m * float64(x))
dst.Set(int(x+p0.X), int(y+p0.Y), c)
}
} else {
if d.Y < 0 {
inc = -1
}
m := d.ToFloat().Inverse().Mult(1.0 / l).Slope()
for y := int32(0); y != d.Y; y += inc {
x := int32(m * float64(y))
dst.Set(int(x+p0.X), int(y+p0.Y), c)
}
}
}
示例2: Blit
func (m *MonsterGhost) Blit(surface *sdl.Surface) {
m.H = float64(IM.Monsters[0][0].H)
m.W = float64(IM.Monsters[0][0].W)
if difftime(m.GotHit) > 0 {
surface.Blit(&sdl.Rect{int16(m.X - m.W/2), int16(m.Y - m.H/2), 0, 0}, IM.Monsters[0][0], nil)
}
}
示例3: Blit
func (t *Teleport) Blit(surface *sdl.Surface) {
if t.O == TELE_HORIZONTAL {
for x := 0; x < t.S*2; x++ {
surface.Blit(&sdl.Rect{int16(t.X-t.W/2) + int16(20*x), int16(t.Y - t.H/2), 0, 0}, t.Image, nil)
}
} else {
for x := 0; x < t.S*2; x++ {
surface.Blit(&sdl.Rect{int16(t.X - t.W/2), int16(t.Y-t.H/2) + int16(20*x), 0, 0}, t.Image, nil)
}
}
}
示例4: filledCircle
func filledCircle(dst *sdl.Surface, org Point, r int) {
colour := image.RGBAColor{0, 255, 0, 255}
// add a bias for smoother poles
br := float64(r) + 0.5
for x := -r; x <= r; x++ {
dy := int(math.Sqrt(br*br - float64(x*x)))
for y := -dy; y <= dy; y++ {
dst.Set(int(org.X)+x, int(org.Y)+y, colour)
}
}
}
示例5: filledEllipse
func filledEllipse(dst *sdl.Surface, org Point, a, b int) {
colour := image.RGBAColor{0, 255, 0, 255}
// add a bias to a and b for smoother poles
ba := float64(a) + 0.5
bb := float64(b) + 0.5
for x := -a; x <= a; x++ {
dy := int(math.Sqrt((bb * bb) * (1.0 - float64(x*x)/(ba*ba))))
for y := -dy; y <= dy; y++ {
dst.Set(int(org.X)+x, int(org.Y)+y, colour)
}
}
}
示例6: BlitHeartsAndTimer
func BlitHeartsAndTimer(surface *sdl.Surface, antal int, t GameTime) {
x := 18*BOXSIZE + 10
y := 5
for i := 0; i < antal; i++ {
surface.Blit(&sdl.Rect{int16(x), int16(i*30 + y), 0, 0}, IM.Misc[0], nil)
}
max := t.End - t.Start
nu := t.End - now()
if nu <= 0 {
return
}
surface.FillRect(&sdl.Rect{int16(x + BOXSIZE), 5 + BOXSIZE, 15, uint16((200 * nu) / max)}, 0xFFFFFF)
}
示例7: teardownTextRendering
func (f *Font) teardownTextRendering(texture gl.GLuint, initial *sdl.Surface, intermediarya *sdl.Surface, intermediary *sdl.Surface) (endw int, endh int) {
//
gl.Disable(gl.BLEND)
/* Bad things happen if we delete the texture before it finishes */
gl.Finish()
/* return the deltas in the unused w,h part of the rect */
endw = int(initial.W)
endh = int(initial.H)
/* Clean up */
initial.Free()
intermediarya.Free()
intermediary.Free()
gl.DeleteTextures(1, &texture)
//
return
}
示例8: circle
func circle(dst *sdl.Surface, org Point, r int) {
colour := image.RGBAColor{0, 255, 255, 0}
// set the poles
dst.Set(int(org.X), int(org.Y)+r, colour)
dst.Set(int(org.X), int(org.Y)-r, colour)
dst.Set(int(org.X)+r, int(org.Y), colour)
dst.Set(int(org.X)-r, int(org.Y), colour)
// add a bias for smoother poles
br := float64(r) + 0.5
// draw and rotate an octant
var x int32 = 1
for {
y := int32(math.Sqrt(br*br - float64(x*x)))
if x < y {
dst.Set(int(org.X+x), int(org.Y+y), colour)
dst.Set(int(org.X-x), int(org.Y+y), colour)
dst.Set(int(org.X+x), int(org.Y-y), colour)
dst.Set(int(org.X-x), int(org.Y-y), colour)
dst.Set(int(org.X+y), int(org.Y+x), colour)
dst.Set(int(org.X-y), int(org.Y+x), colour)
dst.Set(int(org.X+y), int(org.Y-x), colour)
dst.Set(int(org.X-y), int(org.Y-x), colour)
} else {
if x == y {
// draw the NE, SE, SW, and NW pixels
dst.Set(int(org.X+x), int(org.Y+y), colour)
dst.Set(int(org.X-x), int(org.Y+y), colour)
dst.Set(int(org.X+x), int(org.Y-y), colour)
dst.Set(int(org.X-x), int(org.Y-y), colour)
}
break
}
x++
}
}
示例9: Blit
func (l *EnemyLaser) Blit(surface *sdl.Surface) {
l.H = float64(IM.Shots[0].H)
l.W = float64(IM.Shots[0].W)
surface.Blit(&sdl.Rect{int16(l.X - l.W/2), int16(l.Y - l.H/2), 0, 0}, IM.Shots[0], nil)
}
示例10: Blit
func (b *Player) Blit(surface *sdl.Surface) {
surface.Blit(&sdl.Rect{int16(b.X - b.W/2), int16(b.Y - b.H/2), 0, 0}, b.Animate(), nil)
surface.Blit(&sdl.Rect{19*BOXSIZE + 10, 10, 0, 0}, IM.Shots[b.Lvl], nil)
}
示例11: ellipse
func ellipse(dst *sdl.Surface, org Point, a, b int) {
colour := image.RGBAColor{0, 255, 0, 255}
// set the poles
dst.Set(int(org.X), int(org.Y)+b, colour)
dst.Set(int(org.X), int(org.Y)-b, colour)
dst.Set(int(org.X)+a, int(org.Y), colour)
dst.Set(int(org.X)-a, int(org.Y), colour)
// add a bias to a and b for smoother poles
ba := float64(a) + 0.5
bb := float64(b) + 0.5
// draw and rotate a quadrant
for x := 1; x < a; x++ {
y1 := (-bb * float64(x)) / (ba * math.Sqrt(ba*ba-float64(x*x)))
y := int(math.Sqrt((bb * bb) * (1.0 - float64(x*x)/(ba*ba))))
if y1 > -1.0 {
dst.Set(int(org.X)+x, int(org.Y)+y, colour)
dst.Set(int(org.X)-x, int(org.Y)+y, colour)
dst.Set(int(org.X)+x, int(org.Y)-y, colour)
dst.Set(int(org.X)-x, int(org.Y)-y, colour)
} else {
for dy := 1; dy <= y; dy++ {
dx := int(math.Sqrt((ba * ba) * (1.0 - float64(dy*dy)/(bb*bb))))
dst.Set(int(org.X)+dx, int(org.Y)+dy, colour)
dst.Set(int(org.X)-dx, int(org.Y)+dy, colour)
dst.Set(int(org.X)+dx, int(org.Y)-dy, colour)
dst.Set(int(org.X)-dx, int(org.Y)-dy, colour)
}
break
}
}
}
示例12: Blit
func (l *Button) Blit(surface *sdl.Surface) {
surface.Blit(&sdl.Rect{int16(l.X - l.W/2), int16(l.Y - l.H/2), 0, 0}, l.Image, nil)
}
示例13: Blit
func (l *Level) Blit(surface *sdl.Surface) {
surface.Blit(&sdl.Rect{0, 0, 0, 0}, l.Surface, nil)
}
示例14: Refresh
func Refresh(surface *sdl.Surface) {
surface.FillRect(&sdl.Rect{0, 0, SCREENWIDTH, SCREENHEIGHT}, 0x000000)
}