Skip to content

Commit

Permalink
Merge pull request #40 from xescugc/fg-2
Browse files Browse the repository at this point in the history
  • Loading branch information
xescugc authored Oct 23, 2023
2 parents 5a87942 + dd20db5 commit 159da58
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 81 deletions.
45 changes: 45 additions & 0 deletions action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Action struct {
CameraZoom *CameraZoomPayload `json:"camera_zoom,omitempty"`
SelectTower *SelectTowerPayload `json:"select_tower,omitempty"`
PlaceTower *PlaceTowerPayload `json:"place_tower,omitempty"`
RemoveTower *RemoveTowerPayload `json:"remove_tower,omitempty"`
SelectedTowerInvalid *SelectedTowerInvalidPayload `json:"selected_tower_invalid,omitempty"`
TowerAttack *TowerAttackPayload `json:"tower_attack,omitempty"`
UnitKilled *UnitKilledPayload `json:"unit_killed,omitempty"`
Expand All @@ -24,6 +25,9 @@ type Action struct {
NavigateTo *NavigateToPayload `json:"navigate_to, omitempty"`
StartGame *StartGamePayload `json:"start_game, omitempty"`

OpenTowerMenu *OpenTowerMenuPayload `json:"open_tower_menu, omitempty"`
CloseTowerMenu *CloseTowerMenuPayload `json:"close_tower_menu, omitempty"`

AddPlayer *AddPlayerPayload `json:"add_player, omitempty"`
RemovePlayer *RemovePlayerPayload `json:"remove_player, omitempty"`
JoinRoom *JoinRoomPayload `json:"join_room, omitempty"`
Expand Down Expand Up @@ -130,6 +134,23 @@ func NewPlaceTower(t, pid string, x, y int) *Action {
}
}

type RemoveTowerPayload struct {
PlayerID string
TowerID string
TowerType string
}

func NewRemoveTower(pid, tid, tt string) *Action {
return &Action{
Type: RemoveTower,
RemoveTower: &RemoveTowerPayload{
PlayerID: pid,
TowerID: tid,
TowerType: tt,
},
}
}

type SelectTowerPayload struct {
Type string
X int
Expand Down Expand Up @@ -303,6 +324,29 @@ func NewStartGame() *Action {
}
}

type OpenTowerMenuPayload struct {
TowerID string
}

func NewOpenTowerMenu(tid string) *Action {
return &Action{
Type: OpenTowerMenu,
OpenTowerMenu: &OpenTowerMenuPayload{
TowerID: tid,
},
}
}

type CloseTowerMenuPayload struct {
}

func NewCloseTowerMenu() *Action {
return &Action{
Type: CloseTowerMenu,
CloseTowerMenu: &CloseTowerMenuPayload{},
}
}

type UpdateStatePayload struct {
Players *UpdateStatePlayersPayload
Towers *UpdateStateTowersPayload
Expand Down Expand Up @@ -333,6 +377,7 @@ type UpdateStateTowersPayload struct {
type UpdateStateTowerPayload struct {
utils.Object

ID string
Type string
LineID int
PlayerID string
Expand Down
3 changes: 3 additions & 0 deletions action/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
RemoveUnit
StealLive
PlaceTower
RemoveTower
SelectTower
SelectedTower
SelectedTowerInvalid
Expand All @@ -23,6 +24,8 @@ const (
PlayerReady
NavigateTo
StartGame
OpenTowerMenu
CloseTowerMenu

// Specific to WS
JoinRoom
Expand Down
138 changes: 75 additions & 63 deletions action/type_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added assets/TilesetLogic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ var CyclopeFaceset_png []byte
//go:embed TilesetHouse.png
var TilesetHouse_png []byte

//go:embed TilesetLogic.png
var TilesetLogic_png []byte

//go:embed cyclope/Cyclopes.png
var Cyclopes_png []byte

Expand Down
26 changes: 23 additions & 3 deletions client/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,16 @@ func (ac *ActionDispatcher) CameraZoom(d int) {

// PlaceTower places the tower 't' on the position X and Y of the player pid
func (ac *ActionDispatcher) PlaceTower(t, pid string, x, y int) {
bta := action.NewPlaceTower(t, pid, x, y)
wsSend(bta)
ac.dispatcher.Dispatch(bta)
pta := action.NewPlaceTower(t, pid, x, y)
wsSend(pta)
ac.dispatcher.Dispatch(pta)
}

// RemoveTower removes the tower tid
func (ac *ActionDispatcher) RemoveTower(pid, tid, tt string) {
rta := action.NewRemoveTower(pid, tid, tt)
wsSend(rta)
ac.dispatcher.Dispatch(rta)
}

// SelectTower selects the tower 't' on the position x, y
Expand Down Expand Up @@ -143,3 +150,16 @@ func (ac *ActionDispatcher) StartGame() {
sg := action.NewStartGame()
ac.dispatcher.Dispatch(sg)
}

// OpenTowerMenu when a tower is clicked and the menu of
// the tower is displayed
func (ac *ActionDispatcher) OpenTowerMenu(tid string) {
otm := action.NewOpenTowerMenu(tid)
ac.dispatcher.Dispatch(otm)
}

// CloseTowerMenu when a tower menu needs to be closed
func (ac *ActionDispatcher) CloseTowerMenu() {
ctm := action.NewCloseTowerMenu()
ac.dispatcher.Dispatch(ctm)
}
12 changes: 8 additions & 4 deletions client/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ func (g *Game) Update() error {
g.HUD.Update()
g.Units.Update()
g.Towers.Update()

return nil
}

func (g *Game) Draw(screen *ebiten.Image) {
g.Camera.Draw(screen)
g.HUD.Draw(screen)
g.Units.Draw(screen)
g.Towers.Draw(screen)

// Draw will draw just a partial image of the map based on the viewport, so it does not render everything but just the
// part that it's seen by the user
// If we want to render everything and just move the viewport around we need o render the full image and change the
// opt.GeoM.Transport to the Map.X/Y and change the Update function to do the opposite in terms of -+
//
// TODO: Maybe create a self Map entity with Update/Draw
op := &ebiten.DrawImageOptions{}
s := g.Camera.GetState().(CameraState)
op.GeoM.Scale(s.Zoom, s.Zoom)
inverseZoom := maxZoom - s.Zoom + zoomScale
screen.DrawImage(g.Map.GetState().(store.MapState).Image.(*ebiten.Image).SubImage(image.Rect(int(s.X), int(s.Y), int((s.X+s.W)*inverseZoom), int((s.Y+s.H)*inverseZoom))).(*ebiten.Image), op)

g.Camera.Draw(screen)
g.HUD.Draw(screen)
g.Units.Draw(screen)
g.Towers.Draw(screen)
}
Loading

0 comments on commit 159da58

Please sign in to comment.