Exemple #1
0
func (game *Game) Setup() {
	game.SetBg(0x2d3638)

	texture := engi.NewTexture(engi.Files.Image("bot"))
	region := engi.NewRegion(texture, 0, 0, texture.Width(), texture.Height())

	bot := engi.NewSprite(region, game.Width()/2, game.Height()/1.75)
	game.AddChild(bot)
	bot.Anchor.Set(0.5, 1)
	bot.Scale.SetTo(14)
	game.bot = bot

	bot2 := engi.NewSprite(region, 0, 5)
	bot.AddChild(bot2)
	bot2.Anchor.Set(0.5, 0)
	bot2.Scale.SetTo(0.33)

	/*
		font := engi.NewGridFont(engi.Files.Image("font"), 20, 20, "")
		text := engi.NewText(font, game.Width()/2, game.Height()/1.75, "ENGi")
		game.AddChild(text.Sprite)
		text.Anchor.Set(0.5, 0)
		text.Scale.Set(3, 4)
		text.SetTint(0x6cb767)
		game.text = text
	*/
}
Exemple #2
0
func (game *Game) Update(dt float32) {
	time += dt
	if time > 1 {
		println(int(engi.Time.Fps()))
		println(num)
		time = 0
	}

	if on {
		for i := 0; i < 10; i++ {
			bot := &Bot{engi.NewSprite(region, 0, 0), rand.Float32() * 500, rand.Float32()*500 - 250}
			bots = append(bots, bot)
		}
		num += 10
	}

	minX := float32(0)
	maxX := float32(800)
	minY := float32(0)
	maxY := float32(600)

	for _, bot := range bots {
		bot.Position.X += bot.DX * dt
		bot.Position.Y += bot.DY * dt
		bot.DY += 750 * dt

		if bot.Position.X < minX {
			bot.DX *= -1
			bot.Position.X = minX
		} else if bot.Position.X > maxX {
			bot.DX *= -1
			bot.Position.X = maxX
		}

		if bot.Position.Y < minY {
			bot.DY = 0
			bot.Position.Y = minY
		} else if bot.Position.Y > maxY {
			bot.DY *= -.85
			bot.Position.Y = maxY
			if rand.Float32() > 0.5 {
				bot.DY -= rand.Float32() * 200
			}
		}
	}
}