Point&Click


start:
  - play morningBGM:
  - show room: WITH PaCTransition CONTINUE
  - show deuzi: happy AT CENTER WITH FADE
  - deuzi says: Hello, welcome to (bold)the Point and Click demo!(end)
  - deuzi says normal: After this scene is over, you can click on any object in the screen.
  - deuzi says: Are you ready?
  - choice:
    - "Yes!":
      - deuzi says happy: That's great! Go ahead!
  - hide deuzi:
  - var rat: 0
  - call PointAndClick: activate

ratScene:
  - var rat: "{rat} + 1"
  - text: You touched the rat {rat} times.
  - call PointAndClick: activate

slimeSceneDay:
  - text: You touch the slime and fall asleep
  - show room_night: WITH PaCTransition
  - text: The night brings other creatures.
  - text: Each room has its own objects, you define them in the Setup.yaml file.
  - call PointAndClick: activate

batScene:
  - text: You try to touch the bat, but it flies away.
  - call PointAndClick: remove bat
  - text: You can add and remove objects from the current room.
  - call PointAndClick: add
    name: slime
    x: 500
    y: 300
    scene: slimeSceneNight
  - call PointAndClick: activate

slimeSceneNight:
  - text: You again touch the slime, and fall asleep.
  - show room: WITH PaCTransition
  - text: When you wake up, it's morning. The bat enters again throught the window.
  - call PointAndClick: add
    name: bat
    key: bat
    x: 200
    y: 50
    scene: endGame
  - call PointAndClick: activate

endGame:
  - show deuzi: happy AT CENTER WITH FADE
  - deuzi says: And that was the Point And Click plugin!
  - effect ROLLINGCREDITS:
    endGame: true
    text:
      - RenJS.V2 created by
      - lunafromthemoon
      - null
      - In collaboration with
      - RockDaFox
      - Sean S. LeBlanc
      - null
      - Powered by PhaserJS
      - null
      - null
      - Thanks for playing
      - The PointAndClick Plugin Game
      - null
      - background art and cgs by
      - konett
      - null
      - characters by
      - Shida
      - null
      - music by
      - Evan Schaeffer
      - null
      - monsters by
      - Red Chan

									


backgrounds:
  room: assets/backgrounds/room_day.jpg
  room_night: assets/backgrounds/room_night.jpg
  room_night_light: assets/backgrounds/room_night_light.jpg

characters:
  deuzi:
    displayName: Deuzilene
    speechColour: "#ca90cf"
    looks:
      normal: assets/characters/Char3NormalSchool.png
      happy: assets/characters/Char3HappySchool.png
      angry: assets/characters/Char3AngrySchool.png

music:
  rollingCredits: assets/audio/Evan_Schaeffer_-_01_-_Aqueduct.mp3
  morningBGM: assets/audio/Evan_Schaeffer_-_03_-_Glow.mp3

pointAndClick:
  room:
    rat: rat 50 300 ratScene
    slime: slime 500 300 slimeSceneDay
  room_night:
    bat: bat 200 50 batScene

extra:
  spritesheets:
    bat: assets/objects/bat.png 400 238
    rat: assets/objects/rat.png 250 210
    slime: assets/objects/slime.png 250 187

								


class PointAndClick extends RenJS.Plugin {

	config = null;
	infoPaC = null;

	onStart() {
		this.config = this.game.setup.pointAndClick;
		// create new point and click added and removed data
		this.infoPaC = {removed:{},added:{}}
		this.game.managers.logic.vars.pointAndClick = this.infoPaC;
	}

	onLoad(slot,data) { 
		// load point and click data from saved variables
		this.infoPaC = data.vars.pointAndClick;
	}

	onInit(){
		// Add new point and click transition
		this.game.screenEffects.transition['PaCTransition'] = (from, to, position, scaleX) => {
			// Transitioning from one background to another
			// Add objects to the background before showing it
			let room = to.name;
			if (this.config[room]){
				for (const obj in this.config[room]){
					// Objects in initial configuration
					if(this.infoPaC.removed[room] && this.infoPaC.removed[room][obj]){
						// object was removed, don't add it
						continue;
					}

					const attr = this.config[room][obj].split(" ");
					let newObj = {
						name:obj,
						key:attr[0],
						x: parseInt(attr[1])-to.width/2,
						y: parseInt(attr[2])-to.height/2,
						scene: attr[3]
					}
					this.createObject(to,newObj)
				}
			}
			
			// Objects added during runtime
			if (this.infoPaC.added[room]){
				for (const obj in this.infoPaC.added[room]){
					this.createObject(to,this.infoPaC.added[room][obj]);
				}
			}
			
			// enable input globally just in case
			this.game.input.enabled = true;
			// FADE TO BLACK to the new background
			return this.game.screenEffects.transition.FADETOBLACK(from, to, position, scaleX);
		}
	}

	createObject(room,obj, transition){
		// Create object in room
		if (!room.pointAndClick){
			room.pointAndClick = {
				map:{}, 
				group:this.game.add.group()
			}
			room.addChild(room.pointAndClick.group);
		}
		const btn = this.game.add.button(obj.x,obj.y,obj.key,async () => {
			if(!this.game.managers.story.interpreting){
				// remove objects input so they won't interrupt the scene
				// Call activate after each scene
				room.pointAndClick.group.ignoreChildInput = true;
				// prevent scene interruption
				await this.game.managers.story.startScene(obj.scene);
	        	this.game.resolveAction();
			}
	        
	    },this.game,1,0,1,0,room.pointAndClick.group);
		room.pointAndClick.map[obj.name] = btn;
		if (transition){
			btn.alpha=0;
			this.game.screenEffects.transition.FADEIN(btn);
		} else {
			// Objects are added but not clickable until activated explicitly in the story
			room.pointAndClick.group.ignoreChildInput = true;
		}
	}

	onCall(params) {
		// called during runtime to activate, add or remove objects
		const action = params.body.split(" ")[0];
		const obj = params.body.split(" ")[1];
		const infoPaC = this.game.managers.logic.vars.pointAndClick;
		const room = this.game.managers.background.current;
		if (params.body == 'activate'){
			// make objects clickable
			room.pointAndClick.group.ignoreChildInput = false;
			this.game.resolveAction();
			return
		}
		if (action=="remove"){
			if (obj in room.pointAndClick.map){
				this.game.screenEffects.transition.FADEOUT(room.pointAndClick.map[obj]).then(()=>{
					if (!infoPaC.removed[room.name]){
						infoPaC.removed[room.name]={};
					}
					infoPaC.removed[room.name][obj]=true;
					// if it was previously added, remove it from there too
					if (infoPaC.added[room.name] && infoPaC.added[room.name][obj]){
						delete infoPaC.added[room.name][obj];
					}
					room.pointAndClick.map[obj].destroy();
					this.game.resolveAction();
					
				})
				return;
			}
		}
		if (action=="add"){
			if (!infoPaC.added[room.name]){
				infoPaC.added[room.name]={};
			}
			infoPaC.added[room.name][obj]={
				name:params.name,
				key:params.key ? params.key : params.name,
				x:params.x-room.width/2,
				y:params.y-room.height/2,
				scene:params.scene
			}
			// if it was previously deleted
			if (infoPaC.removed[room.name] && infoPaC.removed[room.name][obj]){
				delete infoPaC.removed[room.name][obj];
			}
			this.createObject(room,infoPaC.added[room.name][obj],"FADE");
			this.game.resolveAction();
			return;
		}
		this.game.resolveAction();
	}
}

RenJSGame.addPlugin('PointAndClick',PointAndClick)



								

Return to the Gallery Download from Github