Skip to content

Instantly share code, notes, and snippets.

View cheikhshift's full-sized avatar

Cheikh Seck cheikhshift

View GitHub Profile
// +build windows
package lib
func FindExe() (string,string){
return "C:\\Windows\\System32\\explorer.exe", "Windows"
}
//+build windows_test
package lib
import "testing"
func TestFindExe(t * testing.T){
_, os := FindExe()
// +build linux darwin
package lib
func FindExe() (string, string){
return "/bin/bash","Unix"
}
//+build unix_test
package lib
import "testing"
func TestFindExe(t * testing.T){
_, os := FindExe()
func HandleEnt(e *entities.Entity) {
for {
time.Sleep(WaitTime)
// set speed to move left, hence `-` sign
e.Delta[0] = -e.Speed.X()
// perform shift
go func() {
for {
wait := rand.Intn(20)
timeOut := time.Duration(wait) * time.Second
time.Sleep(timeOut)
fmt.Println("Spawn")
event.Bind(sc, event.Enter, char, func(c *entities.Entity, ev event.EnterPayload) event.Response {
oldX, oldY := char.X(), char.Y()
char.ShiftDelta()
aboveGround := false
hit := collision.HitLabel(char.Space, Ground)
gameOver := collision.HitLabel(char.Space, Obstacle)
if gameOver != nil {
sc.Window.SetTitle("Infinite Dash")
char := entities.New(sc,
entities.WithRect(floatgeom.NewRect2WH(100, 100, 16, 32)),
entities.WithColor(color.RGBA{255, 0, 0, 255}),
entities.WithSpeed(floatgeom.Point2{3, 7}),
)
platform := floatgeom.NewRect2WH(0, 420, 640, 20)
func main() {
oak.AddScene("firstScene", scene.Scene{
Start: func(sc *scene.Context) {
// ... draw entities, bind callbacks ...
},
})
oak.Init("firstScene")
}
const (
// The only collision label we need for this demo is 'ground',
// indicating something we shouldn't be able to fall or walk through
Ground collision.Label = 1
Obstacle collision.Label = 2
WaitTime time.Duration = 50 * time.Millisecond
)