mekonbekon's Forum Posts

  • PixelByPixel

    Hi there, you need to use Pick Overlapping Point, not Pick by Evaluate.

    And also your local variables should only be referencing the starting object, i.e. the object in the middle - you don't need to pick all.

  • sbz For future reference, seeing as you've already found a solution

    The first line would be using the System|Compare two values condition, and you'd fill the fields in as follows:

    First value: distance(player.X,player.Y,object.X,object.Y)

    Comparison: less than

    Second value: 4 (for example)

    Hope that makes more sense.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Make sure you're not playing the sound every tick - use a "trigger once", for example.

  • Hi Trimeister No worries

    To make NOT you invert the condition: right click on the condition and select the "invert" option; it should add a big red cross to the condition. This is very useful for lots of conditions, so bear it in mind for the future.

    For the angle you need to use the "angle" expression: select the "within angle" condition and in the angle field write "angle(enemy.X, enemy.Y, object1.X, object1.Y)". This provides you with the angle between two objects.

    If that doesn't work give us a shout.

  • FabianB

    Glad to be of help

  • The wait 2 seconds will trigger every tick as well, so after two seconds it will start trying to turn to object 2, but at the same time it's still trying every tick to turn to object 1 so it will remain facing object 1.

    I'm guessing what you would like it to do is rotate to object 1, wait 2 seconds and then rotate to object 2?

    If so, this should work:

    Add an instance variable to the enemy called "target"; set it to 1.

    Add a timer behaviour to the enemy.

    Add this code to your event sheet:

    Event: enemy| instance variable "target" = 1

    Sub-event: enemy| NOT is within angle 2 of angle(enemy.X, enemy.Y, object1.X, object1.Y): Action: enemy| rotate 2 degrees towards (object1.X,object1.Y)

    Sub-event: enemy| is within angle 2 of angle(enemy.X, enemy.Y, object1.X, object1.Y): Action: enemy | set timer "wait" to 2 seconds

    Action: enemy | set instance variable "target" = 0

    Event: Enemy| On timer "wait": set instance variable "target" = 2

    Event: enemy| instance variable "target" = 2

    Sub-event: enemy| NOT is within angle 2 of angle(enemy.X, enemy.Y, object2.X, object2.Y): Action: enemy| rotate 2 degrees towards (object2.X,object2.Y)

    Hope that helps

  • Do you mean each enemy has it's own health bar, for example over its own head?

    If so, create a sprite called "healthbar" Add the pin behaviour to it. Add an instance variable called initialWidth and set it to the starting width you want for the healthbar.

    Add it to a container with the enemy; when an enemy is created it will automatically create a healthbar object. Give the enemy "health" and "healthMax" instance variables - set both of these to the max health of the enemy.

    Add this code:

    On enemy created: Set healthbar position to (enemyX, enemyY-(enough pixels so that it appears above the enemy's head))

    Pin healthbar to enemy.

    When an enemy takes damage you want to reduce the width of the health bar, e.g.:

    If enemy collides with bullet: enemy|subtract 1 from health

    healthbar set width to healthbar.initialWidth*(enemy.health)/(enemy.healthMax)

    Because the healthbar is in a container with the enemy, only the healthbar for that enemy will be affected.

  • Building on 's answer:

    Create a sprite, call it spawner.

    Add the rotate behaviour to it and give it a value

    Add the timer behaviour.

    Add an instance variable "shoot" to the spawner and give a value for how often you want the spawner to shoot a bullet.

    Create another sprite, call it bullet. Add the bullet behaviour to it.

    Add the following code to your event sheet:

    On (choose a trigger) set timer "shoot" to spawner.shoot (continuous)

    On timer "shoot" : spawner| create bullet;

    bullet|set bullet angle of motion to spawner; (make sure you use the bullet behaviour action here)

    On (choose a trigger): stop timer "shoot".

    You can then adjust the spawner rotate speed & direction and shoot variable, and the bullet speed to vary the pattern.

    Use whatever triggers you want to start and stop the spawner.

    For some variety try adding the sine behaviour to the spawner and use the angle, vertical or horizontal settings to move the spawner. Remember to remove/stop the rotate behaviour before doing this or things might go a bit weird - or maybe that's what you're after!

  • Hard to say without seeing a capx, but I would suggest having a play around with the density, friction and elasticity; probably the last one would be best to adjust first - try setting it to 0 and see what happens.

    Also reduce the number of blocks you are using to 2 or 3 - check whether you get the same issue with a small number first, fix that and then scale up.

  • You can store array items in a json file (just rename with *.json instead of *.txt) in the following format:

    {

    "c2array":true,

    "size":[5,6,1],

    "data":

    [ [

    [0],[1],[0],[-1],[-1], [0.5]], [

    [1],[0],[1],[0],[-1], [0.5]], [

    [0],[3],[1],[3],[-1], [0.5]], [

    [1],[3],[0],[3],[-1], [0.5]], [

    [2],[3],[2],[3],[-1], [0.5]],

    ]

    }

    You can make the data items what ever you want, of course.

    You can make the array as big as you like and even turn it into a 3D array by adding extra items within the inner square brackets, just make sure to adjust the size values at the top.

    Import the file into the files folder for your project on the "Project" tab.

    Add an array object to your game (e.g. yourArrayObject)

    Add the AJAX object.

    System|On start of layout: AJAX| Request (your json).json (tag "your tag")

    AJAX | On "your tag" completed: yourArrayObject|Load from JSON string AJAX.LastData

    This will grab your json array and add it to the array object - I don't think you have to stipulate the size of your array object - it should automatically fill up from the json - but it probably doesn't hurt to set the dimensions the same.

    Hope that makes sense!

  • I've updated the code above as I'd missed out a "trigger once" in the second section.

    This should work for saving your highest score, not your most recent - it's what I'm currently using in my projects without any problems.

    Do you have a capx you can share?

  • Create two global variables: g_score, g_hiscore.

    Add the Local Storage object to your project.

    Add this code to the start of your main event sheet:

    1. System|On start of layout: LocalStorage|Check item "savehiscore" exists

    2. LocalStorage|On item "savehiscore" exists: System|Set g_hiscore to LocalStorage.ItemValue

    3. LocalStorage|On item "savehiscore" missing: System|Set item "savehiscore" to 0

    This code checks whether you've already saved a hiscore to Local Storage - if you have it loads that value into your g_hiscore global variable, if you haven't it creates the item in Local Storage and then assigns it the value of 0.

    During your game session add whatever points you are scoring to g_score.

    At the end of the game session and before you start the next session add the following code into your event sheet:

    Edit: I forgot to include a trigger once:

    1Trigger Once:

    >>System| if g_score>g_hiscore: System|Set g_hiscore to g_score; LocalStorage| set item "savehiscore" to g_hiscore

    This code checks whether g_score is greater than g_hiscore and if so updates "savehiscore" in LocalStorage.

    If you've accessed other items in LocalStorage between retrieving "savehiscore" at the start and updating it at the end you may need to retrieve it again before updating (I think? Maybe someone can confirm)

    Hope that helps!

  • You could check:

    if distance(player.X,player.Y,object.X,object.Y)<variable:

    set player position to (object.X,objectY)

    set movement to zero (i.e. stop inputs, bullet behaviour, whatever)

    variable would be whatever the maximum distance player can travel in 1 tick, to ensure you catch it (in fact I guess it could be half that distance - just have a play around with the figure).

    Distance returns the absolute value so it's direction independent.

  • RobertoFreemano

    Glad to be able to help

  • jhjconstruct

    You're welcome

    Sadly I'm uncertain how to go about exactly what you're after - it's something I really need to learn too (I've been spoiled by the convenience of bitballoon!) Hopefully somebody else on here will help us both out.