IT rekvalifikace s garancí práce. Seniorní programátoři vydělávají až 160 000 Kč/měsíc a rekvalifikace je prvním krokem. Zjisti, jak na to!
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.
Avatar
heavyblack1
Člen
Avatar
heavyblack1:4.3.2015 22:45

Ahoj,
nevíte jak na timery nevím co totiž dělám špatně

např vtéto situaci chci aby každých 1.5 sekundy pavouk ubral 5 životu
ale stane se že když se pavouk dotkne hráče na 10 sekund tak po těch 10 sekundách se ten timer konečně aktivuje
myslím že je to tím že každý steep se timer nastaví na 1.5 sekundy když se dotýkají

Alarm Event for alarm 1:

set the health relative to -5


Collision Event with object obj_hrac:

set Alarm 1 to 1.5*room_speed

zde i když nastavím jakoukoliv hodnotu vystřelí jednou a pak se hráč musí pohnout
aby se něco stalo nebo se vytvoří náboj ale stojí na místě neumím zařídit aby se náboj vytvořil před hlavní kanonu když se otočí k hráči

execute code:

//This turret detects if the player enters its line of sight


zivoty=100
los = 300;//the line of sight of the turret, 300 pixels
rspeed = 6;//rychlost otáčení turnrtu
distance_to_player = 10000;//distance between the turret and player
active = false;//turret inactive at start
can_shoot = false;//disable shooting on start
ANG = 0;//set angle between player and turret to 0 on start
//set point of interest to the right hand side
xPointOfInterest = x + 1;
yPointOfInterest = y;

Alarm Event for alarm 0:

execute code:

instance_create(x,y,obj_chrchle)

Step Event:

execute code:

/*NOTE:
In the video tutorial, I opted for the use of the distance_to_object(obj_player) function.
However, because of the rectangular sprite used for the turret, it would mean the distance was calculated
from the player to the closed sprite pixel of obj_mobCannon. This is why I have rather decided to use
a point accurate distance measure that will result in the distance being calculated from the origin
of the player to the origin of the turret.
*/
distance_to_player = sqrt(sqr(x - obj_hrac.x) + sqr(y - obj_hrac.y));//update the distance to player

//get the player's dimensions which can then be used to figure
//out the best angle to start shooting at
player_width = sprite_get_width(obj_hrac.sprite_index);
player_height = sprite_get_height(obj_hrac.sprite_index);
player_average_size = (player_width + player_height) /2;

//Check if player is within the turret's line of sight
//AND not behind an obstruction
if (distance_to_player <= los) && !collision_line(x,y,obj_hrac.x,obj_hrac.y,obj_crate,false,true)
{
    xPointOfInterest = obj_hrac.x;//update x point of interest with player's x coordinate
    yPointOfInterest = obj_hrac.y;//update y point of interest with player's y coordinate

    active = true;//become active
}
else//otherwise
{
    active = false;//deactivate
}

ANG = point_direction(x, y, obj_hrac.x, obj_hrac.y) - image_angle;

if (ANG >= 360)//if the angle ever goes over 360
{
    ANG = ANG mod 360;//minus 360 from it. 361 degrees becomes 1 degree, 400 becomes 40, etc
}

if (active == true)//if active
{
    if (ANG < (player_average_size/4) || ANG > (360 - player_average_size/4))//work out if the player is is an acceptable angle away from the turret's gun on either side of its direction
    {
        can_shoot = true;//enable shooting
    }
    else//otherwise
    {
        can_shoot = false;//continue to deactivate shooting
    }
}

pointdir = point_direction(x, y, xPointOfInterest, yPointOfInterest);//find the last known direction to the player
image_angle += sin(degtorad(pointdir - image_angle)) * rspeed;//rotate smoothly

//fire system

if (can_shoot==true)
{
    alarm[0]=0.5*room_speed
}
if zivoty <=0
{
    instance_destroy()
}

Collision Event with object obj_strela:

execute code:

zivoty -=5

Děkuji všem za pomoc.

 
Odpovědět
4.3.2015 22:45
Avatar
Neaktivní uživatel:5.3.2015 7:06

Ahoj,

předně: vkládej sem kusy zdrojáku ne log z gm. Nějak sem nepochopil popis problému.

Nevím co vlastně chceš, ale v tom kusu kódu kde ti začíná fire system si přidej za spuštění alarmu

can_shoot = 0

V tom alarmu zase přidej:

can_shoot = 1

Pokud chceš širší informace zkonkretizuj problém.

Nahoru Odpovědět
5.3.2015 7:06
Neaktivní uživatelský účet
Avatar
heavyblack1
Člen
Avatar
Odpovídá na Neaktivní uživatel
heavyblack1:5.3.2015 23:11

Nevím jak bych to víc zkonkretizovat
zde je můj projekt abys mohl vyzkoušet a přijít tak na problém
http://ulozto.cz/…-new-gmx-rar
obj_kulomet by měl střílet každou 0.5 sekundy
obj_prisera1 má přijít k hráči každych 0.5 sekundy ubrat 5 životu

jinak zbytek projektu je rozkopaný takže to zkoušej ve volné hře

 
Nahoru Odpovědět
5.3.2015 23:11
Avatar
TomBen
Tvůrce
Avatar
Odpovídá na heavyblack1
TomBen:6.3.2015 1:28

Pavouk i kulomet stejný problém. Nastavuj alarm jen když neběží.

if alarm[0]=-1 alarm[0]=0.5*room_speed;
Akceptované řešení
+20 Zkušeností
+2,50 Kč
Řešení problému
Nahoru Odpovědět
6.3.2015 1:28
Za posledních 200 miliónů let se nic zvláštního nestalo, akorát dinosauři vymřeli a opice se naučily programovat.
Avatar
Odpovídá na TomBen
Neaktivní uživatel:6.3.2015 11:39

To je to samé...

:D
Nahoru Odpovědět
6.3.2015 11:39
Neaktivní uživatelský účet
Avatar
Neaktivní uživatel:6.3.2015 11:46

Mimochodem v podmínkách ti stačí jedno rovnítko, dvě jsou c like.
Je to samozřejmě o zvyku. Osobně ale nemám s podobnými přechody na c++/# a zpět na gml problém.

Je to rychlejší :)

Nahoru Odpovědět
6.3.2015 11:46
Neaktivní uživatelský účet
Avatar
TomBen
Tvůrce
Avatar
Odpovídá na Neaktivní uživatel
TomBen:6.3.2015 17:21

Není to stejné.

Editováno 6.3.2015 17:21
Nahoru Odpovědět
6.3.2015 17:21
Za posledních 200 miliónů let se nic zvláštního nestalo, akorát dinosauři vymřeli a opice se naučily programovat.
Avatar
heavyblack1
Člen
Avatar
heavyblack1:6.3.2015 17:23

Ještě bych dodal pro lidi se stejným problémem to jsem dal do alarmu aby se náboj vytvořil před hlavní
instance_create(x + lengthdir_x(64, image_angle), y + lengthdir_y(64, image_angle), obj_turnet_bulet);

Děkuji za pomoc

Editováno 6.3.2015 17:24
 
Nahoru Odpovědět
6.3.2015 17:23
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 8 zpráv z 8.