How to make player restrict of boundries only left right not up and down in phaser js game? - phaser-framework

How to make player restrict of boundries only left right not up and down in phaser js game?

You can set the custom world bounds, with the function this.physics.world.setBounds(...).
Here a link to the documentation.
So, you just would have to put this line, into your code:
`this.physics.world.setBounds(0, 0, widthOfTheGame, heightOfTheGame, true, true, false, true);`.
in the create function.
following the documenttation setBounds(x, y, width, height [, checkLeft] [, checkRight] [, checkUp] [, checkDown])
The third false is for the world-bounds-top, and so no colliding should occure.

Related

Generate all possible alternative strings based on a dictionary node.js

I'm not a coder and I'm trying to get a freelancer to understand my needs. So this question may be simple.
I have a list of automotive parts and would like to generate their alternative descriptions based on a predefined list.
ie.
"LH FENDER" is in my DB
I want to generate alternative descriptions by the following list.
"LHF","LEFT HAND FRONT","LH","LEFT HAND","PINK"
RESULT:
LH FENDER
LHF FENDER
LEFT HAND FRONT FENDER
LEFT HAND FENDER
PINK FENDER
There is 500,000 different items in my DB that may or may not contain words that need to be substituted.
Also please note that the replacement must be of whole words within the description.
It's quite easily doable I think. For example:
const data = "LH FENDER";
const replacements = [
"LHF", "LEFT HAND FRONT", "LH", "LEFT HAND", "PINK"
];
const to_replace = data.split(" ").find(w => replacements.includes(w));
const result = replacements.map(r => data.replace(to_replace, r));
console.log(result);

Select or Highlight all instances of a word type or color in Sublime Text 4

Note: I am not trying to select all instances of a single word.
I can not find a way to select all instances of a word type, similarly how different words are colored according to the format rules from the file type you have.
Here is an image of some sample code of a SQL file.
For example, I would like to Highlight all instances of this reddish pink color, or the baby blue colored words in the whole file. So that way I can capitalize them or copy them or what have you.
From the Tools menu -> Developer -> New Plugin...
Replace the template with the following:
import sublime
import sublime_plugin
class SelectByScopeSelectorCommand(sublime_plugin.TextCommand):
def run(self, edit, scope_selector=None, last_scope_only=True, auto_select=False):
if not scope_selector:
scope_at_first_caret = self.view.scope_name(self.view.sel()[0].a)
if last_scope_only:
scope_at_first_caret = scope_at_first_caret.split()[-1]
if auto_select:
scope_selector = scope_at_first_caret
else:
self.view.window().show_input_panel('Scope Selector', scope_at_first_caret, lambda value: self.view.run_command('select_by_scope_selector', { 'scope_selector': value }), None, None)
return
regions = self.view.find_by_selector(scope_selector)
if regions:
self.view.sel().clear()
self.view.sel().add_all(regions)
self.view.show_at_center(self.view.sel()[0])
else:
self.view.window().status_message('Unable to find anything matching selector "' + scope_selector + '"')
Save it, in the folder ST recommends, as something like select_by_selector.py (the filename doesn't matter too much, but the extension is important).
Then, in your User keybindings, you can add something like:
{ "keys": ["alt+;"], "command": "select_by_scope_selector", "args": { "last_scope_only": true, "auto_select": true } },
Then, pressing Alt+; with the selection caret somewhere in SELECT, it will automatically select all other words in the buffer with the same scope, like DELETE, UPDATE, INSERT etc. Or on INT, it could select all INT, CHAR etc.
You may notice that the "types" you referred to in your question are called scopes in ST parlance. Note that colors don't necessarily have a one to one mapping with scopes depending on your color scheme, so it may select more or less than you expect it to.
You can play around with the keybinding, by removing all arguments for example, to see what effect it has and customize which scopes are being searched for. You can also add it to a menu or the command palette, if that is more to your liking. I suggest to read the ST docs for more info.

Why Text cursor coordinates are not updated correctly?

To create a simple line-column counter for my text editor, I decided to simply use the index function of the tkinter.Text widget. In fact, the index function returns a string representing the line and column of the coordinates passed as argument to it.
Specifically, I am using cursor_pos = text.index(tkinter.INSERT) to get the index of the cursor, since, from the effbot website on tkinter.INSERT:
tkinter.INSERT corresponds to the insertion cursor.
The problem is that tkinter.INSERT seems to give me the last cursor position until I move the cursor with the arrows (for example).
This is the function that handles the count of the lines and columns:
def on_key_pressed(self, event=None):
"""Docs """
if self.tpane is not None:
print(self.lines, self.columns)
self.tpane.update()
cursor_pos = self.tpane._tabs[self.tpane.selected()].text.index(tkinter.INSERT)
self.lines = int(cursor_pos.split('.')[0])
self.columns = int(cursor_pos.split('.')[1])
print(self.lines, self.columns)
self.line_c.config(text='Lines: ' + str(self.lines))
self.col_c.config(text='Columns: ' + str(self.columns))
self.update()
I don't know if you can understand the situation... When I first type a letter on the editor, the self.columns variable does not update to 1 (remains 0) until I write the second letter, where it updates to 1, and so on. But there's a trick to make it update without writing a new letter. Once written the first letter, if I move the cursor with the arrows, it updates the self.columns to actually 1.
Another problem is when I try to delete a existent character. For example, if I have 3 characters (and suppose I have self.columns to 3), and I press delete, self.columns update inexplicably to 4, and if I try to remove another character, at this point, it updates to 3.
This problems exists also for the self.lines in the on_key_pressed event handler. I am not sure if this is supposed to happen, and if yes, then I am missing something...
This happens because your custom binding fire before the built-in bindings, and it is the built-in bindings that actually modify the widget and change the cursor position.
You can change the order by leveraging bindtags. For more information see this question: Basic query regarding bindtags in tkinter
For an example of how to change the bindtags, see this answer: https://stackoverflow.com/a/3513906/7432
If you don't want to deal with bindtags, you can bind to <KeyRelease>. Built-in bindings happen on a key press, so the release binding will always fire after the widget has been updated.

Last vertex in vertex buffer not being set

I'm attempting to render a sphere in Direct11 using SharpDX. I have correctly read in the OBJ model, created the vertex buffers, and set the buffers on the context for rendering.
My problem is that everything rendering perfectly EXCEPT the very last vertex, which is rendered as if it were at 0, 0, 0. Below is a screen shot of this:
I have checked the vectors that get used when creating the buffers and there is no missing data in there, I even changed the last element in the array like this:
vertexBufferArray[vertexBufferArray.Length - 1].X = 1.0f;
and had no result. Whereas if I change the second to last element like this:
vertexBufferArray[vertexBufferArray.Length - 2].X = 1.0f;
I get this result:
The vertex count that I am passing to the render call is correct because if I pass it VertexCount - 1, I don't get the last triangle at all, and if I pass it VertexCount + 100, nothing changes at all.
Any ideas?
As usual I end up fixing the problem 10 mins after I make a big post about it.
The problem was my Input Assembler, my input elements for POSITION and NORMAL were of Format.R32G32B32A32_Float, when they should have been Format.R32G32B32_Float since I was giving my vertices in as Vector3s.

How do I get NERDCommenter to add comments in a particular column?

NERDCommenter works like this by default:
//level1
//level2
//level3
How do I get to work like this?
//level1
// level2
// level3
From the documentation:
[count]<leader>cl
[count]<leader>cb |NERDComAlignedComment|
Same as |NERDComComment| except that the delimiters are aligned down
the left side (cl) or both sides (cb).
It is possible to change the default behaviour of ToggleComment (<leader>c<space>) to use left alignment. However this means changing two lines in $vimfiles/bundle/nerdcommenter/plugin/NERDCommenter.vim (assuming the usual pathogen setup for managing plugins).
Find the definition of function function s:CommentLinesToggle. As the first line add the following to determine the correct indentation index:
let leftAlignIndx = s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine).
You can now use this index for setting the comment alignment. For this change the line:
let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine) to
let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, leftAlignIndx).
Done. Toggling comments now gives you:
for i in range(10):
#if i / 2 == 0:
# print "Ciao"
print "finito"

Resources