From 148ea2197b050e6353d62dc2ed7c706d16942826 Mon Sep 17 00:00:00 2001 From: rick Date: Sat, 5 Dec 2020 17:19:25 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20fonction=20check=20rectangle=20et=20d?= =?UTF-8?q?=C3=A9tection=20d'un=20ennemi=20lors=20de=20l'attaque?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- objects/oPlayer/KeyPress_74.gml | 22 +++++++++++++++++++--- objects/oPlayer/oPlayer.yy | 1 + scripts/Script1/Script1.gml | 22 +++++++++++++++++++--- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/objects/oPlayer/KeyPress_74.gml b/objects/oPlayer/KeyPress_74.gml index d4ab0e8..a04445e 100644 --- a/objects/oPlayer/KeyPress_74.gml +++ b/objects/oPlayer/KeyPress_74.gml @@ -7,24 +7,40 @@ switch (image_index) { case 0: inst = collision_rectangle(x+5, y+tailleEpee, x-5, y+tailleEpee, oMonster, true, oPlayer); + //inst = getCollisionArea(x-5, y+tailleEpee, x+5, y+tailleEpee, oMonster); break; case 1: inst = collision_rectangle(x+tailleEpee, y+5, x+tailleEpee, y-5, oMonster, true, oPlayer); + //inst = getCollisionArea(x+tailleEpee, y+5, x+tailleEpee, y-5, oMonster) break; case 2: inst = collision_rectangle(x+5, y-tailleEpee, x-5, y-tailleEpee, oMonster, true, oPlayer); + //inst = getCollisionArea(x+5, y-tailleEpee, x-5, y-tailleEpee, oMonster) break; case 3: inst = collision_rectangle(x-tailleEpee, y+5, x-tailleEpee, y-5, oMonster, true, oPlayer); + //inst = getCollisionArea(x-tailleEpee, y+5, x-tailleEpee, y-5, oMonster); break; default: inst = noone; } if (inst != noone) { - show_debug_message("objet trouvé !"); - // attaque + show_debug_message("objet trouvé !"); + // attaque } else { //a supp show_debug_message("pas d'objet..."); - } \ No newline at end of file + } + + /* + if (inst != noone && !ds_list_empty(inst)) { + show_debug_message("objet trouvé !"); + show_debug_message(inst); + with (inst) instance_destroy(); + // attaque + } else { + //a supp + show_debug_message("pas d'objet..."); + } + */ \ No newline at end of file diff --git a/objects/oPlayer/oPlayer.yy b/objects/oPlayer/oPlayer.yy index 788e135..aef0b23 100644 --- a/objects/oPlayer/oPlayer.yy +++ b/objects/oPlayer/oPlayer.yy @@ -24,6 +24,7 @@ {"isDnD":false,"eventNum":0,"eventType":3,"collisionObjectId":null,"parent":{"name":"oPlayer","path":"objects/oPlayer/oPlayer.yy",},"resourceVersion":"1.0","name":"","tags":[],"resourceType":"GMEvent",}, {"isDnD":false,"eventNum":0,"eventType":0,"collisionObjectId":null,"parent":{"name":"oPlayer","path":"objects/oPlayer/oPlayer.yy",},"resourceVersion":"1.0","name":"","tags":[],"resourceType":"GMEvent",}, {"isDnD":false,"eventNum":74,"eventType":9,"collisionObjectId":null,"parent":{"name":"oPlayer","path":"objects/oPlayer/oPlayer.yy",},"resourceVersion":"1.0","name":"","tags":[],"resourceType":"GMEvent",}, + {"isDnD":false,"eventNum":0,"eventType":4,"collisionObjectId":{"name":"oMonster","path":"objects/oMonster/oMonster.yy",},"parent":{"name":"oPlayer","path":"objects/oPlayer/oPlayer.yy",},"resourceVersion":"1.0","name":"","tags":[],"resourceType":"GMEvent",}, ], "properties": [ {"varType":1,"value":"0","rangeEnabled":false,"rangeMin":0.0,"rangeMax":10.0,"listItems":[],"multiselect":false,"filters":[],"resourceVersion":"1.0","name":"deplaceHorizontal","tags":[],"resourceType":"GMObjectProperty",}, diff --git a/scripts/Script1/Script1.gml b/scripts/Script1/Script1.gml index 907c494..043fdb7 100644 --- a/scripts/Script1/Script1.gml +++ b/scripts/Script1/Script1.gml @@ -1,7 +1,23 @@ // Script assets have changed for v2.3.0 see // https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information -function Test(){ - // C'est un test de git - //retest git +/* +@description Récupère tous les instances d'obj se trouvant dans un rectangle +@param {x1} coordonnée x gauche du rectangle +@param {y1} coordonnée y haut du rectangle +@param {x2} coordonnée x droit du rectangle +@param {y2} coordonnée y bas du rectangle +@param {obj} le type des instances à chercher +@return la liste des id des instances se trouvant dans le restangle +*/ +function getCollisionArea(x1, y1, x2, y2, obj){ + list = ds_list_create(); + + with(obj) { + if ( x >= x1 && x <= x2 && y >= y1 && y <= y2) { + ds_list_add(list, obj.id); + } + } + + return list; } \ No newline at end of file