查看: 8443|回复: 5

[已经解决] 想做一个恐怖游戏,需要一个烛光系统

[复制链接]
梦石
0
星屑
75
在线时间
231 小时
注册时间
2014-10-5
回帖
226
发表于 2015-10-29 22:33:37 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
VA和XP有很多烛光系统,都是用的遮罩图片什么的,在MV里面要做一个烛光系统,要怎么做?
直接建立一个图片始终覆盖在游戏里面?
创建一个始终在地图上覆盖的精灵的JS代码我都不知道怎么打,有没有大神出来教教我啊
梦石
0
星屑
275
在线时间
1373 小时
注册时间
2005-10-16
回帖
5038

贵宾

发表于 2015-10-29 23:02:21 | 显示全部楼层
显示个图片就好
$gameScreen.pictures[1].move(...)
好像还是这样,参数的意义也都和之前一样
依然可以用一个巨大无比的掏了一个窟窿个黑纸来通过移动图片的方式来解决。

评分

参与人数 1星屑 +166 收起 理由
余烬之中 + 166 认可答案

查看全部评分

我只个搬答案的
叔叔我已经当爹了~
婚后闪人了……
回复 0 1

使用道具 举报

梦石
0
星屑
80
在线时间
243 小时
注册时间
2007-2-10
回帖
46

开拓者

发表于 2015-10-30 13:28:51 | 显示全部楼层
本帖最后由 203X 于 2015-10-30 23:06 编辑

这样
QQ截图20151030132510.jpg
QQ截图20151030132554.jpg
QQ截图20151030230426.jpg

图片文件
l.png

点评

我试过强行更改变量,中心对准人物了,可是随着人物的移动,中线点会偏移,你是怎么解决这个的  发表于 2015-10-30 22:07
我按照你说的做了,可是总是对不上,我做的显示的空白中心在左上角,怎么设置都没办法  发表于 2015-10-30 20:51

评分

参与人数 1梦石 +1 收起 理由
余烬之中 + 1 认可答案

查看全部评分

。。。
回复

使用道具 举报

梦石
0
星屑
80
在线时间
243 小时
注册时间
2007-2-10
回帖
46

开拓者

发表于 2015-10-30 23:08:32 | 显示全部楼层
203X 发表于 2015-10-30 13:28
这样

原点设置中点,
坐标记得是取画面的X,Y,而不是地图的X,Y
。。。
回复

使用道具 举报

名侦探小柯

梦石
10
星屑
4393
在线时间
3739 小时
注册时间
2006-9-6
回帖
36595

极短27获奖MZ评测员开拓者贵宾第3届短篇游戏大赛主流游戏组亚军第5届短篇游戏比赛亚军

发表于 2015-10-31 00:37:03 | 显示全部楼层
其实原理就是ULDS一类的,本区已经有一堆这类的系统发布了……

点评

本区查找ULDS、overlay、图层之类的关键字  发表于 2015-10-31 14:36
在哪里,,,,我怎么没看到哦  发表于 2015-10-31 07:38
不定期回归 ~ 游戏开发之旅
———————————————————————————————
回复

使用道具 举报

梦石
0
星屑
22879
在线时间
8598 小时
注册时间
2011-12-31
回帖
3270
发表于 2015-11-6 11:56:32 | 显示全部楼层
本帖最后由 tseyik 于 2015-11-8 11:44 编辑

150528162402e54ec3f2f14cf5.png
範例1.06,開新工程,把東西放到新工程柤応文件夾
demo.zip (328.86 KB, 下载次数: 523)
增加点滅功能(Fire)
[fold=Terrax Plugins - Lighting system1.06][pre lang="ruby"]//=============================================================================
// Terrax Plugins - Lighting system
// TerraxLighting.js
// Version: 1.06
//=============================================================================
//
// This script should be compatible with most other scripts, it overwrites one
// core script (Spriteset_Map.prototype.createLowerLayer) in rpg_sprites.js to
// add a new layer.

//=============================================================================
/*:
* @plugindesc v1.06 Creates an extra layer that darkens a map and adds lightsources!
* @author Terrax
*
* @param Player radius
* @desc Adjust the light radius around the player
* Default: 300
* @default 300
*
* @param Reset Lights
* @desc Resets the light switches each map
* Default: No
* @default No

*
* @help
* To activate the script in an area, do the following:
* 1. Put an event switch into the map.
* 2. In the 'Note' field (Next to the name) put the following text :
* Light 250 #FFFFFF
* - Light activates the script
* - 250 is the lightradius of the object
* - #FFFFFF is the lightcolor (white in this case)
* 3. You're done, its that simple.
*
* To alter the player radius in game use the following plugin command :
* Light radius 200 #FFFFFF  
* (to change the radius and the color)
*
* Optional: to turn on and off lightsources in the game, do the following:
* Give the lightsource the normal def :  Light 250 #FFFFFF and an extra number
* so it becomes 'Light 250 #FFFFFF 1'
* To turn on this light use plugin command : 'Light on 1'.
* The plugin command will also trigger SelfSwitch 'D' on the targeted light(s).
* To turn off the light use plugin command : 'Light off 1'.
* You can reset the switches each map with the option or manualy by
* the plugin command 'Light switch reset'
*
* Replacing the 'Light' keyworld with 'Fire' will give the lights a subtle flicker
*
* Released under the MIT license,
* if used for commercial projects feel free to make a donation or
* better yet, give me a free version of what you have created.
* e-mail : fox(AT)caiw.nl / terraxz2 on steam.
*

*/
//=============================================================================
//  ps.. if my code looks funky, i'm an old guy..
// object orientated programming bugs the hell out of me.
var testcounter = 0;
//var lightarray_id = [];
//var lightarray_state = [];

(function() {
        var lightarray_id = [];
        var lightarray_state = [];
        var oldmap = 0;
    var playercolor = '#FFFFFF';  
    var playerflicker = false;
    var playerflashlight = false;
        var parameters = PluginManager.parameters('TerraxLighting');
    var player_radius = Number(parameters['Player radius'] || 300);       
        var reset_each_map = parameters['Reset Lights'] || No;  
   
    var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        _Game_Interpreter_pluginCommand.call(this, command, args);
      
        if (command === 'Light' || command === 'light'  || command === 'Fire' || command === 'fire' || command === 'Flashlight' || command === 'flashlight') {
            
                if (command === 'Flashlight' || command === 'flashlight') {
                            playerflashlight = true;
                           
                    } else {
                                playerflashlight = false;   
                        }
                
                if (command === 'Fire' || command === 'fire') {
                            playerflicker = true;
                    } else {
                                playerflicker = false;   
                        }                       
                       
                var evid = this._eventId;
                // Light radius 100 #FFFFFF              
                if (args[0] == 'radius') {
                            var newradius = Number(args[1]);
                            if (newradius >= 0) {
                                    player_radius = newradius;
                                   
                                }
                       
                                if (args.length > 2) {
                                        playercolor = args[2];
                                        var isValidPlayerColor  = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(playercolor);             
                                        if (!isValidPlayerColor) {
                                                playercolor = '#FFFFFF'   
                                        }
                                }
                        }
                        if (args[0] == 'on') {
                             var lightid = Number(args[1]);
                            var idfound = false;
                                for (var i = 0; i < lightarray_id.length; i++) {
                                        if (lightarray_id == lightid) {
                                                idfound = true;
                                                lightarray_state = true;
                                                //Graphics.printError('test','found');
                                        }
                                }
                                if (idfound == false) {
                                        lightarray_id.push(lightid);
                                        lightarray_state.push(true);
                                       
                                }
                        }       
                        if (args[0] == 'off') {
                            var lightid = Number(args[1]);
                            var idfound = false;
                                for (var i = 0; i < lightarray_id.length; i++) {
                                        if (lightarray_id == lightid) {
                                                idfound = true;
                                                lightarray_state = false;
                                        }
                                }
                                if (idfound == false) {
                                        lightarray_id.push(lightid);
                                        lightarray_state.push(false);
                                }
                        }
                        if (args[0] == 'switch' && args[1] == 'reset') {
                                // reset switches to false
                                for (var i = 0; i < $dataMap.events.length; i++) {
                                if ($dataMap.events) {
                                                for (var j = 0; j < lightarray_id.length; j++) {
                                                        if (lightarray_id[j] == lightid) {
                                                                var mapid = $gameMap.mapId();
                                                                var eventid = $dataMap.events.id;
                                                                var key = [mapid,eventid,'D'];
                                                                $gameSelfSwitches.setValue(key, false);
                                                        }
                                                }
                                        }
                                }
                            Lightarray_id = [];
                                lightarray_state = [];
                        }
                       
                }  
        }
   
        Spriteset_Map.prototype.createLightmask = function() {
            this._lightmask = new Lightmask();
            this.addChild(this._lightmask);
        };
       
       
        function Lightmask() {
            this.initialize.apply(this, arguments);
        }
       
        Lightmask.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
        Lightmask.prototype.constructor = Lightmask;
       
        Lightmask.prototype.initialize = function() {
            PIXI.DisplayObjectContainer.call(this);
       
            this._width = Graphics.width;
            this._height = Graphics.height;
            this._sprites = [];
            this._createBitmap();
            
        };
       
        //Updates the Lightmask for each frame.
       
        Lightmask.prototype.update = function() {
            this._updateMask();
        };
       
        //@method _createBitmaps
       
        Lightmask.prototype._createBitmap = function() {
       
            this._maskBitmap = new Bitmap(2500,1500);   // one big bitmap to fill the intire screen with black
            var canvas = this._maskBitmap.canvas;
        };
       
        /**
         * @method _updateAllSprites
         * @private
         */
        Lightmask.prototype._updateMask = function() {
       
       
                // ****** DETECT MAP CHANGES ********
                var map_id = $gameMap.mapId();
                if (map_id != oldmap) {
                        oldmap = map_id;
                       
                        if (reset_each_map == 'Yes' || reset_each_map == 'yes') {
                                // reset switches to false
                                for (var i = 0; i < $dataMap.events.length; i++) {
                                if ($dataMap.events) {
                                                for (var j = 0; j < lightarray_id.length; j++) {
                                                        if (lightarray_id[j] == lightid) {
                                                                var mapid = $gameMap.mapId();
                                                                var eventid = $dataMap.events.id;
                                                                var key = [mapid,eventid,'D'];
                                                                $gameSelfSwitches.setValue(key, false);
                                                        }
                                                }
                                        }
                                }
                            Lightarray_id = [];
                                lightarray_state = [];
                        }
                }
       
                               
                // remove old sprites
                for (var i = 0; i < this._sprites.length; i++) {          // remove all old sprites
                        this._removeSprite();
                }
                               
                // are there lightsources on this map?
                for (var i = 0; i < $dataMap.events.length; i++) {
                if ($dataMap.events) {
                    var note = $dataMap.events.note
                    var note_args = note.split(" ");
                            var note_command = note_args.shift();
                    if (note_command == "Light" || note_command == "light" || note_command == "Fire" || note_command == "fire") {
                       
                                        this._addSprite(0,0,this._maskBitmap); // yes.. then turn off the lights               
                                        break;
                                }
                        }
                }
                       
                       
                       
               
            // ****** PLAYER LIGHTGLOBE ********
       
            var canvas = this._maskBitmap.canvas;
                   var ctx = canvas.getContext("2d");
            this._maskBitmap.fillRect(0, 0, 2500, 1500, 'black');
          
                //ctx.globalCompositeOperation = 'lighten';
                ctx.globalCompositeOperation = 'lighter';
               
                var pw = $gameMap.tileWidth()
            var ph = $gameMap.tileHeight();
                var dx = $gameMap.displayX();
                var dy = $gameMap.displayY();
                var px = $gamePlayer._realX;
                var py = $gamePlayer._realY;
                var pd = $gamePlayer._direction;       
               
                var x1 = (pw/2)+( (px-dx)*pw);
                var y1 = (ph/2)+( (py-dy)*ph);
            var paralax = false;
                // paralax does something weird with coordinates.. recalc needed
                if (dx>$gamePlayer.x) {
                        var xjump = $gameMap.width() - Math.floor(dx-px);  
                        x1 = (pw/2)+(xjump*pw);
                }
                if (dy>$gamePlayer.y) {
                        var yjump = $gameMap.height() - Math.floor(dy-py);
                        y1 = (ph/2)+(yjump*ph);
                }
                if (player_radius > 0) {
                        if (playerflashlight == true) {
                                this._maskBitmap.radialgradientFillRect2(x1,y1, 20, player_radius, playercolor, 'black', pd);
                        } else {
                                if (player_radius < 100){
                                        this._maskBitmap.radialgradientFillRect(x1,y1, 0, player_radius, '#999999', 'black', playerflicker);
                                } else {        
                                        this._maskBitmap.radialgradientFillRect(x1,y1, 20, player_radius, playercolor, 'black', playerflicker);
                                }
                        }
                }
                // ********** OTHER LIGHTSOURCES **************
               
                for (var i = 0; i < $dataMap.events.length; i++) {
                if ($dataMap.events) {
                    var note = $dataMap.events.note;
                    //var eventid = $dataMap.events.id;
                    var note_args = note.split(" ");
                            var note_command = note_args.shift();
                    if (note_command == "Light" || note_command == "light" || note_command == "Fire" || note_command == "fire") {
                           
                            var objectflicker = false;
                            if (note_command == "Fire" || note_command == "fire") {
                                        objectflicker = true;
                                }
                           
                                var light_radius = note_args.shift();
                                                               
                                // light radius
                                if (light_radius >= 0) {
                                       
                                        // light color
                                        var colorvalue = note_args.shift();
                                        var isValidColor  = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(colorvalue)             
                                    if (!isValidColor) {
                                                colorvalue = '#FFFFFF'   
                                    }     
                                                 
                                    // conditional lighting
                                            var lightid = note_args.shift();
                                            var state = true;
                                             
                                        if (lightid > 0) {
                                                var state = false;
                                                    for (var j = 0; j < lightarray_id.length; j++) {
                                                                if (lightarray_id[j] == lightid) {
                                                                        idfound = true;
                                                                        state = lightarray_state[j];
                                                                        var mapid = $gameMap.mapId();
                                                                        var eventid = $dataMap.events.id;
                                                                        //Graphics.printError('test',mapid+' '+eventid);
                                                                        key = [mapid,eventid,'D'];
                                                                        if (state == true) {
                                                                                $gameSelfSwitches.setValue(key, true);
                                                                        } else {
                                                                                $gameSelfSwitches.setValue(key, false);
                                                                        }
                                                                }
                                                        }
                                                }  
                                                                                   
                                        // show light
                                    if (state == true) {
                                                                               
                                            var lpx = $dataMap.events.x;
                                            var lpy = $dataMap.events.y;
                                            var lx1 = (pw/2)+( (lpx-dx)*pw);
                                                        var ly1 = (ph/2)+( (lpy-dy)*ph);
                                                        // paralax does something weird with coordinates.. recalc needed
                                                        if (dx-10>lpx) {
                                                                var lxjump = $gameMap.width() - (dx-lpx);
                                                                lx1 = (pw/2)+(lxjump*pw);
                                                        }
                                                        if (dy-10>lpy) {
                                                                var lyjump = $gameMap.height() -(dy-lpy);
                                                                ly1 = (ph/2)+(lyjump*ph);
                                                        }

                                            this._maskBitmap.radialgradientFillRect(lx1,ly1, 0, light_radius , colorvalue, 'black', objectflicker);
                                    }
                            }
                    }
                   
                }
            }
               
                // reset drawmode to normal
            ctx.globalCompositeOperation =  'source-over';            
       
        };
       
       
        /**
         * @method _addSprite
         * @private
         */
        Lightmask.prototype._addSprite = function(x1,y1,selectedbitmap) {
               
            var sprite = new Sprite(this.viewport);
            sprite.bitmap = selectedbitmap;
            sprite.opacity = 255;
            sprite.blendMode = 2;
            sprite.x = x1;
                 sprite.y = y1;
            this._sprites.push(sprite);
            this.addChild(sprite);
            sprite.rotation = 0;
            sprite.ax = 0
            sprite.ay = 0
                 sprite.opacity = 255;
        };
       
        /**
         * @method _removeSprite
         * @private
         */
        Lightmask.prototype._removeSprite = function() {
            this.removeChild(this._sprites.pop());
        };
       
        // *******************  NORMAL LIGHT SHAPE ***********************************
        // Fill gradient circle
       
        Bitmap.prototype.radialgradientFillRect = function(x1, y1, r1, r2, color1, color2, flicker) {
            var context = this._context;
            var grad;          
                   if (flicker == true) {
                    var gradrnd = Math.floor((Math.random()*7)+1);
                          var colorrnd = Math.floor((Math.random()*10)-5);
                    var r = hexToRgb(color1).r;
                    var g = hexToRgb(color1).g;
                    var b = hexToRgb(color1).b;
                    g = g + colorrnd;
                    if (g<0) { g = 0; }
                        if (g>255) { g = 255; }
                          color1 = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
                    r2 = r2 - gradrnd;  
                  }
                  grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
            grad.addColorStop(0, color1);
            grad.addColorStop(1, color2);
            context.save();
            context.fillStyle = grad;
            context.fillRect(x1-r2, y1-r2, r2*2, r2*2);
            context.restore();
            this._setDirty();
        };
       
        // ********************************** FLASHLIGHT *************************************
        // Fill gradient Cone
       
        Bitmap.prototype.radialgradientFillRect2 = function(x1, y1, r1, r2, color1, color2, direction) {
            var context = this._context;
            var grad;       
            
            // smal dim glove around player
                   context.save();
                        
            r1 = 0;
                  r2 = 40;
                grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
                grad.addColorStop(0, '#999999');
                grad.addColorStop(1, color2);
       
                context.fillStyle = grad;
                context.fillRect(x1-r2, y1-r2, r2*2, r2*2);
            
            // flashlight
            
            //direction = 4;

                for (var cone = 0; cone < 8; cone++) {
                           r1 = cone * 2;
                          r2 = cone * 12;
                         
                          switch(direction) {
                            case 6:
                                    x1 = x1 + cone*6;
                                   break;
                                   case 4:
                                           x1 = x1 - cone*6;
                                   break;
                                   case 2:
                                           y1 = y1 + cone*6;
                                   break;
                    case 8:
                            y1 = y1 - cone*6;
                                   break;
                        }
                                           

                          grad = context.createRadialGradient(x1, y1, r1, x1, y1, r2);
                    grad.addColorStop(0, color1);
                    grad.addColorStop(1, color2);
       
                    context.fillStyle = grad;
                    context.fillRect(x1-r2, y1-r2, r2*2, r2*2);
            }
            
            context.restore();            
            
            
            this._setDirty();
        };
       
       
        function hexToRgb(hex) {
            var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
            return result ? {
                r: parseInt(result[1], 16),
                g: parseInt(result[2], 16),
                b: parseInt(result[3], 16)
            } : null;
        }
       
        //****
        // This function is overwritten from rpg_sprites.js
        //****

        Spriteset_Map.prototype.createLowerLayer = function() {
            Spriteset_Base.prototype.createLowerLayer.call(this);
            this.createParallax();
            this.createTilemap();
            this.createCharacters();
            this.createShadow();
            this.createDestination();
            this.createLightmask();
            this.createWeather();
       
        };
       


})();[/pre][/fold]

评分

参与人数 1梦石 +1 收起 理由
余烬之中 + 1 认可答案

查看全部评分

回复 1 0

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部