Added full-surface alpha and rotaiton and scaling support
[luagame.git] / demos / shine_on / scripts / Sun.lua
bloba8b642014ba0f965bfa82053cde3d7831404645c
1 Sun = Object:new()
2 Sun.type = "Sun"
3 Sun.image, Sun.w, Sun.h = get_image("images/sun_base.png")
4 Sun.image_o, Sun.w_o, Sun.h_o = get_image("images/sun_overlay.png")
5 Sun.image_b = get_image("images/sunbeam.png")
7 Sun.x_offset = 64
8 Sun.y_offset = 0
9 Sun.x = 320
10 Sun.y = 0
11 Sun.rd = 0
12 Sun.sp = 0
13 Sun.heading = 0
14 Sun.speed_mov = 8
15 Sun.beam_time = 0
17 Sun.beam_on = false
19 function Sun:new(o)
20 o = o or {}
21 setmetatable(o, self)
22 self.__index = self
23 o.in_lerp = create_relative_lerp(20,0,255)
24 o.out_lerp = create_relative_lerp(20,255,0)
25 return o
26 end
28 function Sun:draw()
29 if self.beam_on == true then
30 display(self.image_b,self.x-32,self.y+64,0,1,1, self.b_alpha)
31 end
33 Object.draw(self)
34 display(self.image_o, self.x-self.x_offset, self.y-self.y_offset, 0, 1, 1, 255)
35 end
37 function Sun:update(delta)
38 if self.beam_on then
39 self.beam_time = self.beam_time - 1
40 if self.beam_time > 20 then
41 self.b_alpha = self.in_lerp(1)
42 else
43 self.b_alpha = self.out_lerp(1)
44 end
45 end
47 if self.beam_on and self.beam_time <= 0 then self.beam_on = false beam_psys_o.on = false beam_psys_w.on = false end
48 self.speed = (math.cos(math.rad(self.sp))*self.speed_mov)
50 Object.update(self,delta)
51 Sun_psys.x = self.x
52 Sun_psys.y = self.y + 16
53 self.rotation = math.cos(math.rad(self.rd))*20
54 self.rd = self.rd + 1.5
55 self.sp = self.sp + 2.0
56 if self.rd > 360 then self.rd = self.rd - 360 end
57 if self.sp > 360 then self.sp = self.sp - 360 end
58 end
60 function Sun:collide(ids, object)
62 end