Sunday, March 28, 2021

Edward Lance Lorilla

Edward Lance Lorilla


【GAMEMAKER】Branching Dialogue

Posted: 28 Mar 2021 02:27 AM PDT

 Information about object: obj_diag_set_up_and_splash

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

///set up array to hold data
// 1 question
// 2 answer a
// 3 answer b
// 4 answer a target [0 is none]
// 5 answer b target [0 is none]
global.diag[1,1]="Are you in a good mood?";
global.diag[1,2]="Yes, I'm in great mood.";
global.diag[1,3]="No, I'm sad.";
global.diag[1,4]=2;
global.diag[1,5]=3;

global.diag[2,1]="That's great!#Would you like#some cheese?";
global.diag[2,2]="Yyes, I love cheese.";
global.diag[2,3]="No. I'll pass.";
global.diag[2,4]=4;
global.diag[2,5]=5;

global.diag[3,1]="Too bad.#Can I sing#you a song?";
global.diag[3,2]="Yes. Sing me a#shanty song.";
global.diag[3,3]="No. I'd rather you didn't.";
global.diag[3,4]=6;
global.diag[3,5]=7;

global.diag[4,1]="Brie or stilton?";
global.diag[4,2]="Brie, please.";
global.diag[4,3]="Stilton, please.";
global.diag[4,4]=10;
global.diag[4,5]=8;

global.diag[5,1]="How about some gold?";
global.diag[5,2]="Yes, i'm after gold.";
global.diag[5,3]="No, i have enough already.";
global.diag[5,4]=11;
global.diag[5,5]=14;

global.diag[6,1]="Yo ho ho &#a bottle of rum.#Want some rum?";
global.diag[6,2]="Yes. Hmm rum.";
global.diag[6,3]="No. I don't drink.";
global.diag[6,4]=15;
global.diag[6,5]=12;

global.diag[7,1]="OK. Want to go fishing?";
global.diag[7,2]="Yes. Sounds good!";
global.diag[7,3]="No. Fishing is boring.";
global.diag[7,4]=9;
global.diag[7,5]=13;

global.diag[8,1]="Yuck! I prefer brie.##[r to restart]";
global.diag[8,2]="";
global.diag[8,3]="";
global.diag[8,4]=0;
global.diag[8,5]=0;

global.diag[9,1]="Awesome! I'll get my rod.##[r to restart]";
global.diag[9,2]="";
global.diag[9,3]="";
global.diag[9,4]=0;
global.diag[9,5]=0;

global.diag[10,1]="Great choice!##[r to restart]";
global.diag[10,2]="";
global.diag[10,3]="";
global.diag[10,4]=0;
global.diag[10,5]=0;

global.diag[11,1]="Here's 1,000 coins.##[r to restart]";
global.diag[11,2]="";
global.diag[11,3]="";
global.diag[11,4]=0;
global.diag[11,5]=0;

global.diag[12,1]="Probably for the best!##[r to restart]";
global.diag[12,2]="";
global.diag[12,3]="";
global.diag[12,4]=0;
global.diag[12,5]=0;

global.diag[13,1]="OK be boring then!##[r to restart]";
global.diag[13,2]="";
global.diag[13,3]="";
global.diag[13,4]=0;
global.diag[13,5]=0;

global.diag[14,1]="No gold! Your choice.##[r to restart]";
global.diag[14,2]="";
global.diag[14,3]="";
global.diag[14,4]=0;
global.diag[14,5]=0;

global.diag[15,1]="Don't drink too much!##[r to restart]";
global.diag[15,2]="Continue";
global.diag[15,3]="";
global.diag[15,4]=16;
global.diag[15,5]=0;

global.diag[16,1]="Maybe just have a coffee.##[r to restart]";
global.diag[16,2]="";
global.diag[16,3]="";
global.diag[16,4]=0;
global.diag[16,5]=0;




global.message=1;
global.gold=0;
room_goto(room_dialogue);
Information about object: obj_button_one
Sprite: spr_button
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Mouse Event for Left Released:
execute code:

///Example Do Something - ie choose yes to question 5
if global.message==5
{
global.gold+=1000;
}
//for every click
global.message=global.diag[global.message,4];

Draw Event:
execute code:

if global.diag[global.message,2]!=""
{
var width=string_width(global.diag[global.message,2]);
if width>50 // adjust image size if a long text option
{
var size=(250+(width-50))/250
image_xscale=size;
}
draw_self();
draw_set_font(font_message);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_set_colour(c_black);
draw_text(x,y,global.diag[global.message,2]);
}
Information about object: obj_button_two
Sprite: spr_button
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Mouse Event for Left Pressed:
execute code:

global.message=global.diag[global.message,5];
Draw Event:
execute code:

if global.diag[global.message,3]!=""
{
var width=string_width(global.diag[global.message,3]);
if width>50 // adjust image size if a long text option
{
var size=(250+(width-50))/250
image_xscale=size;
}
draw_self();
draw_set_font(font_message);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_set_colour(c_black);
draw_text(x,y,global.diag[global.message,3]);
}
Information about object: obj_show_message
Sprite: spr_message_bg
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Step Event:
execute code:

if keyboard_check_released(ord('R'))
{
game_restart();
}
Draw Event:
execute code:

draw_self();
draw_set_font(font_message_big);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_set_colour(c_black);
draw_text(x,y,global.diag[global.message,1]);
Information about object: obj_gold_hud
Sprite:
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Draw Event:
execute code:

draw_set_font(font_message_big);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_set_colour(c_black);
draw_text(room_width/2,room_height-50,"Gold: "+string(global.gold));

【VISUAL VB.NET】Check .NET Frameworks

Posted: 28 Mar 2021 01:37 AM PDT

' make sure that using Microsoft.Win32.SafeHandles; is included
Imports Microsoft.Win32.SafeHandles
' make sure that using Microsoft.Win32; is included
Imports Microsoft.Win32
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim hkNDP = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP", False)
Keys(hkNDP, "")
hkNDP.Close()
End Sub
Private Sub Keys(hk As RegistryKey, relPath As String)
If relPath <> "" Then
relPath += "/"
End If
For Each keyname As String In hk.GetSubKeyNames()
Dim key = hk.OpenSubKey(keyname, False)
Dim keySP = key.GetValue("SP")
Dim keyVersion = key.GetValue("Version")
If keyVersion IsNot Nothing Then
listBox1.Items.Add(relPath & keyname & ": Version " & keyVersion.ToString() & (If((keySP IsNot Nothing), " SP " & keySP.ToString(), "")) & (If(1.Equals(key.GetValue("Install")), " installed", "")))
End If
Keys(key, relPath & keyname)
key.Close()
Next
End Sub
End Class
view raw Form1.vb hosted with ❤ by GitHub

【FLUTTER ANDROID STUDIO and IOS】real-time object detection with bounding box using tensorflow lite

Posted: 27 Mar 2021 07:33 PM PDT

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'ui/object_detection_page.dart';
class MyApp extends HookWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: true,
title: 'MyApp',
theme: ThemeData.from(
colorScheme: const ColorScheme.light(),
),
darkTheme: ThemeData.from(
colorScheme: const ColorScheme.dark(),
),
navigatorKey: GlobalKey<NavigatorState>(),
initialRoute: ObjectDetectionPage.routeName,
routes: {
ObjectDetectionPage.routeName: (context) => ObjectDetectionPage(),
},
);
}
}
view raw app.dart hosted with ❤ by GitHub
import 'dart:math';
import '../entity/recognition.dart';
import '../../util/logger.dart';
import 'package:image/image.dart' as image_lib;
import 'package:tflite_flutter/tflite_flutter.dart';
import 'package:tflite_flutter_helper/tflite_flutter_helper.dart';
class Classifier {
Classifier({
Interpreter
interpreter
,
List
<
String
>
labels
,
}) {
loadModel(interpreter);
loadLabels(labels);
}
Interpreter _interpreter;
Interpreter get interpreter => _interpreter;
List<String> _labels;
List<String> get labels => _labels;
static const String modelFileName = 'detect.tflite';
static const String labelFileName = 'labelmap.txt';
static const int inputSize = 300;
static const double threshold = 0.6;
ImageProcessor imageProcessor;
List<List<int>> _outputShapes;
List<TfLiteType> _outputTypes;
static const int numResults = 10;
Future<void> loadModel(Interpreter interpreter) async {
try {
_interpreter = interpreter ??
await Interpreter.fromAsset(
'$modelFileName',
options: InterpreterOptions()
..threads = 4,
);
final outputTensors = _interpreter.getOutputTensors();
_outputShapes = [];
_outputTypes = [];
for (final tensor in outputTensors) {
_outputShapes.add(tensor.shape);
_outputTypes.add(tensor.type);
}
} on Exception catch (e) {
logger.warning(e.toString());
}
}
Future<void> loadLabels(List<String> labels) async {
try {
_labels = labels ?? await FileUtil.loadLabels('assets/$labelFileName');
} on Exception catch (e) {
logger.warning(e);
}
}
TensorImage getProcessedImage(TensorImage inputImage) {
final padSize = max(
inputImage.height,
inputImage.width,
);
imageProcessor ??= ImageProcessorBuilder()
.add(
ResizeWithCropOrPadOp(
padSize,
padSize,
),
)
.add(
ResizeOp(
inputSize,
inputSize,
ResizeMethod.BILINEAR,
),
)
.build();
return imageProcessor.process(inputImage);
}
List<Recognition> predict(image_lib.Image image) {
if (_interpreter == null) {
return null;
}
var inputImage = TensorImage.fromImage(image);
inputImage = getProcessedImage(inputImage);
final outputLocations = TensorBufferFloat(_outputShapes[0]);
final outputClasses = TensorBufferFloat(_outputShapes[1]);
final outputScores = TensorBufferFloat(_outputShapes[2]);
final numLocations = TensorBufferFloat(_outputShapes[3]);
final inputs = [inputImage.buffer];
final outputs = {
0: outputLocations.buffer,
1: outputClasses.buffer,
2: outputScores.buffer,
3: numLocations.buffer,
};
_interpreter.runForMultipleInputs(inputs, outputs);
final resultCount = min(numResults, numLocations.getIntValue(0));
const labelOffset = 1;
final locations = BoundingBoxUtils.convert(
tensor: outputLocations,
valueIndex: [1, 0, 3, 2],
boundingBoxAxis: 2,
boundingBoxType: BoundingBoxType.BOUNDARIES,
coordinateType: CoordinateType.RATIO,
height: inputSize,
width: inputSize,
);
final recognitions = <Recognition>[];
for (var i = 0; i < resultCount; i++) {
final score = outputScores.getDoubleValue(i);
final labelIndex = outputClasses.getIntValue(i) + labelOffset;
final label = _labels.elementAt(labelIndex);
if (score > threshold) {
final transformRect = imageProcessor.inverseTransformRect(
locations[i],
image.height,
image.width,
);
recognitions.add(
Recognition(i, label, score, transformRect),
);
}
}
return recognitions;
}
}
view raw classifier.dart hosted with ❤ by GitHub
import 'package:camera/camera.dart';import 'package:image/image.dart' as image_lib;
class ImageUtils {
static image_lib.Image convertYUV420ToImage(CameraImage cameraImage) {
final width = cameraImage.width;
final height = cameraImage.height;
final uvRowStride = cameraImage.planes[1].bytesPerRow;
final uvPixelStride = cameraImage.planes[1].bytesPerPixel;
final image = image_lib.Image(width, height);
for (var w = 0; w < width; w++) {
for (var h = 0; h < height; h++) {
final uvIndex =
uvPixelStride * (w / 2).floor() + uvRowStride * (h / 2).floor();
final index = h * width + w;
final y = cameraImage.planes[0].bytes[index];
final u = cameraImage.planes[1].bytes[uvIndex];
final v = cameraImage.planes[2].bytes[uvIndex];
image.data[index] = ImageUtils.yuv2rgb(y, u, v);
}
}
return image;
}
static int yuv2rgb(int y, int u, int v) {
var r = (y + v * 1436 / 1024 - 179).round();
var g = (y - u * 46549 / 131072 + 44 - v * 93604 / 131072 + 91).round();
var b = (y + u * 1814 / 1024 - 227).round();
r = r.clamp(0, 255).toInt();
g = g.clamp(0, 255).toInt();
b = b.clamp(0, 255).toInt();
return 0xff000000 |
((b << 16) & 0xff0000) |
((g << 8) & 0xff00) |
(r & 0xff);
}
}
import 'package:simple_logger/simple_logger.dart';
final logger = SimpleLogger()
..setLevel(
Level.FINEST,
includeCallerInfo: true,
);
view raw logger.dart hosted with ❤ by GitHub
import 'package:flutter/material.dart';
import 'app.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(
const ProviderScope(
child: MyApp(),
),
);
}
view raw main.dart hosted with ❤ by GitHub
import 'dart:io';
import 'package:camera/camera.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../entity/recognition.dart';
import '../../util/image_utils.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:image/image.dart' as image_lib;
import 'package:tflite_flutter/tflite_flutter.dart';
import 'classifier.dart';
final recognitionsProvider = StateProvider<List<Recognition>>((ref) => []);
final mlCameraProvider =
FutureProvider.autoDispose.family<MLCamera, Size>((ref, size) async {
final cameras = await
availableCameras();
final cameraController = CameraController(
cameras[0],
ResolutionPreset.low,
enableAudio: false,
);
await
cameraController.initialize();
final mlCamera = MLCamera(
ref.read,
cameraController,
size,
);return mlCamera;});
class MLCamera {
MLCamera(this._read,
this.cameraController,
this.cameraViewSize,) {
Future(() async {
classifier = Classifier();
ratio = Platform.isAndroid
? cameraViewSize.width / cameraController.value.previewSize.height
: cameraViewSize.width / cameraController.value.previewSize.width;
actualPreviewSize = Size(
cameraViewSize.width,
cameraViewSize.width * ratio,
);
await cameraController.startImageStream(onLatestImageAvailable);
});
}
final Reader _read;
final CameraController cameraController;
Size cameraViewSize;
double ratio;
Classifier classifier;
bool isPredicting = false;
Size actualPreviewSize;
Future<void> onLatestImageAvailable(CameraImage cameraImage) async {
if (classifier.interpreter == null || classifier.labels == null) {
return;
}
if (isPredicting) {
return;
}
isPredicting = true;
final isolateCamImgData = IsolateData(
cameraImage: cameraImage,
interpreterAddress: classifier.interpreter.address,
labels: classifier.labels,
);
_read(recognitionsProvider).state =
await compute(inference, isolateCamImgData);
isPredicting = false;
}
static Future<List<Recognition>> inference(
IsolateData isolateCamImgData) async {
var image = ImageUtils.convertYUV420ToImage(
isolateCamImgData.cameraImage,
);
if (Platform.isAndroid) {
image = image_lib.copyRotate(image, 90);
}
final classifier = Classifier(
interpreter: Interpreter.fromAddress(
isolateCamImgData.interpreterAddress,
),
labels: isolateCamImgData.labels,
);
return classifier.predict(image);
}
}
class IsolateData {
IsolateData({
this
.
cameraImage
,
this
.
interpreterAddress
,
this
.
labels
,
});
final CameraImage cameraImage;
final int interpreterAddress;
final List<String> labels;
}
view raw ml_camera.dart hosted with ❤ by GitHub
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import '../data/entity/recognition.dart';
import '../data/model/ml_camera.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
class ObjectDetectionPage extends HookWidget {
static String routeName = '/object_detection';
@override
Widget build(BuildContext context) {
final size = MediaQuery
.of(context)
.size;
final mlCamera = useProvider(mlCameraProvider(size));
final recognitions = useProvider(recognitionsProvider);
return Scaffold(
appBar: AppBar(
title: const Text('Object Detection'),
),
body: mlCamera.when(
data: (mlCamera) =>
Stack(
children: [
CameraView(
mlCamera.cameraController,
),
buildBoxes(
recognitions.state,
mlCamera.actualPreviewSize,
mlCamera.ratio,
),
],
),
loading: () =>
const Center(
child: CircularProgressIndicator(),
),
error: (err, stack) =>
Center(
child: Text(
err.toString(),
),
),
),
);
}
Widget buildBoxes(List<Recognition> recognitions,
Size actualPreviewSize,
double ratio,) {
if (recognitions == null || recognitions.isEmpty) {
return const SizedBox();
}
return Stack(
children: recognitions.map((result) {
return BoundingBox(
result,
actualPreviewSize,
ratio,
);
}).toList(),
);
}
}
class CameraView extends StatelessWidget {
const CameraView(this.cameraController,);
final CameraController cameraController;
@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: 0.75,
child: CameraPreview(cameraController),
);
}
}
class BoundingBox extends HookWidget {
const BoundingBox(this.result,
this.actualPreviewSize,
this.ratio,);
final Recognition result;
final Size actualPreviewSize;
final double ratio;
@override
Widget build(BuildContext context) {
final renderLocation = result.getRenderLocation(
actualPreviewSize,
ratio,
);
return Positioned(
left: renderLocation.left,
top: renderLocation.top,
width: renderLocation.width,
height: renderLocation.height,
child: Container(
width: renderLocation.width,
height: renderLocation.height,
decoration: BoxDecoration(
border: Border.all(
color: Theme
.of(context)
.accentColor,
width: 3,
),
borderRadius: const BorderRadius.all(
Radius.circular(2),
),
),
child: buildBoxLabel(result, context),
),
);
}
Align buildBoxLabel(Recognition result, BuildContext context) {
return Align(
alignment: Alignment.topLeft,
child: FittedBox(
child: ColoredBox(
color: Theme
.of(context)
.accentColor,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
result.label,
),
Text(
' ${result.score.toStringAsFixed(2)}',
),
],
),
),
),
);
}
}
import 'dart:math';
import 'package:flutter/material.dart';
class Recognition {
Recognition(this._id, this._label, this._score, [this._location]);
final int _id;
int get id => _id;
final String _label;
String get label => _label;
final double _score;
double get score => _score;
final Rect _location;
Rect get location => _location;
Rect getRenderLocation(Size actualPreviewSize, double pixelRatio) {
final ratioX = pixelRatio;
final ratioY = ratioX;
final transLeft = max(0.1, location.left * ratioX);
final transTop = max(0.1, location.top * ratioY);
final transWidth = min(
location.width * ratioX,
actualPreviewSize.width,
);
final transHeight = min(
location.height * ratioY,
actualPreviewSize.height,
);
final transformedRect =
Rect.fromLTWH(transLeft, transTop, transWidth, transHeight);
return transformedRect;
}
}

【PYTHON OPENCV】K-means clustering applied color quantization calculates the color distribution image

Posted: 27 Mar 2021 06:34 PM PDT

"""
K-means clustering algorithm applied to color quantization and calculates also the color distribution image
"""
# Import required packages:
import numpy as np
import cv2
from matplotlib import pyplot as plt
import collections
def show_img_with_matplotlib(color_img, title, pos):
"""Shows an image using matplotlib capabilities"""
# Convert BGR image to RGB
img_RGB = color_img[:, :, ::-1]
ax = plt.subplot(2, 3, pos)
plt.imshow(img_RGB)
plt.title(title)
plt.axis('off')
def color_quantization(image, k):
"""Performs color quantization using K-means clustering algorithm"""
# Transform image into 'data':
data = np.float32(image).reshape((-1, 3))
# print(data.shape)
# Define the algorithm termination criteria (the maximum number of iterations and/or the desired accuracy):
# In this case the maximum number of iterations is set to 20 and epsilon = 1.0
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 20, 1.0)
# Apply K-means clustering algorithm:
ret, label, center = cv2.kmeans(data, k, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS)
# At this point we can make the image with k colors
# Convert center to uint8:
center = np.uint8(center)
# Replace pixel values with their center value:
result = center[label.flatten()]
result = result.reshape(img.shape)
# Build the 'color_distribution' legend.
# We will use the number of pixels assigned to each center value:
counter = collections.Counter(label.flatten())
print(counter)
# Calculate the total number of pixels of the input image:
total = img.shape[0] * img.shape[1]
# Assign width and height to the color_distribution image:
desired_width = img.shape[1]
# The difference between 'desired_height' and 'desired_height_colors'
# will be the separation between the images
desired_height = 70
desired_height_colors = 50
# Initialize the color_distribution image:
color_distribution = np.ones((desired_height, desired_width, 3), dtype="uint8") * 255
# Initialize start:
start = 0
for key, value in counter.items():
# Calculate the normalized value:
value_normalized = value / total * desired_width
# Move end to the right position:
end = start + value_normalized
# Draw rectangle corresponding to the current color:
cv2.rectangle(color_distribution, (int(start), 0), (int(end), desired_height_colors), center[key].tolist(), -1)
# Update start:
start = end
return np.vstack((color_distribution, result))
# Create the dimensions of the figure and set title:
fig = plt.figure(figsize=(16, 8))
plt.suptitle("Color quantization using K-means clustering algorithm", fontsize=14, fontweight='bold')
fig.patch.set_facecolor('silver')
# Load BGR image:
img = cv2.imread('landscape_2.jpg')
# Apply color quantization:
color_3 = color_quantization(img, 3)
color_5 = color_quantization(img, 5)
color_10 = color_quantization(img, 10)
color_20 = color_quantization(img, 20)
color_40 = color_quantization(img, 40)
# Plot the images:
show_img_with_matplotlib(img, "original image", 1)
show_img_with_matplotlib(color_3, "color quantization (k = 3)", 2)
show_img_with_matplotlib(color_5, "color quantization (k = 5)", 3)
show_img_with_matplotlib(color_10, "color quantization (k = 10)", 4)
show_img_with_matplotlib(color_20, "color quantization (k = 20)", 5)
show_img_with_matplotlib(color_40, "color quantization (k = 40)", 6)
# Show the Figure:
plt.show()

【GAMEMAKER】Boss Battle

Posted: 27 Mar 2021 07:39 AM PDT

 Information about object: obj_pirate

Sprite: spr_pirate_idle
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

slot=4;
alarm[0]=global.game_speed;
alarm[1]=room_speed*5; //scatter bombs
alarm[2]=room_speed*8; //throw sword
alarm[3]=room_speed*10; //jump up
dir=choose("left","right");
Alarm Event for alarm 0:
execute code:

///drop a bomb / fruit & increase speed
global.game_speed--;
if global.game_speed<2 global.game_speed=2;
alarm[0]=global.game_speed;
drop=choose("bomb","fruit","fruit");
if drop=="bomb"
{
var bomb=instance_create(slot*64,120,obj_bomb);
bomb.direction=270;
bomb.speed=2;
//audio_play_sound(choose(snd_ar_1,snd_ar_2),1,false);
}
if drop=="fruit"
{
var fruit=instance_create(slot*64,120,obj_fruit);
fruit.direction=270;
fruit.speed=2;
//audio_play_sound(snd_bonus_coming,1,false);
}
execute code:

///reset alarm
alarm[0]=global.game_speed;
execute code:

///move
//weigh it to move away from edge
if slot==11 dir="left";
if slot==1 dir="right";
//choose next direction - wieghed to move in same direction
dir=choose("left","right",dir,dir);
if dir=="left"
{
image_xscale=-1;
slot--;

}
if dir=="right"
{
image_xscale=1;
slot++;
}
//keep in range
if slot<1 slot=1;
if slot>11 slot=11;


Alarm Event for alarm 1:
execute code:

///send bomb scatter
alarm[1]=room_speed*5;

var loop;
for (loop = 210; loop < 350; loop += 15)
{
//audio_play_sound(choose(snd_ar_3,snd_ar_4),1,false);
var bomb=instance_create(x,y,obj_scatter_bomb);
bomb.direction=loop;
bomb.speed=3;
}


Alarm Event for alarm 2:
execute code:

alarm[2]=room_speed*8; //throw sword
var sword=instance_create(x,y,obj_enemy_sword);
sword.direction=point_direction(x,y,obj_player.x,obj_player.y);
sword.speed=5;
Alarm Event for alarm 3:
execute code:

///jump up
sprite_index=spr_pirate_jump;
image_speed=0.5;
image_index=0;
alarm[3]=room_speed*10;
Step Event:
execute code:

///move to position slot
move_towards_point(64*slot,y,4);
//stop
if x==64*slot
{
dir="idle";
speed=0;
}

execute code:

///sprite control
if sprite_index==spr_pirate_jump && image_index>=15
{
sprite_index=spr_pirate_idle;
image_index=0;
image_speed=1;
}
Collision Event with object obj_player_sword:
execute code:

if sprite_index==spr_pirate_jump
{
global.enemyhp-=5;
//audio_play_sound(choose(snd_pirate_ouch_1,snd_pirate_ouch_2),1,false);
}
with (other) instance_destroy();
Information about object: obj_player_sword
Sprite: spr_sword_player
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Create Event:
execute code:

motion_set(180,1);
ang=0;//initial angle
sw=0;//for sine wave
move_angle=40;

Step Event:
execute code:

///rotate && check if outside room
sw += pi/30;//for sine wave - ie speed
angle=sin(sw) * move_angle;//for sine wave
image_angle=angle+225;

if y<0 instance_destroy();
Information about object: obj_bomb
Sprite: spr_bomb
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Step Event:
execute code:

if y>room_height instance_destroy();
Information about object: obj_player
Sprite: spr_player_left
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Create Event:
execute code:

slot=4;
idle=0;
left=1;
right=2
dir=left;
can_shoot=true;
Alarm Event for alarm 0:
execute code:

can_shoot=true;
Step Event:
execute code:

///movement && shoot
if keyboard_check_pressed(vk_left) && slot>1
{
slot--;
dir=left;
move_towards_point(64*slot,y,4);
}
if keyboard_check_pressed(vk_right) && slot<11
{
slot++;
dir=right;
move_towards_point(64*slot,y,4);
}

//keep in range
if slot<1 slot=1;
if slot>11 slot=11;

//stop
if x==64*slot
{
dir=idle;
speed=0;
}


//make a sword
if keyboard_check_pressed(vk_up) && can_shoot
{
can_shoot=false;
alarm[0]=room_speed;
var sword=instance_create(x,y,obj_player_sword);
sword.direction=90;
sword.speed=5;
}
execute code:

///animation
if dir=left sprite_index=spr_player_left;
if dir=right sprite_index=spr_player_right;
Collision Event with object obj_bomb:
execute code:

global.p1hp-=1;
//audio_play_sound(choose(snd_laugh_1,snd_laugh_2),1,false);
with(other) instance_destroy();

Collision Event with object obj_fruit:
execute code:

global.enemyhp-=1;
//audio_play_sound(snd_bonus,1,false);
with(other) instance_destroy();

Collision Event with object obj_scatter_bomb:
execute code:

global.p1hp-=1;
//audio_play_sound(choose(snd_ouch,snd_ouch_2,snd_ouch_3),1,false);
with(other) instance_destroy();
Collision Event with object obj_enemy_sword:
execute code:

global.p1hp-=5;
//audio_play_sound(snd_ouch_4,1,false);
with (other) instance_destroy();
Information about object: obj_fruit
Sprite: spr_fruit
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Create Event:
execute code:

irandom(image_number-1);
image_speed=0;
Step Event:
execute code:

if y>room_height instance_destroy();
Information about object: obj_scatter_bomb
Sprite: spr_bomb_mini
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Step Event:
execute code:

///destroy off screen
if y>room_height instance_destroy();
Information about object: obj_enemy_sword
Sprite: spr_sword_enemy
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Create Event:
execute code:

motion_set(180,1);
ang=0;//initial angle
sw=0;//for sine wave
move_angle=40;

Step Event:
execute code:

///rotate && check if outside room
sw += pi/30;//for sine wave - ie speed
angle= sin(sw) * move_angle;//for sine wave
image_angle=angle+45;

if y>room_height instance_destroy();
Information about object: obj_hud
Sprite:
Solid: false
Visible: true
Depth:
20
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Step Event:
execute code:

if global.p1hp<0
{
global.message="Enemy Wins"; // for gameover screen
room_goto(room_game_over);
}
if global.enemyhp<0
{
global.message="Player Wins"; // for gameover screen
room_goto(room_game_over);
}
Draw Event:
execute code:

draw_rectangle_colour(0, 0, room_width, room_height, c_blue, c_blue, c_white, c_white, false);
Draw GUI Event:
execute code:

///draw hp
//hp player
draw_rectangle_colour(334,10,334-(global.p1hp*2),30,c_green,c_red,c_red,c_green,false);
draw_set_colour(c_red);
draw_rectangle(334,10,334-200,30,true);
//draw enemy
draw_rectangle_colour(434,10,434+(global.enemyhp*2),30,c_red,c_green,c_green,c_red,false);
draw_set_colour(c_red);
draw_rectangle(434,10,434+200,30,true);

//draw text
draw_set_font(font_mini);
draw_set_colour(c_black);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_text(234,20,"Player HP");
draw_text(534,20,"Enemy HP");

draw_text(room_width/2,620,"Arrow Keys To Move And Fire - Shoot Enemy (when jumping)#Collect Fruit - Avoid Bombs");

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

No Physics Object

Create Event:
execute code:

///set up
global.p1hp=100;
global.enemyhp=100;
global.game_speed=150;
room_goto(room_game);

Keyboard Event for <Left> Key:
execute code:

global.p1hp-=1;
Keyboard Event for <Right> Key:
execute code:

global.p1hp+=1;
Information about object: obj_game_over
Sprite:
Solid: false
Visible: true
Depth:
0
Persistent: false
Parent:
Children:
Mask:

No Physics Object

Create Event:
execute code:

alarm[0]=room_speed*5;
Alarm Event for alarm 0:
execute code:

game_restart();
Draw Event:
execute code:

draw_text(200,200,global.message);

No comments:

Post a Comment