Difference between revisions of "Short-Issue-1"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
Line 15: Line 15:
  
 
=== The code ===
 
=== The code ===
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
SCREEN_W, SCREEN_H = 320,480
 
SCREEN_W, SCREEN_H = 320,480
 
function makeShape(p,fcol,px,lcol,scale)
 
function makeShape(p,fcol,px,lcol,scale)

Revision as of 14:30, 13 July 2023

Overheat By PaulH

Gideros Short— N°1 —June 2023 PDF link

Description

Short-OverHeat-Img.png

This one is a side-scrolling flight game. You're flying an airplane over rugged terrain, but the engine is overheating. As you climb the heat increases, both with rate of climb and with altitude. As you glide it cools down. If it overheats too much, you lose power.

Graphically it's a 3 layer scrolling landscape, with the mountains you need to clear in the foreground, and two more distant layers of mountains in the background.

How to play: how high you click or touch on the screen controls how sharply the airplane will pitch upwards, and how fast the heat will build up. Touching near the top will turn the plane upwards as quickly as possible, but will also build up heat the fastest. Ending the touch will let the engine cool but the airplane will begin to dive. If you crash, relaunch the game to try again.


If I had space to spare I'd love to add power-ups, like clouds you could fly through to cool the engine.

The code

<syntaxhighlight lang="lua"> SCREEN_W, SCREEN_H = 320,480 function makeShape(p,fcol,px,lcol,scale) local s=Shape.new() s:setLineStyle(px or 0,lcol or 0) s:setFillStyle(Shape.SOLID,fcol) s:beginPath() local sc=scale or 1 s:moveTo(p[1]*sc,p[2]*sc) for i = 3, #p,2 do s:lineTo(p[i]*sc,p[i+1]*sc) end s:endPath() return s end local bg = makeShape({0,0,SCREEN_W,0,SCREEN_W,SCREEN_H,0,SCREEN_H,0,0}, 0xbbffee) stage:addChild(bg) LandScroll = gideros.class(Sprite) function LandScroll:init(speed,col,min_h,max_h,rugged,block_w) self.speed, self.col, self.min_h, self.max_h, self.rugged, self.block_w=speed,col,min_h,max_h,rugged,block_w self.right, self.height = -block_w, math.random(self.min_h, self.max_h) while self.right < SCREEN_W + self.block_w do self:addBlock() end self:addEventListener(Event.ENTER_FRAME, function() self.right-=self.speed*gspeed for i = self:getNumChildren(), 1, -1 do local ch = self:getChildAt(i) local x, y = ch:getPosition() ch:setPosition(x - self.speed*gspeed, y) if x < 0 - block_w then ch:removeFromParent() self:addBlock() end end end ) end function LandScroll:addBlock() local new_h = math.min(self.max_h, math.max(self.min_h, self.height + math.random(-20, 20) * 0.001 * self.rugged)) local s=makeShape({0, SCREEN_H*(1-self.height),self.block_w+1,SCREEN_H*(1-new_h),self.block_w+1, SCREEN_H,0, SCREEN_H,0,0},self.col) s:setAnchorPoint(0,1) s:setPosition(self.right, SCREEN_H) self.right+=self.block_w self:addChild(s) s.start_height, s.end_height = self.height, new_h self.height = new_h end function LandScroll:getHeight(x) local h = 0 for i = 1, self:getNumChildren() do local ch = self:getChildAt(i) local chx, chy = ch:getPosition() if x >= chx and x <= chx + self.block_w then h = ch.start_height + (ch.end_height - ch.start_height) * (x - chx) / self.block_w break end end return (1-h)*SCREEN_H end stage:addChild(LandScroll.new(0.1,0xff9944,0.5, 0.8,2,10)) stage:addChild(LandScroll.new(0.3,0xee8833,0.2, 0.7,1.5,20)) t1=LandScroll.new(1,0x773322,0.05,0.6,5,30) stage:addChild(t1) plane=makeShape({0,0,3,0,6,3,7,4,15,4.5,18,4,20,2.2,23.5,2.5,24,4,18,4,17,5,20,6,24,6,26,5,24,4,26,5,30,5,31,5.5,30,6,30,3,30,8, 30,5,30,6,29,7.5,27,8,21,8.5,20,8.2,4,6,2,5.5,1.7,5,6.5,5,6.4,5.2,1.7,5,0,0},0x00ffff,1,0,1) plane:setAnchorPoint(0.75,0.5) stage:addChild(plane) px,py = SCREEN_W * 0.3, SCREEN_H * 0.2 heat_tf=TextField.new(null,"HEAT") stage:addChild(heat_tf) heat_tf:setPosition(100, 50) heat_tf:setScale(3) needle=makeShape({2,0,4,50,0,50,2,0},0xff0000) needle:setPosition(132,55) stage:addChild(needle) needle:setAnchorPoint(0,1) heat,max_heat,climb=0,200,0 gspeed,climb = 1,0 function on_enter_frame() if not game_over then if in_y and heat < max_heat then climb -= ((in_y > SCREEN_H * 0.5 and 1) or -1) * 0.01 heat+=(SCREEN_H - py)/ SCREEN_H * 2 else heat=math.max(0, heat-1) climb-=0.01 end py = math.min(SCREEN_H, math.max(SCREEN_H * 0.1, py - climb)) plane:setPosition(px, py) local h=t1:getHeight(px) if py>h then py=h game_over=1 gspeed=0 end plane:setRotation(climb*-30) needle:setRotation(heat/max_heat*180-90) end end stage:addEventListener(Event.ENTER_FRAME, on_enter_frame) stage:addEventListener(Event.MOUSE_DOWN, function(e) in_y = e.y end) stage:addEventListener(Event.MOUSE_MOVE, function(e) in_y = e.y end) stage:addEventListener(Event.MOUSE_UP, function() in_y = nil end) </source>