Created
July 21, 2014 22:40
-
-
Save dradtke/9d2f347563aa30f30f89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "github.com/dradtke/allegory" | |
| "github.com/dradtke/allegory/config" | |
| "github.com/dradtke/go-allegro/allegro" | |
| "math" | |
| ) | |
| var ( | |
| FULL_ROTATION = float32(2 * math.Pi) | |
| ) | |
| type SpinningState struct { | |
| allegory.BaseState | |
| Square *allegro.Bitmap | |
| Angle float32 | |
| } | |
| func (s *SpinningState) InitState() { | |
| s.Square = allegro.CreateBitmap(100, 100).AsTarget(func() { | |
| allegro.ClearToColor(allegro.MapRGB(255, 0, 0)) | |
| }) | |
| } | |
| func (s *SpinningState) UpdateState() { | |
| s.Angle += (FULL_ROTATION / 240) // at 60fps, this takes about 4 seconds to do a full rotation | |
| for s.Angle > FULL_ROTATION { | |
| s.Angle -= FULL_ROTATION | |
| } | |
| } | |
| func (s *SpinningState) RenderState(delta float32) { | |
| dw, dh := config.DisplaySize() | |
| s.Square.DrawRotated(50, 50, float32(dw/2), float32(dh/2), s.Angle, allegro.FLIP_NONE) | |
| } | |
| func main() { | |
| allegory.Init(new(SpinningState)) | |
| defer allegory.Cleanup() | |
| allegory.Loop() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment