79 lines
1.5 KiB
Go
79 lines
1.5 KiB
Go
package main
|
|
|
|
/*
|
|
#cgo CFLAGS: -I ${SRCDIR}/lib
|
|
#cgo LDFLAGS: -L ${SRCDIR}/lib -l ffi_wrapper
|
|
#include "ffi-wrapper.h"
|
|
#include <stdlib.h>
|
|
*/
|
|
import "C"
|
|
|
|
// Circles
|
|
type Circle struct {
|
|
cptr *C.Circle
|
|
}
|
|
|
|
func NewCircle(x float64, y float64, rad float64) Circle {
|
|
return Circle{
|
|
cptr: C.new_circle(C.double(x), C.double(y), C.double(rad)),
|
|
}
|
|
}
|
|
|
|
func (c *Circle) UpdatePos(x float64, y float64) {
|
|
c.cptr.x = C.double(x)
|
|
c.cptr.y = C.double(y)
|
|
}
|
|
|
|
func DestroyCircle(circle Circle) {
|
|
if circle.cptr == nil {
|
|
return
|
|
}
|
|
|
|
C.destroy_circle(circle.cptr)
|
|
}
|
|
|
|
func (c *Circle) GetPos() (float64, float64) {
|
|
return float64(c.cptr.x), float64(c.cptr.y)
|
|
}
|
|
|
|
// Bullets
|
|
type Bullet struct {
|
|
cptr *C.Bullet
|
|
}
|
|
|
|
func NewLinearBullet(tick int64, spawnX float64, spawnY float64, radius float64, velX float64, velY float64) Bullet {
|
|
return Bullet{
|
|
cptr: C.new_bullet(
|
|
C.uint8_t(0),
|
|
C.int64_t(tick),
|
|
C.double(spawnX),
|
|
C.double(spawnY),
|
|
C.double(radius),
|
|
C.double(velX),
|
|
C.double(velY),
|
|
),
|
|
}
|
|
}
|
|
|
|
func DestroyBullet(bullet Bullet) {
|
|
if bullet.cptr == nil {
|
|
return
|
|
}
|
|
|
|
C.destroy_bullet(bullet.cptr)
|
|
}
|
|
|
|
func (b *Bullet) BeyondKillBoundary(tick int64) bool {
|
|
return bool(C.bullet_beyond_kill_boundary(b.cptr, C.int64_t(tick)))
|
|
}
|
|
|
|
func (b *Bullet) CollidesWith(circle Circle, tick int64) bool {
|
|
return bool(C.bullet_collides_with(b.cptr, C.int64_t(tick), circle.cptr))
|
|
}
|
|
|
|
func (b *Bullet) GetPos(tick int64) (float64, float64) {
|
|
var x, y C.double
|
|
C.bullet_get_current_pos(b.cptr, C.int64_t(tick), &x, &y)
|
|
|
|
return float64(x), float64(y)
|
|
}
|