Galaxy
Nov 2014 to Jan 2015
Galaxy is an idle strategic game. Player manage a space fleet with one to eight ships. The fleet keep travelling automatically, even when the player is offline. During the travel, the fleet may fighting enemy or exploiting planet. Player may customize their ships and weapons. My main responsibility was front-end programming, I also helped UI design and battle design.
Overview
- Role: Front-end Programmer
- Team: 5 People (2 designers, 2 front-end programmer, 1 back-end programmer)
- Time: 10 Weeks
- Tools: Cocos2D, Lua
Responsibilities
- Most of front-end programming.
- Design and implemented the animation mode in battle system.
Challenges
Battle Logic
For security, we compute battle in server, and send the process detail and result to front-end. I design the finite state machine as shown below:
I also design a intuitive and simple code framework for finite state machine:
state.Current = function(arg) -- do something transition (state.Next, duration, {nextArg}) end
Because of the clear state machine logic and the simple code framework, I finished the entire state machine quickly.
Battle Animation
The biggest problem to implement battle animation was to align the missile animation. Which means use translation, rotation and scaling to make the missile launch from the attacker and hit the target. The missile animations were frame animation. And our animation resources were not uniform, so I record the launch point and hit point of every missile animation.
Then I translation, rotation and scaling them to the proper position.
local vec1 = {x = hit.defX - hit.attX, y = hit.defY - hit.attY} local vec2 = {x = to.x - from.x, y = to.y - from.y} local sqrtVecsLenMult = math.sqrt(vec1.x^2 + vec1.y^2) * math.sqrt(vec2.x^2 + vec2.y^2) local vecsCos = (vec1.x * vec2.x + vec1.y * vec2.y) / sqrtVecsLenMult local vecsSin = (vec1.x * vec2.y - vec2.x * vec1.y) / sqrtVecsLenMult local rad = (vecsSin > 0 and math.acos(vecsCos)) or -math.acos(vecsCos) local angle = math.deg(rad) local scale = math.sqrt(((from.x-to.x)^2) + ((from.y-to.y)^2)) / math.sqrt(((hit.attX-hit.defX)^2) + ((hit.attY-hit.defY)^2)) local centerX , centerY = GEOMETRY.rotatePoint(hit.attX, hit.attY, 0, 0, rad) centerX = (centerX - hit.attX) * scale + from.x centerY = (centerY - hit.attY) * scale + from.y