Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Building a cheap Star Control wannabe — Gideros Forum

Building a cheap Star Control wannabe

Cliff76Cliff76 Member
edited May 2013 in Game & application design
SO I'm trying to build something vaguely similar to one of my favorite child hood video games, Star Control. I'm having a slow start with an extremely busy schedule and various things getting me side tracked. I'm starting to learn more about Lua and Gideros and have even started playing with ZeroBrane for live coding! (Pretty cool stuff!) Anyhow, I'm fooling with sounds and I've mocked up my very first Gideros class called Multi-sound. The idea is to play 2 or more sounds in succession with the last sound on a continuous loop until some event occurs. The purpose is to build a multi-stage laser sound which powers up when fired but continuously pulses while you hold the fire button. I'm going to post my naive code here for feedback. Has anyone done something similar? Am I following any bad practices? Please comment on code and direction as I have no clue what I'm doing, just having fun doing it! :)
MultiSound = {}
meta = {}
 
function MultiSound:new(soundFiles)
  self.soundFiles = soundFiles
  return self
end
 
function MultiSound:play()
  local index = 1
  local sound = Sound.new(self.soundFiles[index])
  index = index+1
  self.sound_channel = sound:play()
  local sound_channel_callback = function()
      if index==#self.soundFiles then
        self.sound_channel = Sound.new(self.soundFiles[index]):play(0, math.huge)
      else
        self.sound_channel = Sound.new(self.soundFiles[index]):play()
        index = index+1
        self.sound_channel:addEventListener(Event.COMPLETE,sound_channel_callback)
      end
  end
  self.sound_channel:addEventListener(Event.COMPLETE, sound_channel_callback)
 
end
 
function MultiSound:stop()
  self.sound_channel:stop()
end

Comments

  • Cliff76Cliff76 Member
    Oh, and here's an example of how I'm using it. I've hacked the Audio Example project and added a MultiSoundButton:
    function MultiSoundButton:init(upimage, downimage, soundfiles)
    	local up = Bitmap.new(Texture.new(upimage))
    	local down = Bitmap.new(Texture.new(downimage))
    	local button = Button.new(up, down)
      local sound_channel = nil
     
    	self:addChild(button)
      self.multi = MultiSound:new(soundfiles)
      button:addEventListener("press", function() self.multi:play() end)
      button:addEventListener("click", function() self.multi:stop() end)
     
    end
     
    --later in main.lua...
    local laser = MultiSoundButton.new("3-up.png", "3-down.png", {"laser-start.wav","laser.wav",})
Sign In or Register to comment.