Cant make jump in gamemaker studio2 - game-maker-studio-2

I can't make the jump work in my game made in game maker studio 2
this project uses gravity and the game maker's language.
this is now just random words so stack overflow lets me post this question so Minecraft is a cool game :).
here is the code:
/// #description this is the create event
// You can write your code in this editor
sprite_index=Sprite1;
image_speed = 1;
image_index = 0;
step event:
/// #description Insert description here
// You can write your code in this editor
#region //gravedad
if place_free(x,y+1){
gravity =1;
}else{
gravity=0;
}
if vspeed >=20{vspeed=20}
#endregion
#region //movimiento
if keyboard_check(ord("D")){
direction=0
speed = brr;
}
else{
speed=0;
}
if keyboard_check(ord("A")){
direction=180
speed = brr;
}
if keyboard_check_pressed(vk_space) && !place_free(x,y+1){
vspeed = -broo;
}
#endregion

I think the !place_free(x,y+1) is the problem here
if keyboard_check_pressed(vk_space) && !place_free(x,y+1){
vspeed = -broo;
}
Assuming place_free checks if there's no collision, it may either be a case of setting the origin point of the player object to the bottom center, or not having a solid instance or collision mask. (as seen in the manual)
I personally prefer using place_meeting to check on collisions with a specific object, and ignore the requirements needed for place_free to work, maybe that could work better for you.

Related

Unity - Score stays on 1

Looking around in the forum. Finally, I decided to join in this big community for the support it provides!
I am creating this post because I am struggling in a 2D game that I am creating in Unity.
The game keeps scoring the number one once the play button is clicked. It increases the score once the food is collected, but the problem here is that once I click on "Play" button the score is already on "1" instead of "0".
Code in the following statement:
Scoring System
Collect C#
Thank you for your help!
You could do 2 things:
Add a Start() function in Scoring System script.
private void Start(){
// This would make sure that score is 0 from the first frame
scoreText.GetComponent<Text>().text = " " + 0;
}
2)Instead of directly running the code on trigger use tags, assign the tag of Player to your player gameObject, then add this code.
void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == "Player"){
ScoringSystem.theScore += 1;
// Destroy(collision.gameObject);
}
}

Bad relocalization after motion tracking loss

With my team we want to implement area learning for relocalization purposes in our projects.
I added this functionnality and it seems to work well. But when a drift disaster happens (motion tracking lost) and that the main camera is instantaneously projected in "the other side of the universe" the program doesn't succeed in relocalizing it : the camera is 2 meters below, or 3 meters beside than where it should be.
Is it an area description error (because it has got not enough point of interests) ?
Or I still have not understood how to use area learning ?
Thanks a lot.
P.S.:
I use the Unity SDK.
public void Update()
{
TangoPoseData pose = new TangoPoseData ();
TangoCoordinateFramePair pair;
if(poseLocalized)
{
pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION;
pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
}
else
{
pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE;
pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
}
double timestamp = VideoOverlayProvider.RenderLatestFrame(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR);
PoseProvider.GetPoseAtTime (pose, timestamp, pair);
m_status = pose.status_code;
if (pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID)
{
// it does not differ with the pair base frame
Matrix4x4 ssTd = UpdateTransform(pose);
m_uwTuc = m_uwTss * ssTd * m_dTuc;
}
}
public void OnTangoPoseAvailable(TangoPoseData pose)
{
if (pose == null)
{
return;
}
// Relocalization signal
if (pose.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION &&
pose.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE)
{
poseLocalized = true;
}
// If pose status is not valid, nothing is valid
if (!(pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID))
{
poseLocalized = false;
// Do I forget something here ?
}
}
I've regularly observed that the localization and re-localization of the Area Learning can produce x,y Pose coordinates off by a few meters.
Coordinates can be more accurate if I take more care in recording an area well before moving to a new area.
Upon re-localization the coordinate accuracy is improved if the tablet is able to observe the area using slow, consistent movements before traveling to a new area.
If I learn a new area I always return to a well known area for better accuracy as described by drift correction:
I have two Tango tablets using a Java app that is autonomously navigating an iRobot in my home. I've setup a grid test site using 1 meter tape marks to make the observations.

XNA game : calculate time between two shoots

I'm trying to make a game with the XNA library. I want a sprite to throw a fireball to hit falling asteroids. But I have a problem with pressing the concrete key: I want to throw fireballs, for example, with one second between throws.
I want to measure the time difference between creating instances. How can I do that?
UYou can use the ElapsedGameTime property of the gameTime variable passed to the Update method like this:
const float shootTimer = 1.0f;
float elapsedTime = 0f;
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
elapsedTime += gameTime.ElapsedGameTime.TotalSeconds;
if(elapsedTime >= shootTimer && /* Your logic to see if you should shoot a fireball */ )
{
// Shoot the fireball!
elapsedTime = 0f;
}
base.Update(gameTime);
}
Basically, what you are doing in the above code is setting a minimum value (seconds) that need to pass between each shot.
Then you create a variable that will store the amount of time that has passed between each shot.
In the Update method, you add the time between each Update call and then check if it is bigger than the timer, and if it is, then you shoot and reset the elapsed time.
Note: I wrote that piece of code out of the top of my mind so it may have some minor issue.
Each call to Update of your main Game class or any GameComponent receives an instance of GameTime as an argument. Its property ElapsedGameTime can be used to accumulate the passage of time.

Flixel Game Over Screen

I am new to game development but familiar with programming languages. I have started using Flixel and have a working Breakout game with score and lives.
I am just stuck on how I can create a new screen/game over screen if a player runs out of lives. I would like the process to be like following:
Check IF lives are equal to 0
Pause the game and display a new screen (probably transparent) that says 'Game Over'
When a user clicks or hits ENTER restart the level
Here is the function I currently have to update the lives:
private function loseLive(_ball:FlxObject, _bottomWall:FlxObject):void
{
// check for game over
if (lives_count == 0)
{
}
else
{
FlxG:lives_count -= 1;
lives.text = 'Lives: ' + lives_count.toString()
}
}
Here is my main game.as:
package
{
import org.flixel.*;
public class Game extends FlxGame
{
private const resolution:FlxPoint = new FlxPoint(640, 480);
private const zoom:uint = 2;
private const fps:uint = 60;
public function Game()
{
super(resolution.x / zoom, resolution.y / zoom, PlayState, zoom);
FlxG.flashFramerate = fps;
}
}
}
There are multiple ways to go about doing this...
You could use different FlxStates, like I described in the answer to your other post: Creating user UI using Flixel, although you'll have to get smart with passing the score or whatever around, or use a Registry-type setup
If you want it to actually work like you described above, with a transparent-overlay screen, you can try something like this (keep in mind, the exact details may differ for your project, I'm just trying to give you an idea):
First, make sure you have good logic for starting a level, lets say it's a function called StartLevel.
You'll want to define a flag - just a Boolean - that tracks whether or not the game is still going on or not: private var _isGameOver:Boolean; At the very end of StartLevel(), set this to false.
In your create() function for your PlayState, build a new FlxGroup which has all the things you want on your Game Over screen - some text, an image, and something that says "Press ENTER to Restart" (or whatever). Then set it to visible = false. The code for that might look something like:
grpGameOver = new FlxGroup();
grpGameOver.add(new FlxSprite(10,10).makeGraphic(FlxG.Width-20,FlxG.Height-20,0x66000000)); // just a semi-transparent black box to cover your game screen.
grpGameOver.add(new FlxText(...)); // whatever you want to add to the group...
grpGameOver.visible = false;
add(grpGameOver); // add the group to your State.
Depending on how your game is setup, you may also want to set the objects in your group's scrollFactor to 0 - if your game screen scrolls at all:
grpGameOver.setAll("scrollFactor", new FlxPoint(0,0));
In your update() function, you'll need to split it into 2 parts: one for when the game is over, and one for if the game is still going on:
if (_isGameOver)
{
if (FlxG.keys.justReleased("ENTER"))
{
grpGameOver.visible = false;
StartLevel();
}
}
else
{
... the rest of your game logic that you already have ...
}
super.update();
Keep in mind, if you have things that respond to user input anywhere else - like a player object or something, you might need to change their update() functions to check for that flag as well.
Then, the last thing you need to do is in your loseLive() logic:
if (lives_count == 0)
{
_isGameOver = true;
grpGameOver.visible = true;
}
else
...
That should do it!
I would highly recommend spending some time with different tutorials and sample projects to kind of get a better feel for Flixel in general. Photon Storm has some great material to play with (even though he's jumped over to HTML5 games)
I also want to note that if you get comfortable with the way Flixel handles updates, you can get really smart with your state's update() function and have it only call update on the grpGameOver objects, instead of having to change all your other objects updates individually. Pretty advanced stuff, but can be worth it to learn it.

ListBox is Not Automatically Expanding with Dynamic Data Adding through 'PhoneTextBox' wp7

I would like to perform something's like fb comment Layout.
and I am Using Following Code To perform this task :
// Constructor
string []content;
public MainPage()
{
InitializeComponent();
content = new string[11] { "Great stories produce the ideas which help children to know how the cleverness and wise decisions take the people out of the dangerous and most tricky situations.",
"No virtue is as noble as kindness. The stories “Prince Frog”, “Dove and the ant” and others teaches them the importance of being kind to even to the small god made creatures of this earth.",
"Honesty is a key to success and honest people are duly rewarded. These stories show honesty is a most beautiful quality to be possessed, liked and appreciated.",
"Humbleness makes us kind hearted and soft spoken- the virtues which will always be deemed and valued in the eyes of the others.",
"Realize the importance of hard work through these evergreen stories. These popular stories are the inroads to the very roots of the concept “Hard work is a road to success.",
"If you speak the truth, your children will speak too. This would help them built the trust and reputation in their society and around them.",
"Courageous child can easily cross each milestones of life with ease, then why not we too help our children to be strong for the others too to follow.",
"True Friendship is a God’s precious gift and a commitment for togetherness, and sharing and caring.",
"Understand the value of being united, to overcome any difficult situation and understand the meaning of working in a team and grow as a virtuous and a strong human being.",
"Obeying the elders will ultimately be good for you. Stories like \"Three goats and the Wolf\" can help your children understand the value of being obedient.",
"Greediness leads to destruction. It causes obsession which is more harmful. Let us know how through these great stories." };
populate_list();
}
private void populate_list()
{
for (int i = 0; i < content.Length; i++)
{
//mainlist.Items.Add(content[i]);
var maintext = new TextBlock();
maintext.Text = content[i];
maintext.TextWrapping = TextWrapping.Wrap;
StackPanel stkpanel = new StackPanel();
stkpanel.Width = 480;
stkpanel.Height = 124;
stkpanel.Children.Add(maintext);
var expander = new ExpanderView();
var phonetextbox = new PhoneTextBox();
phonetextbox.Hint = "Add a Comment";
phonetextbox.ActionIcon = new System.Windows.Media.Imaging.BitmapImage(new Uri("/search.png", UriKind.RelativeOrAbsolute));
StackPanel stkpanel_new = new StackPanel();
stkpanel_new.Width = 480;
phonetextbox.ActionIconTapped += (s, e) =>
{
if (!string.IsNullOrEmpty(phonetextbox.Text))
{
expander.Items.Add(phonetextbox.Text);
expander.IsExpanded = true;
//stkpanel_new.Height = stkpanel_new.Height + 20;
}
};
stkpanel_new.Children.Add(phonetextbox);
stkpanel_new.Children.Add(expander);
mainlist.Items.Add(stkpanel);
mainlist.Items.Add(stkpanel_new);
}
}
But i Got problem on Dynamic Comment insertion when user entered text in phonetextbox and press on its Icon the comment just added behind the listbox 2nd element (means ExpanderView will be expanded but listbox further elements are not adjusting it dynamically ).
Am i Doing Something wrong or it is a Framework limitation ?? Help .
Regards
Pardeep Sharma
for this type of dynamic height I recommend the longlistselector control, which is useful in both orientation and for main container use Grid that will set it self as per content's size because its height is by default "Auto"
Replacing you action handler by this one should fix your problem:
phonetextbox.ActionIconTapped += (s, e) =>
{
if (!string.IsNullOrEmpty(phonetextbox.Text))
{
expander.Items.Add(phonetextbox.Text);
this.Dispatcher.BeginInvoke(() => {
expander.IsExpanded = true;
});
//stkpanel_new.Height = stkpanel_new.Height + 20;
}
};
but you should really look into using mvvm. One of the big downside of your implementation (among a lot of others architectural benefit) is that you are going to lost the benefit of UI virtualisation (A ListBox don't build all the ui element of all the items just the one into view and a little more but since you are creating them all your self you lost that benefit).

Resources