Wednesday, April 21, 2021

Edward Lance Lorilla

Edward Lance Lorilla


【GAMEMAKER】Quest (mini map, timer)

Posted: 20 Apr 2021 08:34 AM PDT

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

///set up
enum player_state {
idle,
up,
down,
left,
right
}

dir=player_state.down;
is_moving=false;
image_speed=0.5;
Step Event:
execute code:

///keypress code
if (keyboard_check(vk_left))
{
dir=player_state.left;
is_moving=true;
}
else
if (keyboard_check(vk_right))
{
dir=player_state.right;
is_moving=true;
}
else
if (keyboard_check(vk_up))
{
dir=player_state.up;
is_moving=true;
}
else
if (keyboard_check(vk_down))
{
dir=player_state.down;
is_moving=true;
}
else
{
is_moving=false;
}
execute code:

///movement
if is_moving
{
switch (dir)
{
case player_state.up:
if !position_meeting(x,y-4,obj_wall) y -= 4;
break;

case player_state.down:
if !position_meeting(x,y+4,obj_wall) y += 4;
break;

case player_state.left:
if !position_meeting(x-4,y,obj_wall) x -= 4;
break;

case player_state.right:
if !position_meeting(x+4,y,obj_wall) x += 4;
break;
}
}
depth=-y;
execute code:

///animation
if is_moving
{
switch (dir)
{
case player_state.up:
sprite_index=spr_walk_up;
break;

case player_state.down:
sprite_index=spr_walk_down;
break;

case player_state.left:
sprite_index=spr_walk_left;
break;

case player_state.right:
sprite_index=spr_walk_right;
break;
}
}
else
{
switch (dir)
{
case player_state.up:
sprite_index=spr_idle_up;
break;

case player_state.down:
sprite_index=spr_idle_down;
break;

case player_state.left:
sprite_index=spr_idle_left;
break;

case player_state.right:
sprite_index=spr_idle_right;
break;
}

 Information about object: obj_wall

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

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

///Draw Outline
draw_set_alpha(0.2);
draw_circle(75,600,75,0);
draw_set_alpha(1);
draw_set_colour(c_green);
draw_circle(75,600,75,1);
draw_circle(75,600,10,1);

//set up variables
var d,a,radarX,radarY;
radarX = obj_player.x;
radarY = obj_player.y;

//draw the wall instance that are in range
with(obj_wall)
{
//how far
d = point_distance(radarX,radarY,x,y);
if(d <= 600) // This is the distance to check for
{
d = d/600*75;
a = point_direction(radarX,radarY,x,y)
draw_sprite(spr_map_wall, 0, 75 + lengthdir_x(d,a), 600 + lengthdir_y(d,a));
}
}

//draw the chest on the mini map
with(obj_chest)
{
//how far
d = point_distance(radarX,radarY,x,y);
//in range
if( d > 600) //for detecting long range chest instances
{
//convert range to draw
d = 75;
//angle to target
a = point_direction(radarX,radarY,x,y)
//draw relative to center of radar using simplified lengthdir function
draw_sprite(spr_map_chest, 0, 75 + lengthdir_x(d,a), 600 + lengthdir_y(d,a));
}
else if(d <= 600) // This is the standard distance to check for
{
d = d/600*75;
a = point_direction(radarX,radarY,x,y)
draw_sprite(spr_map_chest, 0, 75 + lengthdir_x(d,a), 600 + lengthdir_y(d,a));
}
}

Information about object: obj_chest
Sprite: spr_chest
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Create Event:
execute code:

///Set Up
image_speed=0;
image_index=0;
has_opened=false;
Alarm Event for alarm 0:
execute code:

instance_destroy();
Collision Event with object obj_player:
execute code:

///Open the chest, change image and set alarm
if !has_opened
{
has_opened=true;
image_index=1;
alarm[0]=room_speed*4; //to destroy
}

Information about object: obj_clock_and_level_control
Sprite: spr_clock_face
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Create Event:
execute code:

///set time and alarm
clock_time=360;
alarm[0]=room_speed;
Alarm Event for alarm 0:
execute code:

///reset alarm and change time
alarm[0]=room_speed;
clock_time--;
Step Event:
execute code:

///Check if out of time or quest completed
if clock_time==0
{
show_message("Out Of Time");
game_restart();
}
if instance_number(obj_chest)==0
{
show_message("Quest Complete");
game_end();
}
Draw Event:
execute code:

///comment to prevent default drawing

Draw GUI Event:
execute code:

draw_self();
draw_sprite_ext(spr_clock_hand,0,x,y,1,1,clock_time,0,1);


【PYTHON OPENCV】Tracking any object using dlib discriminative correlation filter tracker

Posted: 20 Apr 2021 08:17 AM PDT

 """

Tracking any object using dlib discriminative correlation filter tracker """ # Import required packages:import cv2import dlib def draw_text_info(): """Draw text information""" # We set the position to be used for drawing text and the menu info: menu_pos = (10, 20) menu_pos_2 = (10, 40) menu_pos_3 = (10, 60) info_1 = "Use left click of the mouse to select the object to track" info_2 = "Use '1' to start tracking, '2' to reset tracking and 'q' to exit" # Write text: cv2.putText(frame, info_1, menu_pos, cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255)) cv2.putText(frame, info_2, menu_pos_2, cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255)) if tracking_state: cv2.putText(frame, "tracking", menu_pos_3, cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0)) else: cv2.putText(frame, "not tracking", menu_pos_3, cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255)) # Structure to hold the coordinates of the object to track:points = [] # This is the mouse callback function:def mouse_event_handler(event, x, y, flags, param): # references to the global points variable global points # If left button is click, add the top left coordinates of the object to be tracked: if event == cv2.EVENT_LBUTTONDOWN: points = [(x, y)] # If left button is released, add the bottom right coordinates of the object to be tracked: elif event == cv2.EVENT_LBUTTONUP: points.append((x, y)) # Create the video capture to read from the webcam:capture = cv2.VideoCapture(0) # Set window name:window_name = "Object tracking using dlib correlation filter algorithm" # Create the window:cv2.namedWindow(window_name) # We bind mouse events to the created window:cv2.setMouseCallback(window_name, mouse_event_handler) # First step is to initialize the correlation tracker.tracker = dlib.correlation_tracker() # This variable will hold if we are currently tracking the object:tracking_state = Falsewhile True: # Capture frame from webcam: ret, frame = capture.read() # We draw a basic instructions to the user: draw_text_info() # We set and draw the rectangle where the object will be tracked if it has the two points: if len(points) == 2: cv2.rectangle(frame, points[0], points[1], (0, 0, 255), 3) dlib_rectangle = dlib.rectangle(points[0][0], points[0][1], points[1][0], points[1][1]) # If tracking, update tracking and get the position of the tracked object to be drawn: if tracking_state == True: # Update trackingtracker.update(frame) # Get the position of the tracked object: pos = tracker.get_position() # Draw the position: cv2.rectangle(frame, (int(pos.left()), int(pos.top())), (int(pos.right()), int(pos.bottom())), (0, 255, 0), 3) # We capture the keyboard event: key = 0xFF & cv2.waitKey(1) # Press '1' to start tracking using the selected region: if key == ord("1"): if len(points) == 2: # Start tracking: tracker.start_track(frame, dlib_rectangle) tracking_state = True points = [] # Press '2' to stop tracking. This will reset the points: if key == ord("2"): points = [] tracking_state = False # To exit, press 'q': if key == ord('q'): break # Show the resulting image: cv2.imshow(window_name, frame) # Release everything:capture.release()cv2.destroyAllWindows()

【VISUAL VB.NET】Item Box Color

Posted: 20 Apr 2021 08:13 AM PDT

Public Class Form1 Public Sub New() MyBase.New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ListBox1.DrawMode = DrawMode.OwnerDrawFixed End Sub Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged End Sub Private Sub ListBox1_QueryContinueDrag(sender As Object, e As QueryContinueDragEventArgs) Handles ListBox1.QueryContinueDrag End Sub Private Sub ListBox1_DrawItem(sender As Object, e As DrawItemEventArgs) Handles ListBox1.DrawItem e.DrawBackground() Dim g As Graphics = e.Graphics Dim color__1 As Color = Color.Blue For i As Integer = 0 To ListBox1.Items.Count - 1 g.DrawString("ListBoxItem", e.Font, New SolidBrush(color__1), New PointF(e.Bounds.X, e.Bounds.Y)) Next e.DrawFocusRectangle() End SubEnd Class

【JAVASCRIPT】Click on the pop-up window to pop up the login box

Posted: 20 Apr 2021 07:03 AM PDT

No comments:

Post a Comment