func initWindow(sys system.System, width int, height int) { sys.CreateWindow(10, 10, width, height) sys.EnableVSync(true) err := gl.Init() if err != nil { panic(err) } // gl.Ortho(gl.Double(0), gl.Double(width), gl.Double(0), gl.Double(height), // 1000, -1000) }
func (camera *cameraInfo) doArchitectFocusRegion(g *Game, sys system.System) { if camera.limit.mid.X == 0 && camera.limit.mid.Y == 0 { // On the very first frame the limit midpoint will be (0,0), which should // never happen after the game begins. We use this as an opportunity to // init the data now that we know the region we're working with. rdx := float64(g.Levels[GidInvadersStart].Room.Dx) rdy := float64(g.Levels[GidInvadersStart].Room.Dy) if camera.regionDims.X/camera.regionDims.Y > rdx/rdy { camera.limit.dims.Y = rdy camera.limit.dims.X = rdy * camera.regionDims.X / camera.regionDims.Y } else { camera.limit.dims.X = rdx camera.limit.dims.Y = rdx * camera.regionDims.Y / camera.regionDims.X } camera.limit.mid.X = rdx / 2 camera.limit.mid.Y = rdy / 2 camera.current = camera.limit camera.zoom = 0 base.Log().Printf("Region Dims: %2.2v", camera.regionDims) base.Log().Printf("Room Dims: %2.2v %2.2v", rdx, rdy) base.Log().Printf("Limit Dims: %2.2v", camera.limit.dims) } wheel := gin.In().GetKeyFlat(gin.MouseWheelVertical, gin.DeviceTypeAny, gin.DeviceIndexAny) camera.zoom += wheel.FramePressAmt() / 500 if camera.zoom < 0 { camera.zoom = 0 } if camera.zoom > 2 { camera.zoom = 2 } zoom := 1 / math.Exp(camera.zoom) camera.current.dims = camera.limit.dims.Scale(zoom) if gin.In().GetKey(gin.AnySpace).CurPressAmt() > 0 { if !camera.cursorHidden { sys.HideCursor(true) camera.cursorHidden = true } x := gin.In().GetKey(gin.AnyMouseXAxis).FramePressAmt() y := gin.In().GetKey(gin.AnyMouseYAxis).FramePressAmt() camera.current.mid.X -= float64(x) * 2 camera.current.mid.Y -= float64(y) * 2 } else { if camera.cursorHidden { sys.HideCursor(false) camera.cursorHidden = false } } }
func LocalThink(sys system.System, engine *cgf.Engine, game *Game) { sys.Think() engine.Pause() // We might have no level if the event has not gone through yet. if game.Level != nil { render.Queue(func() { game.Render() sys.SwapBuffers() }) game.Level.LocalThink(sys, engine) } render.Purge() engine.Unpause() }
func initWindow(sys system.System, width int, height int) { sys.CreateWindow(10, 10, width, height) sys.EnableVSync(false) err := gl.Init() if err != nil { panic(err) } gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.EnableClientState(gl.VERTEX_ARRAY) gl.EnableClientState(gl.COLOR_ARRAY) gl.Enable(gl.CULL_FACE) gl.FrontFace(gl.CW) gl.ClearColor(0, 0, 0, 1) }
func (l *Level) LocalThink(sys system.System, engine *cgf.Engine) { // Convert the mouse screen coordinates to paddleWidth, paddleHeight range. pixelX, pixelY := sys.GetCursorPos() pb := &l.LevelBlueprint.Players[0] transformedX := float64(pixelX-Config.WindowWidth/2) * (pb.PaddleAreaWidth / float64(Config.WindowWidth)) transformedY := -float64(pixelY-Config.WindowHeight/2) * (pb.PaddleAreaHeight / float64(Config.WindowHeight)) // Clip this to a valid range. p := &l.Paddle x := math.Max(-pb.PaddleAreaWidth/2+p.Width/2, math.Min(transformedX, pb.PaddleAreaWidth/2-p.Width/2)) y := math.Max(-pb.PaddleAreaHeight/2+p.Height/2, math.Min(transformedY, pb.PaddleAreaHeight/2-p.Height/2)) // Create the event. engine.ApplyEvent(&MovePlayerEvent{x, y}) }