Esempio n. 1
0
func NewCar(owner *Player, spriteFG, spriteBG *Sprite, carSize float32, font *ttf.Font) *Car {
	textNick := ttf.RenderUTF8_Blended(font, owner.Nick, sdl.Color{255, 255, 255, 0})
	spriteNick := NewSpriteFromSurface(textNick)
	return &Car{
		position:        Vector{0, 0},
		velocity:        Vector{0, 0},
		maxVelocity:     100,
		zLevel:          0,
		layer:           0,
		owner:           owner,
		force:           Vector{0, 0},
		torque:          0,
		angularVelocity: 0,
		angle:           0,
		mass:            5,
		inertia:         200,
		wheels: [2]*Wheel{
			NewWheel(Vector{0, carSize / 2.0}, 4),
			NewWheel(Vector{0, -carSize / 2.0}, 4),
		},
		spriteFG:   spriteFG,
		spriteBG:   spriteBG,
		size:       carSize,
		width:      carSize * 18 / 32.0,
		height:     carSize * 1,
		spriteNick: spriteNick,
	}
}
Esempio n. 2
0
func NewRacer(levelDir string) (*Racer, error) {
	r := &Racer{cars: make([]*Car, 0)}

	var err error
	if r.obstaclemap, err = LoadImageGray(filepath.Join(levelDir, "velocity.png")); err != nil {
		return nil, err
	}
	if r.heightmap, err = LoadImageGray(filepath.Join(levelDir, "z.png")); err != nil {
		return nil, err
	}

	carSize := 0.02 * float32(screenWidth)
	if r.spriteCarFG, err = NewSprite("data/cars/car1/fg.png", carSize, carSize); err != nil {
		return nil, err
	}
	if r.spriteCarBG, err = NewSprite("data/cars/car1/bg.png", carSize, carSize); err != nil {
		return nil, err
	}

	r.carSize = carSize

	if r.spriteForeground, err = NewSprite(filepath.Join(levelDir, "foreground.png"), screenWidth, screenHeight); err != nil {
		return nil, err
	}
	if r.spriteBackground, err = NewSprite(filepath.Join(levelDir, "background.png"), screenWidth, screenHeight); err != nil {
		return nil, err
	}

	if r.music = mixer.LoadMUS("data/music.ogg"); r.music == nil {
		return nil, errors.New(sdl.GetError())
	}

	if r.font = ttf.OpenFont("data/font.otf", 32); r.font == nil {
		return nil, errors.New(sdl.GetError())
	}

	textWaiting := ttf.RenderUTF8_Blended(r.font, "Waiting for other players. Press space to start....", sdl.Color{0, 0, 255, 0})
	r.spriteWaiting = NewSpriteFromSurface(textWaiting)

	return r, nil
}
Esempio n. 3
0
func (renderer *SDLRenderer) renderLine(pos int, line string) {
	x := renderer.commandLineRect.X
	y := int16(renderer.commandLineRect.Y) - int16(renderer.fontHeight*uint(pos))
	w := renderer.commandLineRect.W
	h := renderer.commandLineRect.H

	renderer.internalSurface.FillRect(&sdl.Rect{x, y, w, h}, 0)

	if len(line) == 0 {
		return
	}

	var textSurface *sdl.Surface
	if renderer.Blended {
		textSurface = ttf.RenderUTF8_Blended(renderer.Font, line, renderer.Color)
	} else {
		textSurface = ttf.RenderUTF8_Solid(renderer.Font, line, renderer.Color)
	}

	if textSurface != nil {
		renderer.internalSurface.Blit(&sdl.Rect{x, y, w, h}, textSurface, nil)
		textSurface.Free()
	}
}