Esempio n. 1
0
func NewPaddle(speed, max_speed float32, size sf.Vector2f, color sf.Color) *Paddle {
	shape := sf.NewRectangleShape()
	//Take 3 off each edge to account for outline thickness
	shape.SetSize(sf.Vector2f{size.X - 3, size.Y - 3})
	shape.SetOutlineThickness(3)
	shape.SetOutlineColor(sf.ColorBlack())
	shape.SetFillColor(color)
	shape.SetOrigin(sf.Vector2f{size.X / 2, size.Y / 2})

	return &Paddle{speed, max_speed, size, shape}
}
Esempio n. 2
0
func NewPlayer(WorldWidth int, WorldHeight int, Textures []Texture) *Player {
	Player := new(Player)
	Player.WorldWidth = WorldWidth
	Player.WorldHeight = WorldHeight
	Player.Shape, _ = sf.NewRectangleShape()
	Player.Shape.SetSize(sf.Vector2f{32, 32})
	Player.Shape.SetTexture((GetTexture("Player.png", Textures)).Data, false)
	//Player.Shape.SetFillColor(sf.Color{255,128,0,255})
	x := rand.Intn(WorldWidth)
	if x > 32 {
		x -= 32
	}
	Player.Shape.SetPosition(sf.Vector2f{float32(x), float32(WorldHeight-64)})
	return Player
}
Esempio n. 3
0
func NewEnemy(WorldWidth int, Textures []Texture) *Enemy {
	Enemy := new(Enemy)
	rand.Seed(time.Now().UnixNano())
	Enemy.HasChild = true
	if rand.Intn(100) < 80 {
		Enemy.HasMother = true
	} else {
		Enemy.HasMother = false
	}
	if Enemy.HasMother == true {
		if rand.Intn(1) == 1 {
			Enemy.HasFather = true
		} else {
			Enemy.HasFather = false
		}
	} else {
		Enemy.HasFather = true
	}
	if rand.Intn(1000) == 1 {
		Enemy.FatherHasWeapon = true
	} else {
		Enemy.FatherHasWeapon = false
	}
	Enemy.Shape, _ = sf.NewRectangleShape()
	if Enemy.HasMother == true && Enemy.HasFather == true && Enemy.HasChild == true {
		Enemy.Shape.SetSize(sf.Vector2f{96, 32})
		Enemy.Shape.SetFillColor(sf.Color{128, 128, 128, 255})
		Enemy.Shape.SetTexture((GetTexture("ParentsAndChild.png", Textures)).Data, false)
	} else if Enemy.HasMother == true && Enemy.HasFather == false && Enemy.HasChild == true {
		Enemy.Shape.SetSize(sf.Vector2f{64, 32})
		Enemy.Shape.SetFillColor(sf.Color{128, 0, 128, 255})
		Enemy.Shape.SetTexture((GetTexture("MotherAndChild.png", Textures)).Data, false)
	} else if Enemy.HasMother == false && Enemy.HasFather == true && Enemy.HasFather == true {
		Enemy.Shape.SetSize(sf.Vector2f{64, 32})
		if Enemy.FatherHasWeapon == true {
			Enemy.Shape.SetFillColor(sf.Color{0, 128, 255, 255})
		} else {
			Enemy.Shape.SetFillColor(sf.Color{0, 128, 128, 255})
		}
		Enemy.Shape.SetTexture((GetTexture("FatherAndChild.png", Textures)).Data, false)
	}
	x := rand.Intn(WorldWidth)
	if x > 96 {
		x -= 96
	}
	Enemy.Shape.SetPosition(sf.Vector2f{float32(x), 0.0})
	return Enemy
}