[Moeng-cvs] CaveAdventure/data/scripts Enemy.lua,NONE,1.1 Hud.lua,NONE,1.1 Rat.lua,NONE,1.1
Status: Alpha
Brought to you by:
b_lindeijer
From: <b_l...@us...> - 2004-01-13 19:23:07
|
Update of /cvsroot/moeng/CaveAdventure/data/scripts In directory sc8-pr-cvs1:/tmp/cvs-serv29553 Added Files: Enemy.lua Hud.lua Rat.lua Log Message: Any problems here? --- NEW FILE: Enemy.lua --- import("Character.lua") Enemy = Character:subclass { name = "Enemy"; --== Commands ==-- attack = function(self) if (self.bAttacking == false and self.walking == 0 and self.charging == 0) then self:log("attacking.") self.bAttacking = true -- See if there is something at the attacked location local ax, ay = self.x, self.y if (self.dir == DIR_LEFT) then ax = ax - 1 end if (self.dir == DIR_RIGHT) then ax = ax + 1 end if (self.dir == DIR_UP) then ay = ay - 1 end if (self.dir == DIR_DOWN) then ay = ay + 1 end local attackedObjs = m_get_objects_at(ax, ay, self.map) local damage = self.attackMinDam + math.random(self.attackMaxDam - self.attackMinDam) -- Deal damage for index, object in attackedObjs do if (object:instanceOf(Actor)) then object:takeDamage(damage, self) end end -- Enable next attack after attackTime + chargeTime game ticks ActionController:addSequence{ ActionWait(self.attackTime), ActionSetVariable(self, "bAttacking", false), ActionSetVariable(self, "charging", self.chargeTime), } end end; --== Notifications ==-- died = function(self, killer, damageType, location) -- Let character adapt to dead status Character.died(self, killer, damageType, location) -- Give players experience if (killer and killer:instanceOf(Player)) then killer:gainExperience(self.experience) end -- Fade away ActionController:addSequence({ ActionWait(100), ActionSetVariable(self, "draw_mode", DM_TRANS), ActionTweenVariable(self, "alpha", 200, 0), ActionDestroyObject(self), }) -- Enemies don't need tick when dead self.tick_time = 0 end; defaultproperties = { experience = 0, attackTime = 50, chargeTime = 100, charging = 0, attackMinDam = 0, attackMaxDam = 5, bAttacking = false, deathBitmap = nil, controllerClass = AIController, }; } --- NEW FILE: Hud.lua --- -- -- This file contains the code for putting the HUD on the screen. -- By Bjorn Lindeijer import("Interaction.lua") -- -- The actual HUD. -- Hud = Interaction:subclass { name = "Hud"; init = function(self) -- Screen size self.screen_w, self.screen_h = m_screen_size() -- Health bar images self.hb_empty = m_get_bitmap("healthbar_empty.bmp") self.hb_full = m_get_bitmap("healthbar_full.bmp") self.hb_w, self.hb_h = m_bitmap_size(self.hb_full) -- Experience bar images self.eb_empty = m_get_bitmap("expbar_empty.bmp") self.eb_full = m_get_bitmap("expbar_full.bmp") self.eb_w, self.eb_h = m_bitmap_size(self.eb_full) -- Game over image self.game_over = m_get_bitmap("game_over.bmp") self.game_over_s = m_get_bitmap("game_over_s.bmp") self.go_w, self.go_h = m_bitmap_size(self.game_over) end; -- A chance to put something on the screen (requires bVisible) postRender = function(self, canvas) --[[ local player = m_get_player() local health_perc = player.health / player.maxHealth local experience_perc = player.experience / player.nextLevelExperience -- Draw the health bar m_set_alpha(128) m_set_cursor(16, 16) draw_icon(self.hb_empty) m_set_cursor(16, 16) draw_pattern(self.hb_full, self.hb_w * health_perc, self.hb_h) -- Draw the experience bar m_set_cursor(16, 27) draw_icon(self.eb_empty) m_set_cursor(16, 27) draw_pattern(self.eb_full, self.eb_w * experience_perc, self.eb_h) m_set_alpha(255) ]] -- Map name if (self.map_name ~= nil and self.map_name_alpha > 0) then local w, h = m_bitmap_size(self.map_name) local x, y = (self.screen_w - w)/2, (self.screen_h - h)/6 * 5 local alpha = self.map_name_alpha -- Take map fading into account if (map_fade ~= nil and map_fade.alpha ~= nil and map_fade.alpha > 0) then alpha = alpha * (255 - map_fade.alpha) / 255 end canvas:setCursor(x, y); canvas:setAlpha(0.75 * alpha); canvas:drawIcon(self.map_name) canvas:setCursor(0, y - 10); canvas:setAlpha(alpha); canvas:drawRect(m_get_bitmap("pixel_black.bmp"), self.screen_w, 1) canvas:setCursor(0, y - 10); canvas:setAlpha(0.25 * alpha); canvas:drawRect(m_get_bitmap("pixel_black.bmp"), self.screen_w, h + 20) canvas:setCursor(0, y + h + 10); canvas:setAlpha(alpha); canvas:drawRect(m_get_bitmap("pixel_black.bmp"), self.screen_w, 1) end -- Draw gameover screen stuff if (game.game_over and game.game_over_alpha and game.game_over_alpha > 0) then canvas:setAlpha(0.25 * game.game_over_alpha) canvas:setCursor((self.screen_w - self.go_w)/2 + 6, (self.screen_h - self.go_h)/3 + 4) canvas:drawIcon(self.game_over_s) canvas:setAlpha(game.game_over_alpha) canvas:setCursor((self.screen_w - self.go_w)/2, (self.screen_h - self.go_h)/3) canvas:drawIcon(self.game_over) end end; defaultproperties = { count = 0, map_name_alpha = 0, } } --- NEW FILE: Rat.lua --- -- -- A rat. -- -- bodged by Hedde Bosman import("Player.lua") import("AdvAIRandom.lua") import("Shadow.lua") RatShadow = Shadow:subclass { name = "RatShadow"; defaultproperties = { offset_z = -3, bitmap = m_get_bitmap("rat_s.tga"), }; } Rat = Enemy:subclass { name = "Rat"; bPlaceable = true; defaultproperties = { attackMinDam = 0, attackMaxDam = 2, maxHealth = 20, speed = 4, experience = 12, draw_mode = DM_MASKED, charAnim = extr_char_anim(m_get_bitmap("rat.bmp"), 16, 16), deathBitmap = m_get_bitmap("rat_dead.bmp"), nature = NEUTRAL, controllerClass = AdvAIRandom, shadowClass = RatShadow, hitEffectHeight = 0, }; } |