Skip to content

Instantly share code, notes, and snippets.

@jpleau
Created July 5, 2014 17:33
Show Gist options
  • Save jpleau/033bcf0fa816dc35026e to your computer and use it in GitHub Desktop.
Save jpleau/033bcf0fa816dc35026e to your computer and use it in GitHub Desktop.
package main
func main() {
videoMode := gosfml2.VideoMode{800, 600, 24}
window := gosfml2.NewRenderWindow(videoMode, "Test", gosfml2.StyleDefault, gosfml2.DefaultContextSettings())
window.SetFramerateLimit(60)
rect, _ := gosfml2.NewRectangleShape()
rect.SetPosition(gosfml2.Vector2f{50, 50})
rect.SetSize(gosfml2.Vector2f{200, 150})
rect.SetFillColor(gosfml2.Color{0, 0, 255, 255})
for window.IsOpen() {
window.Display()
for event := window.PollEvent(); event != nil; event = window.PollEvent() {
switch ev := event.(type) {
case gosfml2.EventKeyPressed:
switch ev.Code {
case gosfml2.KeyEscape:
window.Close()
}
case gosfml2.EventClosed:
window.Close()
}
}
movement := gosfml2.Vector2f{0, 0}
if gosfml2.KeyboardIsKeyPressed(gosfml2.KeyRight) {
movement.X = 10
}
if gosfml2.KeyboardIsKeyPressed(gosfml2.KeyLeft) {
movement.X = -010
}
if gosfml2.KeyboardIsKeyPressed(gosfml2.KeyUp) {
movement.Y = -10
}
if gosfml2.KeyboardIsKeyPressed(gosfml2.KeyDown) {
movement.Y = 10
}
window.Clear(gosfml2.Color{128, 0, 0, 255})
rect.Move(movement)
rect.Draw(window, gosfml2.DefaultRenderStates())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment