Exemple #1
0
func joystick(buttons uint, x, y, z int) {
	if buttons&0x1 > 0 {
		thrust = true
		thrustTime = glut.Get(glut.ELAPSED_TIME)
		joyThrust = true
	} else {
		if joyThrust {
			thrust = false
			joyThrust = false
		}
	}
	if buttons&0x2 > 0 {
		shotBullet()
	}
	if buttons&0x4 > 0 {
		shield = true
		joyShield = true
	} else {
		if joyShield {
			shield = false
			joyShield = false
		}
	}
	if x < -300 {
		left = true
		leftTime = glut.Get(glut.ELAPSED_TIME)
		joyLeft = true
	} else {
		/* joyLeft helps avoid "joystick in neutral"
		   from continually stopping rotation. */
		if joyLeft {
			left = false
			joyLeft = false
		}
	}
	if x > 300 {
		right = true
		rightTime = glut.Get(glut.ELAPSED_TIME)
		joyRight = true
	} else {
		/* joyRight helps avoid "joystick in neutral"
		   from continually stopping rotation. */
		if joyRight {
			right = false
			joyRight = false
		}
	}
}
Exemple #2
0
func key(key byte, px, py int) {
	switch key {
	case 27:
		os.Exit(0)
	case 'A':
	case 'a':
		thrust = true
		thrustTime = glut.Get(glut.ELAPSED_TIME)
	case 'S':
	case 's':
		shield = true
	case 'C':
	case 'c':
		cursor = !cursor
		if cursor {
			glut.SetCursor(glut.CURSOR_INHERIT)
		} else {
			glut.SetCursor(glut.CURSOR_NONE)
		}
	case 'z':
	case 'Z':
		x = 20
		y = 20
		xv = 0
		yv = 0
	case 'f':
		glut.GameModeString("640x480:32@60")
		glut.EnterGameMode()
		initWindow()
	case 'g':
		glut.GameModeString("800x600:32@60")
		glut.EnterGameMode()
		initWindow()
	case 'l':
		if originalWindow != 0 && currentWindow != originalWindow {
			glut.LeaveGameMode()
			currentWindow = originalWindow
		}
	case 'P':
	case 'p':
		paused = !paused
		if paused {
			glut.IdleFunc(nil)
		} else {
			glut.IdleFunc(idle)
			resuming = true
		}
	case 'Q':
	case 'q':
	case ' ':
		shotBullet()
	}
}
Exemple #3
0
func special(key, x, y int) {
	switch key {
	case glut.KEY_F1:
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.Enable(gl.BLEND)
		gl.Enable(gl.LINE_SMOOTH)
		gl.Enable(gl.POINT_SMOOTH)
	case glut.KEY_F2:
		gl.Disable(gl.BLEND)
		gl.Disable(gl.LINE_SMOOTH)
		gl.Disable(gl.POINT_SMOOTH)
	case glut.KEY_UP:
		thrust = true
		thrustTime = glut.Get(glut.ELAPSED_TIME)
	case glut.KEY_LEFT:
		left = true
		leftTime = glut.Get(glut.ELAPSED_TIME)
	case glut.KEY_RIGHT:
		right = true
		rightTime = glut.Get(glut.ELAPSED_TIME)
	}
}
Exemple #4
0
func idle() {
	var delta int

	time := glut.Get(glut.ELAPSED_TIME)
	if resuming {
		lastTime = time
		resuming = false
	}
	if left {
		delta = time - leftTime
		angle = angle + float32(delta)*float32(0.4)
		leftTime = time
	}
	if right {
		delta = time - rightTime
		angle = angle - float32(delta)*float32(0.4)
		rightTime = time
	}
	if thrust {
		delta = time - thrustTime
		v = float32(delta) * 0.00004
		xv = xv + float32(math.Cos(float64(angle)*math.Pi/180.0))*v
		yv = yv + float32(math.Sin(float64(angle)*math.Pi/180.0))*v
		thrustTime = time
	}
	delta = time - lastTime
	x = x + xv*float32(delta)
	y = y + yv*float32(delta)
	x = x / 40.0
	x = (x - float32(math.Floor(float64(x)))) * 40.0
	y = y / 40.0
	y = (y - float32(math.Floor(float64(y)))) * 40.0
	lastTime = time
	advanceBullets(delta, time)
	currentWindow.PostRedisplay()
}
Exemple #5
0
func shotBullet() {
	entry := allocBullet()
	if entry >= 0 {
		initBullet(entry, glut.Get(glut.ELAPSED_TIME))
	}
}