示例#1
0
 def update_boundary(self):
     """Calculate cubes within screen bounds."""
     top_left_pixel = cubic.Point(0, 0)
     top_left_cube = cubic.pixel_to_cube(self.layout, top_left_pixel)
     bottom_right_pixel = cubic.Point(SCREEN_WIDTH, SCREEN_HEIGHT)
     bottom_right_cube = cubic.pixel_to_cube(self.layout,
                                             bottom_right_pixel)
     self.boundary.clear()
     if self.layout.orientation == cubic.layout_pointy:
         for cube in self.world:
             if (top_left_cube.q <= cube.q <= bottom_right_cube.q
                     or top_left_cube.r <= cube.r <= bottom_right_cube.r
                     or top_left_cube.s >= cube.s >= bottom_right_cube.s):
                 self.boundary.add(cube)
示例#2
0
def align_hex_top_left(radius):
    # R = Layout.size
    # r = cos30 R = sqrt(3)/2 R
    factor = sqrt(3)/2
    r = cubic.Point(layout.size.x * factor, layout.size.y * factor)
    R = cubic.Point(layout.size.x, layout.size.y)
    if layout.orientation == cubic.layout_pointy:
        x = (2 * r.x * radius) - r.x
        # every 4 tiles skip one R
        y = (2 * R.y * radius) - (2 * R.y * radius/4) + R.y
    else:
        y = (2 * r.y * radius)
        # every 4 tiles skip one R
        x = (2 * R.x * radius) - (2 * R.x * radius/4) -R.x/2
    layout.origin = cubic.Point(x,y)
示例#3
0
def poll_inputs(game, camera):
    """Listens for user input."""
    sdl2.SDL_PumpEvents()  # unsure if necessary
    keystatus = sdl2.SDL_GetKeyboardState(None)
    # continuous-response keys
    if keystatus[sdl2.SDL_SCANCODE_LEFT]:
        camera.pan(cubic.Point(1, 0))
    if keystatus[sdl2.SDL_SCANCODE_RIGHT]:
        camera.pan(cubic.Point(-1, 0))
    if keystatus[sdl2.SDL_SCANCODE_UP]:
        camera.pan(cubic.Point(0, 1))
    if keystatus[sdl2.SDL_SCANCODE_DOWN]:
        camera.pan(cubic.Point(0, -1))

    for event in sdl2.ext.get_events():
        if event.type == sdl2.SDL_QUIT:
            sdl2.ext.quit()

        elif (event.type == sdl2.SDL_MOUSEBUTTONDOWN
              and not game.current_player.ai):
            mousepos_cube = gfx.get_cube_mousepos(
                game.current_player.camera.layout)
            mousepos_tile = game.world.get(mousepos_cube)
            tilepair = mousepos_cube, mousepos_tile
            if mousepos_cube in game.world:
                print(mousepos_cube, mousepos_tile, mousepos_tile.owner)
                if mousepos_tile.army:
                    print(mousepos_tile.army, mousepos_tile.army.owner)
                neighbours = str()
                for neighbour in cubic.get_nearest_neighbours(mousepos_cube):
                    neighbours += str(neighbour)
                print('neighbours:', neighbours)
            if mousepos_tile:
                game.current_player.click_on_tile(tilepair)

        elif event.type == sdl2.SDL_MOUSEWHEEL:
            camera.zoom(event.wheel.y)
示例#4
0
def shape_classic():
    """Generates a cube:tile dict to be used as the game world map,
    identical to the original hex empire 1 world map. Returns the dict.
    """
    layout.orientation = cubic.layout_flat
    layout.origin = cubic.Point(-10, 10)
    MAP_WIDTH = 20
    MAP_HEIGHT = 11
    world_map = dict()
    q = 0
    while (q < MAP_WIDTH):
        q += 1
        q_offset = floor((q+1)/2) # or q>>1
        r = -q_offset
        while (r < MAP_HEIGHT - q_offset):
            r += 1
            world_map[(cubic.Cube(q, r, -q-r))] = Tile()
    return world_map
示例#5
0
"""The worldgen module contains random world generation functions.
It exports the generate_world() function for the Game class __init__()
method. In the future it will be used by some other module that will
allow the user to tweak the worldgen settings from within the game.
"""
from dataclasses import dataclass
from math import sqrt, floor
import random

import cubic
import data
# from playergen import Player

layout = cubic.Layout(cubic.layout_pointy, cubic.Point(50, 50), cubic.Point(800, 550))

@dataclass
class Locality:
    name: str = ''
    category: str = ''

@dataclass
class Tile:
    """Represents the data held by a game tile

    Attributes
    ----------
    owner : Player | None
        The tile owner.
    category : str
        Tile type - i.e. water/land.
    locality: Locality | None