Permalink
Browse files

add displaying players from different angles

  • Loading branch information...
1 parent 388c6c3 commit 8204288e900d47bcbda3acbcebe711894482fe84 @anttisalonen committed Apr 30, 2010
View
BIN share/player1-e.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN share/player1-n.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
0 share/player1.png → share/player1-s.png
File renamed without changes
View
BIN share/player1-w.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
14 src/Main.hs
@@ -316,9 +316,15 @@ startMatch
startMatch f1 f2 ht ho at ao _ = do
ptex <- liftIO $ loadDataTexture Nothing "share/grass1.png" Nothing Nothing
let hcf = colorKit (primarykit ht)
- pltex1 <- liftIO $ loadDataTexture (Just hcf) "share/player1.png" (Just 0) (Just 32)
+ pltexhs <- liftIO $ loadDataTexture (Just hcf) "share/player1-s.png" (Just 0) (Just 32)
+ pltexhn <- liftIO $ loadDataTexture (Just hcf) "share/player1-n.png" (Just 0) (Just 32)
+ pltexhw <- liftIO $ loadDataTexture (Just hcf) "share/player1-w.png" (Just 0) (Just 32)
+ pltexhe <- liftIO $ loadDataTexture (Just hcf) "share/player1-e.png" (Just 0) (Just 32)
let acf = colorKit (primarykit at)
- pltex2 <- liftIO $ loadDataTexture (Just acf) "share/player1.png" (Just 0) (Just 32)
+ pltexas <- liftIO $ loadDataTexture (Just acf) "share/player1-s.png" (Just 0) (Just 32)
+ pltexan <- liftIO $ loadDataTexture (Just acf) "share/player1-n.png" (Just 0) (Just 32)
+ pltexaw <- liftIO $ loadDataTexture (Just acf) "share/player1-w.png" (Just 0) (Just 32)
+ pltexae <- liftIO $ loadDataTexture (Just acf) "share/player1-e.png" (Just 0) (Just 32)
balltex <- liftIO $ loadDataTexture Nothing "share/ball1.png" (Just 0) (Just 8)
playershadowtex <- liftIO $ loadDataTexture Nothing "share/player1shadow.png" (Just 0) (Just 32)
ballshadowtex <- liftIO $ loadDataTexture Nothing "share/ball1shadow.png" (Just 0) (Just 8)
@@ -334,8 +340,8 @@ startMatch f1 f2 ht ho at ao _ = do
atac = fromMaybe (snd $ head allTactics) $ lookup (numPositions (teamtactics at)) allTactics
liftIO $ playMatch
(MatchTextureSet ptex
- pltex1
- pltex2
+ (PlayerTextureSet pltexhs pltexhn pltexhw pltexhe)
+ (PlayerTextureSet pltexas pltexan pltexaw pltexae)
playershadowimg
ballimg
ballshadowimg
View
10 src/Match/Match.hs
@@ -1,6 +1,6 @@
{-# LANGUAGE TemplateHaskell #-}
module Match.Match(playMatch, TeamOwner(..),
- MatchTextureSet(..))
+ MatchTextureSet(..), PlayerTextureSet(..))
where
import Control.Monad
@@ -38,8 +38,8 @@ import Match.State.Controls
data MatchTextureSet = MatchTextureSet {
pitchtexture :: TextureObject
- , hometexture :: TextureObject
- , awaytexture :: TextureObject
+ , hometextureset :: PlayerTextureSet
+ , awaytextureset :: PlayerTextureSet
, playershadowinfo :: ImageInfo
, ballimginfo :: ImageInfo
, ballshadowinfo :: ImageInfo
@@ -95,8 +95,8 @@ createPlayers home texs psize t =
(zip plnums
(map (swosPlayerToPlayer onPitchZ
home
- (hometexture texs)
- (awaytexture texs)
+ (hometextureset texs)
+ (awaytextureset texs)
(playershadowinfo texs)
(humandrawsize texs)
psize)
View
37 src/Match/Player.hs
@@ -23,26 +23,43 @@ data PlayerSkills = PlayerSkills {
}
$(deriveMods ''PlayerSkills)
+data PlayerTextureSet = PlayerTextureSet {
+ pltextures :: TextureObject
+ , pltexturen :: TextureObject
+ , pltexturew :: TextureObject
+ , pltexturee :: TextureObject
+ }
+
data Player = Player {
- plposition :: FRange
- , plimage :: ImageInfo
- , plshadow :: ImageInfo
- , plposz :: Float
- , playerid :: PlayerID
- , plpos :: PlPosition
- , kicktimer :: Int
- , plskills :: PlayerSkills
+ plposition :: FRange
+ , plimgsize :: FRange
+ , pltextureset :: PlayerTextureSet
+ , plshadow :: ImageInfo
+ , plposz :: Float
+ , playerid :: PlayerID
+ , plpos :: PlPosition
+ , kicktimer :: Int
+ , plskills :: PlayerSkills
+ , plrotation :: Float
}
$(deriveMods ''Player)
instance Eq Player where
p1 == p2 = playerid p1 == playerid p2
instance Sprite Player where
- getTexture = imgtexture . plimage
+ getTexture = getPlayerTexture
getRectangle = playerTexRectangle
getDepth = playerHeight
+-- reduce jitter on diagonal movement with an offset of one degree.
+getPlayerTexture :: Player -> TextureObject
+getPlayerTexture p
+ | plrotation p >= 134 && plrotation p < 226 = pltextures . pltextureset $ p
+ | plrotation p >= 226 && plrotation p < 316 = pltexturew . pltextureset $ p
+ | plrotation p >= 44 && plrotation p < 134 = pltexturee . pltextureset $ p
+ | otherwise = pltexturen . pltextureset $ p
+
playerHome :: Player -> Bool
playerHome = snd . playerid
@@ -53,7 +70,7 @@ playerTexRectangle :: Player -> Rectangle
playerTexRectangle p =
((a - c / 2, b), (c, d))
where (a, b) = plposition p
- (c, d) = imgsize $ plimage p
+ (c, d) = plimgsize p
playerHeight :: Player -> Float
playerHeight p = topDownDepth (plposition p) (plposz p)
View
18 src/Match/SWOSShell.hs
@@ -1,8 +1,6 @@
module Match.SWOSShell
where
-import Graphics.Rendering.OpenGL as OpenGL
-
import qualified Swos
import Drawing
import FVector
@@ -22,10 +20,18 @@ swosSkillToSkill = (/1000) . fromIntegral . (*60) . (+1)
swosValueToSkill :: Int -> Skill
swosValueToSkill = (/1000) . fromIntegral . (*19) . (+1)
-swosPlayerToPlayer :: Float -> Bool -> TextureObject -> TextureObject -> ImageInfo -> FRange -> FRange -> Swos.SWOSPlayer -> Player
-swosPlayerToPlayer inz home htex atex plshimg hsize (px, py) p =
- Player (px - 10, py / 2) (ImageInfo tex hsize) plshimg inz ((Swos.plnumber p), home) npos 0 psk
- where tex = if home then htex else atex
+swosPlayerToPlayer :: Float
+ -> Bool
+ -> PlayerTextureSet
+ -> PlayerTextureSet
+ -> ImageInfo
+ -> FRange
+ -> FRange
+ -> Swos.SWOSPlayer
+ -> Player
+swosPlayerToPlayer inz home htexset atexset plshimg hsize (px, py) p =
+ Player (px - 10, py / 2) hsize pltexset plshimg inz ((Swos.plnumber p), home) npos 0 psk 180
+ where pltexset = if home then htexset else atexset
npos = swosPositionToPosition (Swos.plposition p)
psk = PlayerSkills shoots passs speeds controls
shoots | Swos.isGoalkeeper (Swos.plposition p) = swosValueToSkill $ Swos.plvalue p
View
4 src/Match/State/Actions.hs
@@ -8,6 +8,7 @@ where
import Control.Monad.State as State
import System.Random
+import Utils
import FVector
import Match.Ball
@@ -62,6 +63,9 @@ goto (x, y) pl = do
sModBall $ modBallvelocity (const nullFVector3)
sModPendingevents $ (BallKicked:)
sModLasttouch $ const $ Just $ playerid pl
+ -- yup, this is correct (0 degrees = north)
+ when (len2squared runvec > 0.0000001) $
+ sModPlayer c $ modPlrotation $ const $ wrap 0 360 $ radToDeg $ atan2 (-diffx) (-diffy)
modify $ modPlayer c $ modPlposition $ add2 runvec
getRandomR :: (Random a) => (a, a) -> State StdGen a

0 comments on commit 8204288

Please sign in to comment.