【Android Studio】 Activity Lifecycle

package com.example.activitylifecycle;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((TextView)findViewById(R.id.textViewState)).setText("onCreate()\n");
}
@Override
protected void onStart() {
super.onStart();
((TextView) findViewById(R.id.textViewState)).append("onStart()\n");
}

@Override
protected void onResume() {
super.onResume();
((TextView) findViewById(R.id.textViewState)).append("onResume()\n");
}


@Override
public void onPause() {
super.onPause();
((TextView) findViewById(R.id.textViewState)).append("onPause()\n");
if (isFinishing()) {
((TextView) findViewById(R.id.textViewState)).append(" ... finishing");
}
}


@Override
protected void onStop() {
super.onStop();
((TextView) findViewById(R.id.textViewState)).append("onStop()\n");
}

@Override
protected void onRestart() {
super.onRestart();
((TextView) findViewById(R.id.textViewState)).append("onRestart()\n");
}

@Override
protected void onDestroy() {
super.onDestroy();
((TextView) findViewById(R.id.textViewState)).append("onDestroy()\n");
}


}

【GameMaker】 Zelda Style Views

Information about object: obj_player
Sprite: spr_player
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Step Event:
execute code:

dx = (keyboard_check(vk_right) - keyboard_check(vk_left)) * 4
dy = (keyboard_check(vk_down) - keyboard_check(vk_up)) * 4
if !place_meeting(x+dx,y,obj_solid) x += dx
if !place_meeting(x,y+dy,obj_solid) y += dy    


Information about object: obj_room
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

view_enabled[0] = true;
view_visible[0] = true;

view_wview[0]=240;
view_hview[0]=160;
view_xport[0]=0;//set position of port
view_yport[0]=0;
view_wport[0]=240;//set size of port
view_hport[0]=160;






view_x = view_xview[0];
view_y = view_yview[0];
view_x1 = view_x;
view_y1 = view_y;
view_xspeed = 16; // x movement speed of view
view_yspeed = 8; // y movement speed of view
Step Event:
execute code:

if obj_player.x > view_x + view_wview[0] view_x += view_wview[0];
if obj_player.x < view_x view_x -= view_wview[0];
if obj_player.y > view_y + view_hview[0] view_y += view_hview[0];
if obj_player.y < view_y view_y -= view_hview[0];

if view_x1 < view_x view_x1 = min(view_x,view_x1 + view_xspeed);
if view_x1 > view_x view_x1 = max(view_x,view_x1 - view_xspeed);
if view_y1 < view_y view_y1 = min(view_y,view_y1 + view_yspeed);
if view_y1 > view_y view_y1 = max(view_y,view_y1 - view_yspeed);

view_xview[0] = view_x1;
view_yview[0] = view_y1;

【GameMaker】 Top Down Racing

Information about object: obj_wall
Sprite: spr_wall
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object

Information about object: obj_car
Sprite: spr_car
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Step Event:
execute code:


if (keyboard_check(vk_left))  {image_angle+=2;} //rotate
if (keyboard_check(vk_right))  {image_angle-=2;} 
if (keyboard_check(vk_up))  {speed+=0.5} //accelerate
if speed>5 speed=5;//cap speed
speed=speed*0.98;//add friction
direction=image_angle;//move in direction car is pointing
if place_meeting(x,y,obj_wall)
{
speed*=-1;
}
if abs(speed)<0.1 speed=0;




Information about object: obj_room
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

view_enabled[0] = true;
view_visible[0] = true;
view_wview[0]=800;
view_hview[0]=800;

view_object[0]=obj_car;//set object to follow
view_hborder[0] = view_wview[0] / 2;
view_vborder[0] = view_hview[0] / 2;

Vue.js File Upload Storage

【GameMaker】 change sprite color using color pallete

Information about object: obj_pallete
Sprite: spr_palette
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

ini_open("colours.ini");//open file
global.save = ini_read_real("colours","colour",0)
ini_close();//close ini
if(global.save  == 0){
my_colour=c_black;
}else{
my_colour = global.save;
}

Mouse Event for Left Released:
execute code:

if position_meeting(x,y,id)
{
my_colour=draw_getpixel(mouse_x,mouse_y);
global.save = my_colour
ini_open("colours.ini");//open ini
ini_write_real("colours","colour",my_colour);//write a value
ini_close();//close value

}
Draw Event:
execute code:

draw_self();
draw_set_colour(my_colour);
draw_circle(x,y,40,false);



Information about object: obj_red
Sprite: spr_red
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Step Event:
execute code:

if (keyboard_check(ord('A')))  {x-=5;} //make inst move
if (keyboard_check(ord('D')))  {x+=5;} 
if (keyboard_check(ord('W')))  {y-=5;} 
if (keyboard_check(ord('S')))  {y+=5;}
Draw Event:
execute code:


draw_self();
draw_set_colour(global.save);
draw_sprite_ext(sprite_index, sprite_index, x, y, 1, 1, 0, global.save, 1);

【GameMaker】 Top Down Football

Information about object: obj_ball
Sprite: spr_ball
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent: obj_parent
Children:
Mask:
No Physics Object
Create Event:
execute code:

motion_set(random(360),2);
Step Event:
execute code:

inst=instance_nearest(x,y,obj_player);//get id of nearest player

if (keyboard_check(ord('A')))  {inst.x-=5;} //make inst move
if (keyboard_check(ord('D')))  {inst.x+=5;} 
if (keyboard_check(ord('W')))  {inst.y-=5;} 
if (keyboard_check(ord('S')))  {inst.y+=5;}
Collision Event with object obj_border:
execute code:

hspeed*=-1;
vspeed*=-1;
Collision Event with object obj_player:
execute code:

hspeed*=-1;
vspeed*=-1;

【GAMEMAKER】 Save colour to INI

Information about object: obj_pallete
Sprite: spr_palette
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

ini_open("colours.ini");//open file
save = ini_read_real("colours","colour",0)
ini_close();//close ini
show_debug_message(save);
if(save  == 0){
my_colour=c_black;
}else{
my_colour = save;
}

Mouse Event for Left Pressed:
execute code:






if position_meeting(x,y,id)
{
 my_colour=draw_getpixel(mouse_x,mouse_y);
     ini_open("colours.ini");//open ini
    ini_write_real("colours","colour",my_colour);//write a value
    ini_close();//close value
   
}
Draw Event:
execute code:

draw_self();
draw_set_colour(my_colour);
draw_circle(x,y,40,false);

【GameMaker】 Sokoban

/// soko_move(dx, dy) script
// Attempts to move the current instance, puhsing things around as needed.

// calculate new coordinates:
var dx = argument0, nx = x + dx;
var dy = argument1, ny = y + dy;

if (place_meeting(nx, ny, obj_wall))
{
    // if there's a wall there, definitely can't move there
    return false;
}
else if (place_free(nx, ny)) 
{
    // if there's nothing there, just move there
    x = nx; y = ny;
    return true;
}
else
{
    // otherwise attempt to move every pushable object touched:
    with (obj_pushable) if (place_meeting(x - dx, y - dy, other))
    {
       // (if any object fails to move, stop trying to move them)
       if (!soko_move(dx, dy)) return false;
     
   }
    // if it's now possible to move to the position, do that
    if (place_free(nx, ny))
    {
        x = nx; y = ny;
        return true;
    }
    else return false;
}


Information about object: obj_pushable
Sprite:
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent:
Children
obj_block
obj_player
Mask:
No Physics Object

Information about object: obj_block
Sprite: spr_block
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent: obj_pushable
Children:
Mask:
No Physics Object
Begin Step Event:
execute code:

global.collisions=0;
End Step Event:
execute code:

if position_meeting(x,y,obj_hole)
{
    global.collisions++;
}


Information about object: obj_player
Sprite: spr_player
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: obj_pushable
Children:
Mask:
No Physics Object
Create Event:
execute code:

move_dx = 0;
move_dy = 0;
move_amt = 0;
global.collisions=0;//set up

Step Event:
execute code:

if (move_amt > 0)
{
    // moving towards destination
    if (soko_move(move_dx, move_dy))
    {
        move_amt -= 1;
    }
    else move_amt = 0; // if hit a wall, stop moving
}
else
{
    var spd = 4; // movement speed (grid size should divide by it w/o remainder)
    move_amt = 32 div spd; // calculate number of steps for movement
    move_dx = 0;
    move_dy = 0;
    if (keyboard_check(vk_left)) && !((position_meeting(x-18,y,obj_block) && (position_meeting(x-50,y,obj_block))))
    {
        move_dx = -spd;
    }
    else if (keyboard_check(vk_right))&& !((position_meeting(x+18,y,obj_block) && (position_meeting(x+50,y,obj_block))))
    {
        move_dx = spd;
    }
    else if (keyboard_check(vk_up)) && !((position_meeting(x,y-18,obj_block) && (position_meeting(x,y-50,obj_block))))
    {
        move_dy = -spd;
    }
    else if (keyboard_check(vk_down))&& !((position_meeting(x,y+18,obj_block) && (position_meeting(x,y+50,obj_block))))
    {
        move_dy = spd;
    }
    else move_amt = 0; // don't move if no buttons are pressed
}
End Step Event:
execute code:

if global.collisions==instance_number(obj_hole) && move_amt <= 0//check if all crates in place and stopped movi
{
    show_message("You Win");
    room_goto_next();//goto next room
    
}
Draw Event:
execute code:

draw_self();
draw_text(20,20,"Done="+string(global.collisions)+" of "+string(instance_number(obj_hole)));


Information about object: obj_wall
Sprite: spr_wall
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object


Information about object: obj_hole
Sprite: spr_hole
Solid: false
Visible: true
Depth: 3
Persistent: false
Parent:
Children:
Mask:
No Physics Object


Information about object: obj_restart
Sprite: spr_restart
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Mouse Event for Left Released:
execute code:

room_restart();


Information about object: obj_game_end
Sprite: sprite6
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Mouse Event for Left Released:
execute code:

game_restart();

【Vuejs】 idle timer

【GameMaker】Torpedo

Information about object: obj_player
Sprite: spr_player
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

motion_set(0,2);//start moving
Step Event:
execute code:

if (keyboard_check(vk_left))  {direction+=2;} //rotate left
if (keyboard_check(vk_right))  {direction-=2;} //rotate right
if (keyboard_check(vk_up))  {speed+=1;} //increasespeed
image_angle=direction;//point in direction moving
if speed>3 speed=3;//cap speed
if speed>2 speed-=0.1;//cap boost speed
Collision Event with object obj_wall:
execute code:

show_message("You Die");
game_restart();
Collision Event with object obj_target:
execute code:

show_message("You Win");
game_restart();

【GameMaker】 program a button

Information about object: obj_dynamic_button
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

message="Hello";
bg_colour=c_white;

//code below is updated in step event, here to prevent error
width=string_width(message)+50;
height=string_height(message)+50;
xpos=x-(width/2);
xpos2=x+(width/2);
ypos=y-(height/2);
ypos2=y+(height/2);
Step Event:
execute code:

if point_in_rectangle(mouse_x,mouse_y,xpos,ypos,xpos2,ypos2) && mouse_check_button(mb_left)
{
bg_colour=c_red;
}
else if point_in_rectangle(mouse_x,mouse_y,xpos,ypos,xpos2,ypos2)
{
bg_colour=c_blue;
}
else bg_colour=c_white;

width=string_width(message)+50;
height=string_height(message)+50;
xpos=x-(width/2);
xpos2=x+(width/2);
ypos=y-(height/2);
ypos2=y+(height/2);
Draw Event:
execute code:

draw_set_colour(bg_colour);
draw_rectangle(xpos,ypos,xpos2,ypos2,false);
draw_set_font(font_text);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_set_colour(c_black);
draw_text(x,y,message);

【GameMaker】Predicting the Motion of an Object using motion predict script

Information about object: obj_player_1
Sprite: spr_player_1
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

//set initial values
strength=0;
angle=0;
global.player=1;//set player to go first
Alarm Event for alarm 0:
execute code:

global.player=2;//allow next player to go
Step Event:
execute code:

if global.player==1//check if players go
{
    strength=distance_to_point(mouse_x,mouse_y)/50;//calculate strength based on distance to mouse
    angle=point_direction(x,y,mouse_x,mouse_y);//get the angle
    if mouse_check_button_released(mb_left)//do this when mouse released
    {
        bullet=instance_create(x,y,obj_bullet_1);//create a bullet and assign
        bullet.speed=strength;//set its speed
        bullet.direction=angle;//set direction
        global.player=0;//prevent shooting
        alarm[0]=room_speed*2;//start an alarm
        
    }
}
Draw Event:
execute code:

draw_self();
if global.player==1// do this if players go
{
    draw_text(x,y-40,"strength="+string(strength));
    draw_text(x,y-80,"angle="+string(angle));
    draw_line(x,y,mouse_x,mouse_y);
}

Information about object: obj_player_2
Sprite: spr_player_2
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

//set initial values
strength=0;
angle=0;

Alarm Event for alarm 0:
execute code:

global.player=1;//allow next player to go
Step Event:
execute code:

if global.player==2//check if players go
{
    strength=distance_to_point(mouse_x,mouse_y)/50;//calculate strength based on distance to mouse
    angle=point_direction(x,y,mouse_x,mouse_y);//get the angle
    if mouse_check_button_released(mb_left)//do this when mouse released
    {
        bullet=instance_create(x,y,obj_bullet_2);//create a bullet and assign
        bullet.speed=strength;//set its speed
        bullet.direction=angle;//set direction
        global.player=0;//prevent shooting
        alarm[0]=room_speed*2;//start an alarm
        
    }
}
Draw Event:
execute code:

draw_self();
if global.player==2// do this if players go
{
    draw_text(x,y-40,"strength="+string(strength));
    draw_text(x,y-80,"angle="+string(angle));
    draw_line(x,y,mouse_x,mouse_y);
}


Information about object: obj_bullet_1
Sprite: spr_bullet
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

alarm[0]=1;
gravity=0.08//apply gravity effect
points=ds_list_create();
Alarm Event for alarm 0:
execute code:

points=motion_predict(obj_bullet_1,50);
alarm[0]=room_speed/2;
Collision Event with object obj_player_2:
execute code:

show_message("player 1 wins");
game_restart();
Draw Event:
execute code:

draw_self();//draw the bullet
if !ds_list_empty(points)
{
    size=ds_list_size(points);//get size of ds_list
    for (var i = 0; i < size; i += 2)//2 steps at a time
    {
        draw_point(points[|i],points[|i+1]);//get value to draw points
    }
}


Information about object: obj_bullet_2
Sprite: spr_bullet
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

alarm[0]=1;
points=ds_list_create();
gravity=0.08//apply gravity effect
Alarm Event for alarm 0:
execute code:

points=motion_predict(obj_bullet_2,50);
alarm[0]=room_speed/2;
Step Event:
execute code:

gravity=0.08//apply gravity effect

Collision Event with object obj_player_1:
execute code:

show_message("player 1 wins");
game_restart();
Draw Event:
execute code:

draw_self();//draw the bullet
if !ds_list_empty(points)
{
    size=ds_list_size(points);//get size of ds_list
    for (var i = 0; i < size; i += 2)//2 steps at a time
    {
        draw_point(points[|i],points[|i+1]);//get value to draw points
    }
}

Information about object: obj_ground
Sprite: spr_ground
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object

【GameMaker】 Gradually rotating an object towards a target

Information about object: obj_projectile
Sprite: spr_projectile
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Step Event:
execute code:

var dir = point_direction(x, y, mouse_x, mouse_y);
var angle = angle_difference(image_angle, dir);
if abs(angle)<=25
{
image_angle -= angle;
}
Draw Event:
execute code:

draw_self();
draw_text(x-100,y,image_angle);

【GameMaker】 Distance from Object to Mouse

Information about object: obj_distance Sprite: spr_distance Solid: false Visible: true Depth: 0 Persistent: false Parent: Children: Mask: No Physics Object Create Event: execute code: //set variables: dist=0; dir=0; Step Event: execute code: dist=distance_to_point(mouse_x,mouse_y);//store distance in variable angle=point_direction(x,y,mouse_x,mouse_y);//store the angle Draw GUI Event: execute code: draw_set_alpha(0.5); draw_self(); draw_set_alpha(1); //draw variables draw_text(x,y-40,"Distance "+string(dist)); draw_text(x,y-60,"Direction "+string(angle));

【GameMaker】 Drop the Coin physics engine

Information about object: obj_wall
Sprite: spr_wall
Solid: true
Visible: true
Depth: 0
Persistent: false
Parent: obj_solid_parent
Children:
Mask:
No Physics Object


Information about object: obj_dropper
Sprite: spr_dropper
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Step Event:
execute code:

x=mouse_x;//update x position
Mouse Event for Glob Left Released:
execute code:

instance_create(x,50,obj_ball);//create a ball

Draw GUI Event:
execute code:

draw_text(50,50,"score "+string(score));//draw score


Information about object: obj_ball
Sprite: spr_ball Solid: true Visible: true Depth: 0 Persistent: false Parent: Children: Mask:
No Physics Object
Create Event:
execute code:

move_bounce_solid(true);//set to bounce on solid objects
motion_set(270,0.5);//set the ball moving down
gravity_direction = 270;//set gravity direction
gravity=1;//set gravity strength

Step Event:
execute code:

vspeed*=0.9;//reduce speed
Collision Event with object obj_solid_parent:
execute code:

move_bounce_solid(true);
var rand_direction=irandom_range(-3,3);//create slightly random direction to stop getting stuck
direction+=rand_direction;//update direction


Information about object: obj_peg
Sprite: spr_peg Solid: true Visible: true Depth: 0 Persistent: false Parent: obj_solid_parent Children: Mask:
No Physics Object
Information about object: obj_solid_parent
Sprite: Solid: false Visible: true Depth: 0 Persistent: false Parent:
Children obj_wall obj_peg
Mask:
No Physics Object
Information about object: obj_10_points
Sprite: spr_points Solid: false Visible: true Depth: 0 Persistent: false Parent: Children: Mask:
No Physics Object
Collision Event with object obj_ball:
execute code:

score+=10;
with (other) instance_destroy();


Information about object: obj_20_points
Sprite: spr_points Solid: false Visible: true Depth: 0 Persistent: false Parent: Children: Mask:
No Physics Object
Collision Event with object obj_ball:
execute code:

score+=20;
with (other) instance_destroy();


Information about object: obj_30_points
Sprite: spr_points Solid: false Visible: true Depth: 0 Persistent: false Parent: Children: Mask:
No Physics Object
Collision Event with object obj_ball:
execute code:

score+=30;
with (other) instance_destroy();


Information about object: obj_50_points
Sprite: spr_points Solid: false Visible: true Depth: 0 Persistent: false Parent: Children: Mask:
No Physics Object
Collision Event with object obj_ball:
execute code:

score+=50;
with (other) instance_destroy();

【GameMaker】 find length and width of rectangle given perimeter

Information about object: object3
Sprite:
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

global.click=0;
Step Event:
execute code:


if global.click==2
{
width=x2-x1;
height=y2-y1;
global.click++;
}
if mouse_check_button_released(mb_left) && global.click==1
{
x2=mouse_x;
y2 =mouse_y;
global.click+=1;
}
if mouse_check_button_released(mb_left) && global.click==0
{
x1=mouse_x;
y1= mouse_y;
global.click+=1;
}

Draw Event:
execute code:

if global.click==3
{
    draw_set_colour(c_white);
        draw_rectangle(x1,y1,x2,y2,false);
            draw_set_colour(c_blue);
                draw_text(10,20,"width "+string(width));
                    draw_text(10,40,"height "+string(height));
                        draw_text(10,60,"perimeter "+string(2*(width+height)));
                            draw_text(10,80,"area "+string(width*height));
                                
                            }
                            draw_text(100,100,"Click "+string(global.click));



Information about object: object4
Sprite: sprite1 Solid: false Visible: true Depth: 0 Persistent: false Parent: Children: Mask:
No Physics Object
Mouse Event for Left Released:
restart the game
execute code:

global.click = 0;

Renowned Water Expert Reynold Aquino Offers Exclusive Water Softener Discounts

Los Angeles, California - November 21, 2024 - World-renowned water expert Reynold Aquino is excited to announce exclusive discounts on prem...

Contact Form

Name

Email *

Message *