Пример #1
0
// 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
0
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
0
func (r *Robot) Blit(surface *sdl.Surface) {
	img := IM.Monsters[2][r.Direction+r.IsBoss]
	r.H = float64(img.H)
	r.W = float64(img.W)
	if difftime(r.GotHit) > 0 {
		surface.Blit(&sdl.Rect{int16(r.X - r.W/2), int16(r.Y - r.H/2), 0, 0}, img, nil)
	}
}
Пример #4
0
func (d *Malboro) Blit(surface *sdl.Surface) {
	img := IM.Monsters[3][0]
	d.H = float64(img.H)
	d.W = float64(img.W)

	if difftime(d.GotHit) > 0 {
		surface.Blit(&sdl.Rect{int16(d.X - d.W/2), int16(d.Y - d.H/2), 0, 0}, img, nil)
	}
}
Пример #5
0
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)
		}
	}
}
Пример #6
0
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)
		}
	}
}
Пример #7
0
func (s *Spoils) Blit(surface *sdl.Surface) {
	switch s.Type {
	case SP_HEART:
		surface.Blit(&sdl.Rect{int16(s.X - s.W/2), int16(s.Y - s.H/2), 0, 0}, IM.Misc[0], nil)
	case SP_UPGRADE:
		surface.FillRect(&sdl.Rect{int16(s.X - s.W/2), int16(s.Y - s.H/2), 10, 10}, uint32(s.Frame))
		s.Frame = s.Frame*s.Frame + 1
		if s.Frame > 0xFFFFFF {
			s.Frame = 0
		}
	}
}
Пример #8
0
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)
		}
	}
}
Пример #9
0
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)
}
Пример #10
0
func (d *Deathshell) Blit(surface *sdl.Surface) {
	var img *sdl.Surface
	if d.IsBoss == DS_ISBOSS {
		img = IM.Monsters[1][1+d.Direction]
	} else {
		img = IM.Monsters[1][0]
	}

	d.H = float64(img.H)
	d.W = float64(img.W)

	if difftime(d.GotHit) > 0 {
		surface.Blit(&sdl.Rect{int16(d.X - d.W/2), int16(d.Y - d.H/2), 0, 0}, img, nil)
	}
}
Пример #11
0
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
}
Пример #12
0
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++
	}
}
Пример #13
0
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)
}
Пример #14
0
func (s *Spike) Blit(surface *sdl.Surface) {
	surface.Blit(&sdl.Rect{int16(s.X - s.W/2), int16(s.Y - s.H/2), 0, 0}, IM.Shots[2], nil)
}
Пример #15
0
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)
}
Пример #16
0
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
		}
	}
}
Пример #17
0
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)
}
Пример #18
0
func (l *ScreenObject) Blit(surface *sdl.Surface) {
	if l == selected {
		surface.FillRect(&sdl.Rect{int16(l.X - l.W/2), int16(l.Y - l.H/2), uint16(l.W), uint16(l.H)}, 0xFFFFFF)
	}
	surface.Blit(&sdl.Rect{int16(l.X - l.W/2), int16(l.Y - l.H/2), 0, 0}, l.image(), nil)
}
Пример #19
0
func (l *Level) Blit(surface *sdl.Surface) {
	surface.Blit(&sdl.Rect{0, 0, 0, 0}, l.Surface, nil)
}
Пример #20
0
func Refresh(surface *sdl.Surface) {
	surface.FillRect(&sdl.Rect{0, 0, SCREENWIDTH, SCREENHEIGHT}, 0x000000)
}