Esempio n. 1
0
func main() {
	window := sf.NewRenderWindow(
		sf.VideoMode{800, 600, 32},
		"Hallo Welt",
		sf.StyleDefault,
		sf.DefaultContextSettings(),
	)

	game := game.New()
	game.Start(window)
}
Esempio n. 2
0
func main() {
	ticker := time.NewTicker(time.Second / 30)
	setting := sf.DefaultContextSettings()
	setting.AntialiasingLevel = 8
	renderWindow := sf.NewRenderWindow(sf.VideoMode{800, 600, 32}, "Events (GoSFML2)", sf.StyleDefault, setting)

	grid, err := shapes.NewGirdShape(sf.Vector2f{500, 400}, sf.Vector2f{50, 40}, sf.ColorWhite())

	imageGot, _, err := images.ReadImage("./011.jpg", 0, 0, 500, 400)
	texture, err := images.ReadTextureFromImage(*imageGot)
	if err != nil {
		fmt.Println(err)
		return
	}
	texture.SetSmooth(true)
	grid.SetTexture(texture)
	grid.Move(sf.Vector2f{100, 100})
	grid.Rotate(15)
	var pointX, pointY int
	var gotPoint bool

	for renderWindow.IsOpen() {
		select {
		case <-ticker.C:
			mousePosi := sf.MouseGetPosition(renderWindow)
			mousePosf := sf.Vector2f{float32(mousePosi.X), float32(mousePosi.Y)}
			for event := renderWindow.PollEvent(); event != nil; event = renderWindow.PollEvent() {
				switch event.(type) {
				case sf.EventClosed:
					renderWindow.Close()
				case sf.EventMouseButtonPressed:
					pointX, pointY, gotPoint = grid.GetNearestPointIndex(mousePosf)
				}
			}
			if sf.IsMouseButtonPressed(0) {
				if gotPoint {
					grid.SmoothPointsTo(pointX, pointY, mousePosf, 10, func(data float32) float32 {
						return (mathUtil.Sin(data, -0.5, 1)/2 + 0.5) / 5
					})
				}
			}
		}
		renderWindow.Clear(sf.ColorWhite())
		renderWindow.Draw(grid, sf.DefaultRenderStates())
		renderWindow.Display()
	}
}
Esempio n. 3
0
func main() {

	if len(os.Args) < 3 {
		fmt.Println("add the color range function: operiation x ,like + 2 ")
		return
	}

	colorRangeFunc := func(r, g, b, anivalue float32) (outr, outg, outb float32) {
		if os.Args[len(os.Args)-1] != "a" {
			anivalue = 0
		}
		outr = argsCheckAndAddColor(r, 1, anivalue)
		outg = argsCheckAndAddColor(g, 2, anivalue)
		outb = argsCheckAndAddColor(g, 3, anivalue)
		return
	}

	ticker := time.NewTicker(time.Second / 30)
	setting := sf.DefaultContextSettings()
	setting.AntialiasingLevel = 8
	renderWindow := sf.NewRenderWindow(sf.VideoMode{800, 600, 32}, "Events (GoSFML2)", sf.StyleDefault, setting)

	round, err := sf.NewCircleShape()

	imageGot, _, err := images.ReadImage("./011.jpg", -50, -50, 600, 600)
	if err != nil {
		fmt.Println(err)
		return
	}
	imageGot__ := images.ImageEnhanceRGBWithFunc(imageGot, func(r, g, b float32) (outr, outg, outb float32) {
		outr = 127 * float32(math.Sin(float64(r-127)/255*math.Pi+1))
		outg = g
		outb = b
		return
	})
	texture, err := images.ReadTextureFromImage(*imageGot__)
	if err != nil {
		fmt.Println(err)
		return
	}
	texture.SetSmooth(true)
	round.SetPosition(sf.Vector2f{100, 50})
	round.SetRadius(300)
	round.SetTexture(texture, true)

	clip := animations.NewLoopAnimation([]float32{0}, []float32{255}, -1, animations.Pingpong, func(values []float32) {
		imageGot__ = images.ImageEnhanceRGBWithFunc(imageGot, func(r, g, b float32) (outr, outg, outb float32) {
			outr, outg, outb = colorRangeFunc(r, g, b, values[0])
			return
		})
		texture, _ := images.ReadTextureFromImage(*imageGot__)
		round.SetTexture(texture, true)
	}, nil)
	clip.SetFrameCount(60)
	animation := animations.NewAnimation(0)
	animation.AddClip(clip)
	animation.Play()
	for renderWindow.IsOpen() {
		select {
		case <-ticker.C:
			for event := renderWindow.PollEvent(); event != nil; event = renderWindow.PollEvent() {
				switch event.(type) {
				case sf.EventClosed:
					renderWindow.Close()
				}
			}
		}
		animation.Animate()
		renderWindow.Clear(sf.ColorWhite())
		renderWindow.Draw(round, sf.DefaultRenderStates())
		renderWindow.Display()
	}
}
Esempio n. 4
0
func NewGame(title string, width uint, height uint, bpp uint, vsync bool) *Game {
	Game := new(Game)
	Game.Width = width
	Game.Height = height
	Game.RenderWindow = sf.NewRenderWindow(sf.VideoMode{width, height, bpp}, title, sf.StyleDefault, sf.DefaultContextSettings())
	Game.RenderWindow.SetVSyncEnabled(vsync)
	Game.Font, _ = sf.NewFontFromFile("res/fonts/UbuntuMono-R.ttf")
	Game.State = 0
	Game.StartStateInit()
	Game.Textures = NewTextures("res/images/")
	return Game
}
Esempio n. 5
0
func main() {
	ticker := time.NewTicker(time.Second / 30)
	setting := sf.DefaultContextSettings()
	setting.AntialiasingLevel = 8
	renderWindow := sf.NewRenderWindow(sf.VideoMode{800, 600, 32}, "Events (GoSFML2)", sf.StyleDefault, setting)

	shape, _ := shapeEX.NewCurveCicleShape(10, 100, 8)
	shape.SetFillColor(sf.Color{255, 100, 55, 255})

	animation1 := animations.NewAnimation(1)
	clip10 := animations.NewSingleAnimationClip(
		shape.GetPosition(),
		sf.Vector2f{500, 200},
		func(step interface{}) {
			stepv2, _ := step.(sf.Vector2f)
			shape.SetPosition(stepv2)
		}, func() {
		})
	clip11 := animations.NewSingleAnimationClip(
		sf.Vector2f{500, 200},
		sf.Vector2f{200, 400},
		func(step interface{}) {
			stepv2, _ := step.(sf.Vector2f)
			shape.SetPosition(stepv2)
		}, func() {
		})
	clip10.SetFrameCount(120)
	clip11.SetFrameCount(120)
	animation1.AddClip(clip10)
	animation1.AddClip(clip11)

	animation2 := animations.NewAnimation(1)
	clip20 := animations.NewLoopAnimation(
		0.2, 1.8, -1, animations.Pingpong,
		func(step interface{}) {
			stepv1, _ := step.(float32)
			for i := 0; i < 8; i++ {
				if i%2 == 0 {
					shape.ExpendPointTo(uint(i), stepv1)
				}

			}
		}, func() {
		})
	clip20.SetAnimationCurve(func(num float32) float32 {
		return num * num
	})
	clip20.SetFrameCount(20)
	animation2.AddClip(clip20)

	animation1.Play()
	animation2.Play()
	for renderWindow.IsOpen() {
		select {
		case <-ticker.C:
			for event := renderWindow.PollEvent(); event != nil; event = renderWindow.PollEvent() {
				switch event.(type) {
				case sf.EventClosed:
					renderWindow.Close()
				}
			}
		}
		animation1.Animate()
		animation2.Animate()
		renderWindow.Clear(sf.ColorWhite())
		renderWindow.Draw(shape, sf.DefaultRenderStates())
		renderWindow.Display()
	}
}
Esempio n. 6
0
//NewGame initializes a Game struct.
func NewGame() *Game {
	g := new(Game)
	g.Settings = readSettings()
	g.window = sf.NewRenderWindow(sf.VideoMode{uint(g.resW), uint(g.resH), 32}, "GoSFMLike", sf.StyleDefault, sf.DefaultContextSettings())
	g.state = PLAY

	g.area = NewArea()
	g.player = NewEntity("player", 0, 0, 3, 4, g.area)
	g.cursor = NewEntity("cursor", 0, 0, 2, 2, g.area)

	for i := 0; i < 3; i++ {
		g.mobs = append(g.mobs, NewEntityFromFile("orc", 3+i, 1, g.area))
		g.items = append(g.items, NewEntityFromFile("potion", 4, 4, g.area))
	}
	g.mobs = append(g.mobs, g.player)

	g.gameView = sf.NewView()
	g.gameView.SetCenter(g.player.PosVector())
	g.gameView.SetSize(sf.Vector2f{g.resW * 0.75, g.resH * 0.75})
	g.gameView.SetViewport(sf.FloatRect{0, 0, .75, .75})

	g.statusView = sf.NewView()
	g.statusView.SetSize(sf.Vector2f{g.resW * 0.25, g.resH})
	g.statusView.SetCenter(sf.Vector2f{(g.resW * 0.25) / 2, g.resH / 2})
	g.statusView.SetViewport(sf.FloatRect{.77, 0, .25, 1})

	g.hpText, _ = sf.NewText(Font)
	g.hpText.SetCharacterSize(12)

	g.logView = sf.NewView()

	var err error
	g.lookText, err = sf.NewText(Font)
	if err != nil {
		panic(err)
	}
	g.lookText.SetCharacterSize(12)

	g.logText, _ = sf.NewText(Font)
	g.logText.SetCharacterSize(12)

	return g
}